-
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.
add support for anvilCanRepairUseIronBlock
- Loading branch information
Showing
9 changed files
with
100 additions
and
8 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
21 changes: 21 additions & 0 deletions
21
src/main/java/cc/sukazyo/nukos/carpet/anvils/extend/AnvilBlockExt.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,21 @@ | ||
package cc.sukazyo.nukos.carpet.anvils.extend; | ||
|
||
import net.minecraft.block.AnvilBlock; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
|
||
public class AnvilBlockExt { | ||
|
||
public static boolean isBroken (BlockState currentState) { | ||
return (currentState.isOf(Blocks.DAMAGED_ANVIL) || currentState.isOf(Blocks.CHIPPED_ANVIL)); | ||
} | ||
|
||
public static BlockState getRepairedState (BlockState currentState) { | ||
if (currentState.isOf(Blocks.DAMAGED_ANVIL)) | ||
return Blocks.CHIPPED_ANVIL.getDefaultState().with(AnvilBlock.FACING, currentState.get(AnvilBlock.FACING)); | ||
if (currentState.isOf(Blocks.CHIPPED_ANVIL)) | ||
return Blocks.ANVIL.getDefaultState().with(AnvilBlock.FACING, currentState.get(AnvilBlock.FACING)); | ||
return currentState; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/cc/sukazyo/nukos/carpet/mixin/MixinAnvilBlock.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,48 @@ | ||
package cc.sukazyo.nukos.carpet.mixin; | ||
|
||
import cc.sukazyo.nukos.carpet.CarpetNukosSettings; | ||
import cc.sukazyo.nukos.carpet.ModCarpetNukos; | ||
import cc.sukazyo.nukos.carpet.anvils.extend.AnvilBlockExt; | ||
import net.minecraft.block.AnvilBlock; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.block.FallingBlock; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.stat.Stats; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
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.CallbackInfoReturnable; | ||
|
||
@Mixin(AnvilBlock.class) | ||
public abstract class MixinAnvilBlock extends FallingBlock { | ||
public MixinAnvilBlock (Settings settings) { super(settings); } | ||
|
||
@Inject(method = "onUse", at = @At("HEAD"), cancellable = true) | ||
public void inject_onUse ( | ||
BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, | ||
CallbackInfoReturnable<ActionResult> cir | ||
) { | ||
if (!CarpetNukosSettings.anvilCanRepairUseIronBlock) return; | ||
if (world.isClient) return; | ||
ItemStack item = player.getStackInHand(hand); | ||
if (AnvilBlockExt.isBroken(state) && item.isOf(Blocks.IRON_BLOCK.asItem())) { | ||
ModCarpetNukos.LOGGER.info("fixed anvil!!!"); | ||
world.setBlockState(pos, AnvilBlockExt.getRepairedState(state), 2); | ||
world.playSound(null, pos, SoundEvents.BLOCK_ANVIL_USE, SoundCategory.BLOCKS, 1f, 1f); | ||
if (!player.getAbilities().creativeMode) | ||
item.decrement(1); | ||
player.increaseStat(Stats.USED.getOrCreateStat(Blocks.IRON_BLOCK.asItem()), 1); | ||
cir.setReturnValue(ActionResult.CONSUME); | ||
} | ||
} | ||
|
||
} |
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