Browse Source

Make it do the slime things

master
Colin Reeder 3 years ago
parent
commit
e1958bbbf1
3 changed files with 44 additions and 4 deletions
  1. +1
    -3
      src/main/java/click/vpzom/coloredslime/mixin/PistonBlockEntityMixin.java
  2. +42
    -0
      src/main/java/click/vpzom/coloredslime/mixin/PistonHandlerMixin.java
  3. +1
    -1
      src/main/resources/coloredslime.mixins.json

+ 1
- 3
src/main/java/click/vpzom/coloredslime/mixin/PistonBlockEntityMixin.java View File

@@ -5,9 +5,7 @@ import net.minecraft.block.SlimeBlock;
import net.minecraft.block.entity.PistonBlockEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(PistonBlockEntity.class)
@@ -20,7 +18,7 @@ public class PistonBlockEntityMixin {
@Shadow
private BlockState pushedBlock;

@ModifyVariable(at = @At(value = "INVOKE", target = "Ljava/util/List;size()I"), method = "method_11503(F)V")
@ModifyVariable(at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", ordinal = 0), method = "method_11503(F)V", allow = 1)
private boolean isSlime(boolean _ignored) {
return pushedBlock.getBlock() instanceof SlimeBlock;
}


+ 42
- 0
src/main/java/click/vpzom/coloredslime/mixin/PistonHandlerMixin.java View File

@@ -0,0 +1,42 @@
package click.vpzom.coloredslime.mixin;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.SlimeBlock;
import net.minecraft.block.piston.PistonHandler;
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.gen.Invoker;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(PistonHandler.class)
public abstract class PistonHandlerMixin {
@Shadow
private World world;

@Invoker
protected abstract boolean callMethod_11538(BlockPos pos);

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getBlock()Lnet/minecraft/block/Block;"), method = "calculatePush()Z", allow = 1, locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void calculatePushSlime(CallbackInfoReturnable<Boolean> info, int _i, BlockPos pos) {
if(world.getBlockState(pos).getBlock() instanceof SlimeBlock && !callMethod_11538(pos)) {
info.setReturnValue(false);
}
}

@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getBlock()Lnet/minecraft/block/Block;"), method = "tryMove(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Z")
private Block hackSlimeBlock(BlockState state) {
Block block = state.getBlock();
if(block instanceof SlimeBlock) {
return Blocks.SLIME_BLOCK;
}
return block;
}
}

+ 1
- 1
src/main/resources/coloredslime.mixins.json View File

@@ -2,7 +2,7 @@
"required": true,
"package": "click.vpzom.coloredslime.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": ["SlimeBlockMixin", "BlockSettingsSounds", "PistonBlockEntityMixin"],
"mixins": ["SlimeBlockMixin", "BlockSettingsSounds", "PistonBlockEntityMixin", "PistonHandlerMixin"],
"injectors": {
"defaultRequire": 1
}


Loading…
Cancel
Save