-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change: RailPlacement without updates
- Loading branch information
Showing
4 changed files
with
72 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package mendedminecarts; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class RailPlacementHelper { | ||
public static final ThreadLocal<BlockPos> NO_CONNECT_POS = new ThreadLocal<>(); | ||
|
||
} |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/mendedminecarts/mixin/placement/DetectorRailBlockMixin.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,34 @@ | ||
package mendedminecarts.mixin.placement; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.DetectorRailBlock; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import static mendedminecarts.RailPlacementHelper.NO_CONNECT_POS; | ||
|
||
@Mixin(DetectorRailBlock.class) | ||
public abstract class DetectorRailBlockMixin { | ||
|
||
@Shadow protected abstract void updatePoweredStatus(World world, BlockPos pos, BlockState state); | ||
|
||
@Inject( | ||
method = "onBlockAdded", at = @At("HEAD"), cancellable = true | ||
) | ||
private void cancelUpdates(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify, CallbackInfo ci) { | ||
BlockPos noUpdatePos = NO_CONNECT_POS.get(); | ||
if (pos.equals(noUpdatePos)) { | ||
ci.cancel(); | ||
this.updatePoweredStatus(world, pos, state); | ||
} | ||
|
||
if (noUpdatePos != null) { | ||
NO_CONNECT_POS.set(null); | ||
} | ||
} | ||
} |
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