-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2c28bf
commit eff1565
Showing
15 changed files
with
230 additions
and
42 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
64 changes: 32 additions & 32 deletions
64
fabric/src/main/java/ziyue/tjmetro/fabric/mixin/FallingBlockMixin.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,32 +1,32 @@ | ||
//package ziyue.tjmetro.fabric.mixin; | ||
// | ||
//import net.minecraft.block.Block; | ||
//import net.minecraft.block.BlockState; | ||
//import net.minecraft.block.FallingBlock; | ||
//import net.minecraft.server.world.ServerWorld; | ||
//import net.minecraft.util.math.BlockPos; | ||
//import org.spongepowered.asm.mixin.Mixin; | ||
//import org.spongepowered.asm.mixin.injection.At; | ||
//import org.spongepowered.asm.mixin.injection.Inject; | ||
//import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
//import ziyue.tjmetro.mapping.BooleanGameRule; | ||
//import ziyue.tjmetro.mod.TianjinMetro; | ||
// | ||
//@Mixin(FallingBlock.class) | ||
//public abstract class FallingBlockMixin extends Block | ||
//{ | ||
// public FallingBlockMixin(Settings settings) { | ||
// super(settings); | ||
// } | ||
// | ||
// @Inject(at = @At("HEAD"), method = "scheduledTick", cancellable = true) | ||
//#if MC_VERSION < "11904" | ||
// private void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, java.util.Random random, CallbackInfo ci) | ||
//#else | ||
// private void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, net.minecraft.util.math.random.Random random, CallbackInfo ci) | ||
//#endif | ||
// { | ||
// if (BooleanGameRule.getValue(new org.mtr.mapping.holder.ServerWorld(world), TianjinMetro.NO_FALLING_BLOCK)) | ||
// ci.cancel(); | ||
// } | ||
//} | ||
package ziyue.tjmetro.fabric.mixin; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.FallingBlock; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPos; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import ziyue.tjmetro.mapping.BooleanGameRule; | ||
import ziyue.tjmetro.mod.TianjinMetro; | ||
|
||
@Mixin(FallingBlock.class) | ||
public abstract class FallingBlockMixin extends Block | ||
{ | ||
public FallingBlockMixin(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "scheduledTick", cancellable = true) | ||
#if MC_VERSION < "11904" | ||
private void beforeScheduledTick(BlockState state, ServerWorld world, BlockPos pos, java.util.Random random, CallbackInfo ci) | ||
#else | ||
private void beforeScheduledTick(BlockState state, ServerWorld world, BlockPos pos, net.minecraft.util.math.random.Random random, CallbackInfo ci) | ||
#endif | ||
{ | ||
if (BooleanGameRule.getValue(new org.mtr.mapping.holder.ServerWorld(world), TianjinMetro.NO_FALLING_BLOCK)) | ||
ci.cancel(); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
forge/src/main/java/ziyue/tjmetro/forge/mixin/ATGameRuleBooleanMixin.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,47 @@ | ||
package ziyue.tjmetro.forge.mixin; | ||
|
||
// Dumb accessTransformer can't do anything. | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import ziyue.tjmetro.forge.property.PropertyCreateBooleanGameRule; | ||
|
||
#if MC_VERSION <= "11605" | ||
import net.minecraft.world.GameRules; | ||
@Mixin(GameRules.BooleanValue.class) | ||
public abstract class ATGameRuleBooleanMixin extends GameRules.RuleValue<GameRules.BooleanValue> implements PropertyCreateBooleanGameRule | ||
{ | ||
@Shadow | ||
private static GameRules.RuleType<GameRules.BooleanValue> create(boolean p_223568_0_) { | ||
return null; | ||
} | ||
|
||
public ATGameRuleBooleanMixin(GameRules.RuleType<GameRules.BooleanValue> p_i51530_1_) { | ||
super(p_i51530_1_); | ||
} | ||
|
||
@Override | ||
public GameRules.RuleType<GameRules.BooleanValue> createBoolean(boolean value) { | ||
return create(value); | ||
} | ||
} | ||
#else | ||
import net.minecraft.world.level.GameRules; | ||
@Mixin(GameRules.BooleanValue.class) | ||
public abstract class ATGameRuleBooleanMixin extends GameRules.Value<GameRules.BooleanValue> implements PropertyCreateBooleanGameRule | ||
{ | ||
@Shadow | ||
static GameRules.Type<GameRules.BooleanValue> create(boolean p_46251_) { | ||
return null; | ||
} | ||
|
||
public ATGameRuleBooleanMixin(GameRules.Type<GameRules.BooleanValue> p_46362_) { | ||
super(p_46362_); | ||
} | ||
|
||
@Override | ||
public GameRules.Type<GameRules.BooleanValue> createBoolean(boolean value) { | ||
return create(value); | ||
} | ||
} | ||
#endif |
56 changes: 56 additions & 0 deletions
56
forge/src/main/java/ziyue/tjmetro/forge/mixin/FallingBlockMixin.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,56 @@ | ||
package ziyue.tjmetro.forge.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import ziyue.tjmetro.mod.TianjinMetro; | ||
|
||
#if MC_VERSION <= "11605" | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.FallingBlock; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.server.ServerWorld; | ||
import java.util.Random; | ||
|
||
@Mixin(FallingBlock.class) | ||
public abstract class FallingBlockMixin extends Block | ||
{ | ||
public FallingBlockMixin(Properties p_i48440_1_) { | ||
super(p_i48440_1_); | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "tick", cancellable = true) | ||
private void beforeTick(BlockState p_225534_1_, ServerWorld world, BlockPos p_225534_3_, Random p_225534_4_, CallbackInfo ci) { | ||
if (world.getGameRules().getBoolean(TianjinMetro.NO_FALLING_BLOCK.data)) ci.cancel(); | ||
} | ||
} | ||
#else | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Fallable; | ||
import net.minecraft.world.level.block.FallingBlock; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
import java.util.Random; | ||
|
||
@Mixin(FallingBlock.class) | ||
public abstract class FallingBlockMixin extends Block implements Fallable | ||
{ | ||
public FallingBlockMixin(Properties p_49795_) { | ||
super(p_49795_); | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "tick", cancellable = true) | ||
#if MC_VERSION >= "11802" | ||
private void beforeTick(BlockState p_221124_, ServerLevel world, BlockPos p_221126_, net.minecraft.util.RandomSource p_221127_, CallbackInfo ci) | ||
#else | ||
private void beforeTick(BlockState p_53216_, ServerLevel world, BlockPos p_53218_, Random p_53219_, CallbackInfo ci) | ||
#endif | ||
{ | ||
if (world.getGameRules().getBoolean(TianjinMetro.NO_FALLING_BLOCK.data)) ci.cancel(); | ||
} | ||
} | ||
#endif |
17 changes: 17 additions & 0 deletions
17
forge/src/main/java/ziyue/tjmetro/forge/property/PropertyCreateBooleanGameRule.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,17 @@ | ||
package ziyue.tjmetro.forge.property; | ||
|
||
#if MC_VERSION <= "11605" | ||
import net.minecraft.world.GameRules; | ||
|
||
public interface PropertyCreateBooleanGameRule | ||
{ | ||
GameRules.RuleType<GameRules.BooleanValue> createBoolean(boolean value); | ||
} | ||
#else | ||
import net.minecraft.world.level.GameRules; | ||
|
||
public interface PropertyCreateBooleanGameRule | ||
{ | ||
GameRules.Type<GameRules.BooleanValue> createBoolean(boolean value); | ||
} | ||
#endif |
32 changes: 32 additions & 0 deletions
32
forge/src/main/java/ziyue/tjmetro/mapping/BooleanGameRule.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,32 @@ | ||
package ziyue.tjmetro.mapping; | ||
|
||
import org.mtr.mapping.holder.ServerWorld; | ||
import org.mtr.mapping.tool.HolderBase; | ||
|
||
#if MC_VERSION <= "11605" | ||
import net.minecraft.world.GameRules; | ||
|
||
public class BooleanGameRule extends HolderBase<GameRules.RuleKey<GameRules.BooleanValue>> | ||
{ | ||
public BooleanGameRule(GameRules.RuleKey<GameRules.BooleanValue> data) { | ||
super(data); | ||
} | ||
|
||
public static boolean getValue(ServerWorld world, BooleanGameRule rule) { | ||
return world.data.getGameRules().getBoolean(rule.data); | ||
} | ||
} | ||
#else | ||
import net.minecraft.world.level.GameRules; | ||
|
||
public class BooleanGameRule extends HolderBase<GameRules.Key<GameRules.BooleanValue>> | ||
{ | ||
public BooleanGameRule(GameRules.Key<GameRules.BooleanValue> data) { | ||
super(data); | ||
} | ||
|
||
public static boolean getValue(ServerWorld world, BooleanGameRule rule) { | ||
return world.data.getGameRules().getBoolean(rule.data); | ||
} | ||
} | ||
#endif |
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
16 changes: 16 additions & 0 deletions
16
forge/src/main/java/ziyue/tjmetro/mapping/GameRuleRegistry.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,16 @@ | ||
package ziyue.tjmetro.mapping; | ||
|
||
#if MC_VERSION <= "11605" | ||
import net.minecraft.world.GameRules; | ||
#else | ||
import net.minecraft.world.level.GameRules; | ||
#endif | ||
import net.minecraft.world.GameRules; | ||
import ziyue.tjmetro.forge.property.PropertyCreateBooleanGameRule; | ||
|
||
public class GameRuleRegistry | ||
{ | ||
public static BooleanGameRule registerBoolean(String name, boolean defaultValue) { | ||
return new BooleanGameRule(GameRules.register(name, GameRules.Category.MISC, ((PropertyCreateBooleanGameRule)new GameRules.BooleanValue(null, false)).createBoolean(defaultValue))); | ||
} | ||
} |
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,16 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8", | ||
"package": "ziyue.tjmetro.forge.mixin", | ||
"compatibilityLevel": "JAVA_8", | ||
"mixins": [ | ||
"ATGameRuleBooleanMixin", | ||
"FallingBlockMixin" | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"client": [ | ||
], | ||
"refmap": "tjmetro-forge.refmap.json" | ||
} |
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