From b1dba3d9999e2853d7fab246831b124a2aa86d85 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sun, 28 Jun 2020 23:20:40 -0500 Subject: [PATCH] Use ID's for paintable block registration instead of registry delegates --- src/main/java/vazkii/botania/api/BotaniaAPI.java | 8 ++++---- .../botania/common/core/handler/IMCSender.java | 14 +++++++------- .../vazkii/botania/common/impl/BotaniaAPIImpl.java | 6 +++--- .../vazkii/botania/common/item/lens/LensPaint.java | 13 ++++++++----- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/vazkii/botania/api/BotaniaAPI.java b/src/main/java/vazkii/botania/api/BotaniaAPI.java index 1344f9645..cdcdc47db 100644 --- a/src/main/java/vazkii/botania/api/BotaniaAPI.java +++ b/src/main/java/vazkii/botania/api/BotaniaAPI.java @@ -81,22 +81,22 @@ public interface BotaniaAPI { return Collections.emptyMap(); } - default Map, Function> getPaintableBlocks() { + default Map> getPaintableBlocks() { return Collections.emptyMap(); } default void registerPaintableBlock(Block block, Function transformer) { - registerPaintableBlock(block.delegate, transformer); + registerPaintableBlock(Registry.BLOCK.getKey(block), transformer); } /** * Make Botania aware of how to transform between different colors of a block, for use in the paint lens. * This method can be safely called during parallel mod initialization * - * @param block The block + * @param blockId The block ID * @param transformer Function from color to a new block */ - default void registerPaintableBlock(IRegistryDelegate block, Function transformer) { + default void registerPaintableBlock(ResourceLocation blockId, Function transformer) { } diff --git a/src/main/java/vazkii/botania/common/core/handler/IMCSender.java b/src/main/java/vazkii/botania/common/core/handler/IMCSender.java index ba06fc484..40a43350e 100644 --- a/src/main/java/vazkii/botania/common/core/handler/IMCSender.java +++ b/src/main/java/vazkii/botania/common/core/handler/IMCSender.java @@ -119,12 +119,12 @@ public class IMCSender { BotaniaAPI.instance().registerPaintableBlock(Blocks.GLASS, color -> ColorHelper.STAINED_GLASS_MAP.get(color).get()); for (IRegistryDelegate b : ColorHelper.STAINED_GLASS_MAP.values()) { - BotaniaAPI.instance().registerPaintableBlock(b, color -> ColorHelper.STAINED_GLASS_MAP.get(color).get()); + BotaniaAPI.instance().registerPaintableBlock(b.get(), color -> ColorHelper.STAINED_GLASS_MAP.get(color).get()); } BotaniaAPI.instance().registerPaintableBlock(Blocks.GLASS_PANE, color -> ColorHelper.STAINED_GLASS_PANE_MAP.get(color).get()); for (IRegistryDelegate b : ColorHelper.STAINED_GLASS_PANE_MAP.values()) { - BotaniaAPI.instance().registerPaintableBlock(b, color -> ColorHelper.STAINED_GLASS_PANE_MAP.get(color).get()); + BotaniaAPI.instance().registerPaintableBlock(b.get(), color -> ColorHelper.STAINED_GLASS_PANE_MAP.get(color).get()); } BotaniaAPI.instance().registerPaintableBlock(Blocks.TERRACOTTA, color -> ColorHelper.TERRACOTTA_MAP.get(color).get()); @@ -133,23 +133,23 @@ public class IMCSender { } for (IRegistryDelegate b : ColorHelper.GLAZED_TERRACOTTA_MAP.values()) { - BotaniaAPI.instance().registerPaintableBlock(b, color -> ColorHelper.GLAZED_TERRACOTTA_MAP.get(color).get()); + BotaniaAPI.instance().registerPaintableBlock(b.get(), color -> ColorHelper.GLAZED_TERRACOTTA_MAP.get(color).get()); } for (IRegistryDelegate b : ColorHelper.WOOL_MAP.values()) { - BotaniaAPI.instance().registerPaintableBlock(b, color -> ColorHelper.WOOL_MAP.get(color).get()); + BotaniaAPI.instance().registerPaintableBlock(b.get(), color -> ColorHelper.WOOL_MAP.get(color).get()); } for (IRegistryDelegate b : ColorHelper.CARPET_MAP.values()) { - BotaniaAPI.instance().registerPaintableBlock(b, color -> ColorHelper.CARPET_MAP.get(color).get()); + BotaniaAPI.instance().registerPaintableBlock(b.get(), color -> ColorHelper.CARPET_MAP.get(color).get()); } for (IRegistryDelegate b : ColorHelper.CONCRETE_MAP.values()) { - BotaniaAPI.instance().registerPaintableBlock(b, color -> ColorHelper.CONCRETE_MAP.get(color).get()); + BotaniaAPI.instance().registerPaintableBlock(b.get(), color -> ColorHelper.CONCRETE_MAP.get(color).get()); } for (IRegistryDelegate b : ColorHelper.CONCRETE_POWDER_MAP.values()) { - BotaniaAPI.instance().registerPaintableBlock(b, color -> ColorHelper.CONCRETE_POWDER_MAP.get(color).get()); + BotaniaAPI.instance().registerPaintableBlock(b.get(), color -> ColorHelper.CONCRETE_POWDER_MAP.get(color).get()); } } diff --git a/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java b/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java index 34334d0bc..2fe1f31c0 100644 --- a/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java +++ b/src/main/java/vazkii/botania/common/impl/BotaniaAPIImpl.java @@ -285,7 +285,7 @@ public class BotaniaAPIImpl implements BotaniaAPI { public Map oreWeights = Collections.emptyMap(); public Map netherOreWeights = Collections.emptyMap(); - private final Map, Function> paintableBlocks = new ConcurrentHashMap<>(); + private final Map> paintableBlocks = new ConcurrentHashMap<>(); @Override public Map getOreWeights() { @@ -298,12 +298,12 @@ public class BotaniaAPIImpl implements BotaniaAPI { } @Override - public Map, Function> getPaintableBlocks() { + public Map> getPaintableBlocks() { return Collections.unmodifiableMap(paintableBlocks); } @Override - public void registerPaintableBlock(IRegistryDelegate block, Function transformer) { + public void registerPaintableBlock(ResourceLocation block, Function transformer) { paintableBlocks.put(block, transformer); } } diff --git a/src/main/java/vazkii/botania/common/item/lens/LensPaint.java b/src/main/java/vazkii/botania/common/item/lens/LensPaint.java index 72f8b6b19..b8ac40a8d 100644 --- a/src/main/java/vazkii/botania/common/item/lens/LensPaint.java +++ b/src/main/java/vazkii/botania/common/item/lens/LensPaint.java @@ -15,8 +15,10 @@ import net.minecraft.entity.projectile.ThrowableEntity; import net.minecraft.item.DyeColor; import net.minecraft.item.ItemStack; import net.minecraft.util.Direction; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.*; +import net.minecraft.util.registry.Registry; import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.internal.IManaBurst; import vazkii.botania.common.network.PacketBotaniaEffect; @@ -49,8 +51,9 @@ public class LensPaint extends Lens { } else if (pos.getType() == RayTraceResult.Type.BLOCK) { BlockPos hit = ((BlockRayTraceResult) pos).getPos(); BlockState state = entity.world.getBlockState(hit); - Block block = state.getBlock(); - if (BotaniaAPI.instance().getPaintableBlocks().containsKey(block.delegate)) { + ResourceLocation blockId = Registry.BLOCK.getKey(state.getBlock()); + + if (BotaniaAPI.instance().getPaintableBlocks().containsKey(blockId)) { List coordsToPaint = new ArrayList<>(); List coordsFound = new ArrayList<>(); coordsFound.add(hit); @@ -62,8 +65,8 @@ public class LensPaint extends Lens { coordsToPaint.add(coords); for (Direction dir : Direction.values()) { - BlockState state_ = entity.world.getBlockState(coords.offset(dir)); - BlockPos coords_ = new BlockPos(coords.offset(dir)); + BlockPos coords_ = coords.offset(dir); + BlockState state_ = entity.world.getBlockState(coords_); if (state_ == state && !coordsFound.contains(coords_) && !coordsToPaint.contains(coords_)) { coordsFound.add(coords_); } @@ -75,7 +78,7 @@ public class LensPaint extends Lens { DyeColor placeColor = DyeColor.byId(storedColor == 16 ? entity.world.rand.nextInt(16) : storedColor); BlockState stateThere = entity.world.getBlockState(coords); - Function f = BotaniaAPI.instance().getPaintableBlocks().get(block.delegate); + Function f = BotaniaAPI.instance().getPaintableBlocks().get(blockId); Block newBlock = f.apply(placeColor); if (newBlock != stateThere.getBlock()) { entity.world.setBlockState(coords, newBlock.getDefaultState());