diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockStateArgumentSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockStateArgumentSerializer.java index 96231923..b16446ce 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockStateArgumentSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockStateArgumentSerializer.java @@ -2,22 +2,24 @@ import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; +import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.BlockStateArgument; import net.minecraft.command.argument.BlockStateArgumentType; -import net.minecraft.registry.Registry; -import net.minecraft.state.property.Property; +import net.minecraft.registry.Registries; public class BlockStateArgumentSerializer extends BrigadierSerializer { - private static final BlockStateArgumentSerializer INSTANCE = new BlockStateArgumentSerializer(); + private static BlockStateArgumentSerializer INSTANCE; - private BlockStateArgumentSerializer() { - super(BlockStateArgument.class, BlockStateArgumentType.blockState()); + private BlockStateArgumentSerializer(CommandRegistryAccess registryAccess) { + super(BlockStateArgument.class, BlockStateArgumentType.blockState(registryAccess)); } - public static BlockStateArgumentSerializer blockState() { + public static BlockStateArgumentSerializer blockState(CommandRegistryAccess registryAccess) { + if (INSTANCE == null) { + INSTANCE = new BlockStateArgumentSerializer(registryAccess); + } + return INSTANCE; } @@ -36,7 +38,7 @@ public String serialize(BlockStateArgument value) { var block = state.getBlock(); var builder = new StringBuilder() - .append(Registry.BLOCK.getId(block)); + .append(Registries.BLOCK.getId(block)); if (state.getProperties().size() == 0) { return builder.toString(); diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/IntLikeSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/IntLikeSerializer.java index 0cfc6974..987d7df1 100644 --- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/IntLikeSerializer.java +++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/IntLikeSerializer.java @@ -58,23 +58,24 @@ private T deserializeUnchecked(String serialized) { return tryParse(serialized); } - if(serialized.charAt(0) == '-' && serialized.chars().filter(ch -> ch == '-').count() == 1){ + if (serialized.charAt(0) == '-' && serialized.chars().filter(ch -> ch == '-').count() == 1) { isNegative = true; - serialized = serialized.replace("-",""); + serialized = serialized.replace("-", ""); } if (serialized.charAt(0) == '0') { - if(serialized.length() > 1) { + if (serialized.length() > 1) { var prefixedBase = serialized.substring(0, 2); var number = serialized.substring(2); var numberBase = NumberBase.fromPrefix(prefixedBase).orElse(null); if (numberBase != null) { - return isNegative ? tryParse("-" + number, numberBase.toInt()) : tryParse(number, numberBase.toInt()); + return isNegative ? tryParse("-" + number, numberBase.toInt()) + : tryParse(number, numberBase.toInt()); } } else { - return tryParse(serialized,10); + return tryParse(serialized, 10); } } @@ -93,10 +94,10 @@ private T deserializeUnchecked(String serialized) { throw new IllegalArgumentException("Invalid base '" + parts[1] + "'."); } - return isNegative ? tryParse("-"+number, base) : tryParse(number, base); + return isNegative ? tryParse("-" + number, base) : tryParse(number, base); } - return isNegative ? tryParse("-"+serialized) : tryParse(serialized); + return isNegative ? tryParse("-" + serialized) : tryParse(serialized); } private T tryParse(String string) { @@ -106,8 +107,8 @@ private T tryParse(String string) { private T tryParse(String string, int radix) { return tryParseOptional(string, radix) .orElseThrow(() -> new IllegalArgumentException(radix == 10 - ? "Invalid number '" + string + "'." - : "Invalid base " + radix + " number '" + string + "'.")); + ? "Invalid number '" + string + "'." + : "Invalid base " + radix + " number '" + string + "'.")); } protected abstract Optional tryParseOptional(String string, int radix); diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java index 06875d91..fdcd7b60 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/BinaryBlockReadFeature.java @@ -27,21 +27,19 @@ import static tools.redstone.redstonetools.features.arguments.serializers.NumberBaseSerializer.numberBase; - @AutoService(AbstractFeature.class) @Feature(name = "Binary Block Read", description = "Interprets your WorldEdit selection as a binary number.", command = "/read", worldedit = true) public class BinaryBlockReadFeature extends CommandFeature { private static final BlockStateArgument LIT_LAMP_ARG = new BlockStateArgument( Blocks.REDSTONE_LAMP.getDefaultState().with(RedstoneLampBlock.LIT, true), Collections.singleton(RedstoneLampBlock.LIT), - null - ); + null); public static final Argument offset = Argument .ofType(integer(1)) .withDefault(2); public static final Argument onBlock = Argument - .ofType(blockState()) + .ofType(blockState(REGISTRY_ACCESS)) .withDefault(LIT_LAMP_ARG); public static final Argument toBase = Argument .ofType(numberBase()) @@ -105,4 +103,4 @@ protected Feedback execute(ServerCommandSource source) throws CommandSyntaxExcep return Feedback.success("{}.", output); } -} \ No newline at end of file +} diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/CommandFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/CommandFeature.java index 1358a33e..0a3ee81a 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/CommandFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/CommandFeature.java @@ -5,6 +5,7 @@ import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.registry.BuiltinRegistries; import net.minecraft.server.command.CommandManager; import tools.redstone.redstonetools.features.AbstractFeature; import tools.redstone.redstonetools.features.Feature; @@ -16,15 +17,17 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; import java.util.ArrayList; import java.util.List; import static tools.redstone.redstonetools.RedstoneToolsClient.INJECTOR; - public abstract class CommandFeature extends AbstractFeature { private static final List keyBindings = new ArrayList<>(); + protected static final CommandRegistryAccess REGISTRY_ACCESS = CommandManager + .createRegistryAccess(BuiltinRegistries.createWrapperLookup()); @Override public void register() { @@ -41,21 +44,21 @@ public void register() { info.name(), InputUtil.Type.KEYSYM, -1, - "Redstone Tools" - )); + "Redstone Tools")); keyBindings.add(keyBinding); ClientTickEvents.END_CLIENT_TICK.register(client -> { while (keyBinding.wasPressed()) { assert client.player != null; - client.player.sendChatMessage("/" + info.command()); + client.player.sendMessage(Text.literal("/" + info.command())); } }); } @Override - protected void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { + protected void registerCommands(CommandDispatcher dispatcher, + CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { var info = ReflectionUtils.getFeatureInfo(getClass()); var arguments = ReflectionUtils.getArguments(getClass()); diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java index 4094b637..c35adc29 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/MinSelectionFeature.java @@ -58,7 +58,6 @@ protected Feedback execute(ServerCommandSource source) throws CommandSyntaxExcep if (isEmpty) { return Feedback.invalidUsage("Cannot minimize empty selections."); } - minimiseSelection(selectionWorld, selection); diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java index d5882195..2662dc13 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/QuickTpFeature.java @@ -19,7 +19,6 @@ import static tools.redstone.redstonetools.features.arguments.serializers.FloatSerializer.floatArg; - @AutoService(AbstractFeature.class) @Feature(name = "Quick TP", description = "Teleports you in the direction you are looking.", command = "quicktp") public class QuickTpFeature extends CommandFeature { diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java index 1dc7a170..df322d3e 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/RStackFeature.java @@ -76,15 +76,13 @@ public Mask2D toMask2D() { var stackVector = directionToBlock(stackDirection); - try (var editSession = localSession.createEditSession(actor)) { for (var i = 1; i <= count.getValue(); i++) { var copy = new ForwardExtentCopy( editSession, selection, editSession, - selection.getMinimumPoint().add(stackVector.multiply(i * offset.getValue())) - ); + selection.getMinimumPoint().add(stackVector.multiply(i * offset.getValue()))); copy.setSourceMask(airFilter); Operations.complete(copy); } diff --git a/src/main/java/tools/redstone/redstonetools/features/toggleable/ToggleableFeature.java b/src/main/java/tools/redstone/redstonetools/features/toggleable/ToggleableFeature.java index acca0071..2e80d9ff 100644 --- a/src/main/java/tools/redstone/redstonetools/features/toggleable/ToggleableFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/toggleable/ToggleableFeature.java @@ -51,14 +51,14 @@ public abstract class ToggleableFeature extends AbstractFeature { @Override public void register() { super.register(); - + // load user settings // and register save hook loadConfig(); ClientLifecycleEvents.CLIENT_STOPPING.register(client -> { saveConfig(); }); - + var containsRequiredArguments = ReflectionUtils.getArguments(getClass()).stream() .anyMatch(a -> !a.isOptional()); if (containsRequiredArguments) { @@ -70,8 +70,7 @@ public void register() { info.name(), InputUtil.Type.KEYSYM, -1, - "Redstone Tools" - )); + "Redstone Tools")); keyBindings.add(keyBinding); @@ -99,7 +98,8 @@ public void register() { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - protected void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, RegistrationEnvironment environment) { + protected void registerCommands(CommandDispatcher dispatcher, + CommandRegistryAccess registryAccess, RegistrationEnvironment environment) { var baseCommand = literal(getCommand()) .executes(this::toggle); @@ -109,7 +109,8 @@ protected void registerCommands(CommandDispatcher dispatche baseCommand.then(literal(name) .executes(context -> { Object value = argument.getValue(); - return Feedback.success("Option {} of feature {} is set to: {}", name, getName(), argument.getType().serialize(value)).send(context); + return Feedback.success("Option {} of feature {} is set to: {}", name, getName(), + argument.getType().serialize(value)).send(context); }) .then(argument("value", argument.getType()).executes(context -> { Object value = context.getArgument("value", argument.getType().getTypeClass()); @@ -123,8 +124,7 @@ protected void registerCommands(CommandDispatcher dispatche IO_EXECUTOR.execute(this::saveConfig); return Feedback.success("Set {} to {} for feature {}", name, value, getName()).send(context); - })) - ); + }))); } dispatcher.register(baseCommand); @@ -183,13 +183,16 @@ public int disable(CommandContext context) throws CommandSy return disable(context.getSource()); } - protected void onEnable() { } - protected void onDisable() { } + protected void onEnable() { + } + + protected void onDisable() { + } // todo: right now the configuration methods are assuming every - // type is serialized to a string, this should be fixed in the future - // but for now it works because every type right now serializes to a string - // + it will probably be refactored soon + // type is serialized to a string, this should be fixed in the future + // but for now it works because every type right now serializes to a string + // + it will probably be refactored soon /** Reloads the configuration from the disk. */ @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -217,9 +220,11 @@ public void loadConfig() { setEnabled(enabled); - RedstoneToolsClient.LOGGER.info("Loaded configuration for feature " + getID() + " file(" + configFile + ")"); + RedstoneToolsClient.LOGGER + .info("Loaded configuration for feature " + getID() + " file(" + configFile + ")"); } catch (Exception e) { - RedstoneToolsClient.LOGGER.error("Failed to load configuration for feature " + getID() + " file(" + configFile + ")"); + RedstoneToolsClient.LOGGER + .error("Failed to load configuration for feature " + getID() + " file(" + configFile + ")"); e.printStackTrace(); } } @@ -252,7 +257,8 @@ public void saveConfig() { RedstoneToolsClient.LOGGER.info("Saved configuration for feature " + getID() + " file(" + configFile + ")"); } catch (Exception e) { - RedstoneToolsClient.LOGGER.error("Failed to save configuration for feature " + getID() + " file(" + configFile + ")"); + RedstoneToolsClient.LOGGER + .error("Failed to save configuration for feature " + getID() + " file(" + configFile + ")"); e.printStackTrace(); } } diff --git a/src/main/java/tools/redstone/redstonetools/macros/MacroManager.java b/src/main/java/tools/redstone/redstonetools/macros/MacroManager.java index d666f9ec..e3d02869 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/MacroManager.java +++ b/src/main/java/tools/redstone/redstonetools/macros/MacroManager.java @@ -12,7 +12,6 @@ import javax.json.JsonObject; import javax.json.JsonReader; import javax.json.JsonWriter; - import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -32,7 +31,6 @@ public MacroManager() { .resolve("redstonetools") .resolve("macros.json"); - JsonArray macrosJson = null; try { Files.createDirectories(macrosFilePath.getParent()); @@ -135,8 +133,7 @@ private List getDefaultMacros() { "/gamerule doContainerDrops false", "/time set noon", "/weather clear" - }) - ); + })); } private Macro createCommandMacro(String name, String[] commands) { diff --git a/src/main/java/tools/redstone/redstonetools/utils/BlockStateNbtUtil.java b/src/main/java/tools/redstone/redstonetools/utils/BlockStateNbtUtil.java index 8938af04..da560228 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/BlockStateNbtUtil.java +++ b/src/main/java/tools/redstone/redstonetools/utils/BlockStateNbtUtil.java @@ -7,7 +7,7 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; -import net.minecraft.registry.Registry; +import net.minecraft.registry.Registries; import net.minecraft.server.world.ServerWorld; import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; @@ -34,7 +34,7 @@ public static NbtCompound toNBT(BlockState state) { } NbtCompound root = new NbtCompound(); - root.putString("Id", Registry.BLOCK.getId(state.getBlock()).toString()); + root.putString("Id", Registries.BLOCK.getId(state.getBlock()).toString()); // serialize properties if (!state.getProperties().isEmpty()) { @@ -69,7 +69,7 @@ public static BlockState fromNBT(NbtCompound compound) { // we use new Identifier(...) here to allow it to throw exceptions // instead of getting a cryptic NPE Identifier identifier = new Identifier(compound.getString("Id")); - Block block = Registry.BLOCK.get(identifier); + Block block = Registries.BLOCK.get(identifier); // deserialize properties BlockState state = block.getDefaultState(); @@ -96,7 +96,7 @@ public static BlockState fromNBT(NbtCompound compound) { * or returns the given default if the tag is null/empty. * * @param compound The NBT tag. - * @param def The default. + * @param def The default. * @return The block state or {@code def} if the tag is null/empty. */ public static BlockState fromNBT(NbtCompound compound, BlockState def) { @@ -171,9 +171,7 @@ public static BlockState getPlacementState(ItemStack stack) { return null; } - BlockState def = stack.getItem() instanceof BlockItem blockItem ? - blockItem.getBlock().getDefaultState() : - null; + BlockState def = stack.getItem() instanceof BlockItem blockItem ? blockItem.getBlock().getDefaultState() : null; return fromNBT(nbt.getCompound(EXACT_STATE_KEY), def); } diff --git a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java index da288a52..c672df25 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlock.java @@ -1,7 +1,7 @@ package tools.redstone.redstonetools.utils; import net.minecraft.block.Block; -import net.minecraft.registry.Registry; +import net.minecraft.registry.Registries; import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; @@ -11,17 +11,20 @@ public class ColoredBlock { private static final Pattern COLORED_BLOCK_REGEX = Pattern.compile( - "^minecraft:(\\w+?)_(wool|stained_glass|concrete_powder|concrete|glazed_terracotta|terracotta)$" - ); + "^minecraft:(\\w+?)_(wool|stained_glass|concrete_powder|concrete|glazed_terracotta|terracotta)$"); - private static final HashMap COLORLESS_BLOCKS = new HashMap<>() {{ - put("minecraft:glass", new ColoredBlock("minecraft:%s_stained_glass", BlockColor.WHITE)); - put("minecraft:terracotta", new ColoredBlock("minecraft:%s_terracotta", BlockColor.WHITE)); - }}; + private static final HashMap COLORLESS_BLOCKS = new HashMap<>() { + { + put("minecraft:glass", new ColoredBlock("minecraft:%s_stained_glass", BlockColor.WHITE)); + put("minecraft:terracotta", new ColoredBlock("minecraft:%s_terracotta", BlockColor.WHITE)); + } + }; - private static final HashMap COLORED_BLOCK_CACHE = new HashMap<>() {{ - putAll(COLORLESS_BLOCKS); - }}; + private static final HashMap COLORED_BLOCK_CACHE = new HashMap<>() { + { + putAll(COLORLESS_BLOCKS); + } + }; private final String blockIdFormat; public final BlockColor color; @@ -60,23 +63,26 @@ public String toBlockId() { } public static ColoredBlock fromBlock(@NotNull Block block) { - var blockId = Registry.BLOCK.getId(block).toString(); + var blockId = Registries.BLOCK.getId(block).toString(); if (COLORED_BLOCK_CACHE.containsKey(blockId)) { return COLORED_BLOCK_CACHE.get(blockId); } var coloredBlock = fromBlockId(blockId); - // The reason we only cache nulls here and not in the fromBlockId method is because the fromBlockId method would - // also cache invalid block ids (literally any string) which would make the cache massive. This method however - // only accepts actual blocks which means that the cache will never grow bigger than the amount of mc blocks. + // The reason we only cache nulls here and not in the fromBlockId method is + // because the fromBlockId method would + // also cache invalid block ids (literally any string) which would make the + // cache massive. This method however + // only accepts actual blocks which means that the cache will never grow bigger + // than the amount of mc blocks. COLORED_BLOCK_CACHE.put(blockId, coloredBlock); return coloredBlock; } public Block toBlock() { - return Registry.BLOCK.get(Identifier.tryParse(toBlockId())); + return Registries.BLOCK.get(Identifier.tryParse(toBlockId())); } @Override diff --git a/src/main/java/tools/redstone/redstonetools/utils/CommandSourceUtils.java b/src/main/java/tools/redstone/redstonetools/utils/CommandSourceUtils.java index fd0b5c4a..939da18a 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/CommandSourceUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/CommandSourceUtils.java @@ -1,12 +1,14 @@ package tools.redstone.redstonetools.utils; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + import net.minecraft.server.command.ServerCommandSource; public class CommandSourceUtils { private CommandSourceUtils() { } - public static void executeCommand(ServerCommandSource source, String command) { - source.getServer().getCommandManager().execute(source, command); + public static void executeCommand(ServerCommandSource source, String command) throws CommandSyntaxException { + source.getServer().getCommandManager().getDispatcher().execute(command, source); } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/DirectionUtils.java b/src/main/java/tools/redstone/redstonetools/utils/DirectionUtils.java index 4ecc2fdb..094b654b 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/DirectionUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/DirectionUtils.java @@ -1,8 +1,9 @@ package tools.redstone.redstonetools.utils; - +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; +import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; public class DirectionUtils { @@ -15,7 +16,7 @@ public static Direction firstOrdinal(Direction playerFacing) { default -> playerFacing; }; } - + public static DirectionArgument relativeToAbsolute(DirectionArgument direction, Direction playerFacing) { return switch (direction) { case ME, FORWARD -> switch (firstOrdinal(playerFacing)) { @@ -72,7 +73,8 @@ public static DirectionArgument relativeToAbsolute(DirectionArgument direction, }; } - // big evil match direction function, there might be a better way to do this but i don't know how + // big evil match direction function, there might be a better way to do this but + // i don't know how @NotNull public static Direction matchDirection(DirectionArgument direction, Direction playerFacing) { var absoluteDirection = relativeToAbsolute(direction, playerFacing); diff --git a/src/main/java/tools/redstone/redstonetools/utils/RaycastUtils.java b/src/main/java/tools/redstone/redstonetools/utils/RaycastUtils.java index 7286b95d..468ba44a 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/RaycastUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/RaycastUtils.java @@ -1,9 +1,9 @@ package tools.redstone.redstonetools.utils; +import org.joml.Vector3f; + import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3f; import net.minecraft.world.RaycastContext; public class RaycastUtils { @@ -11,20 +11,19 @@ private RaycastUtils() { } public static BlockHitResult getBlockHitNeighbor(BlockHitResult hit) { - var sideOffset = hit.getSide().getUnitVector(); + Vector3f sideOffset = hit.getSide().getUnitVector(); - var newBlockPos = hit.getBlockPos().add(sideOffset.getX(), sideOffset.getY(), sideOffset.getZ()); + var newBlockPos = hit.getBlockPos().add((int) sideOffset.x(), (int) sideOffset.y(), (int) sideOffset.z()); return hit.withBlockPos(newBlockPos); } public static BlockHitResult rayCastFromEye(PlayerEntity player, float reach) { - return player.method_48926().raycast(new RaycastContext( + return player.getWorld().raycast(new RaycastContext( player.getEyePos(), player.getEyePos().add(player.getRotationVector().multiply(reach)), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, - player - )); + player)); } } diff --git a/src/main/java/tools/redstone/redstonetools/utils/SignalBlockSupplier.java b/src/main/java/tools/redstone/redstonetools/utils/SignalBlockSupplier.java index d7ff3ead..92354ba8 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/SignalBlockSupplier.java +++ b/src/main/java/tools/redstone/redstonetools/utils/SignalBlockSupplier.java @@ -7,6 +7,7 @@ import net.minecraft.item.Items; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; +import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.text.Text; import net.minecraft.text.MutableText; @@ -39,12 +40,15 @@ static SignalBlockSupplier container(int slots) { int itemsNeeded = Math.max(0, signalStrength == 1 ? 1 : (int) Math.ceil(slots * (signalStrength - 1) / 14D * item.getMaxCount())); - String itemId = Registry.ITEM.getId(item).toString(); + String itemId = Registries.ITEM.getId(item).toString(); // Check that the calculated number of items is correct. - // This is to prevent problems with items that have a maximum stack size of 1 but stackSize > 1. - // TODO: This can be improved by removing an item and adding stackable items up to the desired signal strength. - // Even with the improvement, this will still fail for inventories with no available slots. + // This is to prevent problems with items that have a maximum stack size of 1 + // but stackSize > 1. + // TODO: This can be improved by removing an item and adding stackable items up + // to the desired signal strength. + // Even with the improvement, this will still fail for inventories with no + // available slots. if (calculateComparatorOutput(itemsNeeded, slots, item.getMaxCount()) != signalStrength) throw new IllegalStateException("This signal strength cannot be achieved with the selected container"); @@ -96,7 +100,7 @@ private static boolean isInvalidSignalStrength(int signalStrength, int maxSignal private static int calculateComparatorOutput(int items, int slots, int item$getMaxCount) { float f = (float) items / (float) item$getMaxCount; - return MathHelper.floor((f /= (float)slots) * 14.0f) + (items > 0 ? 1 : 0); + return MathHelper.floor((f /= (float) slots) * 14.0f) + (items > 0 ? 1 : 0); } private static Item getBestItem(int signalStrength, int slots) { diff --git a/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java b/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java index 6f2588d9..99e9566e 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java +++ b/src/main/java/tools/redstone/redstonetools/utils/WorldEditUtils.java @@ -3,14 +3,11 @@ import tools.redstone.redstonetools.features.feedback.Feedback; import com.mojang.datafixers.util.Either; import com.sk89q.worldedit.IncompleteRegionException; -import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.fabric.FabricAdapter; -import com.sk89q.worldedit.fabric.FabricPlayer; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.world.World; import net.minecraft.server.network.ServerPlayerEntity; import java.util.function.Consumer; @@ -26,11 +23,11 @@ public class WorldEditUtils { * * TODO: maybe make an async version of this somehow * - * @param region The region. + * @param region The region. * @param consumer The function to run. */ public static void forEachBlockInRegion(Region region, - Consumer consumer) { + Consumer consumer) { if (!DependencyLookup.WORLDEDIT_PRESENT) { throw new IllegalStateException("WorldEdit is not loaded."); }