diff --git a/src/generated/resources/assets/anvilcraft_pigsplus/lang/en_ud.json b/src/generated/resources/assets/anvilcraft_pigsplus/lang/en_ud.json index 4af142d..a9c2a4c 100644 --- a/src/generated/resources/assets/anvilcraft_pigsplus/lang/en_ud.json +++ b/src/generated/resources/assets/anvilcraft_pigsplus/lang/en_ud.json @@ -1,6 +1,6 @@ { - "anvilcraft_pigsplus.configuration.auto_royal_smithing_table_cooldown": "uʍopןooƆ ǝןqɐ⟘ buıɥʇıɯS ןɐʎoᴚ oʇnⱯ", - "anvilcraft_pigsplus.configuration.auto_royal_smithing_table_cooldown.tooltip": ")sʞɔıʇ uı( ǝןqɐʇ buıɥʇıɯs ןɐʎoɹ oʇnɐ ɟo ǝɯıʇ uʍopןooɔ ɯnɯıxɐW", + "anvilcraft_pigsplus.configuration.auto_machine_cooldown": "uʍopןooƆ ǝuıɥɔɐW oʇnⱯ", + "anvilcraft_pigsplus.configuration.auto_machine_cooldown.tooltip": ")sʞɔıʇ uı( ǝuıɥɔɐɯ oʇnɐ ɟo ǝɯıʇ uʍopןooɔ ɯnɯıxɐW", "anvilcraft_pigsplus.configuration.electric_enchanting_table": "ǝןqɐ⟘ buıʇuɐɥɔuƎ ɔıɹʇɔǝןƎ", "anvilcraft_pigsplus.configuration.electric_enchanting_table.base_power_consumption_limit": "ʇıɯıꞀ uoıʇdɯnsuoƆ ɹǝʍoԀ ǝsɐᗺ", "anvilcraft_pigsplus.configuration.electric_enchanting_table.base_power_consumption_limit.tooltip": "ǝןqɐ⟘ buıʇuɐɥɔuƎ ɔıɹʇɔǝןƎ ɹoɟ ʇıɯıן uoıʇdɯnsuoɔ ɹǝʍod ǝsɐᗺ", @@ -40,11 +40,11 @@ "block.anvilcraft_pigsplus.budding_echo_shard": "pɹɐɥS oɥɔƎ buıppnᗺ", "block.anvilcraft_pigsplus.cauldron_output": "ʇndʇnO uoɹpןnɐƆ", "block.anvilcraft_pigsplus.chain_smithing_table": "ǝןqɐ⟘ buıɥʇıɯS uıɐɥƆ", - "block.anvilcraft_pigsplus.chaotic_raw_ore_block": "ʞɔoןᗺ ǝɹO ʍɐᴚ ɔıʇoɐɥƆ", + "block.anvilcraft_pigsplus.chaotic_raw_ore_block": "ǝɹO ʍɐᴚ ɔıʇoɐɥƆ ɟo ʞɔoןᗺ", "block.anvilcraft_pigsplus.deepslate_chaotic_ore": "ǝɹO ɔıʇoɐɥƆ ǝʇɐןsdǝǝᗡ", "block.anvilcraft_pigsplus.echo_cluster": "ɹǝʇsnןƆ oɥɔƎ", "block.anvilcraft_pigsplus.electric_enchanting_table": "ǝןqɐ⟘ buıʇuɐɥɔuƎ ɔıɹʇɔǝןƎ", - "block.anvilcraft_pigsplus.enchanted_generator": "ɹoʇɐɹǝuǝ⅁ pǝʇuɐɥɔuƎ", + "block.anvilcraft_pigsplus.enchanted_generator": "ɹoʇɐɹǝuǝ⅁ ʇuǝɯʇuɐɥɔuƎ", "block.anvilcraft_pigsplus.enchanted_generator.placement_too_close_to_another": "ɹoʇɐɹǝuǝb pǝʇuɐɥɔuǝ ɹǝɥʇouɐ oʇ ǝsoןɔ oo⟘", "block.anvilcraft_pigsplus.redstone_conduit_block": "ʞɔoןᗺ ʇınpuoƆ ǝuoʇspǝᴚ", "block.anvilcraft_pigsplus.sculk_extractor": "ɹoʇɔɐɹʇxƎ ʞןnɔS", diff --git a/src/generated/resources/assets/anvilcraft_pigsplus/lang/en_us.json b/src/generated/resources/assets/anvilcraft_pigsplus/lang/en_us.json index a0c733a..473f037 100644 --- a/src/generated/resources/assets/anvilcraft_pigsplus/lang/en_us.json +++ b/src/generated/resources/assets/anvilcraft_pigsplus/lang/en_us.json @@ -1,6 +1,6 @@ { - "anvilcraft_pigsplus.configuration.auto_royal_smithing_table_cooldown": "Auto Royal Smithing Table Cooldown", - "anvilcraft_pigsplus.configuration.auto_royal_smithing_table_cooldown.tooltip": "Maximum cooldown time of auto royal smithing table (in ticks)", + "anvilcraft_pigsplus.configuration.auto_machine_cooldown": "Auto Machine Cooldown", + "anvilcraft_pigsplus.configuration.auto_machine_cooldown.tooltip": "Maximum cooldown time of auto machine (in ticks)", "anvilcraft_pigsplus.configuration.electric_enchanting_table": "Electric Enchanting Table", "anvilcraft_pigsplus.configuration.electric_enchanting_table.base_power_consumption_limit": "Base Power Consumption Limit", "anvilcraft_pigsplus.configuration.electric_enchanting_table.base_power_consumption_limit.tooltip": "Base power consumption limit for Electric Enchanting Table", @@ -40,11 +40,11 @@ "block.anvilcraft_pigsplus.budding_echo_shard": "Budding Echo Shard", "block.anvilcraft_pigsplus.cauldron_output": "Cauldron Output", "block.anvilcraft_pigsplus.chain_smithing_table": "Chain Smithing Table", - "block.anvilcraft_pigsplus.chaotic_raw_ore_block": "Chaotic Raw Ore Block", + "block.anvilcraft_pigsplus.chaotic_raw_ore_block": "Block of Chaotic Raw Ore", "block.anvilcraft_pigsplus.deepslate_chaotic_ore": "Deepslate Chaotic Ore", "block.anvilcraft_pigsplus.echo_cluster": "Echo Cluster", "block.anvilcraft_pigsplus.electric_enchanting_table": "Electric Enchanting Table", - "block.anvilcraft_pigsplus.enchanted_generator": "Enchanted Generator", + "block.anvilcraft_pigsplus.enchanted_generator": "Enchantment Generator", "block.anvilcraft_pigsplus.enchanted_generator.placement_too_close_to_another": "Too close to another enchanted generator", "block.anvilcraft_pigsplus.redstone_conduit_block": "Redstone Conduit Block", "block.anvilcraft_pigsplus.sculk_extractor": "Sculk Extractor", diff --git a/src/generated/resources/data/anvilcraft_pigsplus/recipe/enchanted_generator.json b/src/generated/resources/data/anvilcraft_pigsplus/recipe/enchanted_generator.json index 9cf8e58..502b564 100644 --- a/src/generated/resources/data/anvilcraft_pigsplus/recipe/enchanted_generator.json +++ b/src/generated/resources/data/anvilcraft_pigsplus/recipe/enchanted_generator.json @@ -10,11 +10,14 @@ }, "C": { "item": "anvilcraft:frost_metal_ingot" + }, + "D": { + "tag": "c:plates/silver" } }, "pattern": [ - "AAA", - "ABA", + "ADA", + "DBD", "CCC" ], "result": { diff --git a/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoJewelCraftingTableBlockEntity.java b/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoJewelCraftingTableBlockEntity.java index 8afd09a..18c3a78 100644 --- a/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoJewelCraftingTableBlockEntity.java +++ b/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoJewelCraftingTableBlockEntity.java @@ -1,29 +1,16 @@ package dev.anvilcraft.pigsplus.block.entity; -import dev.anvilcraft.pigsplus.block.AutoJewelCraftingTableBlock; import dev.anvilcraft.pigsplus.init.AddonBlocks; import dev.anvilcraft.pigsplus.init.AddonMenuTypes; import dev.anvilcraft.pigsplus.inventory.AutoJewelCraftingMenu; -import dev.dubhe.anvilcraft.api.itemhandler.ItemHandlerUtil; -import dev.dubhe.anvilcraft.api.power.IPowerConsumer; -import dev.dubhe.anvilcraft.api.power.PowerGrid; -import dev.dubhe.anvilcraft.block.BatchCrafterBlock; -import dev.dubhe.anvilcraft.block.entity.BaseMachineBlockEntity; -import dev.dubhe.anvilcraft.init.block.ModBlocks; import dev.dubhe.anvilcraft.recipe.JewelCraftingRecipe; import dev.dubhe.anvilcraft.recipe.anvil.cache.RecipeCaches; import lombok.Getter; -import lombok.Setter; import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientGamePacketListener; -import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -37,84 +24,67 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.Vec3; -import net.neoforged.neoforge.capabilities.Capabilities; -import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.ItemStackHandler; import org.jetbrains.annotations.Nullable; -import org.joml.Vector3f; import java.util.ArrayList; import java.util.List; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; - -import static dev.anvilcraft.pigsplus.AnvilCraftPigsPlus.CONFIG; @Getter -public class AutoJewelCraftingTableBlockEntity extends BaseMachineBlockEntity implements IPowerConsumer { - private static final AtomicInteger COUNTER = new AtomicInteger(0); - @Getter - private final int inputPower = 16; - @Setter - @Getter - private PowerGrid grid; - private boolean poweredBefore = false; - private int cooldown = 0; +public class AutoJewelCraftingTableBlockEntity extends AutoMachineBlockEntity { @Getter private ItemStack resultStack = ItemStack.EMPTY; @Getter private @Nullable JewelCraftingRecipe resultRecipe = null; - @Getter - private final int id; - private final ItemStackHandler itemHandler = new ItemStackHandler(5) { - @Override - public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - if (mayPlace(slot, stack)) { - return super.insertItem(slot, stack, simulate); - } else { - return stack; - } - } + public AutoJewelCraftingTableBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state, 5); + } - public boolean mayPlace(int slot, ItemStack stack) { - // slot 0 是源物品槽位 - if (slot == 0) { - return RecipeCaches.getAllJewelResultItem().contains(stack.getItem()); - } - if (resultRecipe != null) { - int idx = slot - 1; - var mergedIngredients = resultRecipe.mergedIngredients; - if (idx < mergedIngredients.size()) { - var entry = mergedIngredients.get(idx); - Ingredient ingredient = entry.getKey(); - return ingredient.test(stack); + @Override + protected ItemStackHandler createItemHandler(int size) { + return new ItemStackHandler(size) { + @Override + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if (mayPlace(slot, stack)) { + return super.insertItem(slot, stack, simulate); + } else { + return stack; } } - return false; - } - @Override - protected void onContentsChanged(int slot) { - calcResult(); - setChanged(); - } - }; + public boolean mayPlace(int slot, ItemStack stack) { + // slot 0 是源物品槽位 + if (slot == 0) { + return RecipeCaches.getAllJewelResultItem().contains(stack.getItem()); + } + if (resultRecipe != null) { + int idx = slot - 1; + var mergedIngredients = resultRecipe.mergedIngredients; + if (idx < mergedIngredients.size()) { + var entry = mergedIngredients.get(idx); + Ingredient ingredient = entry.getKey(); + return ingredient.test(stack); + } + } + return false; + } - public AutoJewelCraftingTableBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); - id = COUNTER.incrementAndGet(); + @Override + protected void onContentsChanged(int slot) { + calcResult(); + setChanged(); + } + }; } + @Override public void calcResult() { resultStack = ItemStack.EMPTY; resultRecipe = null; if (level == null) return; ItemStack mainStack = itemHandler.getStackInSlot(0); - if (mainStack.isEmpty()) return; RecipeHolder recipeHolder = RecipeCaches.getJewelRecipeByResult(mainStack); @@ -137,25 +107,13 @@ public void calcResult() { resultStack.set(DataComponents.ENCHANTMENTS, enchantments.toImmutable()); } - public void tick(Level level, BlockPos pos) { - flushState(level, pos); - BlockState state = level.getBlockState(pos); - level.updateNeighbourForOutputSignal(pos, state.getBlock()); - boolean powered = state.getValue(AutoJewelCraftingTableBlock.POWERED); - // 红石信号上升沿且冷却完毕,尝试进行自动珠宝加工 - cooldown = Math.max(0, cooldown - 1); - if (powered && !poweredBefore && !level.isClientSide && this.cooldown == 0) { - if (work(level)) cooldown = CONFIG.autoRoyalSmithingTableCooldown; - } - poweredBefore = powered; - } - - private boolean work(Level level) { - if (grid == null || !grid.isWorking()) return false; + @Override + protected boolean work(Level level) { + if (getGrid() == null || !getGrid().isWorking()) return false; calcResult(); if (resultStack.isEmpty() || resultRecipe == null) return false; - if (!exportItem(resultStack, getDirection())) return false; + if (!exportItem(resultStack)) return false; // 消耗输入物品 JewelCraftingRecipe recipe = this.resultRecipe; @@ -171,105 +129,25 @@ private boolean work(Level level) { return true; } - private boolean exportItem(ItemStack result, Direction direction) { - IItemHandler cap = Objects.requireNonNull(getLevel()).getCapability( - Capabilities.ItemHandler.BLOCK, - getBlockPos().relative(direction), - direction.getOpposite() - ); - if (cap != null) { - // 尝试向容器插入物品 - ItemStack remained = ItemHandlerUtil.insertItem(cap, result, true); - if (!remained.isEmpty()) return false; - ItemHandlerUtil.insertItem(cap, result, false); - } else { - // 尝试向世界喷出物品 - Vec3 center = getBlockPos().relative(getDirection()).getCenter(); - AABB aabb = new AABB(center.add(-0.125, -0.125, -0.125), center.add(0.125, 0.125, 0.125)); - if (!getLevel().noCollision(aabb)) return false; - - spawnItemEntity(result); - } - return true; - } - - private void spawnItemEntity(ItemStack stack) { - Vec3 center = getBlockPos().relative(getDirection()).getCenter(); - Vector3f step = getDirection().step(); - Level level = this.getLevel(); - if (level == null) return; - ItemEntity itemEntity = - new ItemEntity(level, center.x, center.y, center.z, stack, 0.25 * step.x, 0.25 * step.y, 0.25 * step.z); - itemEntity.setDefaultPickUpDelay(); - level.addFreshEntity(itemEntity); - } - - public IItemHandler getItemHandler() { - return itemHandler; - } - - - @Override - public Packet getUpdatePacket() { - return ClientboundBlockEntityDataPacket.create(this); - } - - @Override - public CompoundTag getUpdateTag(HolderLookup.Provider provider) { - return this.saveWithoutMetadata(provider); - } @Override protected void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) { super.loadAdditional(tag, provider); - itemHandler.deserializeNBT(provider, tag.getCompound("Inventory")); if (tag.getBoolean("HasResultItemStack") && tag.contains("ResultItemStack")) { CompoundTag ct = tag.getCompound("ResultItemStack"); - resultStack = - ct.contains("id") ? ItemStack.parse(provider, ct).orElse(ItemStack.EMPTY) : ItemStack.EMPTY; + resultStack = ct.contains("id") ? ItemStack.parse(provider, ct).orElse(ItemStack.EMPTY) : ItemStack.EMPTY; } - this.poweredBefore = tag.getBoolean("PoweredBefore"); - this.cooldown = tag.getInt("Cooldown"); } @Override protected void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) { super.saveAdditional(tag, provider); - tag.put("Inventory", this.itemHandler.serializeNBT(provider)); boolean hasResultItemStack = resultStack != null && !resultStack.isEmpty(); tag.putBoolean("HasResultItemStack", hasResultItemStack); if (hasResultItemStack) { CompoundTag item = (CompoundTag) this.resultStack.save(provider); tag.put("ResultItemStack", item); } - tag.putBoolean("PoweredBefore", this.poweredBefore); - tag.putInt("Cooldown", this.cooldown); - } - - @Override - public Direction getDirection() { - return Direction.UP; - } - - @Override - public void setDirection(Direction direction) { - if (level == null) return; - BlockPos pos = getBlockPos(); - BlockState state = level.getBlockState(pos); - if (!state.is(ModBlocks.BATCH_CRAFTER.get())) return; - level.setBlockAndUpdate(pos, state.setValue(BatchCrafterBlock.FACING, direction)); - } - - - public int getRedstoneSignal() { - /*输出等同于有物品的输入槽的数量的红石信号*/ - int strength = 0; - for (int index = 0; index < itemHandler.getSlots(); index++) { - ItemStack itemStack = itemHandler.getStackInSlot(index); - if (itemStack.isEmpty()) continue; - strength++; - } - return strength; } @Nullable @@ -283,14 +161,4 @@ public AbstractContainerMenu createMenu(int i, Inventory inventory, Player playe public Component getDisplayName() { return Component.translatable("block.anvilcraft_pigsplus.auto_jewel_crafting_table"); } - - @Override - public BlockPos getPos() { - return getBlockPos(); - } - - @Override - public @Nullable Level getCurrentLevel() { - return getLevel(); - } } \ No newline at end of file diff --git a/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoMachineBlockEntity.java b/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoMachineBlockEntity.java new file mode 100644 index 0000000..85d3b7b --- /dev/null +++ b/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoMachineBlockEntity.java @@ -0,0 +1,167 @@ +package dev.anvilcraft.pigsplus.block.entity; + +import dev.anvilcraft.pigsplus.AnvilCraftPigsPlus; +import dev.dubhe.anvilcraft.api.itemhandler.ItemHandlerUtil; +import dev.dubhe.anvilcraft.api.power.IPowerConsumer; +import dev.dubhe.anvilcraft.api.power.PowerGrid; +import dev.dubhe.anvilcraft.block.entity.BaseMachineBlockEntity; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.core.HolderLookup; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.ItemStackHandler; +import org.jetbrains.annotations.Nullable; +import org.joml.Vector3f; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; + +@Getter +public abstract class AutoMachineBlockEntity extends BaseMachineBlockEntity implements IPowerConsumer { + private static final AtomicInteger COUNTER = new AtomicInteger(0); + @Getter + private final int inputPower = 16; + @Setter + @Getter + @Nullable + private PowerGrid grid; + protected boolean poweredBefore = false; + protected int cooldown = 0; + @Getter + private final int id; + protected final ItemStackHandler itemHandler; + + protected AutoMachineBlockEntity(BlockEntityType type, BlockPos pos, BlockState state, int inventorySize) { + super(type, pos, state); + id = COUNTER.incrementAndGet(); + this.itemHandler = createItemHandler(inventorySize); + } + + protected abstract ItemStackHandler createItemHandler(int size); + + public abstract void calcResult(); + + public void tick(Level level, BlockPos pos) { + flushState(level, pos); + BlockState state = level.getBlockState(pos); + level.updateNeighbourForOutputSignal(pos, state.getBlock()); + boolean powered = state.getValue(BlockStateProperties.POWERED); + // 红石信号上升沿且冷却完毕,尝试进行自动加工 + cooldown = Math.max(0, cooldown - 1); + if (powered && !poweredBefore && !level.isClientSide && this.cooldown == 0) { + if (work(level)) cooldown = AnvilCraftPigsPlus.CONFIG.autoMachineCooldown; + } + poweredBefore = powered; + } + + protected abstract boolean work(Level level); + + protected boolean exportItem(ItemStack result) { + Direction direction = getDirection(); + IItemHandler cap = Objects.requireNonNull(getLevel()).getCapability( + Capabilities.ItemHandler.BLOCK, + getBlockPos().relative(direction), + direction.getOpposite() + ); + if (cap != null) { + // 尝试向容器插入物品 + ItemStack remained = ItemHandlerUtil.insertItem(cap, result, true); + if (!remained.isEmpty()) return false; + ItemHandlerUtil.insertItem(cap, result, false); + } else { + // 尝试向世界喷出物品 + Vec3 center = getBlockPos().relative(direction).getCenter(); + AABB aabb = new AABB(center.add(-0.125, -0.125, -0.125), center.add(0.125, 0.125, 0.125)); + if (!getLevel().noCollision(aabb)) return false; + + spawnItemEntity(result); + } + return true; + } + + protected void spawnItemEntity(ItemStack stack) { + if (stack.isEmpty()) return; + Vec3 center = getBlockPos().relative(getDirection()).getCenter(); + Vector3f step = getDirection().step(); + Level level = this.getLevel(); + if (level == null) return; + ItemEntity itemEntity = + new ItemEntity(level, center.x, center.y, center.z, stack, 0.25 * step.x, 0.25 * step.y, 0.25 * step.z); + itemEntity.setDefaultPickUpDelay(); + level.addFreshEntity(itemEntity); + } + + @Override + public Packet getUpdatePacket() { + return ClientboundBlockEntityDataPacket.create(this); + } + + @Override + public CompoundTag getUpdateTag(HolderLookup.Provider provider) { + return this.saveWithoutMetadata(provider); + } + + @Override + protected void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) { + super.loadAdditional(tag, provider); + itemHandler.deserializeNBT(provider, tag.getCompound("Inventory")); + this.poweredBefore = tag.getBoolean("PoweredBefore"); + this.cooldown = tag.getInt("Cooldown"); + } + + @Override + protected void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) { + super.saveAdditional(tag, provider); + tag.put("Inventory", this.itemHandler.serializeNBT(provider)); + tag.putBoolean("PoweredBefore", this.poweredBefore); + tag.putInt("Cooldown", this.cooldown); + } + + @Override + public Direction getDirection() { + return Direction.UP; + } + + @Override + public void setDirection(Direction direction) { + return; + } + + public int getRedstoneSignal() { + /*输出等同于有物品的输入槽的数量的红石信号*/ + int strength = 0; + for (int index = 0; index < itemHandler.getSlots(); index++) { + ItemStack itemStack = itemHandler.getStackInSlot(index); + if (itemStack.isEmpty()) continue; + strength++; + } + return Mth.clamp(strength, 0, 15); + } + + @Override + public BlockPos getPos() { + return getBlockPos(); + } + + @Override + public @Nullable Level getCurrentLevel() { + return getLevel(); + } +} diff --git a/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoRoyalGrindstoneBlockEntity.java b/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoRoyalGrindstoneBlockEntity.java index 8bf3ce6..cd9ea8a 100644 --- a/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoRoyalGrindstoneBlockEntity.java +++ b/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoRoyalGrindstoneBlockEntity.java @@ -1,19 +1,11 @@ package dev.anvilcraft.pigsplus.block.entity; -import dev.anvilcraft.pigsplus.AnvilCraftPigsPlus; -import dev.anvilcraft.pigsplus.block.AutoRoyalGrindstoneBlock; import dev.anvilcraft.pigsplus.init.AddonBlocks; import dev.anvilcraft.pigsplus.init.AddonMenuTypes; import dev.anvilcraft.pigsplus.inventory.AutoRoyalGrindstoneMenu; import dev.dubhe.anvilcraft.api.itemhandler.ItemHandlerUtil; -import dev.dubhe.anvilcraft.api.power.IPowerConsumer; -import dev.dubhe.anvilcraft.api.power.PowerGrid; -import dev.dubhe.anvilcraft.block.BatchCrafterBlock; -import dev.dubhe.anvilcraft.block.entity.BaseMachineBlockEntity; -import dev.dubhe.anvilcraft.init.block.ModBlocks; import dev.dubhe.anvilcraft.inventory.RoyalGrindstoneMenu; import lombok.Getter; -import lombok.Setter; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Holder; @@ -22,11 +14,7 @@ import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientGamePacketListener; -import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.tags.EnchantmentTags; -import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -45,53 +33,45 @@ import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.ItemStackHandler; import org.jetbrains.annotations.Nullable; -import org.joml.Vector3f; import java.util.Iterator; import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; import static dev.dubhe.anvilcraft.inventory.RoyalGrindstoneMenu.DEFAULT_REPAIR_MATERIAL; import static dev.dubhe.anvilcraft.inventory.RoyalGrindstoneMenu.GOLD_PER_CURSE; import static dev.dubhe.anvilcraft.inventory.RoyalGrindstoneMenu.REPAIR_COST_RECIPES; @Getter -public class AutoRoyalGrindstoneBlockEntity extends BaseMachineBlockEntity implements IPowerConsumer { - private static final AtomicInteger COUNTER = new AtomicInteger(0); - @Getter - private final int inputPower = 16; - @Setter - @Getter - private PowerGrid grid; - private boolean poweredBefore = false; - private int cooldown = 0; +public class AutoRoyalGrindstoneBlockEntity extends AutoMachineBlockEntity { @Getter private ItemStack resultToolStack = ItemStack.EMPTY; @Getter private ItemStack resultMaterialStack = ItemStack.EMPTY; private int usedMaterialCount = 0; - @Getter - private final int id; - private final ItemStackHandler itemHandler = new ItemStackHandler(2) { - @Override - public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - if (slot == 0 && REPAIR_COST_RECIPES.containsKey(stack.getItem())) return stack; - if (slot == 1 && !REPAIR_COST_RECIPES.containsKey(stack.getItem())) return stack; - return super.insertItem(slot, stack, simulate); - } - - @Override - protected void onContentsChanged(int slot) { - calcResult(); - setChanged(); - } - }; public AutoRoyalGrindstoneBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); - id = COUNTER.incrementAndGet(); + super(type, pos, state, 2); + } + + @Override + protected ItemStackHandler createItemHandler(int size) { + return new ItemStackHandler(size) { + @Override + public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { + if (slot == 0 && REPAIR_COST_RECIPES.containsKey(stack.getItem())) return stack; + if (slot == 1 && !REPAIR_COST_RECIPES.containsKey(stack.getItem())) return stack; + return super.insertItem(slot, stack, simulate); + } + + @Override + protected void onContentsChanged(int slot) { + calcResult(); + setChanged(); + } + }; } + @Override public void calcResult() { resultToolStack = ItemStack.EMPTY; resultMaterialStack = ItemStack.EMPTY; @@ -131,7 +111,8 @@ public void calcResult() { ItemEnchantments.Mutable mutEnch = new ItemEnchantments.Mutable(enchantments); Iterator> iterator = mutEnch.keySet().iterator(); - // 一个一个诅咒附魔 + + // 逐个去除诅咒附魔 while (iterator.hasNext() && remainMaterialCount >= GOLD_PER_CURSE) { Holder curseEnchantment = iterator.next(); if (!curseEnchantment.is(EnchantmentTags.CURSE)) continue; @@ -147,22 +128,9 @@ public void calcResult() { } } - - public void tick(Level level, BlockPos pos) { - flushState(level, pos); - BlockState state = level.getBlockState(pos); - level.updateNeighbourForOutputSignal(pos, state.getBlock()); - boolean powered = state.getValue(AutoRoyalGrindstoneBlock.POWERED); - // 红石信号上升沿且冷却完毕,尝试进行自动研磨 - cooldown = Math.max(0, cooldown - 1); - if (powered && !poweredBefore && !level.isClientSide && this.cooldown == 0) { - if (work(level)) cooldown = AnvilCraftPigsPlus.CONFIG.autoRoyalSmithingTableCooldown; - } - poweredBefore = powered; - } - - private boolean work(Level level) { - if (grid == null || !grid.isWorking()) return false; + @Override + protected boolean work(Level level) { + if (getGrid() == null || !getGrid().isWorking()) return false; calcResult(); if (resultToolStack.isEmpty()) return false; @@ -213,83 +181,24 @@ private boolean exportItem() { return true; } - private void spawnItemEntity(ItemStack stack) { - Vec3 center = getBlockPos().relative(getDirection()).getCenter(); - Vector3f step = getDirection().step(); - Level level = this.getLevel(); - if (level == null) return; - ItemEntity itemEntity = - new ItemEntity(level, center.x, center.y, center.z, stack, 0.25 * step.x, 0.25 * step.y, 0.25 * step.z); - itemEntity.setDefaultPickUpDelay(); - level.addFreshEntity(itemEntity); - } - - public IItemHandler getItemHandler() { - return itemHandler; - } - - - @Override - public Packet getUpdatePacket() { - return ClientboundBlockEntityDataPacket.create(this); - } - - @Override - public CompoundTag getUpdateTag(HolderLookup.Provider provider) { - return this.saveWithoutMetadata(provider); - } - @Override protected void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) { super.loadAdditional(tag, provider); - itemHandler.deserializeNBT(provider, tag.getCompound("Inventory")); if (tag.getBoolean("HasResultItemStack") && tag.contains("ResultItemStack")) { CompoundTag ct = tag.getCompound("ResultItemStack"); - resultToolStack = - ct.contains("id") ? ItemStack.parse(provider, ct).orElse(ItemStack.EMPTY) : ItemStack.EMPTY; + resultToolStack = ct.contains("id") ? ItemStack.parse(provider, ct).orElse(ItemStack.EMPTY) : ItemStack.EMPTY; } - this.poweredBefore = tag.getBoolean("PoweredBefore"); - this.cooldown = tag.getInt("Cooldown"); } @Override protected void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) { super.saveAdditional(tag, provider); - tag.put("Inventory", this.itemHandler.serializeNBT(provider)); boolean hasResultItemStack = resultToolStack != null && !resultToolStack.isEmpty(); tag.putBoolean("HasResultItemStack", hasResultItemStack); if (hasResultItemStack) { CompoundTag item = (CompoundTag) this.resultToolStack.save(provider); tag.put("ResultItemStack", item); } - tag.putBoolean("PoweredBefore", this.poweredBefore); - tag.putInt("Cooldown", this.cooldown); - } - - @Override - public Direction getDirection() { - return Direction.UP; - } - - @Override - public void setDirection(Direction direction) { - if (level == null) return; - BlockPos pos = getBlockPos(); - BlockState state = level.getBlockState(pos); - if (!state.is(ModBlocks.BATCH_CRAFTER.get())) return; - level.setBlockAndUpdate(pos, state.setValue(BatchCrafterBlock.FACING, direction)); - } - - - public int getRedstoneSignal() { - /*输出等同于有物品的输入槽的数量的红石信号*/ - int strength = 0; - for (int index = 0; index < itemHandler.getSlots(); index++) { - ItemStack itemStack = itemHandler.getStackInSlot(index); - if (itemStack.isEmpty()) continue; - strength++; - } - return strength; } @Nullable @@ -303,14 +212,4 @@ public AbstractContainerMenu createMenu(int i, Inventory inventory, Player playe public Component getDisplayName() { return Component.translatable("block.anvilcraft_pigsplus.auto_royal_grindstone"); } - - @Override - public BlockPos getPos() { - return getBlockPos(); - } - - @Override - public @Nullable Level getCurrentLevel() { - return getLevel(); - } } \ No newline at end of file diff --git a/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoRoyalSmithingTableBlockEntity.java b/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoRoyalSmithingTableBlockEntity.java index 600d59f..b21ede9 100644 --- a/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoRoyalSmithingTableBlockEntity.java +++ b/src/main/java/dev/anvilcraft/pigsplus/block/entity/AutoRoyalSmithingTableBlockEntity.java @@ -1,26 +1,13 @@ package dev.anvilcraft.pigsplus.block.entity; -import dev.anvilcraft.pigsplus.block.AutoRoyalSmithingTableBlock; import dev.anvilcraft.pigsplus.init.AddonBlocks; import dev.anvilcraft.pigsplus.init.AddonMenuTypes; import dev.anvilcraft.pigsplus.inventory.AutoRoyalSmithingMenu; -import dev.dubhe.anvilcraft.api.itemhandler.ItemHandlerUtil; -import dev.dubhe.anvilcraft.api.power.IPowerConsumer; -import dev.dubhe.anvilcraft.api.power.PowerGrid; -import dev.dubhe.anvilcraft.block.BatchCrafterBlock; -import dev.dubhe.anvilcraft.block.entity.BaseMachineBlockEntity; -import dev.dubhe.anvilcraft.init.block.ModBlocks; import lombok.Getter; -import lombok.Setter; import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.protocol.Packet; -import net.minecraft.network.protocol.game.ClientGamePacketListener; -import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; -import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; @@ -33,49 +20,37 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.AABB; -import net.minecraft.world.phys.Vec3; -import net.neoforged.neoforge.capabilities.Capabilities; -import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.ItemStackHandler; import org.jetbrains.annotations.Nullable; -import org.joml.Vector3f; import java.util.List; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; - -import static dev.anvilcraft.pigsplus.AnvilCraftPigsPlus.CONFIG; @Getter -public class AutoRoyalSmithingTableBlockEntity extends BaseMachineBlockEntity implements IPowerConsumer { - private static final AtomicInteger COUNTER = new AtomicInteger(0); - @Getter - private final int inputPower = 16; - @Setter - @Getter - private PowerGrid grid; - private boolean poweredBefore = false; - private int cooldown = 0; +public class AutoRoyalSmithingTableBlockEntity extends AutoMachineBlockEntity { @Getter - private @Nullable ItemStack resultItemStack = null; - @Getter - private final int id; - private final ItemStackHandler itemHandler = new ItemStackHandler(3) { - @Override - protected void onContentsChanged(int slot) { - resultItemStack = getResult(); - setChanged(); - } - }; + private @Nullable ItemStack resultStack = null; public AutoRoyalSmithingTableBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); - id = COUNTER.incrementAndGet(); + super(type, pos, state, 3); } - public ItemStack getResult() { - if (level == null) return ItemStack.EMPTY; + @Override + protected ItemStackHandler createItemHandler(int size) { + return new ItemStackHandler(size) { + @Override + protected void onContentsChanged(int slot) { + resultStack = getResult(); + setChanged(); + } + }; + } + + @Override + public void calcResult() { + if (level == null) { + resultStack = ItemStack.EMPTY; + return; + } SmithingRecipeInput input = new SmithingRecipeInput( itemHandler.getStackInSlot(0), @@ -83,36 +58,34 @@ public ItemStack getResult() { itemHandler.getStackInSlot(2) ); List> recipes = level.getRecipeManager().getRecipesFor(RecipeType.SMITHING, input, level); - if (recipes.isEmpty()) return ItemStack.EMPTY; + if (recipes.isEmpty()) { + resultStack = ItemStack.EMPTY; + return; + } RecipeHolder recipeholder = recipes.getFirst(); ItemStack itemstack = recipeholder.value().assemble(input, level.registryAccess()); - if (!itemstack.isItemEnabled(level.enabledFeatures())) return ItemStack.EMPTY; + if (!itemstack.isItemEnabled(level.enabledFeatures())) { + resultStack = ItemStack.EMPTY; + return; + } - return itemstack; + resultStack = itemstack; } - - public void tick(Level level, BlockPos pos) { - flushState(level, pos); - BlockState state = level.getBlockState(pos); - level.updateNeighbourForOutputSignal(pos, state.getBlock()); - boolean powered = state.getValue(AutoRoyalSmithingTableBlock.POWERED); - // 红石信号上升沿且冷却完毕,尝试进行自动锻造 - cooldown = Math.max(0, cooldown - 1); - if (powered && !poweredBefore && !level.isClientSide && this.cooldown == 0) { - if (work(level)) cooldown = CONFIG.autoRoyalSmithingTableCooldown; - } - poweredBefore = powered; + public ItemStack getResult() { + calcResult(); + return resultStack == null ? ItemStack.EMPTY : resultStack; } - private boolean work(Level level) { - if (grid == null || !grid.isWorking()) return false; + @Override + protected boolean work(Level level) { + if (getGrid() == null || !getGrid().isWorking()) return false; - ItemStack result = getResult(); - if (result.isEmpty()) return false; + calcResult(); + if (resultStack == null || resultStack.isEmpty()) return false; - if (!exportItem(result, getDirection())) return false; + if (!exportItem(resultStack)) return false; itemHandler.extractItem(1, 1, false); itemHandler.extractItem(2, 1, false); @@ -120,105 +93,25 @@ private boolean work(Level level) { return true; } - private boolean exportItem(ItemStack result, Direction direction) { - IItemHandler cap = Objects.requireNonNull(getLevel()).getCapability( - Capabilities.ItemHandler.BLOCK, - getBlockPos().relative(direction), - direction.getOpposite() - ); - if (cap != null) { - // 尝试向容器插入物品 - ItemStack remained = ItemHandlerUtil.insertItem(cap, result, true); - if (!remained.isEmpty()) return false; - ItemHandlerUtil.insertItem(cap, result, false); - } else { - // 尝试向世界喷出物品 - Vec3 center = getBlockPos().relative(getDirection()).getCenter(); - AABB aabb = new AABB(center.add(-0.125, -0.125, -0.125), center.add(0.125, 0.125, 0.125)); - if (!getLevel().noCollision(aabb)) return false; - - spawnItemEntity(result); - } - return true; - } - - private void spawnItemEntity(ItemStack stack) { - Vec3 center = getBlockPos().relative(getDirection()).getCenter(); - Vector3f step = getDirection().step(); - Level level = this.getLevel(); - if (level == null) return; - ItemEntity itemEntity = - new ItemEntity(level, center.x, center.y, center.z, stack, 0.25 * step.x, 0.25 * step.y, 0.25 * step.z); - itemEntity.setDefaultPickUpDelay(); - level.addFreshEntity(itemEntity); - } - - public IItemHandler getItemHandler() { - return itemHandler; - } - - - @Override - public Packet getUpdatePacket() { - return ClientboundBlockEntityDataPacket.create(this); - } - - @Override - public CompoundTag getUpdateTag(HolderLookup.Provider provider) { - return this.saveWithoutMetadata(provider); - } @Override protected void loadAdditional(CompoundTag tag, HolderLookup.Provider provider) { super.loadAdditional(tag, provider); - itemHandler.deserializeNBT(provider, tag.getCompound("Inventory")); - if (tag.getBoolean("HasDisplayItemStack") && tag.contains("ResultItemStack")) { + if (tag.getBoolean("HasResultItemStack") && tag.contains("ResultItemStack")) { CompoundTag ct = tag.getCompound("ResultItemStack"); - resultItemStack = - ct.contains("id") ? ItemStack.parse(provider, ct).orElse(ItemStack.EMPTY) : ItemStack.EMPTY; + resultStack = ct.contains("id") ? ItemStack.parse(provider, ct).orElse(ItemStack.EMPTY) : ItemStack.EMPTY; } - this.poweredBefore = tag.getBoolean("PoweredBefore"); - this.cooldown = tag.getInt("Cooldown"); } @Override protected void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) { super.saveAdditional(tag, provider); - tag.put("Inventory", this.itemHandler.serializeNBT(provider)); - boolean hasDisplayItemStack = resultItemStack != null && !resultItemStack.isEmpty(); - tag.putBoolean("HasDisplayItemStack", hasDisplayItemStack); - if (hasDisplayItemStack) { - CompoundTag item = (CompoundTag) this.resultItemStack.save(provider); + boolean hasResultItemStack = resultStack != null && !resultStack.isEmpty(); + tag.putBoolean("HasResultItemStack", hasResultItemStack); + if (hasResultItemStack) { + CompoundTag item = (CompoundTag) this.resultStack.save(provider); tag.put("ResultItemStack", item); } - tag.putBoolean("PoweredBefore", this.poweredBefore); - tag.putInt("Cooldown", this.cooldown); - } - - @Override - public Direction getDirection() { - return Direction.UP; - } - - @Override - public void setDirection(Direction direction) { - if (level == null) return; - BlockPos pos = getBlockPos(); - BlockState state = level.getBlockState(pos); - if (!state.is(ModBlocks.BATCH_CRAFTER.get())) return; - level.setBlockAndUpdate(pos, state.setValue(BatchCrafterBlock.FACING, direction)); - } - - - public int getRedstoneSignal() { - /*输出等同于有物品的输入槽的数量的红石信号*/ - int strength = 0; - for (int index = 0; index < itemHandler.getSlots(); index++) { - ItemStack itemStack = itemHandler.getStackInSlot(index); - if (itemStack.isEmpty()) continue; - strength++; - } - return strength; } @Nullable @@ -232,14 +125,4 @@ public AbstractContainerMenu createMenu(int i, Inventory inventory, Player playe public Component getDisplayName() { return Component.translatable("block.anvilcraft_pigsplus.auto_royal_smithing_table"); } - - @Override - public BlockPos getPos() { - return getBlockPos(); - } - - @Override - public @Nullable Level getCurrentLevel() { - return getLevel(); - } } \ No newline at end of file diff --git a/src/main/java/dev/anvilcraft/pigsplus/block/entity/EnchantedGeneratorBlockEntity.java b/src/main/java/dev/anvilcraft/pigsplus/block/entity/EnchantedGeneratorBlockEntity.java index e5cf88e..3756dd9 100644 --- a/src/main/java/dev/anvilcraft/pigsplus/block/entity/EnchantedGeneratorBlockEntity.java +++ b/src/main/java/dev/anvilcraft/pigsplus/block/entity/EnchantedGeneratorBlockEntity.java @@ -2,6 +2,7 @@ import dev.anvilcraft.pigsplus.block.EnchantedGeneratorBlock; import dev.anvilcraft.pigsplus.init.AddonBlockEntities; +import dev.anvilcraft.pigsplus.util.ChiseledBookShelfUtil; import dev.dubhe.anvilcraft.api.power.IPowerProducer; import dev.dubhe.anvilcraft.api.power.PowerGrid; import dev.dubhe.anvilcraft.api.tooltip.providers.IHasAffectRange; @@ -25,9 +26,6 @@ import java.util.List; import static dev.anvilcraft.pigsplus.AnvilCraftPigsPlus.CONFIG; -import static dev.anvilcraft.pigsplus.util.ChiseledBookShelfUtil.countEnchantmentLevelsInArea; -import static dev.anvilcraft.pigsplus.util.ChiseledBookShelfUtil.countEnchantmentLevelsInBlock; -import static dev.anvilcraft.pigsplus.util.ChiseledBookShelfUtil.countEnchantmentLevelsInItem; public class EnchantedGeneratorBlockEntity extends BlockEntity implements IPowerProducer, IHasAffectRange { public static final int COOLDOWN = 2; @@ -62,7 +60,7 @@ public static EnchantedGeneratorBlockEntity createBlockEntity( } @Override - public void loadAdditional( CompoundTag tag, HolderLookup. Provider registries) { + public void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) { super.loadAdditional(tag, registries); this.cooldownCount = tag.getInt("cooldownCount"); this.power = tag.getInt("power"); @@ -72,7 +70,7 @@ public void loadAdditional( CompoundTag tag, HolderLookup. Provider registries } @Override - public void saveAdditional( CompoundTag tag, HolderLookup. Provider registries) { + public void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) { super.loadAdditional(tag, registries); tag.putInt("cooldownCount", this.cooldownCount); tag.putInt("power", this.power); @@ -88,7 +86,11 @@ public void gridTick() { this.cooldownCount = COOLDOWN; int prePower = power; if (!isAnotherCollectorNearby(level, getBlockPos())) { - int commonPowerAbility = countEnchantmentLevelsInArea(level, getBlockPos(), 1) * CONFIG.enchantedGenerator.powerPerLevel; + int commonPowerAbility = ChiseledBookShelfUtil.countEnchantmentLevelsInArea( + level, + getBlockPos(), + 1 + ) * CONFIG.enchantedGenerator.powerPerLevel; if (oldPowerAbility >= CONFIG.enchantedGenerator.maxCommonPower + 100) { // 进入超频状态 int overclockingPowerAbility = commonPowerAbility * CONFIG.enchantedGenerator.overclockingAmplification; @@ -125,7 +127,7 @@ private void tryConsumeBook() { for (int j = -1; j <= 1; j++) { for (int k = -1; k <= 1; k++) { mpos.set(this.getBlockPos()).move(i, j, k); - if (countEnchantmentLevelsInBlock(level, mpos) != 0) BookShelfBlocksPos.add(mpos.immutable()); + if (ChiseledBookShelfUtil.countEnchantmentLevelsInBlock(level, mpos) != 0) BookShelfBlocksPos.add(mpos.immutable()); } } } @@ -137,7 +139,7 @@ private void tryConsumeBook() { List indexes = new ArrayList<>(); for (int i = 0; i < 6; i++) { ItemStack itemStack = shelfEntity.getItem(i); - if (countEnchantmentLevelsInItem(itemStack) == 0) continue; + if (ChiseledBookShelfUtil.countEnchantmentLevelsInItem(itemStack) == 0) continue; indexes.add(i); } // 随机选择一本书,删除它 diff --git a/src/main/java/dev/anvilcraft/pigsplus/config/AddonServerConfig.java b/src/main/java/dev/anvilcraft/pigsplus/config/AddonServerConfig.java index ad9f85d..ce592e3 100644 --- a/src/main/java/dev/anvilcraft/pigsplus/config/AddonServerConfig.java +++ b/src/main/java/dev/anvilcraft/pigsplus/config/AddonServerConfig.java @@ -9,15 +9,15 @@ @Config(name = AnvilCraftPigsPlus.MOD_ID, type = ModConfig.Type.SERVER) public class AddonServerConfig { - // 自动皇家锻造台 - @Comment("Maximum cooldown time of auto royal smithing table (in ticks)") + // 自动机器 + @Comment("Maximum cooldown time of auto machine (in ticks)") @BoundedDiscrete(min = 1, max = 80) - public int autoRoyalSmithingTableCooldown = 4; + public int autoMachineCooldown = 4; // 便携无线充电器 @Comment("Energy conversion quantity of portable wireless charger (kW)") @BoundedDiscrete(min = 1, max = 1024000) - public int portableWirelessChargerEnergyConversion = 512; + public int portableWirelessChargerEnergyConversion = 16; // 电力附魔台 @CollapsibleObject @@ -60,11 +60,11 @@ public static class EnchantedGenerator { @Comment("Power per enchantment's level") @BoundedDiscrete(min = 1, max = 1000000) - public int powerPerLevel = 2; + public int powerPerLevel = 4; @Comment("Overclocking amplification") - @BoundedDiscrete(min = 1, max = 10) - public int overclockingAmplification = 2; + @BoundedDiscrete(min = 1, max = 100) + public int overclockingAmplification = 4; @Comment("Minimum consume enchanted book cooldown") @BoundedDiscrete(min = 1, max = 1000) diff --git a/src/main/java/dev/anvilcraft/pigsplus/init/AddonBlocks.java b/src/main/java/dev/anvilcraft/pigsplus/init/AddonBlocks.java index c70aab3..b4446c6 100644 --- a/src/main/java/dev/anvilcraft/pigsplus/init/AddonBlocks.java +++ b/src/main/java/dev/anvilcraft/pigsplus/init/AddonBlocks.java @@ -231,7 +231,7 @@ public class AddonBlocks { public static final BlockEntry CHAOTIC_RAW_ORE_BLOCK = REGISTRATE .block("chaotic_raw_ore_block", Block::new) - .lang("Chaotic Raw Ore Block") + .lang("Block of Chaotic Raw Ore") .initialProperties(() -> Blocks.RAW_IRON_BLOCK) .blockstate(DataGenUtil::noExtraModelOrState) .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.BUILDING_BLOCKS, ctx.get()) @@ -262,19 +262,20 @@ public class AddonBlocks { public static final BlockEntry ENCHANTMENT_GENERATOR_BLOCK = REGISTRATE .block("enchanted_generator", EnchantedGeneratorBlock::new) - .lang("Enchanted Generator") + .lang("Enchantment Generator") .initialProperties(() -> Blocks.IRON_BLOCK) .properties(p -> p.lightLevel(state -> 9).strength(5.0f, 1200f).noOcclusion().emissiveRendering(ModBlocks::always)) .blockstate(DataGenUtil::noExtraModelOrState) .tag(BlockTags.MINEABLE_WITH_PICKAXE) .simpleItem() .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) - .pattern("AAA") - .pattern("ABA") + .pattern("ADA") + .pattern("DBD") .pattern("CCC") .define('A', AddonItems.SPIRITUAL_COMPONENT) .define('B', ModBlocks.CHARGE_COLLECTOR) .define('C', ModItems.FROST_METAL_INGOT) + .define('D', ModItemTags.SILVER_PLATES) .unlockedBy( AnvilCraftDatagen.hasItem(AddonItems.SPIRITUAL_COMPONENT), AnvilCraftDatagen.has(AddonItems.SPIRITUAL_COMPONENT) diff --git a/src/main/java/dev/anvilcraft/pigsplus/inventory/AutoRoyalGrindstoneMenu.java b/src/main/java/dev/anvilcraft/pigsplus/inventory/AutoRoyalGrindstoneMenu.java index 00f4bc8..f3e7a73 100644 --- a/src/main/java/dev/anvilcraft/pigsplus/inventory/AutoRoyalGrindstoneMenu.java +++ b/src/main/java/dev/anvilcraft/pigsplus/inventory/AutoRoyalGrindstoneMenu.java @@ -81,7 +81,6 @@ private void addPlayerHotbar(Inventory playerInventory) { } private void onChanged() { - blockEntity.calcResult(); this.resultToolSlot.set(blockEntity.getResultToolStack()); this.resultMaterialSlot.set(blockEntity.getResultMaterialStack()); } diff --git a/src/main/resources/assets/anvilcraft_guideme/anvilcraft_guideme/enchanted_generator.md b/src/main/resources/assets/anvilcraft_guideme/anvilcraft_guideme/enchanted_generator.md index d77fbc9..19b22dc 100644 --- a/src/main/resources/assets/anvilcraft_guideme/anvilcraft_guideme/enchanted_generator.md +++ b/src/main/resources/assets/anvilcraft_guideme/anvilcraft_guideme/enchanted_generator.md @@ -23,7 +23,7 @@ item_ids: ## 常规工作模式 -- 每级附魔提供 2kW 能量 +- 每级附魔提供 4kW 能量 - 最大发电量:1024kW - 不消耗附魔书 @@ -31,6 +31,6 @@ item_ids: *常规工作模式*下,附魔能提供的能量超过常规最大发电量 100kW ,即达到 1124kW 后,进入*超频工作模式* -- 每级附魔提供 4kW 能量 +- 每级附魔提供 16kW 能量 (4倍于常规工作模式) - 最大发电量:32768kW - 吞噬附魔书,吞噬间隔和发电量成反比,发电达到上限时为10s \ No newline at end of file diff --git a/src/main/resources/assets/anvilcraft_pigsplus/lang/zh_cn.json b/src/main/resources/assets/anvilcraft_pigsplus/lang/zh_cn.json index d0d87a2..19ff778 100644 --- a/src/main/resources/assets/anvilcraft_pigsplus/lang/zh_cn.json +++ b/src/main/resources/assets/anvilcraft_pigsplus/lang/zh_cn.json @@ -1,6 +1,6 @@ { - "anvilcraft_pigsplus.configuration.auto_royal_smithing_table_cooldown": "Auto Royal Smithing Table Cooldown", - "anvilcraft_pigsplus.configuration.auto_royal_smithing_table_cooldown.tooltip": "自动皇家锻造台的冷却时长(tick)", + "anvilcraft_pigsplus.configuration.auto_machine_cooldown": "自动机器的冷却时间", + "anvilcraft_pigsplus.configuration.auto_machine_cooldown.tooltip": "自动机器的冷却时间(tick)", "anvilcraft_pigsplus.configuration.electric_enchanting_table": "电力附魔台", "anvilcraft_pigsplus.configuration.electric_enchanting_table.base_power_consumption_limit": "Base Power Consumption Limit", "anvilcraft_pigsplus.configuration.electric_enchanting_table.base_power_consumption_limit.tooltip": "电力附魔台的基础能耗上限",