diff --git a/CHANGELOG.md b/CHANGELOG.md index ca69710df..f37e7368a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,15 +30,17 @@ #### Changes * Coolant Cells now last twice as long * Ticking blocks will now catch more errors caused by addons -* Massive performance improvements +* Massive performance improvements to GPS/GEO machines, especially Oil Pump and GEO Miner * Changed the texture for the Nuclear Reactor * Changed the texture for the Nether Star Reactor +* Performance improvements to Rainbow Blocks #### Fixes * Fixed #2005 * Fixed #2009 * Fixed a chunk caching issue for GEO resources * Fixed Infused Magnet working even if you haven't researched it +* Fixed Rainbow blocks duplication glitch when timing the block break right ## Release Candidate 13 (16 Jun 2020) https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#13 diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/TeleporterPylon.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/TeleporterPylon.java new file mode 100644 index 000000000..1d4bba69d --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/gps/TeleporterPylon.java @@ -0,0 +1,28 @@ +package io.github.thebusybiscuit.slimefun4.implementation.items.gps; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RainbowBlock; +import me.mrCookieSlime.Slimefun.Lists.RecipeType; +import me.mrCookieSlime.Slimefun.Objects.Category; +import me.mrCookieSlime.Slimefun.Objects.handlers.RainbowTicker; +import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; + +/** + * The {@link TeleporterPylon} is a special kind of {@link RainbowBlock} which is required + * for the {@link Teleporter}. + * + * @author TheBusyBiscuit + * + * @see Teleporter + * @see RainbowBlock + * @see RainbowTicker + */ +public class TeleporterPylon extends RainbowBlock { + + public TeleporterPylon(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) { + super(category, item, recipeType, recipe, recipeOutput, new RainbowTicker(Material.CYAN_STAINED_GLASS, Material.PURPLE_STAINED_GLASS)); + } + +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 7b7bf9c0a..3c3585388 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -113,6 +113,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSMarkerTool import io.github.thebusybiscuit.slimefun4.implementation.items.gps.GPSTransmitter; import io.github.thebusybiscuit.slimefun4.implementation.items.gps.PersonalActivationPlate; import io.github.thebusybiscuit.slimefun4.implementation.items.gps.Teleporter; +import io.github.thebusybiscuit.slimefun4.implementation.items.gps.TeleporterPylon; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.InfernalBonemeal; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.InfusedMagnet; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.KnowledgeFlask; @@ -2723,9 +2724,9 @@ public final class SlimefunItemSetup { }.register(plugin); - new RainbowBlock(categories.gps, SlimefunItems.GPS_TELEPORTER_PYLON, RecipeType.ENHANCED_CRAFTING_TABLE, + new TeleporterPylon(categories.gps, SlimefunItems.GPS_TELEPORTER_PYLON, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {SlimefunItems.ZINC_INGOT, new ItemStack(Material.GLASS), SlimefunItems.ZINC_INGOT, new ItemStack(Material.GLASS), SlimefunItems.HEATING_COIL, new ItemStack(Material.GLASS), SlimefunItems.ZINC_INGOT, new ItemStack(Material.GLASS), SlimefunItems.ZINC_INGOT}, - new CustomItem(SlimefunItems.GPS_TELEPORTER_PYLON, 8), new RainbowTicker(Material.CYAN_STAINED_GLASS, Material.PURPLE_STAINED_GLASS)) + new CustomItem(SlimefunItems.GPS_TELEPORTER_PYLON, 8)) .register(plugin); new Teleporter(categories.gps, SlimefunItems.GPS_TELEPORTATION_MATRIX, RecipeType.ENHANCED_CRAFTING_TABLE, diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/RainbowTicker.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/RainbowTicker.java index e7b914741..9b7aa12db 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/RainbowTicker.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/handlers/RainbowTicker.java @@ -26,28 +26,68 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; public class RainbowTicker extends BlockTicker { private final LoopIterator iterator; + private final boolean waterlogged; private Material material; public RainbowTicker(Material... materials) { + if (materials.length == 0) { + throw new IllegalArgumentException("A RainbowTicker must have at least one Material associated with it!"); + } + + waterlogged = containsWaterlogged(materials); iterator = new LoopIterator<>(Arrays.asList(materials)); material = iterator.next(); } + /** + * This method checks whether a given {@link Material} array contains any {@link Material} + * that would result in a {@link Waterlogged} {@link BlockData}. + * This is done to save performance, so we don't have to validate {@link BlockData} at + * runtime. + * + * @param materials + * The {@link Material} Array to check + * + * @return Whether the array contained any {@link Waterlogged} materials + */ + private boolean containsWaterlogged(Material[] materials) { + for (Material type : materials) { + // This BlockData is purely virtual and only created on startup, it should have + // no impact on performance, in fact it should save performance as it preloads + // the data but also saves heavy calls for non-waterlogged Materials + if (type.createBlockData() instanceof Waterlogged) { + return true; + } + } + + return false; + } + public RainbowTicker(MaterialCollection collection) { this(collection.getAsArray()); } @Override public void tick(Block b, SlimefunItem item, Config data) { - BlockData blockData = b.getBlockData(); - boolean waterlogged = blockData instanceof Waterlogged && ((Waterlogged) blockData).isWaterlogged(); - - b.setType(material, true); + if (b.getType() == Material.AIR) { + // The block was broken, setting the Material now would result in a + // duplication glitch + return; + } if (waterlogged) { - Waterlogged block = (Waterlogged) b.getBlockData(); - block.setWaterlogged(true); - b.setBlockData(block); + BlockData blockData = b.getBlockData(); + + b.setType(material, true); + + if (blockData instanceof Waterlogged && ((Waterlogged) blockData).isWaterlogged()) { + Waterlogged block = (Waterlogged) b.getBlockData(); + block.setWaterlogged(true); + b.setBlockData(block); + } + } + else { + b.setType(material, false); } }