diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 35fcb54e..4bf87023 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -140,7 +140,7 @@ jobs: - name: Read SUFFIX file id: getsuffix run: echo "suffix=$(cat SUFFIX)" >> $GITHUB_OUTPUT - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 - run: mkdir upload - run: cp **/LandOfSignals-*.jar upload - name: Upload to GitHub diff --git a/CHANGELOG.md b/CHANGELOG.md index 816c2135..4c705bde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### Release 1.3.1 + +* Fixed [#143] : Manipulator didn't work on multiplayer (NullPointerException on client) + ### Release 1.3.0 We have officially released LandOfSignals 1.3.0 supporting the new UMC 1.2.0 version. diff --git a/VERSION b/VERSION index f0bb29e7..3a3cd8cc 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.3.0 +1.3.1 diff --git a/src/main/java/net/landofrails/landofsignals/LandOfSignals.java b/src/main/java/net/landofrails/landofsignals/LandOfSignals.java index 71cd522a..7c04a91f 100644 --- a/src/main/java/net/landofrails/landofsignals/LandOfSignals.java +++ b/src/main/java/net/landofrails/landofsignals/LandOfSignals.java @@ -29,7 +29,7 @@ public class LandOfSignals extends ModCore.Mod { public static final String MODID = "landofsignals"; // Current version @SuppressWarnings("unused") - public static final String VERSION = "1.3.0"; + public static final String VERSION = "1.3.1"; @Override public String modID() { diff --git a/src/main/java/net/landofrails/landofsignals/gui/GuiManipulator.java b/src/main/java/net/landofrails/landofsignals/gui/GuiManipulator.java index 7de1691e..a53c2779 100644 --- a/src/main/java/net/landofrails/landofsignals/gui/GuiManipulator.java +++ b/src/main/java/net/landofrails/landofsignals/gui/GuiManipulator.java @@ -1,12 +1,14 @@ package net.landofrails.landofsignals.gui; +import cam72cam.mod.MinecraftClient; import cam72cam.mod.block.BlockEntity; import cam72cam.mod.entity.Player; import cam72cam.mod.gui.helpers.GUIHelpers; import cam72cam.mod.gui.screen.*; import cam72cam.mod.math.Vec3d; import cam72cam.mod.math.Vec3i; -import net.landofrails.landofsignals.packet.ManipulatorToClientPacket; +import cam72cam.mod.render.opengl.RenderState; +import cam72cam.mod.world.World; import net.landofrails.landofsignals.packet.ManipulatorToServerPacket; import net.landofrails.landofsignals.utils.IManipulate; import net.landofrails.landofsignals.utils.Static; @@ -50,7 +52,7 @@ public class GuiManipulator implements IScreen { private String scalingYBefore; private String scalingZBefore; - private final Vec3d offset; + private Vec3d offset; private Vec3d scaling; private int rotation; private final Vec3i blockPos; @@ -151,7 +153,7 @@ public void onClick(Player.Hand hand) { public void onClick(Player.Hand hand) { rotation--; renewSlider(screen); - send(); + updateClientBlock(); } }; rotationAddition = new Button(screen, screen.getWidth() / 2 - 50, 100, 20, 20, "+") { @@ -159,7 +161,7 @@ public void onClick(Player.Hand hand) { public void onClick(Player.Hand hand) { rotation++; renewSlider(screen); - send(); + updateClientBlock(); } }; @@ -301,25 +303,20 @@ public void onEnterKey(final IScreenBuilder builder) { @SuppressWarnings("java:S125") @Override public void onClose() { - scaling = new Vec3d( - Double.parseDouble(scalingXField.getText()), - Double.parseDouble(scalingYField.getText()), - Double.parseDouble(scalingZField.getText()) - ); - send(); - //Server + refreshScalingAndOffset(); + ManipulatorToServerPacket serverPacket = new ManipulatorToServerPacket( - new Vec3d(Double.parseDouble(positionXField.getText()), Double.parseDouble(heightYField.getText()), Double.parseDouble(positionZField.getText())), + blockPos, + offset, rotation, scaling, - blockPos, cascadeBox.isChecked() ); serverPacket.sendToServer(); } @Override - public void draw(final IScreenBuilder builder) { + public void draw(final IScreenBuilder builder, final RenderState state) { final String tempX = positionXField.getText(); final String tempY = heightYField.getText(); final String tempZ = positionZField.getText(); @@ -330,37 +327,37 @@ public void draw(final IScreenBuilder builder) { if (!positionXField.getText().isEmpty() && !tempX.equals(textXBefore)) { positionXField.setText(String.valueOf(Static.round(Double.parseDouble(tempX), 3))); textXBefore = tempX; - send(); + updateClientBlock(); } if (!heightYField.getText().isEmpty() && !tempY.equals(textYBefore)) { heightYField.setText(String.valueOf(Static.round(Double.parseDouble(tempY), 3))); textYBefore = tempY; - send(); + updateClientBlock(); } if (!positionZField.getText().isEmpty() && !tempZ.equals(textZBefore)) { positionZField.setText(String.valueOf(Static.round(Double.parseDouble(tempZ), 3))); textZBefore = tempZ; - send(); + updateClientBlock(); } if(!scalingXField.getText().isEmpty() && !tempScalingX.equals(scalingXBefore)){ scalingXField.setText(String.valueOf(Static.round(Double.parseDouble(tempScalingX), 3))); scalingXBefore = tempScalingX; - send(); + updateClientBlock(); } if(!scalingYField.getText().isEmpty() && !tempScalingY.equals(scalingYBefore)){ scalingYField.setText(String.valueOf(Static.round(Double.parseDouble(tempScalingY), 3))); scalingYBefore = tempScalingY; - send(); + updateClientBlock(); } if(!scalingZField.getText().isEmpty() && !tempScalingZ.equals(scalingZBefore)){ scalingZField.setText(String.valueOf(Static.round(Double.parseDouble(tempScalingZ), 3))); scalingZBefore = tempScalingZ; - send(); + updateClientBlock(); } if(!rotationBox.isChecked()){ @@ -369,25 +366,27 @@ public void draw(final IScreenBuilder builder) { } } - private void send() { - //Client + private void refreshScalingAndOffset(){ scaling = new Vec3d( Double.parseDouble(scalingXField.getText()), Double.parseDouble(scalingYField.getText()), Double.parseDouble(scalingZField.getText()) ); - final ManipulatorToClientPacket clientPacket = new ManipulatorToClientPacket( - new Vec3d( - Double.parseDouble(positionXField.getText()), - Double.parseDouble(heightYField.getText()), - Double.parseDouble(positionZField.getText())), - rotation, - blockPos, - scaling, - cascadeBox.isChecked() + offset = new Vec3d( + Double.parseDouble(positionXField.getText()), + Double.parseDouble(heightYField.getText()), + Double.parseDouble(positionZField.getText()) ); - clientPacket.sendToAll(); + } + + private void updateClientBlock() { + refreshScalingAndOffset(); + + //Client + World world = MinecraftClient.getPlayer().getWorld(); + IManipulate.applyChanges(world, blockPos, cascadeBox.isChecked(), offset, rotation, scaling); + } private void setAllInvisible() { @@ -431,7 +430,7 @@ private void renewSlider(IScreenBuilder screen){ @Override public void onSlider() { rotation = rotationSlider.getValueInt(); - send(); + updateClientBlock(); } }; } diff --git a/src/main/java/net/landofrails/landofsignals/packet/ManipulatorToClientPacket.java b/src/main/java/net/landofrails/landofsignals/packet/ManipulatorToClientPacket.java index c607da59..2adefc79 100644 --- a/src/main/java/net/landofrails/landofsignals/packet/ManipulatorToClientPacket.java +++ b/src/main/java/net/landofrails/landofsignals/packet/ManipulatorToClientPacket.java @@ -1,18 +1,15 @@ package net.landofrails.landofsignals.packet; -import cam72cam.mod.block.BlockEntity; import cam72cam.mod.math.Vec3d; import cam72cam.mod.math.Vec3i; import cam72cam.mod.net.Packet; import cam72cam.mod.serialization.TagField; import net.landofrails.landofsignals.utils.IManipulate; -import java.util.ArrayList; - public class ManipulatorToClientPacket extends Packet { @TagField("movement") - private Vec3d movement; + private Vec3d offset; @TagField("blockPos") private Vec3i blockPos; @TagField("rotation") @@ -26,9 +23,9 @@ public ManipulatorToClientPacket() { } - public ManipulatorToClientPacket(final Vec3d offset, final int rotation, final Vec3i blockPos, final Vec3d scaling, final boolean cascade) { - movement = offset; + public ManipulatorToClientPacket(final Vec3i blockPos, final Vec3d offset, final int rotation, final Vec3d scaling, boolean cascade) { this.blockPos = blockPos; + this.offset = offset; this.rotation = rotation; this.scaling = scaling; this.cascade = cascade; @@ -37,33 +34,7 @@ public ManipulatorToClientPacket(final Vec3d offset, final int rotation, final V @Override protected void handle() { - final ArrayList blockPosList = new ArrayList<>(); - if (Boolean.TRUE.equals(cascade)) { - //UP - int i = 0; - while (getWorld().getBlockEntity(blockPos.up(i), BlockEntity.class) instanceof IManipulate) { - blockPosList.add(blockPos.up(i)); - i++; - } - //DOWN - int j = 0; - while (getWorld().getBlockEntity(blockPos.down(j), BlockEntity.class) instanceof IManipulate) { - blockPosList.add(blockPos.down(j)); - j++; - } - } else { - blockPosList.add(blockPos); - } - - for (final Vec3i bp : blockPosList) { - final BlockEntity block = getWorld().getBlockEntity(bp, BlockEntity.class); - if (block instanceof IManipulate) { - final IManipulate manipulate = (IManipulate) block; - manipulate.setOffset(movement); - manipulate.setRotation(rotation); - manipulate.setScaling(scaling); - } - } - + IManipulate.applyChanges(getWorld(), blockPos, cascade, offset, rotation, scaling); } + } diff --git a/src/main/java/net/landofrails/landofsignals/packet/ManipulatorToServerPacket.java b/src/main/java/net/landofrails/landofsignals/packet/ManipulatorToServerPacket.java index c69dd82f..f3c63dda 100644 --- a/src/main/java/net/landofrails/landofsignals/packet/ManipulatorToServerPacket.java +++ b/src/main/java/net/landofrails/landofsignals/packet/ManipulatorToServerPacket.java @@ -1,14 +1,11 @@ package net.landofrails.landofsignals.packet; -import cam72cam.mod.block.BlockEntity; import cam72cam.mod.math.Vec3d; import cam72cam.mod.math.Vec3i; import cam72cam.mod.net.Packet; import cam72cam.mod.serialization.TagField; import net.landofrails.landofsignals.utils.IManipulate; -import java.util.ArrayList; - public class ManipulatorToServerPacket extends Packet { @TagField("offset") @@ -26,42 +23,18 @@ public ManipulatorToServerPacket() { } - public ManipulatorToServerPacket(final Vec3d offset, final int rotation, final Vec3d scaling, final Vec3i blockPos, boolean cascade) { + public ManipulatorToServerPacket(final Vec3i blockPos, final Vec3d offset, final int rotation, final Vec3d scaling, boolean cascade) { + this.blockPos = blockPos; this.offset = offset; this.rotation = rotation; this.scaling = scaling; - this.blockPos = blockPos; this.cascade = cascade; } @Override protected void handle() { - final ArrayList blockPosList = new ArrayList<>(); - if (Boolean.TRUE.equals(cascade)) { - //UP - int i = 0; - while (getWorld().getBlockEntity(blockPos.up(i), BlockEntity.class) instanceof IManipulate) { - blockPosList.add(blockPos.up(i)); - i++; - } - //DOWN - int j = 0; - while (getWorld().getBlockEntity(blockPos.down(j), BlockEntity.class) instanceof IManipulate) { - blockPosList.add(blockPos.down(j)); - j++; - } - } else { - blockPosList.add(blockPos); - } - - for (final Vec3i bp : blockPosList) { - final BlockEntity block = getWorld().getBlockEntity(bp, BlockEntity.class); - if (block instanceof IManipulate) { - final IManipulate manipulate = (IManipulate) block; - manipulate.setOffset(offset); - manipulate.setRotation(rotation); - manipulate.setScaling(scaling); - } - } + IManipulate.applyChanges(getWorld(), blockPos, cascade, offset, rotation, scaling); + ManipulatorToClientPacket clientPacket = new ManipulatorToClientPacket(blockPos, offset, rotation, scaling, cascade); + clientPacket.sendToAll(); } } diff --git a/src/main/java/net/landofrails/landofsignals/utils/IManipulate.java b/src/main/java/net/landofrails/landofsignals/utils/IManipulate.java index 33f5f478..c76a640f 100644 --- a/src/main/java/net/landofrails/landofsignals/utils/IManipulate.java +++ b/src/main/java/net/landofrails/landofsignals/utils/IManipulate.java @@ -1,6 +1,12 @@ package net.landofrails.landofsignals.utils; +import cam72cam.mod.block.BlockEntity; import cam72cam.mod.math.Vec3d; +import cam72cam.mod.math.Vec3i; +import cam72cam.mod.world.World; + +import java.util.HashSet; +import java.util.Set; public interface IManipulate { @@ -16,4 +22,49 @@ public interface IManipulate { Vec3d getScaling(); + // Util + + /** + * Applies changes to the listed blocks. + * Can be called from either server or client. + * Won't sync. + * + * @param world Client or server world + * @param blockPos Position of the core block + * @param cascade Should the changes be cascaded down and upwards? + * @param offset Amount of offset the block(s) should be set to + * @param rotation Amount of rotation the block(s) should be set to + * @param scaling Scaling the block(s) should be set to + */ + static void applyChanges(World world, Vec3i blockPos, Boolean cascade, Vec3d offset, int rotation, Vec3d scaling){ + final Set blockPositions = new HashSet<>(); + if (Boolean.TRUE.equals(cascade)) { + //UP + int i = 0; + while (world.getBlockEntity(blockPos.up(i), BlockEntity.class) instanceof IManipulate) { + blockPositions.add(blockPos.up(i)); + i++; + } + blockPositions.add(blockPos); + //DOWN + int j = 0; + while (world.getBlockEntity(blockPos.down(j), BlockEntity.class) instanceof IManipulate) { + blockPositions.add(blockPos.down(j)); + j++; + } + } else { + blockPositions.add(blockPos); + } + + for (final Vec3i bp : blockPositions) { + final BlockEntity block = world.getBlockEntity(bp, BlockEntity.class); + if (block instanceof IManipulate) { + final IManipulate manipulate = (IManipulate) block; + manipulate.setOffset(offset); + manipulate.setRotation(rotation); + manipulate.setScaling(scaling); + } + } + } + } diff --git a/umc.json b/umc.json index ff11a582..5da41458 100644 --- a/umc.json +++ b/umc.json @@ -4,7 +4,7 @@ "cls": "LandOfSignals", "name": "LandOfSignals", "id": "landofsignals", - "version": "1.3.0", + "version": "1.3.1", "dependencies": {} }, "umc": {