Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with main #152

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
65 changes: 32 additions & 33 deletions src/main/java/net/landofrails/landofsignals/gui/GuiManipulator.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -151,15 +153,15 @@ 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, "+") {
@Override
public void onClick(Player.Hand hand) {
rotation++;
renewSlider(screen);
send();
updateClientBlock();
}
};

Expand Down Expand Up @@ -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();
Expand All @@ -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()){
Expand All @@ -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() {
Expand Down Expand Up @@ -431,7 +430,7 @@ private void renewSlider(IScreenBuilder screen){
@Override
public void onSlider() {
rotation = rotationSlider.getValueInt();
send();
updateClientBlock();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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;
Expand All @@ -37,33 +34,7 @@ public ManipulatorToClientPacket(final Vec3d offset, final int rotation, final V
@Override
protected void handle() {

final ArrayList<Vec3i> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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<Vec3i> 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();
}
}
51 changes: 51 additions & 0 deletions src/main/java/net/landofrails/landofsignals/utils/IManipulate.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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<Vec3i> 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);
}
}
}

}
2 changes: 1 addition & 1 deletion umc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cls": "LandOfSignals",
"name": "LandOfSignals",
"id": "landofsignals",
"version": "1.3.0",
"version": "1.3.1",
"dependencies": {}
},
"umc": {
Expand Down