Ore generators V2 (#15)
* Fix typo in island gui * Add glow for challenges that are completed. * Enhance ore generators to generate the ore when the block is broken.
This commit is contained in:
parent
09525f0be1
commit
94b3abb0f5
|
|
@ -177,10 +177,9 @@ public class ChallengesGUI extends GUIInventory {
|
||||||
lore.add(miniMessage.deserialize("<yellow>Reward: " + StringUtil.splitMiniMessageString(
|
lore.add(miniMessage.deserialize("<yellow>Reward: " + StringUtil.splitMiniMessageString(
|
||||||
(challenge.challengeType().equals(ChallengeType.ON_PLAYER) && challengeCount != 0) ?
|
(challenge.challengeType().equals(ChallengeType.ON_PLAYER) && challengeCount != 0) ?
|
||||||
challenge.repeatRewardText() : challenge.rewardText())));
|
challenge.repeatRewardText() : challenge.rewardText())));
|
||||||
// TODO -- Add glow for challenges that are completed
|
if (challengeCount > 0) {
|
||||||
// if (challengeCount > 0 || challenge.repeatRewards() != null && !challenge.repeatRewards().isEmpty()) {
|
meta.addEnchant(Enchantment.MENDING, 1, true);
|
||||||
// meta.addEnchant(Enchantment.MENDING, 1, true);
|
}
|
||||||
// }
|
|
||||||
meta.addItemFlags(ItemFlag.values());
|
meta.addItemFlags(ItemFlag.values());
|
||||||
|
|
||||||
meta.lore(lore);
|
meta.lore(lore);
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class IslandGUI extends GUIInventory {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
new SettingsGUI(island).open(player);
|
new SettingsGUI(island).open(player);
|
||||||
}));
|
}));
|
||||||
addButton(13, createMenuButton(Material.ENCHANTED_BOOK, "Challenes", new ArrayList<>(), event -> {
|
addButton(13, createMenuButton(Material.BOOKSHELF, "Challenges", new ArrayList<>(), event -> {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
new ChallengesGUI(island).open(player);
|
new ChallengesGUI(island).open(player);
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,12 @@ public class GeneratorHandler {
|
||||||
return deepslate ? deepslateVariant(ore) : ore;
|
return deepslate ? deepslateVariant(ore) : ore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Material generateOre(Island island, Material material) {
|
||||||
|
boolean deepslate = material == Material.DEEPSLATE;
|
||||||
|
Material ore = rollGenerator(island, material == Material.STONE || material == Material.COBBLESTONE || deepslate);
|
||||||
|
return deepslate ? deepslateVariant(ore) : ore;
|
||||||
|
}
|
||||||
|
|
||||||
private Material rollGenerator(Island island, boolean cobblestone) {
|
private Material rollGenerator(Island island, boolean cobblestone) {
|
||||||
double random = Math.random() * 100;
|
double random = Math.random() * 100;
|
||||||
double checkedChance = 0;
|
double checkedChance = 0;
|
||||||
|
|
|
||||||
|
|
@ -2,70 +2,92 @@ package com.alttd.cometskyblock.listeners;
|
||||||
|
|
||||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
import com.alttd.cometskyblock.island.Island;
|
import com.alttd.cometskyblock.island.Island;
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.BlockFormEvent;
|
import org.bukkit.event.block.*;
|
||||||
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.List;
|
||||||
|
|
||||||
public class CobbestoneGeneratorListener implements Listener {
|
public class CobbestoneGeneratorListener implements Listener {
|
||||||
|
|
||||||
|
public static final @NotNull String GENERATOR_METADATA_KEY = "comet:oregenerator";
|
||||||
|
|
||||||
private final CometSkyBlockPlugin plugin;
|
private final CometSkyBlockPlugin plugin;
|
||||||
// public static Cache<Location, Long> generatorCache = CacheBuilder.newBuilder()
|
|
||||||
// .maximumSize(1000)
|
|
||||||
// .expireAfterAccess(10, TimeUnit.MINUTES)
|
|
||||||
// .build();
|
|
||||||
|
|
||||||
public CobbestoneGeneratorListener(CometSkyBlockPlugin plugin) {
|
public CobbestoneGeneratorListener(CometSkyBlockPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onBockForm(BlockFormEvent blockFormEvent) {
|
public void onBockForm(BlockFormEvent blockFormEvent) {
|
||||||
Block block = blockFormEvent.getNewState().getBlock();
|
Block block = blockFormEvent.getNewState().getBlock();
|
||||||
|
if (block.getType() == Material.OBSIDIAN)
|
||||||
|
return;
|
||||||
|
|
||||||
Island island = Island.getIsland(block.getWorld().getUID());
|
Island island = Island.getIsland(block.getWorld().getUID());
|
||||||
if (island.worldName() == null || island.worldName().isEmpty()) // Worlds not generated by us will have this as null or empty
|
if (island.worldName() == null || island.worldName().isEmpty()) // Worlds not generated by us will have this as null or empty
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Material formedMaterial = blockFormEvent.getNewState().getType();
|
BlockState blockState = blockFormEvent.getNewState();
|
||||||
boolean cobblestone;
|
blockState.setMetadata(GENERATOR_METADATA_KEY, new CometMeta());
|
||||||
switch (formedMaterial) {
|
if (blockFormEvent.getNewState().getType() == Material.COBBLESTONE && block.getLocation().getBlockY() <= 16)
|
||||||
case COBBLESTONE -> cobblestone = true;
|
blockFormEvent.getNewState().setType(Material.DEEPSLATE);
|
||||||
case BASALT -> cobblestone = false;
|
}
|
||||||
default -> {
|
|
||||||
return;
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
Block block = event.getBlock();
|
||||||
|
if(!block.hasMetadata(GENERATOR_METADATA_KEY)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Island island = Island.getIsland(block.getWorld().getUID());
|
||||||
|
Material generatedMaterial = plugin.generatorHandler().generateOre(island, block.getType());
|
||||||
|
block.setType(generatedMaterial);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onBlockDropItem(BlockDropItemEvent event) {
|
||||||
|
Block block = event.getBlock();
|
||||||
|
if(!block.hasMetadata(GENERATOR_METADATA_KEY)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// At This point we can inject bonus items
|
||||||
|
block.removeMetadata(GENERATOR_METADATA_KEY, plugin);
|
||||||
|
for (Item item : event.getItems()) {
|
||||||
|
item.setFireInvulnerableTicks(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
||||||
|
cleanPistonBlocks(event.getBlocks());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
||||||
|
cleanPistonBlocks(event.getBlocks());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cleanPistonBlocks(List<Block> blocks) {
|
||||||
|
for (Block block : blocks) {
|
||||||
|
if(block.hasMetadata(GENERATOR_METADATA_KEY)) {
|
||||||
|
block.removeMetadata(GENERATOR_METADATA_KEY, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Material generatedMaterial = plugin.generatorHandler().generateOre(island, cobblestone, blockFormEvent.getBlock().getLocation().getBlockY());
|
|
||||||
blockFormEvent.getNewState().setType(generatedMaterial);
|
|
||||||
// TODO - set to infested variants - turn them into ore when breaking them?
|
|
||||||
// if infested block -> rollgenerator -> block::breaknaturally?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @EventHandler
|
public class CometMeta extends FixedMetadataValue {
|
||||||
// public void cobblestoneGeneratorDrops(BlockBreakEvent event) {
|
|
||||||
// // TODO - multiply drops from cobble gen?
|
|
||||||
// Block block = event.getBlock();
|
|
||||||
// if (block.getType().equals(Material.COBBLESTONE)) {
|
|
||||||
// if (relativeEqualsMaterial(block, Material.LAVA)) { // any other way to detect if they are from cobble gen
|
|
||||||
// // set some data during blockform event?
|
|
||||||
// if (relativeEqualsMaterial(block, Material.WATER)) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
boolean relativeEqualsMaterial(Block block, Material material) {
|
public CometMeta() {
|
||||||
return block.getRelative(BlockFace.NORTH).getType().equals(material)
|
super(plugin, true);
|
||||||
|| block.getRelative(BlockFace.EAST).getType().equals(material)
|
}
|
||||||
|| block.getRelative(BlockFace.SOUTH).getType().equals(material)
|
|
||||||
|| block.getRelative(BlockFace.WEST).getType().equals(material);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user