Use ID's for paintable block registration instead of registry delegates

This commit is contained in:
Vincent Lee committed 2020-06-28 23:20:40 -05:00
1 parent 986ccfd670
commit b1dba3d999
4 files changed
+22 -19

No files matched your search

@@ -81,22 +81,22 @@ public interface BotaniaAPI {
return Collections.emptyMap();
}
default Map<IRegistryDelegate<Block>, Function<DyeColor, Block>> getPaintableBlocks() {
default Map<ResourceLocation, Function<DyeColor, Block>> getPaintableBlocks() {
return Collections.emptyMap();
}
default void registerPaintableBlock(Block block, Function<DyeColor, Block> 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> block, Function<DyeColor, Block> transformer) {
default void registerPaintableBlock(ResourceLocation blockId, Function<DyeColor, Block> transformer) {
}
@@ -119,12 +119,12 @@ public class IMCSender {
BotaniaAPI.instance().registerPaintableBlock(Blocks.GLASS, color -> ColorHelper.STAINED_GLASS_MAP.get(color).get());
for (IRegistryDelegate<Block> 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<Block> 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<Block> 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<Block> 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<Block> 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<Block> 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<Block> 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());
}
}
@@ -285,7 +285,7 @@ public class BotaniaAPIImpl implements BotaniaAPI {
public Map<ResourceLocation, Integer> oreWeights = Collections.emptyMap();
public Map<ResourceLocation, Integer> netherOreWeights = Collections.emptyMap();
private final Map<IRegistryDelegate<Block>, Function<DyeColor, Block>> paintableBlocks = new ConcurrentHashMap<>();
private final Map<ResourceLocation, Function<DyeColor, Block>> paintableBlocks = new ConcurrentHashMap<>();
@Override
public Map<ResourceLocation, Integer> getOreWeights() {
@@ -298,12 +298,12 @@ public class BotaniaAPIImpl implements BotaniaAPI {
}
@Override
public Map<IRegistryDelegate<Block>, Function<DyeColor, Block>> getPaintableBlocks() {
public Map<ResourceLocation, Function<DyeColor, Block>> getPaintableBlocks() {
return Collections.unmodifiableMap(paintableBlocks);
}
@Override
public void registerPaintableBlock(IRegistryDelegate<Block> block, Function<DyeColor, Block> transformer) {
public void registerPaintableBlock(ResourceLocation block, Function<DyeColor, Block> transformer) {
paintableBlocks.put(block, transformer);
}
}
@@ -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<BlockPos> coordsToPaint = new ArrayList<>();
List<BlockPos> 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<DyeColor, Block> f = BotaniaAPI.instance().getPaintableBlocks().get(block.delegate);
Function<DyeColor, Block> f = BotaniaAPI.instance().getPaintableBlocks().get(blockId);
Block newBlock = f.apply(placeColor);
if (newBlock != stateThere.getBlock()) {
entity.world.setBlockState(coords, newBlock.getDefaultState());