Anvil crafting fixes

This commit is contained in:
Aleksey 2021-02-13 00:15:11 +03:00
parent c5182a4418
commit 7e367a1971
9 changed files with 76 additions and 83 deletions

View file

@ -1,5 +1,6 @@
package ru.betterend.mixin.common;
import net.minecraft.state.property.IntProperty;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -15,10 +16,16 @@ public class AnvilBlockMixin {
@Inject(method = "getLandingState", at = @At("HEAD"), cancellable = true)
private static void be_getLandingState(BlockState fallingState, CallbackInfoReturnable<BlockState> info) {
if (fallingState.getBlock() instanceof EndAnvilBlock) {
int destruction = fallingState.get(BlockProperties.DESTRUCTION);
BlockState state = (destruction < 2) ? fallingState.with(BlockProperties.DESTRUCTION, destruction + 1) : null;
info.setReturnValue(state);
info.cancel();
IntProperty destructionProperty = ((EndAnvilBlock) fallingState.getBlock()).getDestructionProperty();
int destruction = fallingState.get(destructionProperty);
try {
BlockState state = fallingState.with(destructionProperty, destruction + 1);
info.setReturnValue(state);
info.cancel();
} catch (Exception ex) {
info.setReturnValue(null);
info.cancel();
}
}
}
}