Skip to content

Commit

Permalink
Split between forge & fabric
Browse files Browse the repository at this point in the history
Should fix #1
  • Loading branch information
FxMorin committed Jan 7, 2023
1 parent 8558d2a commit 99686a4
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"package": "ca.fxco.RailOptimization.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"PoweredRailBlockMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ca.fxco.RailOptimization.fabric.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public interface PoweredRailBlockInvoker {

boolean invokeFindPoweredRailSignal(Level level, BlockPos pos, BlockState state, boolean bl, int distance);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ca.fxco.RailOptimization.fabric.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.PoweredRailBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import static ca.fxco.RailOptimization.RailLogic.customUpdateState;

@Mixin(value = PoweredRailBlock.class, priority = 990)
public abstract class PoweredRailBlockMixin implements PoweredRailBlockInvoker {

@Shadow
protected boolean findPoweredRailSignal(Level Level, BlockPos pos, BlockState state, boolean bl, int distance) {
throw new UnsupportedOperationException();
}

/**
* @author FX
* @reason Required to implement faster alternative
*/
@Overwrite
protected void updateState(BlockState state, Level level, BlockPos pos, Block block) {
customUpdateState((PoweredRailBlock)(Object)this, state, level, pos);
}

@Override
public boolean invokeFindPoweredRailSignal(Level level, BlockPos pos, BlockState state, boolean bl, int distance) {
return this.findPoweredRailSignal(level, pos, state, bl, distance);
}
}
3 changes: 2 additions & 1 deletion fabric/src/main/resources/rail_optimization.mixins.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"required": true,
"minVersion": "0.8",
"package": "ca.fxco.RailOptimization.mixin.fabric",
"package": "ca.fxco.RailOptimization.fabric.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"PoweredRailBlockMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ca.fxco.RailOptimization.mixin;
package ca.fxco.RailOptimization.forge.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ca.fxco.RailOptimization.mixin;
package ca.fxco.RailOptimization.forge.mixin;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
Expand All @@ -9,7 +9,7 @@
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import static ca.fxco.RailOptimization.RailLogic.*;
import static ca.fxco.RailOptimization.RailLogic.customUpdateState;

@Mixin(value = PoweredRailBlock.class, priority = 990)
public abstract class PoweredRailBlockMixin implements PoweredRailBlockInvoker {
Expand Down
3 changes: 2 additions & 1 deletion forge/src/main/resources/rail_optimization.mixins.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"required": true,
"minVersion": "0.8",
"package": "ca.fxco.RailOptimization.mixin.forge",
"package": "ca.fxco.RailOptimization.forge.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"PoweredRailBlockMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 99686a4

Please sign in to comment.