Don't use map color to check for wool color (#1708)

This commit is contained in:
altrisi authored and GitHub committed 2023-04-27 18:07:23 +02:00
1 parent 1c4bcd682d
commit 68a447daf9
1 file changed
+22 -12
+22 -12
View File
@@ -3,11 +3,8 @@ package carpet.utils;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import carpet.helpers.HopperCounter; import carpet.helpers.HopperCounter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@@ -17,6 +14,8 @@ import net.minecraft.tags.BlockTags;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.DyeColor;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MapColor; import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@@ -32,11 +31,27 @@ import static java.util.Map.entry;
public class WoolTool public class WoolTool
{ {
/** /**
* A map of the {@link net.minecraft.world.level.material.MapColor} to the {@link DyeColor} which is used in {@link WoolTool#getWoolColorAtPosition} * A map from a wool {@link Block} to its {@link DyeColor} which is used in {@link WoolTool#getWoolColorAtPosition}
* to get the colour of wool at a position. * to get the colour of wool at a position.
*/ */
private static final Map<MapColor,DyeColor> Material2Dye = Arrays.stream(DyeColor.values()) private static final Map<Block, DyeColor> WOOL_BLOCK_TO_DYE = Map.ofEntries(
.collect(Collectors.toUnmodifiableMap(DyeColor::getMapColor, Function.identity())); entry(Blocks.WHITE_WOOL, DyeColor.WHITE),
entry(Blocks.ORANGE_WOOL, DyeColor.ORANGE),
entry(Blocks.MAGENTA_WOOL, DyeColor.MAGENTA),
entry(Blocks.LIGHT_BLUE_WOOL, DyeColor.LIGHT_BLUE),
entry(Blocks.YELLOW_WOOL, DyeColor.YELLOW),
entry(Blocks.LIME_WOOL, DyeColor.LIME),
entry(Blocks.PINK_WOOL, DyeColor.PINK),
entry(Blocks.GRAY_WOOL, DyeColor.GRAY),
entry(Blocks.LIGHT_GRAY_WOOL, DyeColor.LIGHT_GRAY),
entry(Blocks.CYAN_WOOL, DyeColor.CYAN),
entry(Blocks.PURPLE_WOOL, DyeColor.PURPLE),
entry(Blocks.BLUE_WOOL, DyeColor.BLUE),
entry(Blocks.BROWN_WOOL, DyeColor.BROWN),
entry(Blocks.GREEN_WOOL, DyeColor.GREEN),
entry(Blocks.RED_WOOL, DyeColor.RED),
entry(Blocks.BLACK_WOOL, DyeColor.BLACK)
);
/** /**
* The method which gets triggered when a player places a carpet, and decides what to do based on the carpet's colour: * The method which gets triggered when a player places a carpet, and decides what to do based on the carpet's colour:
@@ -109,11 +124,6 @@ public class WoolTool
public static DyeColor getWoolColorAtPosition(Level worldIn, BlockPos pos) public static DyeColor getWoolColorAtPosition(Level worldIn, BlockPos pos)
{ {
BlockState state = worldIn.getBlockState(pos); BlockState state = worldIn.getBlockState(pos);
// wool and wool carpets return WOOL_BLOCK_TO_DYE.get(state.getBlock());
if (!state.is(BlockTags.WOOL))
{
return null;
}
return Material2Dye.get(state.getMapColor(worldIn, pos));
} }
} }