-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix player placed rails trying to connect to partially connected stra…
…ight rails
- Loading branch information
Showing
6 changed files
with
68 additions
and
13 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
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
49 changes: 49 additions & 0 deletions
49
src/main/java/no2/railplacementfix/mixin/RailStateMixin.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,49 @@ | ||
package no2.railplacementfix.mixin; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.RailState; | ||
import no2.railplacementfix.RailPlacementFix; | ||
import no2.railplacementfix.common.RailPlacementHelper; | ||
import org.spongepowered.asm.mixin.Final; | ||
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.CallbackInfoReturnable; | ||
|
||
import java.util.List; | ||
|
||
@Mixin(RailState.class) | ||
public abstract class RailStateMixin { | ||
|
||
@Shadow protected abstract boolean connectsTo(RailState railState); | ||
|
||
@Shadow @Final private List<BlockPos> connections; | ||
|
||
@Shadow @Final private boolean isStraight; | ||
|
||
@Shadow public abstract List<BlockPos> getConnections(); | ||
|
||
@Shadow @Final private BlockPos pos; | ||
|
||
|
||
@Inject( | ||
method = "canConnectTo", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Ljava/util/List;size()I" | ||
), cancellable = true | ||
) | ||
private void canConnectTo(RailState railState, CallbackInfoReturnable<Boolean> cir) { | ||
BlockPos neighborPos = ((RailStateMixin) (Object) railState).pos; | ||
if (neighborPos.equals(RailPlacementHelper.PLAYER_PLACED_POS.get()) && this.isStraight) { | ||
if (this.connections.size() == 1) { | ||
BlockPos possible_connection = this.pos.offset(this.pos.subtract(this.connections.get(0))); | ||
if (neighborPos.getX() != (possible_connection.getX()) || | ||
neighborPos.getZ() != (possible_connection.getZ())) { | ||
cir.setReturnValue(false); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,10 +1,11 @@ | ||
{ | ||
"required": true, | ||
"package": "no2.railplacementfix.mixin", | ||
"mixins": [ | ||
"BaseRailBlockMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
"required": true, | ||
"package": "no2.railplacementfix.mixin", | ||
"mixins": [ | ||
"BaseRailBlockMixin", | ||
"RailStateMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |