Skip to content

Commit 20bc455

Browse files
committed
Fixed the orientation of RS Blocks when they are loaded from a structure block. #BlameRS
1 parent 9cf6e2a commit 20bc455

File tree

5 files changed

+164
-6
lines changed

5 files changed

+164
-6
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ minecraft {
171171
property 'forge.enabledGameTestNamespaces', 'advancedperipherals,advancedperipheralstest'
172172
property 'advancedperipheralstest.sources', file("src/testMod/resources/data/advancedperipheralstest").absolutePath
173173

174+
args "--mixin.config=ccgametest.mixins.json"
174175
args "--mixin.config=advancedperipheralstest.mixins.json"
175176

176177
mods {
@@ -202,6 +203,7 @@ minecraft {
202203
property 'forge.enabledGameTestNamespaces', 'advancedperipherals,advancedperipheralstest'
203204
property 'advancedperipheralstest.sources', file("src/testMod/resources/data/advancedperipheralstest").absolutePath
204205

206+
args "--mixin.config=ccgametest.mixins.json"
205207
args "--mixin.config=advancedperipheralstest.mixins.json"
206208
parent runs.server
207209

mixin.patch

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
diff --git a/build.gradle b/build.gradle
2+
index c66075c7..d2d3e930 100644
3+
--- a/build.gradle
4+
+++ b/build.gradle
5+
@@ -171,6 +171,7 @@ minecraft {
6+
property 'forge.enabledGameTestNamespaces', 'advancedperipherals,advancedperipheralstest'
7+
property 'advancedperipheralstest.sources', file("src/testMod/resources/data/advancedperipheralstest").absolutePath
8+
9+
+ args "--mixin.config=ccgametest.mixins.json"
10+
args "--mixin.config=advancedperipheralstest.mixins.json"
11+
12+
mods {
13+
@@ -202,6 +203,7 @@ minecraft {
14+
property 'forge.enabledGameTestNamespaces', 'advancedperipherals,advancedperipheralstest'
15+
property 'advancedperipheralstest.sources', file("src/testMod/resources/data/advancedperipheralstest").absolutePath
16+
17+
+ args "--mixin.config=ccgametest.mixins.json"
18+
args "--mixin.config=advancedperipheralstest.mixins.json"
19+
parent runs.server
20+
21+
diff --git a/src/testMod/java/de/srendi/advancedperipherals/test/mixin/RsBaseBlockMixin.java b/src/testMod/java/de/srendi/advancedperipherals/test/mixin/RsBaseBlockMixin.java
22+
new file mode 100644
23+
index 00000000..eaef15c4
24+
--- /dev/null
25+
+++ b/src/testMod/java/de/srendi/advancedperipherals/test/mixin/RsBaseBlockMixin.java
26+
@@ -0,0 +1,35 @@
27+
+package de.srendi.advancedperipherals.test.mixin;
28+
+
29+
+import com.refinedmods.refinedstorage.block.BaseBlock;
30+
+import com.refinedmods.refinedstorage.block.BlockDirection;
31+
+import net.minecraft.core.Direction;
32+
+import net.minecraft.world.level.block.Rotation;
33+
+import net.minecraft.world.level.block.state.BlockState;
34+
+import org.spongepowered.asm.mixin.Mixin;
35+
+import org.spongepowered.asm.mixin.Overwrite;
36+
+import org.spongepowered.asm.mixin.Shadow;
37+
+
38+
+@Mixin(BaseBlock.class)
39+
+public class RsBaseBlockMixin {
40+
+
41+
+ @Shadow
42+
+ public BlockDirection getDirection() {
43+
+ return null;
44+
+ }
45+
+
46+
+ @Overwrite
47+
+ public BlockState rotate(BlockState state, Rotation rot) {
48+
+ BlockDirection dir = this.getDirection();
49+
+ if (dir == BlockDirection.NONE) return state;
50+
+
51+
+ Direction newDirection = switch (rot) {
52+
+ case NONE -> state.getValue(dir.getProperty());
53+
+ case CLOCKWISE_90 -> dir.cycle(state.getValue(dir.getProperty()).getClockWise().getClockWise());
54+
+ case CLOCKWISE_180 -> dir.cycle(state.getValue(dir.getProperty()).getClockWise().getClockWise().getClockWise());
55+
+ case COUNTERCLOCKWISE_90 -> dir.cycle(state.getValue(dir.getProperty()));
56+
+ };
57+
+
58+
+ return state.setValue(dir.getProperty(), newDirection);
59+
+ }
60+
+
61+
+}
62+
diff --git a/src/testMod/resources/advancedperipheralstest.mixins.json b/src/testMod/resources/advancedperipheralstest.mixins.json
63+
index 76ac7799..782eaa71 100644
64+
--- a/src/testMod/resources/advancedperipheralstest.mixins.json
65+
+++ b/src/testMod/resources/advancedperipheralstest.mixins.json
66+
@@ -1,16 +1,12 @@
67+
{
68+
"required": true,
69+
- "package": "dan200.computercraft.mixin.gametest",
70+
+ "package": "de.srendi.advancedperipherals.test.mixin",
71+
"minVersion": "0.8",
72+
"compatibilityLevel": "JAVA_17",
73+
"injectors": {
74+
"defaultRequire": 1
75+
},
76+
"mixins": [
77+
- "GameTestHelperAccessor",
78+
- "GameTestInfoAccessor",
79+
- "GameTestSequenceAccessor",
80+
- "GameTestSequenceMixin",
81+
- "TestCommandAccessor"
82+
+ "RsBaseBlockMixin"
83+
]
84+
}
85+
diff --git a/src/testMod/resources/ccgametest.mixins.json b/src/testMod/resources/ccgametest.mixins.json
86+
new file mode 100644
87+
index 00000000..76ac7799
88+
--- /dev/null
89+
+++ b/src/testMod/resources/ccgametest.mixins.json
90+
@@ -0,0 +1,16 @@
91+
+{
92+
+ "required": true,
93+
+ "package": "dan200.computercraft.mixin.gametest",
94+
+ "minVersion": "0.8",
95+
+ "compatibilityLevel": "JAVA_17",
96+
+ "injectors": {
97+
+ "defaultRequire": 1
98+
+ },
99+
+ "mixins": [
100+
+ "GameTestHelperAccessor",
101+
+ "GameTestInfoAccessor",
102+
+ "GameTestSequenceAccessor",
103+
+ "GameTestSequenceMixin",
104+
+ "TestCommandAccessor"
105+
+ ]
106+
+}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package de.srendi.advancedperipherals.test.mixin;
2+
3+
import com.refinedmods.refinedstorage.block.BaseBlock;
4+
import com.refinedmods.refinedstorage.block.BlockDirection;
5+
import net.minecraft.core.Direction;
6+
import net.minecraft.world.level.block.Rotation;
7+
import net.minecraft.world.level.block.state.BlockState;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.Overwrite;
10+
import org.spongepowered.asm.mixin.Shadow;
11+
12+
/**
13+
* Used to fix the orientation of RS Blocks when they are loaded from a structure block.
14+
*/
15+
@Mixin(BaseBlock.class)
16+
public class RsBaseBlockMixin {
17+
18+
@Shadow
19+
public BlockDirection getDirection() {
20+
return null;
21+
}
22+
23+
@Overwrite
24+
public BlockState rotate(BlockState state, Rotation rot) {
25+
BlockDirection dir = this.getDirection();
26+
if (dir == BlockDirection.NONE) return state;
27+
28+
Direction newDirection = switch (rot) {
29+
case NONE -> state.getValue(dir.getProperty());
30+
case CLOCKWISE_90 -> dir.cycle(state.getValue(dir.getProperty()).getClockWise().getClockWise());
31+
case CLOCKWISE_180 -> dir.cycle(state.getValue(dir.getProperty()).getClockWise().getClockWise().getClockWise());
32+
case COUNTERCLOCKWISE_90 -> dir.cycle(state.getValue(dir.getProperty()));
33+
};
34+
35+
return state.setValue(dir.getProperty(), newDirection);
36+
}
37+
38+
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
{
22
"required": true,
3-
"package": "dan200.computercraft.mixin.gametest",
3+
"package": "de.srendi.advancedperipherals.test.mixin",
44
"minVersion": "0.8",
55
"compatibilityLevel": "JAVA_17",
66
"injectors": {
77
"defaultRequire": 1
88
},
99
"mixins": [
10-
"GameTestHelperAccessor",
11-
"GameTestInfoAccessor",
12-
"GameTestSequenceAccessor",
13-
"GameTestSequenceMixin",
14-
"TestCommandAccessor"
10+
"RsBaseBlockMixin"
1511
]
1612
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"required": true,
3+
"package": "dan200.computercraft.mixin.gametest",
4+
"minVersion": "0.8",
5+
"compatibilityLevel": "JAVA_17",
6+
"injectors": {
7+
"defaultRequire": 1
8+
},
9+
"mixins": [
10+
"GameTestHelperAccessor",
11+
"GameTestInfoAccessor",
12+
"GameTestSequenceAccessor",
13+
"GameTestSequenceMixin",
14+
"TestCommandAccessor"
15+
]
16+
}

0 commit comments

Comments
 (0)