|
@@ -39,19 +39,19 @@ public class DisassemblerBlock extends BlockWithEntity {
|
|
|
|
|
|
|
|
// 检查是否可以拆解
|
|
// 检查是否可以拆解
|
|
|
if (!heldItem.isEmpty() && com.husj.recipe.DisassemblerRecipes.hasRecipe(heldItem)) {
|
|
if (!heldItem.isEmpty() && com.husj.recipe.DisassemblerRecipes.hasRecipe(heldItem)) {
|
|
|
- // 获取拆解结果
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 检查是否为下界合金装备(特殊处理)
|
|
|
|
|
+ if (isNetheriteItem(heldItem)) {
|
|
|
|
|
+ disassembleNetheriteItem(world, pos, player, heldItem);
|
|
|
|
|
+ return ActionResult.SUCCESS;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 普通拆解逻辑
|
|
|
net.minecraft.item.ItemStack result = com.husj.recipe.DisassemblerRecipes.getRecipeResult(heldItem);
|
|
net.minecraft.item.ItemStack result = com.husj.recipe.DisassemblerRecipes.getRecipeResult(heldItem);
|
|
|
|
|
|
|
|
if (!result.isEmpty()) {
|
|
if (!result.isEmpty()) {
|
|
|
// 在方块上方生成掉落物
|
|
// 在方块上方生成掉落物
|
|
|
- net.minecraft.entity.ItemEntity itemEntity = new net.minecraft.entity.ItemEntity(
|
|
|
|
|
- world,
|
|
|
|
|
- pos.getX() + 0.5,
|
|
|
|
|
- pos.getY() + 1.0,
|
|
|
|
|
- pos.getZ() + 0.5,
|
|
|
|
|
- result.copy());
|
|
|
|
|
- itemEntity.setToDefaultPickupDelay();
|
|
|
|
|
- world.spawnEntity(itemEntity);
|
|
|
|
|
|
|
+ spawnItemDrop(world, pos, result.copy());
|
|
|
|
|
|
|
|
// 消耗玩家手中的物品
|
|
// 消耗玩家手中的物品
|
|
|
if (!player.isCreative()) {
|
|
if (!player.isCreative()) {
|
|
@@ -70,4 +70,77 @@ public class DisassemblerBlock extends BlockWithEntity {
|
|
|
return ActionResult.CONSUME;
|
|
return ActionResult.CONSUME;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private boolean isNetheriteItem(net.minecraft.item.ItemStack stack) {
|
|
|
|
|
+ net.minecraft.item.Item item = stack.getItem();
|
|
|
|
|
+ return item == net.minecraft.item.Items.NETHERITE_SWORD ||
|
|
|
|
|
+ item == net.minecraft.item.Items.NETHERITE_PICKAXE ||
|
|
|
|
|
+ item == net.minecraft.item.Items.NETHERITE_AXE ||
|
|
|
|
|
+ item == net.minecraft.item.Items.NETHERITE_SHOVEL ||
|
|
|
|
|
+ item == net.minecraft.item.Items.NETHERITE_HOE ||
|
|
|
|
|
+ item == net.minecraft.item.Items.NETHERITE_HELMET ||
|
|
|
|
|
+ item == net.minecraft.item.Items.NETHERITE_CHESTPLATE ||
|
|
|
|
|
+ item == net.minecraft.item.Items.NETHERITE_LEGGINGS ||
|
|
|
|
|
+ item == net.minecraft.item.Items.NETHERITE_BOOTS;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void disassembleNetheriteItem(World world, BlockPos pos, PlayerEntity player,
|
|
|
|
|
+ net.minecraft.item.ItemStack heldItem) {
|
|
|
|
|
+ net.minecraft.item.Item item = heldItem.getItem();
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 下界合金升级模板
|
|
|
|
|
+ spawnItemDrop(world, pos,
|
|
|
|
|
+ new net.minecraft.item.ItemStack(net.minecraft.item.Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE));
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 对应的钻石工具/装备
|
|
|
|
|
+ net.minecraft.item.Item diamondItem = getDiamondEquivalent(item);
|
|
|
|
|
+ if (diamondItem != null) {
|
|
|
|
|
+ spawnItemDrop(world, pos, new net.minecraft.item.ItemStack(diamondItem));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 下界合金锭
|
|
|
|
|
+ spawnItemDrop(world, pos, new net.minecraft.item.ItemStack(net.minecraft.item.Items.NETHERITE_INGOT));
|
|
|
|
|
+
|
|
|
|
|
+ // 消耗玩家手中的物品
|
|
|
|
|
+ if (!player.isCreative()) {
|
|
|
|
|
+ heldItem.decrement(1);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 播放音效
|
|
|
|
|
+ world.playSound(null, pos, net.minecraft.sound.SoundEvents.BLOCK_ANVIL_USE,
|
|
|
|
|
+ net.minecraft.sound.SoundCategory.BLOCKS, 1.0F, 1.0F);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private net.minecraft.item.Item getDiamondEquivalent(net.minecraft.item.Item netheriteItem) {
|
|
|
|
|
+ if (netheriteItem == net.minecraft.item.Items.NETHERITE_SWORD)
|
|
|
|
|
+ return net.minecraft.item.Items.DIAMOND_SWORD;
|
|
|
|
|
+ if (netheriteItem == net.minecraft.item.Items.NETHERITE_PICKAXE)
|
|
|
|
|
+ return net.minecraft.item.Items.DIAMOND_PICKAXE;
|
|
|
|
|
+ if (netheriteItem == net.minecraft.item.Items.NETHERITE_AXE)
|
|
|
|
|
+ return net.minecraft.item.Items.DIAMOND_AXE;
|
|
|
|
|
+ if (netheriteItem == net.minecraft.item.Items.NETHERITE_SHOVEL)
|
|
|
|
|
+ return net.minecraft.item.Items.DIAMOND_SHOVEL;
|
|
|
|
|
+ if (netheriteItem == net.minecraft.item.Items.NETHERITE_HOE)
|
|
|
|
|
+ return net.minecraft.item.Items.DIAMOND_HOE;
|
|
|
|
|
+ if (netheriteItem == net.minecraft.item.Items.NETHERITE_HELMET)
|
|
|
|
|
+ return net.minecraft.item.Items.DIAMOND_HELMET;
|
|
|
|
|
+ if (netheriteItem == net.minecraft.item.Items.NETHERITE_CHESTPLATE)
|
|
|
|
|
+ return net.minecraft.item.Items.DIAMOND_CHESTPLATE;
|
|
|
|
|
+ if (netheriteItem == net.minecraft.item.Items.NETHERITE_LEGGINGS)
|
|
|
|
|
+ return net.minecraft.item.Items.DIAMOND_LEGGINGS;
|
|
|
|
|
+ if (netheriteItem == net.minecraft.item.Items.NETHERITE_BOOTS)
|
|
|
|
|
+ return net.minecraft.item.Items.DIAMOND_BOOTS;
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void spawnItemDrop(World world, BlockPos pos, net.minecraft.item.ItemStack stack) {
|
|
|
|
|
+ net.minecraft.entity.ItemEntity itemEntity = new net.minecraft.entity.ItemEntity(
|
|
|
|
|
+ world,
|
|
|
|
|
+ pos.getX() + 0.5,
|
|
|
|
|
+ pos.getY() + 1.0,
|
|
|
|
|
+ pos.getZ() + 0.5,
|
|
|
|
|
+ stack);
|
|
|
|
|
+ itemEntity.setToDefaultPickupDelay();
|
|
|
|
|
+ world.spawnEntity(itemEntity);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|