-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Force Relay/Lens movement logic for block structures (#4510)
(fixes #3917, #4411, and #4509) - fix pushing the wrong way if Force Relay is part of a retracting sticky piston's block structure - don't assume that the location where the force push seemingly originates from contains an unmovable block - updated/expanded tests to cover movement behavior in (potentially nested) block structures or with sticky pistons
- Loading branch information
1 parent
9426b0f
commit 3d9b50a
Showing
12 changed files
with
259 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
public net.minecraft.client.gui.screens.worldselection.WorldPreset <init>(Ljava/lang/String;)V | ||
public net.minecraft.client.renderer.RenderType$CompositeRenderType | ||
public net.minecraft.core.registries.BuiltInRegistries$RegistryBootstrap | ||
private-f net.minecraft.world.level.block.piston.PistonStructureResolver pistonPos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 36 additions & 6 deletions
42
Xplat/src/main/java/vazkii/botania/common/helper/ForcePushHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,50 @@ | ||
package vazkii.botania.common.helper; | ||
|
||
import org.apache.commons.lang3.mutable.MutableInt; | ||
import net.minecraft.core.BlockPos; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
|
||
public class ForcePushHelper implements AutoCloseable { | ||
private static final ThreadLocal<MutableInt> forcePushCounter = ThreadLocal.withInitial(MutableInt::new); | ||
/** | ||
* Keeps track of push origins for nested force relay moves. | ||
*/ | ||
private static final ThreadLocal<Deque<BlockPos>> forcePushOriginStack = ThreadLocal.withInitial(ArrayDeque::new); | ||
|
||
/** | ||
* Keeps track of nested block push movement types (extending=true or retracting=false). | ||
*/ | ||
private static final ThreadLocal<Deque<Boolean>> movementTypeContextStack = ThreadLocal.withInitial(ArrayDeque::new); | ||
|
||
public static boolean isForcePush() { | ||
return forcePushCounter.get().intValue() > 0; | ||
return !forcePushOriginStack.get().isEmpty(); | ||
} | ||
|
||
public static BlockPos getForcePushOrigin() { | ||
if (!isForcePush()) { | ||
throw new IllegalStateException("Not currently performing a Force Relay or Force Lens push"); | ||
} | ||
return forcePushOriginStack.get().peek(); | ||
} | ||
|
||
public static void pushMovementTypeContext(boolean extending) { | ||
movementTypeContextStack.get().push(extending); | ||
} | ||
|
||
public static void popMovementTypeContext() { | ||
movementTypeContextStack.get().pop(); | ||
} | ||
|
||
public static boolean isExtendingMovementContext() { | ||
return movementTypeContextStack.get().peek() == Boolean.TRUE; | ||
} | ||
|
||
public ForcePushHelper() { | ||
forcePushCounter.get().increment(); | ||
public ForcePushHelper(BlockPos pushLocation) { | ||
forcePushOriginStack.get().push(pushLocation.immutable()); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
forcePushCounter.get().decrement(); | ||
forcePushOriginStack.get().pop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
Xplat/src/main/java/vazkii/botania/mixin/PistonStructureResolverMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package vazkii.botania.mixin; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.piston.PistonStructureResolver; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.*; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import vazkii.botania.common.helper.ForcePushHelper; | ||
|
||
@Mixin(value = PistonStructureResolver.class) | ||
public class PistonStructureResolverMixin { | ||
// not final, due to access widener/transformer definition: | ||
@SuppressWarnings("ShadowModifiers") | ||
@Shadow | ||
private BlockPos pistonPos; | ||
|
||
/** | ||
* Since the pushing piston block is handled separately via its position, | ||
* replace it with the force relay's position when pushing blocks that way. | ||
*/ | ||
@Inject(method = "<init>", at = @At(value = "RETURN")) | ||
private void modifyForcePushOrigin(Level level, BlockPos pistonPos, Direction pistonDirection, boolean extending, CallbackInfo ci) { | ||
this.pistonPos = ForcePushHelper.isForcePush() ? ForcePushHelper.getForcePushOrigin() : pistonPos; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...in/resources/data/botania/gametest/structures/block/piston_relay_sticky_move_no_pull.snbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
DataVersion: 3465, | ||
size: [5, 3, 6], | ||
data: [ | ||
{pos: [1, 1, 0], state: "minecraft:polished_blackstone_button{face:wall,facing:north,powered:false}"}, | ||
{pos: [1, 1, 1], state: "minecraft:sticky_piston{extended:false,facing:south}"}, | ||
{pos: [1, 1, 2], state: "botania:piston_relay"}, | ||
{pos: [1, 1, 4], state: "minecraft:piston{extended:false,facing:north}"}, | ||
{pos: [1, 1, 5], state: "minecraft:polished_blackstone_button{face:wall,facing:south,powered:false}"}, | ||
{pos: [3, 1, 3], state: "minecraft:polished_granite"} | ||
], | ||
entities: [], | ||
palette: [ | ||
"minecraft:sticky_piston{extended:false,facing:south}", | ||
"botania:piston_relay", | ||
"minecraft:piston{extended:false,facing:north}", | ||
"minecraft:polished_granite", | ||
"minecraft:polished_blackstone_button{face:wall,facing:north,powered:false}", | ||
"minecraft:polished_blackstone_button{face:wall,facing:south,powered:false}" | ||
] | ||
} |
31 changes: 31 additions & 0 deletions
31
...rc/main/resources/data/botania/gametest/structures/block/piston_relay_structure_pull.snbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
DataVersion: 3465, | ||
size: [7, 5, 7], | ||
data: [ | ||
{pos: [0, 1, 1], state: "minecraft:polished_blackstone_button{face:wall,facing:west,powered:false}"}, | ||
{pos: [1, 1, 1], state: "minecraft:sticky_piston{extended:false,facing:east}"}, | ||
{pos: [2, 1, 1], state: "minecraft:slime_block"}, | ||
{pos: [2, 1, 2], state: "minecraft:polished_diorite"}, | ||
{pos: [2, 1, 4], state: "minecraft:slime_block"}, | ||
{pos: [2, 1, 5], state: "minecraft:polished_granite"}, | ||
{pos: [3, 1, 1], state: "minecraft:slime_block"}, | ||
{pos: [3, 1, 2], state: "botania:piston_relay"}, | ||
{pos: [3, 1, 4], state: "minecraft:slime_block"}, | ||
{pos: [3, 1, 5], state: "botania:piston_relay"}, | ||
{pos: [4, 1, 1], state: "minecraft:slime_block"}, | ||
{pos: [4, 1, 2], state: "minecraft:polished_diorite"}, | ||
{pos: [4, 1, 4], state: "minecraft:slime_block"}, | ||
{pos: [4, 1, 5], state: "minecraft:polished_granite"}, | ||
{pos: [3, 3, 3], state: "minecraft:polished_andesite"} | ||
], | ||
entities: [], | ||
palette: [ | ||
"minecraft:sticky_piston{extended:false,facing:east}", | ||
"minecraft:slime_block", | ||
"minecraft:polished_diorite", | ||
"minecraft:polished_granite", | ||
"botania:piston_relay", | ||
"minecraft:polished_andesite", | ||
"minecraft:polished_blackstone_button{face:wall,facing:west,powered:false}" | ||
] | ||
} |