Skip to content

Commit a504793

Browse files
authored
Fix pressed pressure plates, observer and attached tripwire block models. (#1843)
* Render pressed pressure plates properly. * Fix orientation of the observer side quads. * Add proper attached tripwire model. * Refactor tripwire model code to dedupe the orientation logic.
1 parent 41492ea commit a504793

File tree

7 files changed

+831
-504
lines changed

7 files changed

+831
-504
lines changed

chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ private static void addBlocks(Texture texture, String... names) {
965965
addBlock("mangrove_log", (name, tag) -> log(tag, Texture.mangroveLog, Texture.mangroveLogTop));
966966
addBlock("stripped_mangrove_log", (name, tag) -> log(tag, Texture.strippedMangroveLog, Texture.strippedMangroveLogTop));
967967
addBlock("mangrove_planks", Texture.mangrovePlanks);
968-
addBlock("mangrove_pressure_plate", (name, tag) -> new PressurePlate(name, Texture.mangrovePlanks));
968+
addBlock("mangrove_pressure_plate", (name, tag) -> pressurePlate(tag, Texture.mangrovePlanks));
969969
addBlock("mangrove_sign", (name, tag) -> sign(tag, "mangrove"));
970970
addBlock("mangrove_wall_sign", (name, tag) -> wallSign(tag, "mangrove"));
971971
addBlock("mangrove_slab", (name, tag) -> slab(tag, Texture.mangrovePlanks));
@@ -998,7 +998,7 @@ private static void addBlocks(Texture texture, String... names) {
998998
addBlock("stripped_bamboo_block", (name, tag) -> log(tag, Texture.strippedBambooBlock, Texture.strippedBambooBlockTop));
999999
addBlock("bamboo_planks", Texture.bambooPlanks);
10001000
addBlock("bamboo_mosaic", Texture.bambooMosaic);
1001-
addBlock("bamboo_pressure_plate", (name, tag) -> new PressurePlate(name, Texture.bambooPlanks));
1001+
addBlock("bamboo_pressure_plate", (name, tag) -> pressurePlate(tag, Texture.bambooPlanks));
10021002
addBlock("bamboo_sign", (name, tag) -> sign(tag, "bamboo"));
10031003
addBlock("bamboo_wall_sign", (name, tag) -> wallSign(tag, "bamboo"));
10041004
addBlock("bamboo_slab", (name, tag) -> slab(tag, Texture.bambooPlanks));
@@ -1014,7 +1014,7 @@ private static void addBlocks(Texture texture, String... names) {
10141014
addBlock("cherry_log", (name, tag) -> log(tag, Texture.cherryLog, Texture.cherryLogTop));
10151015
addBlock("stripped_cherry_log", (name, tag) -> log(tag, Texture.strippedCherryLog, Texture.strippedCherryLogTop));
10161016
addBlock("cherry_planks", Texture.cherryPlanks);
1017-
addBlock("cherry_pressure_plate", (name, tag) -> new PressurePlate(name, Texture.cherryPlanks));
1017+
addBlock("cherry_pressure_plate", (name, tag) -> pressurePlate(tag, Texture.cherryPlanks));
10181018
addBlock("cherry_sign", (name, tag) -> sign(tag, "cherry"));
10191019
addBlock("cherry_wall_sign", (name, tag) -> wallSign(tag, "cherry"));
10201020
addBlock("cherry_slab", (name, tag) -> slab(tag, Texture.cherryPlanks));
@@ -1132,7 +1132,7 @@ private static void addBlocks(Texture texture, String... names) {
11321132
addBlock("pale_oak_planks", Texture.paleOakPlanks);
11331133
addBlock("pale_oak_slab", (name, tag) -> slab(tag, Texture.paleOakPlanks));
11341134
addBlock("pale_oak_stairs", (name, tag) -> stairs(tag, Texture.paleOakPlanks));
1135-
addBlock("pale_oak_pressure_plate", (name, tag) -> new PressurePlate(name, Texture.sprucePlanks));
1135+
addBlock("pale_oak_pressure_plate", (name, tag) -> pressurePlate(tag, Texture.sprucePlanks));
11361136
addBlock("pale_oak_fence", (name, tag) -> fence(tag, Texture.paleOakPlanks));
11371137
addBlock("pale_oak_fence_gate", (name, tag) -> fenceGate(tag, Texture.paleOakPlanks));
11381138
addBlock("pale_oak_trapdoor", (name, tag) -> orientableTrapdoor(tag, Texture.paleOakTrapdoor));
@@ -1640,19 +1640,19 @@ public Block getBlockByTag(String namespacedName, Tag tag) {
16401640
case "lever":
16411641
return lever(tag);
16421642
case "stone_pressure_plate":
1643-
return new PressurePlate(name, Texture.stone);
1643+
return pressurePlate(tag, Texture.stone);
16441644
case "oak_pressure_plate":
1645-
return new PressurePlate(name, Texture.oakPlanks);
1645+
return pressurePlate(tag, Texture.oakPlanks);
16461646
case "spruce_pressure_plate":
1647-
return new PressurePlate(name, Texture.sprucePlanks);
1647+
return pressurePlate(tag, Texture.sprucePlanks);
16481648
case "birch_pressure_plate":
1649-
return new PressurePlate(name, Texture.birchPlanks);
1649+
return pressurePlate(tag, Texture.birchPlanks);
16501650
case "jungle_pressure_plate":
1651-
return new PressurePlate(name, Texture.jungleTreePlanks);
1651+
return pressurePlate(tag, Texture.jungleTreePlanks);
16521652
case "acacia_pressure_plate":
1653-
return new PressurePlate(name, Texture.acaciaPlanks);
1653+
return pressurePlate(tag, Texture.acaciaPlanks);
16541654
case "dark_oak_pressure_plate":
1655-
return new PressurePlate(name, Texture.darkOakPlanks);
1655+
return pressurePlate(tag, Texture.darkOakPlanks);
16561656
case "redstone_ore":
16571657
return new MinecraftBlock(name, Texture.redstoneOre);
16581658
case "redstone_torch":
@@ -1832,9 +1832,9 @@ public Block getBlockByTag(String namespacedName, Tag tag) {
18321832
case "trapped_chest":
18331833
return chest(tag, Chest.Kind.TRAPPED);
18341834
case "light_weighted_pressure_plate":
1835-
return new PressurePlate(name, Texture.goldBlock);
1835+
return pressurePlate(tag, Texture.goldBlock);
18361836
case "heavy_weighted_pressure_plate":
1837-
return new PressurePlate(name, Texture.ironBlock);
1837+
return pressurePlate(tag, Texture.ironBlock);
18381838
case "daylight_detector": {
18391839
String inverted = tag.get("Properties").get("inverted").stringValue("false");
18401840
return new DaylightDetector(inverted.equals("true"));
@@ -2846,9 +2846,9 @@ public Block getBlockByTag(String namespacedName, Tag tag) {
28462846
case "warped_planks":
28472847
return new MinecraftBlock(name, Texture.warpedPlanks);
28482848
case "crimson_pressure_plate":
2849-
return new PressurePlate(name, Texture.crimsonPlanks);
2849+
return pressurePlate(tag, Texture.crimsonPlanks);
28502850
case "warped_pressure_plate":
2851-
return new PressurePlate(name, Texture.warpedPlanks);
2851+
return pressurePlate(tag, Texture.warpedPlanks);
28522852
case "crimson_slab":
28532853
return slab(tag, Texture.crimsonPlanks);
28542854
case "warped_slab":
@@ -2926,7 +2926,7 @@ public Block getBlockByTag(String namespacedName, Tag tag) {
29262926
case "polished_blackstone_button":
29272927
return button(tag, Texture.polishedBlackstone);
29282928
case "polished_blackstone_pressure_plate":
2929-
return new PressurePlate(name, Texture.polishedBlackstone);
2929+
return pressurePlate(tag, Texture.polishedBlackstone);
29302930
case "quartz_bricks":
29312931
return new MinecraftBlock(name, Texture.quartzBricks);
29322932
case "chain": // < 25w35a
@@ -3584,12 +3584,13 @@ private Block vine(Tag tag) {
35843584

35853585
private Block tripwire(Tag tag) {
35863586
Tag properties = tag.get("Properties");
3587-
String north = properties.get("north").stringValue("false");
3588-
String south = properties.get("south").stringValue("false");
3589-
String east = properties.get("east").stringValue("false");
3590-
String west = properties.get("west").stringValue("false");
35913587
return new Tripwire(
3592-
north.equals("true"), south.equals("true"), east.equals("true"), west.equals("true"));
3588+
BlockProvider.stringToBoolean(properties.get("attached")),
3589+
BlockProvider.stringToBoolean(properties.get("north")),
3590+
BlockProvider.stringToBoolean(properties.get("south")),
3591+
BlockProvider.stringToBoolean(properties.get("east")),
3592+
BlockProvider.stringToBoolean(properties.get("west"))
3593+
);
35933594
}
35943595

35953596
private Block tripwireHook(Tag tag) {
@@ -3739,6 +3740,14 @@ private static Block copperBars(Tag tag, Texture texture) {
37393740
);
37403741
}
37413742

3743+
private static Block pressurePlate(Tag tag, Texture texture) {
3744+
return new PressurePlate(
3745+
BlockProvider.blockName(tag),
3746+
texture,
3747+
BlockProvider.stringToBoolean(tag.get("Properties").get("powered"))
3748+
);
3749+
}
3750+
37423751
private static Block nonSolid(Block block) {
37433752
block.solid = false;
37443753
return block;

chunky/src/java/se/llbit/chunky/block/minecraft/Observer.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,12 @@
2323
import se.llbit.chunky.resources.Texture;
2424

2525
public class Observer extends AbstractModelBlock {
26-
2726
private final String description;
2827

2928
public Observer(String facing, boolean powered) {
3029
super("observer", Texture.observerFront);
31-
this.description = String.format("facing=%s, powered=%s", facing, powered);
32-
int direction;
33-
switch (facing) {
34-
case "up":
35-
direction = 1;
36-
break;
37-
case "down":
38-
direction = 0;
39-
break;
40-
default:
41-
case "north":
42-
direction = 2;
43-
break;
44-
case "east":
45-
direction = 5;
46-
break;
47-
case "south":
48-
direction = 3;
49-
break;
50-
case "west":
51-
direction = 4;
52-
break;
53-
}
54-
this.model = new ObserverModel(direction, powered);
30+
description = String.format("facing=%s, powered=%s", facing, powered);
31+
model = new ObserverModel(facing, powered);
5532
opaque = true;
5633
}
5734

chunky/src/java/se/llbit/chunky/block/minecraft/PressurePlate.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@
2323
import se.llbit.chunky.resources.Texture;
2424

2525
public class PressurePlate extends AbstractModelBlock {
26+
private final String description;
2627

27-
public PressurePlate(String name, Texture texture) {
28+
public PressurePlate(String name, Texture texture, boolean powered) {
2829
super(name, texture);
29-
model = new PressurePlateModel(texture);
30+
model = new PressurePlateModel(texture, powered);
31+
description = String.format("powered=%s", powered);
32+
}
33+
34+
@Override
35+
public String description() {
36+
return description;
3037
}
3138
}

chunky/src/java/se/llbit/chunky/block/minecraft/Tripwire.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,18 @@
1818

1919
package se.llbit.chunky.block.minecraft;
2020

21-
import static se.llbit.chunky.world.BlockData.CONNECTED_EAST;
22-
import static se.llbit.chunky.world.BlockData.CONNECTED_NORTH;
23-
import static se.llbit.chunky.world.BlockData.CONNECTED_SOUTH;
24-
import static se.llbit.chunky.world.BlockData.CONNECTED_WEST;
25-
2621
import se.llbit.chunky.block.AbstractModelBlock;
2722
import se.llbit.chunky.model.minecraft.TripwireModel;
2823
import se.llbit.chunky.resources.Texture;
2924

3025
public class Tripwire extends AbstractModelBlock {
31-
3226
private final String description;
3327

34-
public Tripwire(boolean north, boolean south, boolean east, boolean west) {
28+
public Tripwire(boolean attached, boolean north, boolean south, boolean east, boolean west) {
3529
super("tripwire", Texture.tripwire);
36-
this.description = String.format("north=%s, south=%s, east=%s, west=%s",
37-
north, south, east, west);
38-
int connections = 0;
39-
if (north) {
40-
connections |= CONNECTED_NORTH;
41-
}
42-
if (south) {
43-
connections |= CONNECTED_SOUTH;
44-
}
45-
if (east) {
46-
connections |= CONNECTED_EAST;
47-
}
48-
if (west) {
49-
connections |= CONNECTED_WEST;
50-
}
51-
this.model = new TripwireModel(connections);
30+
description = String.format("attached=%s, north=%s, south=%s, east=%s, west=%s",
31+
attached, north, south, east, west);
32+
model = new TripwireModel(attached, north, south, east, west);
5233
}
5334

5435
@Override

chunky/src/java/se/llbit/chunky/model/minecraft/ObserverModel.java

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,73 +25,69 @@
2525
import se.llbit.math.Vector4;
2626

2727
public class ObserverModel extends QuadModel {
28-
29-
// Facing up:
30-
private static final Quad[] observer = new Quad[] {
31-
// Bottom face.
32-
new Quad(new Vector3(1, 0, 0), new Vector3(0, 0, 0), new Vector3(1, 1, 0),
33-
new Vector4(1, 0, 1, 0)),
34-
35-
// Top face.
36-
new Quad(new Vector3(0, 0, 1), new Vector3(1, 0, 1), new Vector3(0, 1, 1),
37-
new Vector4(0, 1, 1, 0)),
38-
39-
// West face.
40-
new Quad(new Vector3(0, 0, 0), new Vector3(0, 0, 1), new Vector3(0, 1, 0),
41-
new Vector4(0, 1, 0, 1)),
42-
43-
// East face.
44-
new Quad(new Vector3(1, 0, 1), new Vector3(1, 0, 0), new Vector3(1, 1, 1),
45-
new Vector4(1, 0, 0, 1)),
46-
47-
// Front face.
48-
new Quad(new Vector3(1, 1, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 1),
49-
new Vector4(1, 0, 0, 1)),
50-
51-
// Back face.
52-
new Quad(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1),
53-
new Vector4(0, 1, 0, 1)),
28+
private static final Quad[] quadsNorth = new Quad[]{
29+
new Quad(
30+
new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0),
31+
new Vector3(16 / 16.0, 16 / 16.0, 16 / 16.0),
32+
new Vector3(0 / 16.0, 16 / 16.0, 0 / 16.0),
33+
new Vector4(0 / 16.0, 16 / 16.0, 16 / 16.0, 0 / 16.0)
34+
),
35+
new Quad(
36+
new Vector3(0 / 16.0, 0 / 16.0, 0 / 16.0),
37+
new Vector3(16 / 16.0, 0 / 16.0, 0 / 16.0),
38+
new Vector3(0 / 16.0, 0 / 16.0, 16 / 16.0),
39+
new Vector4(0 / 16.0, 16 / 16.0, 0 / 16.0, 16 / 16.0)
40+
),
41+
new Quad(
42+
new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0),
43+
new Vector3(0 / 16.0, 16 / 16.0, 0 / 16.0),
44+
new Vector3(0 / 16.0, 0 / 16.0, 16 / 16.0),
45+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
46+
),
47+
new Quad(
48+
new Vector3(16 / 16.0, 16 / 16.0, 0 / 16.0),
49+
new Vector3(16 / 16.0, 16 / 16.0, 16 / 16.0),
50+
new Vector3(16 / 16.0, 0 / 16.0, 0 / 16.0),
51+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
52+
),
53+
new Quad(
54+
new Vector3(0 / 16.0, 16 / 16.0, 0 / 16.0),
55+
new Vector3(16 / 16.0, 16 / 16.0, 0 / 16.0),
56+
new Vector3(0 / 16.0, 0 / 16.0, 0 / 16.0),
57+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
58+
),
59+
new Quad(
60+
new Vector3(16 / 16.0, 16 / 16.0, 16 / 16.0),
61+
new Vector3(0 / 16.0, 16 / 16.0, 16 / 16.0),
62+
new Vector3(16 / 16.0, 0 / 16.0, 16 / 16.0),
63+
new Vector4(16 / 16.0, 0 / 16.0, 16 / 16.0, 0 / 16.0)
64+
)
5465
};
5566

56-
private static final Quad[][] faces = new Quad[8][];
57-
58-
static {
59-
// Rotate faces for all directions.
60-
faces[1] = observer;
61-
Quad[] temp = Model.rotateX(observer);
62-
// Facing down:
63-
faces[0] = Model.rotateX(temp);
64-
// Facing north:
65-
faces[2] = Model.rotateX(faces[0]);
66-
// Facing east:
67-
faces[5] = Model.rotateY(faces[2]);
68-
// Facing south:
69-
faces[3] = Model.rotateY(faces[5]);
70-
// Facing west:
71-
faces[4] = Model.rotateY(faces[3]);
72-
// Facing down:
73-
faces[6] = faces[1];
74-
// Facing up:
75-
faces[7] = observer;
76-
}
77-
7867
private static final Texture[] texturesOff = {
79-
Texture.observerTop, Texture.observerTop,
80-
Texture.observerSide, Texture.observerSide,
81-
Texture.observerFront, Texture.observerBack
68+
Texture.observerTop, Texture.observerTop,
69+
Texture.observerSide, Texture.observerSide,
70+
Texture.observerFront, Texture.observerBack
8271
};
8372

8473
private static final Texture[] texturesOn = {
85-
Texture.observerTop, Texture.observerTop,
86-
Texture.observerSide, Texture.observerSide,
87-
Texture.observerFront, Texture.observerBackOn
74+
Texture.observerTop, Texture.observerTop,
75+
Texture.observerSide, Texture.observerSide,
76+
Texture.observerFront, Texture.observerBackOn
8877
};
8978

9079
private final Quad[] quads;
9180
private final Texture[] textures;
9281

93-
public ObserverModel(int facing, boolean powered) {
94-
quads = faces[facing];
82+
public ObserverModel(String facing, boolean powered) {
83+
quads = switch (facing) {
84+
case "down" -> Model.rotateNegX(quadsNorth);
85+
case "east" -> Model.rotateY(quadsNorth);
86+
case "south" -> Model.rotateY(quadsNorth, Math.toRadians(180));
87+
case "up" -> Model.rotateX(quadsNorth);
88+
case "west" -> Model.rotateNegY(quadsNorth);
89+
default -> quadsNorth;
90+
};
9591
textures = powered ? texturesOn : texturesOff;
9692
}
9793

0 commit comments

Comments
 (0)