Skip to content

Commit

Permalink
Add gravity toggle to models
Browse files Browse the repository at this point in the history
  • Loading branch information
iam4722202468 committed May 15, 2023
1 parent 8fb0da8 commit ee42101
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/main/java/ca/atlasengine/gui/windows/ModelModifyGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AnimationSelect() {
}
}

public ModelModifyGUI(List<String> animations, UUID uuid, String modelName, int customModelData, boolean hideOnLoad) {
public ModelModifyGUI(List<String> animations, UUID uuid, String modelName, int customModelData, boolean hideOnLoad, boolean gravity) {
WGridPanel root = new WGridPanel();
setRootPanel(root);

Expand Down Expand Up @@ -65,6 +65,14 @@ public ModelModifyGUI(List<String> animations, UUID uuid, String modelName, int
hideOnLoadButton.setToggle(hideOnLoad);
root.add(hideOnLoadButton, 2, 4, 5, 1);

WToggleButton gravityButton = new WToggleButton(Text.of("Has Gravity"));
gravityButton.setOnToggle((b) -> {
ModelManager.setGravity(uuid, b);
});

gravityButton.setToggle(gravity);
root.add(gravityButton, 2, 5, 5, 1);

var moveButton = new WButton(Text.of("Move Model"));
moveButton.setOnClick(() -> {
ModelManager.moveModel(uuid);
Expand All @@ -73,14 +81,6 @@ public ModelModifyGUI(List<String> animations, UUID uuid, String modelName, int

root.add(moveButton, 1, 2, 5, 1);

var closeButton = new WButton(Text.of("Delete Model"));
closeButton.setOnClick(() -> {
ModelManager.deleteModel(uuid);
MinecraftClient.getInstance().setScreen(null);
});

root.add(closeButton, 1, root.getHeight() / 16 - 4, 5, 1);

var stopAnimations = new WButton(Text.of("Stop Animation"));
stopAnimations.setOnClick(() -> {
ModelManager.setAnimation(uuid, "");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ca/atlasengine/models/ModelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ public static void receive(PacketByteBuf packetByteBuf) {
String name = packetByteBuf.readString();
int customModelData = packetByteBuf.readInt();
boolean hideOnLoad = packetByteBuf.readBoolean();
boolean gravity = packetByteBuf.readBoolean();

int count = packetByteBuf.readInt();
List<String> animations = new ArrayList<>();
for (int i = 0; i < count; i++) {
animations.add(packetByteBuf.readString());
}

providedScreen = new GUIScreen(new ModelModifyGUI(animations, uuid, name, customModelData, hideOnLoad));
providedScreen = new GUIScreen(new ModelModifyGUI(animations, uuid, name, customModelData, gravity, hideOnLoad));
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/ca/atlasengine/models/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,13 @@ public static void setHideOnLoad(UUID uuid, Boolean b) {

ClientPlayNetworking.send(animationIdentifier, buf);
}

public static void setGravity(UUID uuid, Boolean b) {
PacketByteBuf buf = PacketByteBufs.create();
buf.writeByte(7);
buf.writeUuid(uuid);
buf.writeBoolean(b);

ClientPlayNetworking.send(animationIdentifier, buf);
}
}

0 comments on commit ee42101

Please sign in to comment.