From 9cced15a12a32d0ee66ceb82fb6e56543150b55a Mon Sep 17 00:00:00 2001 From: Gugle Date: Sat, 13 Apr 2024 16:23:31 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E7=94=B5=E7=BD=91=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/depository/IDepository.java | 45 +++++++++++++++++++ .../{ => item}/FilteredItemDepository.java | 2 +- .../{ => item}/IItemDepository.java | 2 +- .../depository/{ => item}/ItemDepository.java | 2 +- .../{ => item}/ItemDepositoryHelper.java | 2 +- .../{ => item}/ItemDepositorySlot.java | 2 +- .../depository/power/IPowerDepository.java | 10 +++++ .../api/depository/power/Power.java | 8 ++++ .../api/depository/power/PowerType.java | 10 +++++ .../anvilcraft/block/AutoCrafterBlock.java | 2 +- .../dubhe/anvilcraft/block/ChuteBlock.java | 2 +- .../anvilcraft/block/SimpleChuteBlock.java | 2 +- .../block/entity/AutoCrafterBlockEntity.java | 6 +-- .../block/entity/ChuteBlockEntity.java | 4 +- .../block/entity/IFilterBlockEntity.java | 2 +- .../block/entity/SimpleChuteBlockEntity.java | 4 +- .../screen/inventory/AutoCrafterScreen.java | 2 +- .../gui/screen/inventory/ChuteScreen.java | 2 +- .../gui/screen/inventory/IFilterScreen.java | 2 +- .../anvilcraft/inventory/AutoCrafterMenu.java | 2 +- .../dubhe/anvilcraft/inventory/ChuteMenu.java | 2 +- .../fabric/ItemDepositoryHelperImpl.java | 4 +- .../fabric/ItemDepositoryProxyStorage.java | 4 +- .../ItemStorageProxyItemDepository.java | 4 +- .../fabric/AutoCrafterBlockEntityImpl.java | 2 +- .../entity/fabric/ChuteBlockEntityImpl.java | 2 +- .../fabric/SimpleChuteBlockEntityImpl.java | 2 +- .../forge/ItemDepositoryHelperImpl.java | 4 +- .../forge/AutoCrafterBlockEntityImpl.java | 2 +- .../entity/forge/ChuteBlockEntityImpl.java | 2 +- .../forge/SimpleChuteBlockEntityImpl.java | 2 +- 31 files changed, 108 insertions(+), 35 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{ => item}/FilteredItemDepository.java (99%) rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{ => item}/IItemDepository.java (98%) rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{ => item}/ItemDepository.java (99%) rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{ => item}/ItemDepositoryHelper.java (99%) rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{ => item}/ItemDepositorySlot.java (98%) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/Power.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/PowerType.java rename fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/{ => item}/fabric/ItemDepositoryHelperImpl.java (93%) rename fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/{ => item}/fabric/ItemDepositoryProxyStorage.java (97%) rename fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/{ => item}/fabric/ItemStorageProxyItemDepository.java (96%) rename forge/src/main/java/dev/dubhe/anvilcraft/api/depository/{ => item}/forge/ItemDepositoryHelperImpl.java (97%) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java new file mode 100644 index 000000000..5f3ab9207 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java @@ -0,0 +1,45 @@ +package dev.dubhe.anvilcraft.api.depository; + +/** + * 存储 + * + * @param 被存储的内容 + */ +public interface IDepository { + /** + * 向存储中插入 + * + * @param var 插入的内容 + * @param count 插入的数量 + * @param simulate 是否模拟插入 + * @return 剩余的数量 + */ + long insert(T var, long count, boolean simulate); + + /** + * 从存储中提取 + * + * @param var 提取的内容 + * @param count 计划提取的数量 + * @param simulate 是否模拟提取 + * @return 实际提取的数量 + */ + long extract(T var, long count, boolean simulate); + + /** + * 从存储中提取 + * + * @param count 计划提取的数量 + * @param simulate 是否模拟提取 + * @return 实际提取的数量 + */ + long extract(long count, boolean simulate); + + /** + * 判断存储是否能存储指定内容 + * + * @param var 内容 + * @return 存储是否能存储指定内容 + */ + boolean isValid(T var); +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/FilteredItemDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/FilteredItemDepository.java similarity index 99% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/FilteredItemDepository.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/FilteredItemDepository.java index 2ab64456c..2857b3ca7 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/FilteredItemDepository.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/FilteredItemDepository.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository; +package dev.dubhe.anvilcraft.api.depository.item; import lombok.Getter; import net.minecraft.core.NonNullList; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IItemDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/IItemDepository.java similarity index 98% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/IItemDepository.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/IItemDepository.java index 4705a4dd3..b40fdddb5 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IItemDepository.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/IItemDepository.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository; +package dev.dubhe.anvilcraft.api.depository.item; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepository.java similarity index 99% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepository.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepository.java index 01a01d0da..ce5ce5d22 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepository.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepository.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository; +package dev.dubhe.anvilcraft.api.depository.item; import dev.dubhe.anvilcraft.api.INamedTagSerializable; import lombok.Getter; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositoryHelper.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositoryHelper.java similarity index 99% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositoryHelper.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositoryHelper.java index 17285cc4f..62c710c5b 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositoryHelper.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositoryHelper.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository; +package dev.dubhe.anvilcraft.api.depository.item; import dev.architectury.injectables.annotations.ExpectPlatform; import it.unimi.dsi.fastutil.ints.IntArrayList; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositorySlot.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositorySlot.java similarity index 98% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositorySlot.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositorySlot.java index e82147bdf..4f7e42b2e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositorySlot.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositorySlot.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository; +package dev.dubhe.anvilcraft.api.depository.item; import net.minecraft.world.Container; import net.minecraft.world.SimpleContainer; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java new file mode 100644 index 000000000..2b3f6c800 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java @@ -0,0 +1,10 @@ +package dev.dubhe.anvilcraft.api.depository.power; + +import dev.dubhe.anvilcraft.api.depository.IDepository; + +/** + * 电力存储 + */ +public interface IPowerDepository extends IDepository { + PowerType getType(); +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/Power.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/Power.java new file mode 100644 index 000000000..899c133b2 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/Power.java @@ -0,0 +1,8 @@ +package dev.dubhe.anvilcraft.api.depository.power; + +/** + * 能量 + */ +public enum Power { + POWER +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/PowerType.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/PowerType.java new file mode 100644 index 000000000..5b6afdfd3 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/PowerType.java @@ -0,0 +1,10 @@ +package dev.dubhe.anvilcraft.api.depository.power; + +/** + * 电力存储类型 + */ +public enum PowerType { + PRODUCER, + CONSUMER, + STORAGE +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/AutoCrafterBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/AutoCrafterBlock.java index 43a0cc9de..293f35857 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/AutoCrafterBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/AutoCrafterBlock.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block; -import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; import dev.dubhe.anvilcraft.api.hammer.IHammerChangeableBlock; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java index fe3d6622b..7b97c1ff0 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block; -import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; import dev.dubhe.anvilcraft.api.hammer.IHammerChangeableBlock; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java index e25dffd1a..d802bdab8 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block; -import dev.dubhe.anvilcraft.api.depository.ItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepository; import dev.dubhe.anvilcraft.api.hammer.IHammerChangeable; import dev.dubhe.anvilcraft.api.hammer.IHammerChangeableBlock; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java index c1abc8b89..60d9ae50e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java @@ -2,9 +2,9 @@ import dev.architectury.injectables.annotations.ExpectPlatform; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; -import dev.dubhe.anvilcraft.api.depository.IItemDepository; -import dev.dubhe.anvilcraft.api.depository.ItemDepositoryHelper; +import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepositoryHelper; import dev.dubhe.anvilcraft.block.AutoCrafterBlock; import dev.dubhe.anvilcraft.init.ModBlocks; import dev.dubhe.anvilcraft.init.ModMenuTypes; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java index 09037554f..f735b1313 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java @@ -2,8 +2,8 @@ import dev.architectury.injectables.annotations.ExpectPlatform; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; -import dev.dubhe.anvilcraft.api.depository.ItemDepositoryHelper; +import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepositoryHelper; import dev.dubhe.anvilcraft.block.ChuteBlock; import dev.dubhe.anvilcraft.init.ModBlocks; import dev.dubhe.anvilcraft.init.ModMenuTypes; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/IFilterBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/IFilterBlockEntity.java index 44fd0e922..35a2ac379 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/IFilterBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/IFilterBlockEntity.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity; -import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java index f73d85779..ec9aae640 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java @@ -2,8 +2,8 @@ import dev.architectury.injectables.annotations.ExpectPlatform; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.ItemDepository; -import dev.dubhe.anvilcraft.api.depository.ItemDepositoryHelper; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepositoryHelper; import dev.dubhe.anvilcraft.block.SimpleChuteBlock; import lombok.Getter; import net.minecraft.core.BlockPos; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java index 8348a9d2f..306eae1fc 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java @@ -1,7 +1,7 @@ package dev.dubhe.anvilcraft.client.gui.screen.inventory; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; import dev.dubhe.anvilcraft.client.gui.component.EnableFilterButton; import dev.dubhe.anvilcraft.inventory.AutoCrafterMenu; import dev.dubhe.anvilcraft.inventory.IFilterMenu; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java index f9913cb6b..4e36cb5d1 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java @@ -2,7 +2,7 @@ import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; import dev.dubhe.anvilcraft.client.gui.component.EnableFilterButton; import dev.dubhe.anvilcraft.inventory.ChuteMenu; import dev.dubhe.anvilcraft.inventory.IFilterMenu; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java index bb3bae113..0251b59e5 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java @@ -2,7 +2,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; import dev.dubhe.anvilcraft.client.gui.component.EnableFilterButton; import dev.dubhe.anvilcraft.inventory.IFilterMenu; import dev.dubhe.anvilcraft.network.MachineEnableFilterPack; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java b/common/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java index dcf2974bb..5063e08e5 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.inventory; -import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity; import dev.dubhe.anvilcraft.block.entity.IFilterBlockEntity; import dev.dubhe.anvilcraft.init.ModBlocks; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/inventory/ChuteMenu.java b/common/src/main/java/dev/dubhe/anvilcraft/inventory/ChuteMenu.java index 6276e23e2..e8b6ec633 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/inventory/ChuteMenu.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/inventory/ChuteMenu.java @@ -1,7 +1,7 @@ package dev.dubhe.anvilcraft.inventory; -import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; import dev.dubhe.anvilcraft.block.entity.IFilterBlockEntity; import dev.dubhe.anvilcraft.init.ModBlocks; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryHelperImpl.java b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryHelperImpl.java similarity index 93% rename from fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryHelperImpl.java rename to fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryHelperImpl.java index faa53ad25..ae3fbb796 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryHelperImpl.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryHelperImpl.java @@ -1,6 +1,6 @@ -package dev.dubhe.anvilcraft.api.depository.fabric; +package dev.dubhe.anvilcraft.api.depository.item.fabric; -import dev.dubhe.anvilcraft.api.depository.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryProxyStorage.java b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryProxyStorage.java similarity index 97% rename from fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryProxyStorage.java rename to fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryProxyStorage.java index 8658b4c8d..4c91ee352 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryProxyStorage.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryProxyStorage.java @@ -1,6 +1,6 @@ -package dev.dubhe.anvilcraft.api.depository.fabric; +package dev.dubhe.anvilcraft.api.depository.item.fabric; -import dev.dubhe.anvilcraft.api.depository.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemStorageProxyItemDepository.java similarity index 96% rename from fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java rename to fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemStorageProxyItemDepository.java index 0f1242f0c..06a570633 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemStorageProxyItemDepository.java @@ -1,6 +1,6 @@ -package dev.dubhe.anvilcraft.api.depository.fabric; +package dev.dubhe.anvilcraft.api.depository.item.fabric; -import dev.dubhe.anvilcraft.api.depository.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.item.base.SingleItemStorage; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/AutoCrafterBlockEntityImpl.java b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/AutoCrafterBlockEntityImpl.java index 9afb8cdc3..179015573 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/AutoCrafterBlockEntityImpl.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/AutoCrafterBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.fabric; -import dev.dubhe.anvilcraft.api.depository.fabric.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.item.fabric.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.minecraft.core.BlockPos; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/ChuteBlockEntityImpl.java b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/ChuteBlockEntityImpl.java index 0e803e664..1ba3017ab 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/ChuteBlockEntityImpl.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/ChuteBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.fabric; -import dev.dubhe.anvilcraft.api.depository.fabric.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.item.fabric.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.minecraft.core.BlockPos; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/SimpleChuteBlockEntityImpl.java b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/SimpleChuteBlockEntityImpl.java index 2590c159d..1ea8b5e2b 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/SimpleChuteBlockEntityImpl.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/SimpleChuteBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.fabric; -import dev.dubhe.anvilcraft.api.depository.fabric.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.item.fabric.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.SimpleChuteBlockEntity; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.minecraft.core.BlockPos; diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/forge/ItemDepositoryHelperImpl.java b/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java similarity index 97% rename from forge/src/main/java/dev/dubhe/anvilcraft/api/depository/forge/ItemDepositoryHelperImpl.java rename to forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java index 5701469b0..e69adfd92 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/forge/ItemDepositoryHelperImpl.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java @@ -1,6 +1,6 @@ -package dev.dubhe.anvilcraft.api.depository.forge; +package dev.dubhe.anvilcraft.api.depository.item.forge; -import dev.dubhe.anvilcraft.api.depository.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.Entity; diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/AutoCrafterBlockEntityImpl.java b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/AutoCrafterBlockEntityImpl.java index 64ffa4a99..49b766009 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/AutoCrafterBlockEntityImpl.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/AutoCrafterBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.forge; -import dev.dubhe.anvilcraft.api.depository.forge.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.item.forge.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/ChuteBlockEntityImpl.java b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/ChuteBlockEntityImpl.java index f0c82e141..61ba3e7e6 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/ChuteBlockEntityImpl.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/ChuteBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.forge; -import dev.dubhe.anvilcraft.api.depository.forge.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.item.forge.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/SimpleChuteBlockEntityImpl.java b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/SimpleChuteBlockEntityImpl.java index 37f7b5dd5..40404876e 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/SimpleChuteBlockEntityImpl.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/SimpleChuteBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.forge; -import dev.dubhe.anvilcraft.api.depository.forge.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.item.forge.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.SimpleChuteBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; From adbdbe89c9dc11117558d0a3ca6d09557b0a3435 Mon Sep 17 00:00:00 2001 From: Gugle Date: Sat, 13 Apr 2024 16:33:43 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E7=94=B5=E5=8A=9B=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/depository/IDepository.java | 37 ++++++++++++++++++- .../api/depository/IDepositoryView.java | 34 +++++++++++++++++ .../depository/power/IPowerDepository.java | 1 + 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepositoryView.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java index 5f3ab9207..6cb24767b 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java @@ -1,11 +1,25 @@ package dev.dubhe.anvilcraft.api.depository; +import org.jetbrains.annotations.NotNull; + +import java.util.Iterator; +import java.util.Spliterator; +import java.util.function.Consumer; + /** * 存储 * * @param 被存储的内容 */ -public interface IDepository { +@SuppressWarnings("unused") +public interface IDepository extends Iterable> { + /** + * @return 该存储是否接受插入 + */ + default boolean supportsInsertion() { + return true; + } + /** * 向存储中插入 * @@ -16,6 +30,13 @@ public interface IDepository { */ long insert(T var, long count, boolean simulate); + /** + * @return 该存储是否接受提取 + */ + default boolean supportsExtraction() { + return true; + } + /** * 从存储中提取 * @@ -42,4 +63,18 @@ public interface IDepository { * @return 存储是否能存储指定内容 */ boolean isValid(T var); + + @NotNull + @Override + Iterator> iterator(); + + @Override + default void forEach(Consumer> action) { + Iterable.super.forEach(action); + } + + @Override + default Spliterator> spliterator() { + return Iterable.super.spliterator(); + } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepositoryView.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepositoryView.java new file mode 100644 index 000000000..6d51e388e --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepositoryView.java @@ -0,0 +1,34 @@ +package dev.dubhe.anvilcraft.api.depository; + +/** + * {@link IDepository} 中单个存储资源的视图 + * + * @param 被存储的内容 + */ +@SuppressWarnings("unused") +public interface IDepositoryView { + /** + * 从视图中提取 + * + * @param var 提取的内容 + * @param count 计划提取的数量 + * @param simulate 是否模拟提取 + * @return 实际提取的数量 + */ + long extract(T var, long count, boolean simulate); + + /** + * @return 存储在此视图中的资源 + */ + T getResource(); + + /** + * @return 存储在此视图中的资源量 + */ + long getAmount(); + + /** + * @return 此视图可以接受的资源总量 + */ + long getCapacity(); +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java index 2b3f6c800..f1e9f714d 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java @@ -5,6 +5,7 @@ /** * 电力存储 */ +@SuppressWarnings("unused") public interface IPowerDepository extends IDepository { PowerType getType(); } From 424d465f46331471a8882cb4f2a2a4505578a80c Mon Sep 17 00:00:00 2001 From: Gugle Date: Sun, 14 Apr 2024 23:13:36 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E8=AE=BE=E8=AE=A1=E7=94=B5=E7=BD=91?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{item => }/FilteredItemDepository.java | 2 +- .../api/depository/IDepository.java | 80 --------- .../api/depository/IDepositoryView.java | 34 ---- .../{item => }/IItemDepository.java | 2 +- .../depository/{item => }/ItemDepository.java | 2 +- .../{item => }/ItemDepositoryHelper.java | 2 +- .../{item => }/ItemDepositorySlot.java | 2 +- .../depository/power/IPowerDepository.java | 11 -- .../api/depository/power/Power.java | 8 - .../api/depository/power/PowerType.java | 10 -- .../anvilcraft/api/power/IPowerComponent.java | 26 +++ .../anvilcraft/api/power/IPowerConsumer.java | 18 ++ .../anvilcraft/api/power/IPowerProducer.java | 18 ++ .../anvilcraft/api/power/IPowerStorage.java | 27 +++ .../api/power/IPowerTransmitter.java | 11 ++ .../api/power/PowerComponentType.java | 11 ++ .../dubhe/anvilcraft/api/power/PowerGrid.java | 165 ++++++++++++++++++ .../anvilcraft/block/AutoCrafterBlock.java | 2 +- .../dubhe/anvilcraft/block/ChuteBlock.java | 2 +- .../anvilcraft/block/SimpleChuteBlock.java | 2 +- .../block/entity/AutoCrafterBlockEntity.java | 6 +- .../block/entity/ChuteBlockEntity.java | 4 +- .../block/entity/IFilterBlockEntity.java | 2 +- .../block/entity/SimpleChuteBlockEntity.java | 4 +- .../screen/inventory/AutoCrafterScreen.java | 2 +- .../gui/screen/inventory/ChuteScreen.java | 2 +- .../gui/screen/inventory/IFilterScreen.java | 2 +- .../anvilcraft/config/AnvilCraftConfig.java | 12 ++ .../anvilcraft/inventory/AutoCrafterMenu.java | 2 +- .../dubhe/anvilcraft/inventory/ChuteMenu.java | 2 +- .../fabric/ItemDepositoryHelperImpl.java | 4 +- .../fabric/ItemDepositoryProxyStorage.java | 4 +- .../ItemStorageProxyItemDepository.java | 4 +- .../fabric/AutoCrafterBlockEntityImpl.java | 2 +- .../entity/fabric/ChuteBlockEntityImpl.java | 2 +- .../fabric/SimpleChuteBlockEntityImpl.java | 2 +- .../item/forge/ItemDepositoryHelperImpl.java | 2 +- 37 files changed, 319 insertions(+), 174 deletions(-) rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{item => }/FilteredItemDepository.java (99%) delete mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java delete mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepositoryView.java rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{item => }/IItemDepository.java (98%) rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{item => }/ItemDepository.java (99%) rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{item => }/ItemDepositoryHelper.java (99%) rename common/src/main/java/dev/dubhe/anvilcraft/api/depository/{item => }/ItemDepositorySlot.java (98%) delete mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java delete mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/Power.java delete mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/PowerType.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerConsumer.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerProducer.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerComponentType.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java rename fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/{item => }/fabric/ItemDepositoryHelperImpl.java (93%) rename fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/{item => }/fabric/ItemDepositoryProxyStorage.java (97%) rename fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/{item => }/fabric/ItemStorageProxyItemDepository.java (96%) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/FilteredItemDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/FilteredItemDepository.java similarity index 99% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/FilteredItemDepository.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/FilteredItemDepository.java index 2857b3ca7..2ab64456c 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/FilteredItemDepository.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/FilteredItemDepository.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository.item; +package dev.dubhe.anvilcraft.api.depository; import lombok.Getter; import net.minecraft.core.NonNullList; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java deleted file mode 100644 index 6cb24767b..000000000 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepository.java +++ /dev/null @@ -1,80 +0,0 @@ -package dev.dubhe.anvilcraft.api.depository; - -import org.jetbrains.annotations.NotNull; - -import java.util.Iterator; -import java.util.Spliterator; -import java.util.function.Consumer; - -/** - * 存储 - * - * @param 被存储的内容 - */ -@SuppressWarnings("unused") -public interface IDepository extends Iterable> { - /** - * @return 该存储是否接受插入 - */ - default boolean supportsInsertion() { - return true; - } - - /** - * 向存储中插入 - * - * @param var 插入的内容 - * @param count 插入的数量 - * @param simulate 是否模拟插入 - * @return 剩余的数量 - */ - long insert(T var, long count, boolean simulate); - - /** - * @return 该存储是否接受提取 - */ - default boolean supportsExtraction() { - return true; - } - - /** - * 从存储中提取 - * - * @param var 提取的内容 - * @param count 计划提取的数量 - * @param simulate 是否模拟提取 - * @return 实际提取的数量 - */ - long extract(T var, long count, boolean simulate); - - /** - * 从存储中提取 - * - * @param count 计划提取的数量 - * @param simulate 是否模拟提取 - * @return 实际提取的数量 - */ - long extract(long count, boolean simulate); - - /** - * 判断存储是否能存储指定内容 - * - * @param var 内容 - * @return 存储是否能存储指定内容 - */ - boolean isValid(T var); - - @NotNull - @Override - Iterator> iterator(); - - @Override - default void forEach(Consumer> action) { - Iterable.super.forEach(action); - } - - @Override - default Spliterator> spliterator() { - return Iterable.super.spliterator(); - } -} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepositoryView.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepositoryView.java deleted file mode 100644 index 6d51e388e..000000000 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IDepositoryView.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.dubhe.anvilcraft.api.depository; - -/** - * {@link IDepository} 中单个存储资源的视图 - * - * @param 被存储的内容 - */ -@SuppressWarnings("unused") -public interface IDepositoryView { - /** - * 从视图中提取 - * - * @param var 提取的内容 - * @param count 计划提取的数量 - * @param simulate 是否模拟提取 - * @return 实际提取的数量 - */ - long extract(T var, long count, boolean simulate); - - /** - * @return 存储在此视图中的资源 - */ - T getResource(); - - /** - * @return 存储在此视图中的资源量 - */ - long getAmount(); - - /** - * @return 此视图可以接受的资源总量 - */ - long getCapacity(); -} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/IItemDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IItemDepository.java similarity index 98% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/IItemDepository.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/IItemDepository.java index b40fdddb5..4705a4dd3 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/IItemDepository.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/IItemDepository.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository.item; +package dev.dubhe.anvilcraft.api.depository; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepository.java similarity index 99% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepository.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepository.java index ce5ce5d22..01a01d0da 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepository.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepository.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository.item; +package dev.dubhe.anvilcraft.api.depository; import dev.dubhe.anvilcraft.api.INamedTagSerializable; import lombok.Getter; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositoryHelper.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositoryHelper.java similarity index 99% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositoryHelper.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositoryHelper.java index 62c710c5b..17285cc4f 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositoryHelper.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositoryHelper.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository.item; +package dev.dubhe.anvilcraft.api.depository; import dev.architectury.injectables.annotations.ExpectPlatform; import it.unimi.dsi.fastutil.ints.IntArrayList; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositorySlot.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositorySlot.java similarity index 98% rename from common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositorySlot.java rename to common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositorySlot.java index 4f7e42b2e..e82147bdf 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/item/ItemDepositorySlot.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/ItemDepositorySlot.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository.item; +package dev.dubhe.anvilcraft.api.depository; import net.minecraft.world.Container; import net.minecraft.world.SimpleContainer; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java deleted file mode 100644 index f1e9f714d..000000000 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/IPowerDepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.dubhe.anvilcraft.api.depository.power; - -import dev.dubhe.anvilcraft.api.depository.IDepository; - -/** - * 电力存储 - */ -@SuppressWarnings("unused") -public interface IPowerDepository extends IDepository { - PowerType getType(); -} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/Power.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/Power.java deleted file mode 100644 index 899c133b2..000000000 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/Power.java +++ /dev/null @@ -1,8 +0,0 @@ -package dev.dubhe.anvilcraft.api.depository.power; - -/** - * 能量 - */ -public enum Power { - POWER -} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/PowerType.java b/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/PowerType.java deleted file mode 100644 index 5b6afdfd3..000000000 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/depository/power/PowerType.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.dubhe.anvilcraft.api.depository.power; - -/** - * 电力存储类型 - */ -public enum PowerType { - PRODUCER, - CONSUMER, - STORAGE -} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java new file mode 100644 index 000000000..b92fe33b8 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java @@ -0,0 +1,26 @@ +package dev.dubhe.anvilcraft.api.power; + +import net.minecraft.core.BlockPos; + +/** + * 电力元件 + */ +@SuppressWarnings("unused") +public interface IPowerComponent { + /** + * @return 元件位置 + */ + BlockPos getPos(); + + /** + * 设置电网 + * + * @param grid 电网 + */ + void setGrid(PowerGrid grid); + + /** + * @return 元件类型 + */ + PowerComponentType getType(); +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerConsumer.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerConsumer.java new file mode 100644 index 000000000..53d0465bb --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerConsumer.java @@ -0,0 +1,18 @@ +package dev.dubhe.anvilcraft.api.power; + +/** + * 用电 + */ +public interface IPowerConsumer extends IPowerComponent { + /** + * @return 输入功率 + */ + default int getInputPower() { + return 0; + } + + @Override + default PowerComponentType getType() { + return PowerComponentType.CONSUMER; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerProducer.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerProducer.java new file mode 100644 index 000000000..847b6b32a --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerProducer.java @@ -0,0 +1,18 @@ +package dev.dubhe.anvilcraft.api.power; + +/** + * 发电 + */ +public interface IPowerProducer extends IPowerComponent { + /** + * @return 输出功率 + */ + default int getOutputPower() { + return 0; + } + + @Override + default PowerComponentType getType() { + return PowerComponentType.PRODUCER; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java new file mode 100644 index 000000000..c266590b5 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java @@ -0,0 +1,27 @@ +package dev.dubhe.anvilcraft.api.power; + +/** + * 储电 + */ +public interface IPowerStorage extends IPowerProducer { + /** + * 输入电量 + * + * @param power 输入值 + * @return 无法输入的值 + */ + int insert(int power); + + /** + * 获取电量 + * + * @param power 想要获取的值 + * @return 实际获取的值 + */ + int extract(int power); + + @Override + default PowerComponentType getType() { + return PowerComponentType.STORAGE; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java new file mode 100644 index 000000000..a2cc187a4 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java @@ -0,0 +1,11 @@ +package dev.dubhe.anvilcraft.api.power; + +/** + * 电力中继器 + */ +public interface IPowerTransmitter extends IPowerComponent { + @Override + default PowerComponentType getType() { + return PowerComponentType.TRANSMITTER; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerComponentType.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerComponentType.java new file mode 100644 index 000000000..34a899038 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerComponentType.java @@ -0,0 +1,11 @@ +package dev.dubhe.anvilcraft.api.power; + +/** + * 电力元件类型 + */ +public enum PowerComponentType { + PRODUCER, + CONSUMER, + STORAGE, + TRANSMITTER +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java new file mode 100644 index 000000000..2bf58b810 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java @@ -0,0 +1,165 @@ +package dev.dubhe.anvilcraft.api.power; + +import dev.dubhe.anvilcraft.AnvilCraft; +import lombok.Getter; +import net.minecraft.core.BlockPos; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * 电网 + */ +@SuppressWarnings("unused") +public class PowerGrid { + public static final List GRID_LIST = new ArrayList<>(); + public static final int GRID_TICK = 40; + public static int cooldown = 0; + @Getter + private int generate = 0; // 发电功率 + @Getter + private int consume = 0; // 耗电功率 + private final List producers = new ArrayList<>(); // 发电机 + private final List consumers = new ArrayList<>(); // 用电器 + private final List storages = new ArrayList<>(); // 储电 + private final List transmitters = new ArrayList<>(); // 中继 + + /** + * 总电力刻 + */ + public static void tickGrid() { + if (cooldown > 0) { + cooldown--; + return; + } + for (PowerGrid grid : PowerGrid.GRID_LIST) { + grid.tick(); + } + cooldown = GRID_TICK; + } + + /** + * 电力刻 + */ + protected void tick() { + this.generate = 0; + this.consume = 0; + for (IPowerProducer producer : this.producers) { + this.generate += producer.getOutputPower(); + } + for (IPowerConsumer consumer : this.consumers) { + this.consume += consumer.getInputPower(); + } + if (this.isWork()) { + int remainder = this.generate - this.consume; + for (IPowerStorage storage : storages) { + remainder = storage.insert(remainder); + if (remainder <= 0) break; + } + } else { + int need = this.consume - this.generate; + List storages = new ArrayList<>(); + for (IPowerStorage storage : this.storages) { + need -= storage.getOutputPower(); + storages.add(storage); + if (need <= 0) break; + } + if (need > 0) return; + for (IPowerStorage storage : storages) { + this.generate += storage.extract(this.consume - this.generate); + } + } + } + + public boolean isWork() { + return this.generate >= this.consume; + } + + /** + * 增加电力元件 + * + * @param components 元件 + */ + public void add(IPowerComponent @NotNull ... components) { + for (IPowerComponent component : components) { + if (component instanceof IPowerStorage storage) { + this.storages.add(storage); + } else if (component instanceof IPowerProducer producer) { + this.producers.add(producer); + } else if (component instanceof IPowerConsumer consumer) { + this.consumers.add(consumer); + } else if (component instanceof IPowerTransmitter transmitter) { + this.transmitters.add(transmitter); + } + } + } + + /** + * 移除电力元件 + * + * @param components 电力元件 + */ + public void remove(IPowerComponent @NotNull ... components) { + List list = new ArrayList<>(); + list.addAll(this.storages); + list.addAll(this.producers); + list.addAll(this.consumers); + list.addAll(this.transmitters); + for (IPowerComponent component : components) { + list.remove(component); + } + PowerGrid.GRID_LIST.remove(this); + PowerGrid.addComponent(list.toArray(IPowerComponent[]::new)); + } + + /** + * 将另一个电网合并至当前电网 + * + * @param grid 电网 + */ + public void merge(@NotNull PowerGrid grid) { + this.producers.addAll(grid.producers); + this.consumers.addAll(grid.consumers); + this.storages.addAll(grid.storages); + this.transmitters.addAll(grid.transmitters); + PowerGrid.GRID_LIST.remove(grid); + } + + /** + * @param component 元件 + * @return 元件是否在电网范围内 + */ + public boolean isInRange(@NotNull IPowerComponent component) { + int range; + BlockPos pos = component.getPos(); + if (component instanceof IPowerTransmitter) { + range = AnvilCraft.config.powerTransmitterRange; + } else range = AnvilCraft.config.powerComponentRange; + for (IPowerTransmitter transmitter : this.transmitters) { + pos = pos.subtract(transmitter.getPos()); + if (pos.getX() > range || pos.getY() > range || pos.getZ() > range) continue; + return true; + } + return false; + } + + /** + * 增加电力元件 + * + * @param components 元件 + */ + public static void addComponent(IPowerComponent @NotNull ... components) { + for (IPowerComponent component : components) { + PowerGrid grid = null; + for (PowerGrid grid1 : PowerGrid.GRID_LIST) { + if (!grid1.isInRange(component)) continue; + if (grid == null) grid = grid1; + else grid.merge(grid1); + } + if (grid == null) grid = new PowerGrid(); + grid.add(component); + PowerGrid.GRID_LIST.add(grid); + } + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/AutoCrafterBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/AutoCrafterBlock.java index 293f35857..43a0cc9de 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/AutoCrafterBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/AutoCrafterBlock.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block; -import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; import dev.dubhe.anvilcraft.api.hammer.IHammerChangeableBlock; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java index f4cad6cce..f444086bf 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block; -import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; import dev.dubhe.anvilcraft.api.hammer.IHammerChangeableBlock; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java index 36ce8c826..22478a3a6 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepository; +import dev.dubhe.anvilcraft.api.depository.ItemDepository; import dev.dubhe.anvilcraft.api.hammer.IHammerChangeable; import dev.dubhe.anvilcraft.api.hammer.IHammerChangeableBlock; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java index 60d9ae50e..c1abc8b89 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java @@ -2,9 +2,9 @@ import dev.architectury.injectables.annotations.ExpectPlatform; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; -import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepositoryHelper; +import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.ItemDepositoryHelper; import dev.dubhe.anvilcraft.block.AutoCrafterBlock; import dev.dubhe.anvilcraft.init.ModBlocks; import dev.dubhe.anvilcraft.init.ModMenuTypes; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java index f735b1313..09037554f 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java @@ -2,8 +2,8 @@ import dev.architectury.injectables.annotations.ExpectPlatform; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepositoryHelper; +import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.ItemDepositoryHelper; import dev.dubhe.anvilcraft.block.ChuteBlock; import dev.dubhe.anvilcraft.init.ModBlocks; import dev.dubhe.anvilcraft.init.ModMenuTypes; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/IFilterBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/IFilterBlockEntity.java index 35a2ac379..44fd0e922 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/IFilterBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/IFilterBlockEntity.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity; -import dev.dubhe.anvilcraft.api.depository.item.FilteredItemDepository; +import dev.dubhe.anvilcraft.api.depository.FilteredItemDepository; import net.minecraft.core.NonNullList; import net.minecraft.world.item.ItemStack; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java index ec9aae640..f73d85779 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java @@ -2,8 +2,8 @@ import dev.architectury.injectables.annotations.ExpectPlatform; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepository; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepositoryHelper; +import dev.dubhe.anvilcraft.api.depository.ItemDepository; +import dev.dubhe.anvilcraft.api.depository.ItemDepositoryHelper; import dev.dubhe.anvilcraft.block.SimpleChuteBlock; import lombok.Getter; import net.minecraft.core.BlockPos; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java index 306eae1fc..8348a9d2f 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java @@ -1,7 +1,7 @@ package dev.dubhe.anvilcraft.client.gui.screen.inventory; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; import dev.dubhe.anvilcraft.client.gui.component.EnableFilterButton; import dev.dubhe.anvilcraft.inventory.AutoCrafterMenu; import dev.dubhe.anvilcraft.inventory.IFilterMenu; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java index 4e36cb5d1..f9913cb6b 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java @@ -2,7 +2,7 @@ import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; import dev.dubhe.anvilcraft.client.gui.component.EnableFilterButton; import dev.dubhe.anvilcraft.inventory.ChuteMenu; import dev.dubhe.anvilcraft.inventory.IFilterMenu; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java index 0251b59e5..bb3bae113 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java @@ -2,7 +2,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import dev.dubhe.anvilcraft.AnvilCraft; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; import dev.dubhe.anvilcraft.client.gui.component.EnableFilterButton; import dev.dubhe.anvilcraft.inventory.IFilterMenu; import dev.dubhe.anvilcraft.network.MachineEnableFilterPack; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java index 0da0ad353..968d7b75e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java @@ -74,4 +74,16 @@ public class AnvilCraftConfig implements ConfigData { @ConfigEntry.BoundedDiscrete(max = 30, min = 5) @SerializedName("Geode Search Cooldown") public int geodeCooldown = 5; + + @Comment("The power transmitter can identify the range of power components") + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(max = 64, min = 1) + @SerializedName("Range of Power Components") + public int powerComponentRange = 8; + + @Comment("The power transmitter can identify the range of the power transmitter") + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(max = 64, min = 4) + @SerializedName("Range of Power Transmitter") + public int powerTransmitterRange = 16; } \ No newline at end of file diff --git a/common/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java b/common/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java index 5063e08e5..dcf2974bb 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/inventory/AutoCrafterMenu.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.inventory; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity; import dev.dubhe.anvilcraft.block.entity.IFilterBlockEntity; import dev.dubhe.anvilcraft.init.ModBlocks; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/inventory/ChuteMenu.java b/common/src/main/java/dev/dubhe/anvilcraft/inventory/ChuteMenu.java index e8b6ec633..6276e23e2 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/inventory/ChuteMenu.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/inventory/ChuteMenu.java @@ -1,7 +1,7 @@ package dev.dubhe.anvilcraft.inventory; -import dev.dubhe.anvilcraft.api.depository.item.ItemDepositorySlot; +import dev.dubhe.anvilcraft.api.depository.ItemDepositorySlot; import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; import dev.dubhe.anvilcraft.block.entity.IFilterBlockEntity; import dev.dubhe.anvilcraft.init.ModBlocks; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryHelperImpl.java b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryHelperImpl.java similarity index 93% rename from fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryHelperImpl.java rename to fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryHelperImpl.java index ae3fbb796..faa53ad25 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryHelperImpl.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryHelperImpl.java @@ -1,6 +1,6 @@ -package dev.dubhe.anvilcraft.api.depository.item.fabric; +package dev.dubhe.anvilcraft.api.depository.fabric; -import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.IItemDepository; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryProxyStorage.java b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryProxyStorage.java similarity index 97% rename from fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryProxyStorage.java rename to fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryProxyStorage.java index 4c91ee352..8658b4c8d 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemDepositoryProxyStorage.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemDepositoryProxyStorage.java @@ -1,6 +1,6 @@ -package dev.dubhe.anvilcraft.api.depository.item.fabric; +package dev.dubhe.anvilcraft.api.depository.fabric; -import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.IItemDepository; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemStorageProxyItemDepository.java b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java similarity index 96% rename from fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemStorageProxyItemDepository.java rename to fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java index 06a570633..0f1242f0c 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/item/fabric/ItemStorageProxyItemDepository.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/api/depository/fabric/ItemStorageProxyItemDepository.java @@ -1,6 +1,6 @@ -package dev.dubhe.anvilcraft.api.depository.item.fabric; +package dev.dubhe.anvilcraft.api.depository.fabric; -import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.IItemDepository; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; import net.fabricmc.fabric.api.transfer.v1.item.base.SingleItemStorage; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/AutoCrafterBlockEntityImpl.java b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/AutoCrafterBlockEntityImpl.java index 179015573..9afb8cdc3 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/AutoCrafterBlockEntityImpl.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/AutoCrafterBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.fabric; -import dev.dubhe.anvilcraft.api.depository.item.fabric.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.fabric.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.minecraft.core.BlockPos; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/ChuteBlockEntityImpl.java b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/ChuteBlockEntityImpl.java index 1ba3017ab..0e803e664 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/ChuteBlockEntityImpl.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/ChuteBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.fabric; -import dev.dubhe.anvilcraft.api.depository.item.fabric.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.fabric.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.minecraft.core.BlockPos; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/SimpleChuteBlockEntityImpl.java b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/SimpleChuteBlockEntityImpl.java index 1ea8b5e2b..2590c159d 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/SimpleChuteBlockEntityImpl.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/block/entity/fabric/SimpleChuteBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.fabric; -import dev.dubhe.anvilcraft.api.depository.item.fabric.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.fabric.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.SimpleChuteBlockEntity; import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage; import net.minecraft.core.BlockPos; diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java b/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java index e69adfd92..9ce5514a9 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.api.depository.item.forge; -import dev.dubhe.anvilcraft.api.depository.item.IItemDepository; +import dev.dubhe.anvilcraft.api.depository.IItemDepository; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.entity.Entity; From 4bbae77b2ce9b0a69ac9b6d35ad95870117bb601 Mon Sep 17 00:00:00 2001 From: Gugle Date: Mon, 15 Apr 2024 01:50:05 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=9B=E9=80=A0?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=8F=91=E7=94=B5=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolved #268 --- .../anvilcraft/api/power/IPowerComponent.java | 16 +- .../anvilcraft/api/power/IPowerConsumer.java | 4 +- .../anvilcraft/api/power/IPowerProducer.java | 4 +- .../anvilcraft/api/power/IPowerStorage.java | 4 +- .../api/power/IPowerTransmitter.java | 4 +- .../dubhe/anvilcraft/api/power/PowerGrid.java | 1 + .../block/CorruptedBeaconBlock.java | 2 +- .../anvilcraft/block/CreativeDynamoBlock.java | 29 + .../block/entity/AutoCrafterBlockEntity.java | 2 +- .../block/entity/ChuteBlockEntity.java | 2 +- .../entity/CorruptedBeaconBlockEntity.java | 13 +- .../entity/CreativeDynamoBlockEntity.java | 73 ++ .../block/entity/SimpleChuteBlockEntity.java | 2 +- .../anvilcraft/init/ModBlockEntities.java | 6 + .../dev/dubhe/anvilcraft/init/ModBlocks.java | 641 +++++++++--------- .../dubhe/anvilcraft/init/ModItemGroups.java | 1 + .../blockstates/creative_dynamo.json | 7 + .../assets/anvilcraft/lang/en_ud.json | 5 + .../assets/anvilcraft/lang/en_us.json | 5 + .../models/item/creative_dynamo.json | 3 + .../loot_tables/blocks/creative_dynamo.json | 21 + .../event/fabric/ModFabricEvents.java | 1 + .../event/fabric/ServerBlockEntityEvent.java | 29 + .../event/fabric/ServerLifecycleEvent.java | 8 + .../assets/anvilcraft/lang/en_ud.json | 5 + .../assets/anvilcraft/lang/en_us.json | 5 + .../models/item/creative_dynamo.json | 3 + .../loot_tables/blocks/creative_dynamo.json | 21 + .../forge/ItemDepositoryHelperImpl.java | 2 +- .../api/event/forge/BlockEntityEvent.java | 29 + .../forge/AutoCrafterBlockEntityImpl.java | 2 +- .../entity/forge/ChuteBlockEntityImpl.java | 2 +- .../forge/SimpleChuteBlockEntityImpl.java | 2 +- .../event/forge/ServerBlockEntityEvent.java | 35 + .../event/forge/ServerLifecycleEvent.java | 14 +- .../mixin/forge/LevelChunkMixin.java | 89 +++ .../src/main/resources/anvilcraft.mixins.json | 3 +- 37 files changed, 759 insertions(+), 336 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java create mode 100644 common/src/main/resources/assets/anvilcraft/blockstates/creative_dynamo.json create mode 100644 fabric/src/generated/resources/assets/anvilcraft/models/item/creative_dynamo.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/creative_dynamo.json create mode 100644 fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerBlockEntityEvent.java create mode 100644 forge/src/generated/resources/assets/anvilcraft/models/item/creative_dynamo.json create mode 100644 forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/creative_dynamo.json rename forge/src/main/java/dev/dubhe/anvilcraft/api/depository/{item => }/forge/ItemDepositoryHelperImpl.java (98%) create mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/api/event/forge/BlockEntityEvent.java create mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEvent.java create mode 100644 forge/src/main/java/dev/dubhe/anvilcraft/mixin/forge/LevelChunkMixin.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java index b92fe33b8..dc04976f0 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java @@ -1,6 +1,8 @@ package dev.dubhe.anvilcraft.api.power; import net.minecraft.core.BlockPos; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * 电力元件 @@ -10,6 +12,7 @@ public interface IPowerComponent { /** * @return 元件位置 */ + @NotNull BlockPos getPos(); /** @@ -17,10 +20,19 @@ public interface IPowerComponent { * * @param grid 电网 */ - void setGrid(PowerGrid grid); + void setGrid(@Nullable PowerGrid grid); + + /** + * 获取电网 + * + * @return 电网 + */ + @Nullable + PowerGrid getGrid(); /** * @return 元件类型 */ - PowerComponentType getType(); + @NotNull + PowerComponentType getComponentType(); } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerConsumer.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerConsumer.java index 53d0465bb..bd7e2bb78 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerConsumer.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerConsumer.java @@ -1,5 +1,7 @@ package dev.dubhe.anvilcraft.api.power; +import org.jetbrains.annotations.NotNull; + /** * 用电 */ @@ -12,7 +14,7 @@ default int getInputPower() { } @Override - default PowerComponentType getType() { + default @NotNull PowerComponentType getComponentType() { return PowerComponentType.CONSUMER; } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerProducer.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerProducer.java index 847b6b32a..f25774d2a 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerProducer.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerProducer.java @@ -1,5 +1,7 @@ package dev.dubhe.anvilcraft.api.power; +import org.jetbrains.annotations.NotNull; + /** * 发电 */ @@ -12,7 +14,7 @@ default int getOutputPower() { } @Override - default PowerComponentType getType() { + default @NotNull PowerComponentType getComponentType() { return PowerComponentType.PRODUCER; } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java index c266590b5..3d2c90cf4 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java @@ -1,5 +1,7 @@ package dev.dubhe.anvilcraft.api.power; +import org.jetbrains.annotations.NotNull; + /** * 储电 */ @@ -21,7 +23,7 @@ public interface IPowerStorage extends IPowerProducer { int extract(int power); @Override - default PowerComponentType getType() { + default @NotNull PowerComponentType getComponentType() { return PowerComponentType.STORAGE; } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java index a2cc187a4..4893ab1b3 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java @@ -1,11 +1,13 @@ package dev.dubhe.anvilcraft.api.power; +import org.jetbrains.annotations.NotNull; + /** * 电力中继器 */ public interface IPowerTransmitter extends IPowerComponent { @Override - default PowerComponentType getType() { + default @NotNull PowerComponentType getComponentType() { return PowerComponentType.TRANSMITTER; } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java index 2bf58b810..de81e66f0 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java @@ -92,6 +92,7 @@ public void add(IPowerComponent @NotNull ... components) { } else if (component instanceof IPowerTransmitter transmitter) { this.transmitters.add(transmitter); } + component.setGrid(this); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/CorruptedBeaconBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/CorruptedBeaconBlock.java index a721dc2c6..d1a1b9fd9 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/CorruptedBeaconBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/CorruptedBeaconBlock.java @@ -35,7 +35,7 @@ public CorruptedBeaconBlock(Properties properties) { @Override public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { - return CorruptedBeaconBlockEntity.createBlockEntity(ModBlockEntities.CORRUPTED_BEACON.get(), pos, state); + return new CorruptedBeaconBlockEntity(pos, state); } @Override diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java new file mode 100644 index 000000000..9ab4b97de --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java @@ -0,0 +1,29 @@ +package dev.dubhe.anvilcraft.block; + +import dev.dubhe.anvilcraft.block.entity.CreativeDynamoBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nonnull; + +public class CreativeDynamoBlock extends BaseEntityBlock { + public CreativeDynamoBlock(Properties properties) { + super(properties); + } + + @Nullable + @Override + public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { + return new CreativeDynamoBlockEntity(pos, state); + } + + @Override + public @Nonnull RenderShape getRenderShape(@Nonnull BlockState state) { + return RenderShape.MODEL; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java index c1abc8b89..1c4c6ae8f 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/AutoCrafterBlockEntity.java @@ -128,7 +128,7 @@ public void fillStackedContents(StackedContents contents) { }; - public AutoCrafterBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { + protected AutoCrafterBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { super(type, pos, blockState); } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java index 09037554f..aacd83c02 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChuteBlockEntity.java @@ -39,7 +39,7 @@ public void onContentsChanged(int slot) { } }; - public ChuteBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { + protected ChuteBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { super(type, pos, blockState); } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CorruptedBeaconBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CorruptedBeaconBlockEntity.java index c09c537d5..e5568caf1 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CorruptedBeaconBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CorruptedBeaconBlockEntity.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import dev.dubhe.anvilcraft.init.ModBlockEntities; import lombok.Getter; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -33,16 +34,20 @@ public class CorruptedBeaconBlockEntity extends BlockEntity { int levels; private int lastCheckY; - public CorruptedBeaconBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { - super(type, pos, blockState); - } - public static @NotNull CorruptedBeaconBlockEntity createBlockEntity( BlockEntityType type, BlockPos pos, BlockState blockState ) { return new CorruptedBeaconBlockEntity(type, pos, blockState); } + public CorruptedBeaconBlockEntity(BlockPos pos, BlockState blockState) { + this(ModBlockEntities.CORRUPTED_BEACON.get(), pos, blockState); + } + + private CorruptedBeaconBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { + super(type, pos, blockState); + } + /** * tick 逻辑 * diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java new file mode 100644 index 000000000..737ac2ff0 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java @@ -0,0 +1,73 @@ +package dev.dubhe.anvilcraft.block.entity; + +import dev.dubhe.anvilcraft.api.power.IPowerProducer; +import dev.dubhe.anvilcraft.api.power.PowerGrid; +import dev.dubhe.anvilcraft.init.ModBlockEntities; +import lombok.Getter; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +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 org.jetbrains.annotations.NotNull; + +public class CreativeDynamoBlockEntity extends BlockEntity implements IPowerProducer { + @Getter + private PowerGrid grid = null; + private int power = 16; + + public static @NotNull CreativeDynamoBlockEntity createBlockEntity( + BlockEntityType type, BlockPos pos, BlockState blockState + ) { + return new CreativeDynamoBlockEntity(type, pos, blockState); + } + + public CreativeDynamoBlockEntity(BlockPos pos, BlockState blockState) { + this(ModBlockEntities.CREATIVE_DYNAMO.get(), pos, blockState); + } + + private CreativeDynamoBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { + super(type, pos, blockState); + } + + @Override + public void setRemoved() { + super.setRemoved(); + if (this.grid != null) { + this.grid.remove(this); + this.grid = null; + } + } + + @Override + public void clearRemoved() { + super.clearRemoved(); + } + + @Override + protected void saveAdditional(@NotNull CompoundTag tag) { + super.saveAdditional(tag); + tag.putInt("power", power); + } + + @Override + public void load(@NotNull CompoundTag tag) { + super.load(tag); + this.power = tag.getInt("power"); + } + + @Override + public int getOutputPower() { + return this.power; + } + + @Override + public @NotNull BlockPos getPos() { + return this.getBlockPos(); + } + + @Override + public void setGrid(PowerGrid grid) { + this.grid = grid; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java index f73d85779..8e07f6308 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java @@ -28,7 +28,7 @@ public void onContentsChanged(int slot) { } }; - public SimpleChuteBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { + protected SimpleChuteBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { super(type, pos, blockState); } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java index 1e4deae38..10b31cdcb 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java @@ -4,6 +4,7 @@ import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity; import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; import dev.dubhe.anvilcraft.block.entity.CorruptedBeaconBlockEntity; +import dev.dubhe.anvilcraft.block.entity.CreativeDynamoBlockEntity; import dev.dubhe.anvilcraft.block.entity.SimpleChuteBlockEntity; import dev.dubhe.anvilcraft.client.renderer.blockentity.CorruptedBeaconRenderer; @@ -34,6 +35,11 @@ public class ModBlockEntities { .renderer(() -> CorruptedBeaconRenderer::new) .register(); + public static final BlockEntityEntry CREATIVE_DYNAMO = REGISTRATE + .blockEntity("creative_dynamo", CreativeDynamoBlockEntity::createBlockEntity) + .validBlock(ModBlocks.CREATIVE_DYNAMO) + .register(); + public static void register() { } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java index 3761d340b..7b282dadb 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java @@ -6,6 +6,7 @@ import dev.dubhe.anvilcraft.block.AutoCrafterBlock; import dev.dubhe.anvilcraft.block.ChuteBlock; import dev.dubhe.anvilcraft.block.CorruptedBeaconBlock; +import dev.dubhe.anvilcraft.block.CreativeDynamoBlock; import dev.dubhe.anvilcraft.block.FerriteCoreMagnetBlock; import dev.dubhe.anvilcraft.block.HollowMagnetBlock; import dev.dubhe.anvilcraft.block.LavaCauldronBlock; @@ -37,344 +38,352 @@ public class ModBlocks { public static final BlockEntry STAMPING_PLATFORM = REGISTRATE - .block("stamping_platform", StampingPlatformBlock::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .blockstate((ctx, provider) -> { - }) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) - .pattern("BAB") - .pattern("B B") - .pattern("B B") - .define('A', ModItemTags.IRON_PLATES) - .define('B', Items.IRON_INGOT) - .unlockedBy("has_" + ModItemTags.IRON_PLATES.location().getPath(), - AnvilCraftDatagen.has(ModItemTags.IRON_PLATES)) - .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), AnvilCraftDatagen.has(Items.IRON_INGOT)) - .save(provider)) - .register(); + .block("stamping_platform", StampingPlatformBlock::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) + .pattern("BAB") + .pattern("B B") + .pattern("B B") + .define('A', ModItemTags.IRON_PLATES) + .define('B', Items.IRON_INGOT) + .unlockedBy("has_" + ModItemTags.IRON_PLATES.location().getPath(), + AnvilCraftDatagen.has(ModItemTags.IRON_PLATES)) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), AnvilCraftDatagen.has(Items.IRON_INGOT)) + .save(provider)) + .register(); public static final BlockEntry CORRUPTED_BEACON = REGISTRATE - .block("corrupted_beacon", CorruptedBeaconBlock::new) - .initialProperties(() -> Blocks.BEACON) - .blockstate((ctx, provider) -> { - }) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .register(); + .block("corrupted_beacon", CorruptedBeaconBlock::new) + .initialProperties(() -> Blocks.BEACON) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .register(); public static final BlockEntry ROYAL_ANVIL = REGISTRATE - .block("royal_anvil", RoyalAnvilBlock::new) - .initialProperties(() -> Blocks.ANVIL) - .blockstate((ctx, provider) -> { - }) - .simpleItem() - .defaultLoot() - .tag(BlockTags.ANVIL, ModBlockTags.CANT_BROKEN_ANVIL, BlockTags.MINEABLE_WITH_PICKAXE) - .register(); + .block("royal_anvil", RoyalAnvilBlock::new) + .initialProperties(() -> Blocks.ANVIL) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .defaultLoot() + .tag(BlockTags.ANVIL, ModBlockTags.CANT_BROKEN_ANVIL, BlockTags.MINEABLE_WITH_PICKAXE) + .register(); public static final BlockEntry MAGNET_BLOCK = REGISTRATE - .block("magnet_block", MagnetBlock::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .blockstate((ctx, provider) -> { - }) - .simpleItem() - .defaultLoot() - .tag(ModBlockTags.MAGNET, BlockTags.MINEABLE_WITH_PICKAXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) - .pattern("AAA") - .pattern("AAA") - .pattern("AAA") - .define('A', ModItems.MAGNET_INGOT) - .unlockedBy("hasitem", RegistrateRecipeProvider.has(ModItems.MAGNET_INGOT)) - .save(provider) - ) - .register(); + .block("magnet_block", MagnetBlock::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .defaultLoot() + .tag(ModBlockTags.MAGNET, BlockTags.MINEABLE_WITH_PICKAXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) + .pattern("AAA") + .pattern("AAA") + .pattern("AAA") + .define('A', ModItems.MAGNET_INGOT) + .unlockedBy("hasitem", RegistrateRecipeProvider.has(ModItems.MAGNET_INGOT)) + .save(provider) + ) + .register(); public static final BlockEntry HOLLOW_MAGNET_BLOCK = REGISTRATE - .block("hollow_magnet_block", HollowMagnetBlock::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .blockstate((ctx, provider) -> { - }) - .simpleItem() - .defaultLoot() - .tag(ModBlockTags.MAGNET, BlockTags.MINEABLE_WITH_PICKAXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) - .pattern("AAA") - .pattern("A A") - .pattern("AAA") - .define('A', ModItems.MAGNET_INGOT) - .unlockedBy("hasitem", RegistrateRecipeProvider.has(ModItems.MAGNET_INGOT)) - .save(provider)) - .register(); + .block("hollow_magnet_block", HollowMagnetBlock::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .defaultLoot() + .tag(ModBlockTags.MAGNET, BlockTags.MINEABLE_WITH_PICKAXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) + .pattern("AAA") + .pattern("A A") + .pattern("AAA") + .define('A', ModItems.MAGNET_INGOT) + .unlockedBy("hasitem", RegistrateRecipeProvider.has(ModItems.MAGNET_INGOT)) + .save(provider)) + .register(); public static final BlockEntry FERRITE_CORE_MAGNET_BLOCK = REGISTRATE - .block("ferrite_core_magnet_block", FerriteCoreMagnetBlock::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .properties(BlockBehaviour.Properties::randomTicks) - .blockstate((ctx, provider) -> { - }) - .simpleItem() - .defaultLoot() - .tag(ModBlockTags.MAGNET, BlockTags.MINEABLE_WITH_PICKAXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) - .pattern("AAA") - .pattern("ABA") - .pattern("AAA") - .define('A', ModItems.MAGNET_INGOT) - .define('B', Items.IRON_INGOT) - .unlockedBy("has_magnet_ingot", RegistrateRecipeProvider.has(ModItems.MAGNET_INGOT)) - .unlockedBy("has_iron_ingot", RegistrateRecipeProvider.has(Items.IRON_INGOT)) - .save(provider) - ) - .register(); + .block("ferrite_core_magnet_block", FerriteCoreMagnetBlock::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .properties(BlockBehaviour.Properties::randomTicks) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .defaultLoot() + .tag(ModBlockTags.MAGNET, BlockTags.MINEABLE_WITH_PICKAXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) + .pattern("AAA") + .pattern("ABA") + .pattern("AAA") + .define('A', ModItems.MAGNET_INGOT) + .define('B', Items.IRON_INGOT) + .unlockedBy("has_magnet_ingot", RegistrateRecipeProvider.has(ModItems.MAGNET_INGOT)) + .unlockedBy("has_iron_ingot", RegistrateRecipeProvider.has(Items.IRON_INGOT)) + .save(provider) + ) + .register(); public static final BlockEntry CHUTE = REGISTRATE - .block("chute", ChuteBlock::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .properties(BlockBehaviour.Properties::noOcclusion) - .blockstate((ctx, provider) -> { - }) - .item(BlockItem::new) - .onRegister(blockItem -> Item.BY_BLOCK.put(ModBlocks.SIMPLE_CHUTE.get(), blockItem)) - .build() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModBlocks.CHUTE) - .pattern("A A") - .pattern("ABA") - .pattern(" A ") - .define('A', Items.IRON_INGOT) - .define('B', Items.DROPPER) - .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), AnvilCraftDatagen.has(Items.IRON_INGOT)) - .unlockedBy(AnvilCraftDatagen.hasItem(Items.DROPPER), AnvilCraftDatagen.has(Items.DROPPER)) - .save(provider) - ) - .register(); + .block("chute", ChuteBlock::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .properties(BlockBehaviour.Properties::noOcclusion) + .blockstate((ctx, provider) -> { + }) + .item(BlockItem::new) + .onRegister(blockItem -> Item.BY_BLOCK.put(ModBlocks.SIMPLE_CHUTE.get(), blockItem)) + .build() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModBlocks.CHUTE) + .pattern("A A") + .pattern("ABA") + .pattern(" A ") + .define('A', Items.IRON_INGOT) + .define('B', Items.DROPPER) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), AnvilCraftDatagen.has(Items.IRON_INGOT)) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.DROPPER), AnvilCraftDatagen.has(Items.DROPPER)) + .save(provider) + ) + .register(); public static final BlockEntry SIMPLE_CHUTE = REGISTRATE - .block("simple_chute", SimpleChuteBlock::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .properties(BlockBehaviour.Properties::noOcclusion) - .blockstate((ctx, provider) -> { - }) - .loot((tables, block) -> tables.dropOther(block, ModBlocks.CHUTE)) - .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE) - .register(); + .block("simple_chute", SimpleChuteBlock::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .properties(BlockBehaviour.Properties::noOcclusion) + .blockstate((ctx, provider) -> { + }) + .loot((tables, block) -> tables.dropOther(block, ModBlocks.CHUTE)) + .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE) + .register(); public static final BlockEntry AUTO_CRAFTER = REGISTRATE - .block("auto_crafter", AutoCrafterBlock::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .blockstate((ctx, provider) -> { - }) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) - .pattern("AAA") - .pattern("ABA") - .pattern("ACA") - .define('A', Items.IRON_INGOT) - .define('B', Items.CRAFTING_TABLE) - .define('C', Items.DROPPER) - .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), AnvilCraftDatagen.has(Items.IRON_INGOT)) - .unlockedBy(AnvilCraftDatagen.hasItem(Items.CRAFTING_TABLE), - AnvilCraftDatagen.has(Items.CRAFTING_TABLE)) - .unlockedBy(AnvilCraftDatagen.hasItem(Items.DROPPER), AnvilCraftDatagen.has(Items.DROPPER)) - .save(provider) - ) - .register(); + .block("auto_crafter", AutoCrafterBlock::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) + .pattern("AAA") + .pattern("ABA") + .pattern("ACA") + .define('A', Items.IRON_INGOT) + .define('B', Items.CRAFTING_TABLE) + .define('C', Items.DROPPER) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), AnvilCraftDatagen.has(Items.IRON_INGOT)) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.CRAFTING_TABLE), + AnvilCraftDatagen.has(Items.CRAFTING_TABLE)) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.DROPPER), AnvilCraftDatagen.has(Items.DROPPER)) + .save(provider) + ) + .register(); public static final BlockEntry ROYAL_GRINDSTONE = REGISTRATE - .block("royal_grindstone", RoyalGrindstone::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .blockstate((ctx, provider) -> { - }) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .register(); + .block("royal_grindstone", RoyalGrindstone::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .register(); public static final BlockEntry ROYAL_SMITHING_TABLE = REGISTRATE - .block("royal_smithing_table", RoyalSmithingTableBlock::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .blockstate((ctx, provider) -> { - }) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .register(); + .block("royal_smithing_table", RoyalSmithingTableBlock::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .register(); public static final BlockEntry ROYAL_STEEL_BLOCK = REGISTRATE - .block("royal_steel_block", Block::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) - .pattern("AAA") - .pattern("AAA") - .pattern("AAA") - .define('A', ModItems.ROYAL_STEEL_INGOT) - .unlockedBy("hasitem", RegistrateRecipeProvider.has(ModItems.ROYAL_STEEL_INGOT)) - .save(provider) - ) - .register(); + .block("royal_steel_block", Block::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) + .pattern("AAA") + .pattern("AAA") + .pattern("AAA") + .define('A', ModItems.ROYAL_STEEL_INGOT) + .unlockedBy("hasitem", RegistrateRecipeProvider.has(ModItems.ROYAL_STEEL_INGOT)) + .save(provider) + ) + .register(); public static final BlockEntry SMOOTH_ROYAL_STEEL_BLOCK = REGISTRATE - .block("smooth_royal_steel_block", Block::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .register(); + .block("smooth_royal_steel_block", Block::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .register(); public static final BlockEntry CUT_ROYAL_STEEL_BLOCK = REGISTRATE - .block("cut_royal_steel_block", Block::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get(), 4) - .pattern("AA") - .pattern("AA") - .define('A', ModBlocks.ROYAL_STEEL_BLOCK) - .unlockedBy(AnvilCraftDatagen.hasItem(ModBlocks.ROYAL_STEEL_BLOCK.asItem()), - AnvilCraftDatagen.has(ModBlocks.ROYAL_STEEL_BLOCK)) - .save(provider, AnvilCraft.of("craft/cut_royal_steel_block")) - ) - .register(); + .block("cut_royal_steel_block", Block::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get(), 4) + .pattern("AA") + .pattern("AA") + .define('A', ModBlocks.ROYAL_STEEL_BLOCK) + .unlockedBy(AnvilCraftDatagen.hasItem(ModBlocks.ROYAL_STEEL_BLOCK.asItem()), + AnvilCraftDatagen.has(ModBlocks.ROYAL_STEEL_BLOCK)) + .save(provider, AnvilCraft.of("craft/cut_royal_steel_block")) + ) + .register(); public static final BlockEntry CUT_ROYAL_STEEL_SLAB = REGISTRATE - .block("cut_royal_steel_slab", SlabBlock::new) - .initialProperties(() -> Blocks.IRON_BLOCK) - .blockstate((ctx, provider) -> provider.slabBlock(ctx.get(), - AnvilCraft.of("block/cut_royal_steel_block"), - AnvilCraft.of("block/cut_royal_steel_block"))) - .simpleItem() - .loot((tables, block) -> tables.add(block, tables::createSlabItemTable)) - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get(), 6) - .pattern("AAA") - .define('A', ModBlocks.CUT_ROYAL_STEEL_BLOCK) - .unlockedBy(AnvilCraftDatagen.hasItem(ModBlocks.CUT_ROYAL_STEEL_BLOCK.asItem()), - AnvilCraftDatagen.has(ModBlocks.CUT_ROYAL_STEEL_BLOCK)) - .save(provider, AnvilCraft.of("craft/cut_royal_steel_slab"))) - .register(); + .block("cut_royal_steel_slab", SlabBlock::new) + .initialProperties(() -> Blocks.IRON_BLOCK) + .blockstate((ctx, provider) -> provider.slabBlock(ctx.get(), + AnvilCraft.of("block/cut_royal_steel_block"), + AnvilCraft.of("block/cut_royal_steel_block"))) + .simpleItem() + .loot((tables, block) -> tables.add(block, tables::createSlabItemTable)) + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get(), 6) + .pattern("AAA") + .define('A', ModBlocks.CUT_ROYAL_STEEL_BLOCK) + .unlockedBy(AnvilCraftDatagen.hasItem(ModBlocks.CUT_ROYAL_STEEL_BLOCK.asItem()), + AnvilCraftDatagen.has(ModBlocks.CUT_ROYAL_STEEL_BLOCK)) + .save(provider, AnvilCraft.of("craft/cut_royal_steel_slab"))) + .register(); public static final BlockEntry CUT_ROYAL_STEEL_STAIRS = REGISTRATE - .block("cut_royal_steel_stairs", (properties) -> - new StairBlock(ModBlocks.CUT_ROYAL_STEEL_BLOCK.getDefaultState(), properties)) - .initialProperties(() -> Blocks.IRON_BLOCK) - .blockstate((ctx, provider) -> provider.stairsBlock(ctx.get(), - AnvilCraft.of("block/cut_royal_steel_block"))) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get(), 4) - .pattern("A ") - .pattern("AA ") - .pattern("AAA") - .define('A', ModBlocks.CUT_ROYAL_STEEL_BLOCK) - .unlockedBy(AnvilCraftDatagen.hasItem(ModBlocks.CUT_ROYAL_STEEL_BLOCK.asItem()), - AnvilCraftDatagen.has(ModBlocks.CUT_ROYAL_STEEL_BLOCK)) - .save(provider, AnvilCraft.of("craft/cut_royal_steel_stairs"))) - .register(); + .block("cut_royal_steel_stairs", (properties) -> + new StairBlock(ModBlocks.CUT_ROYAL_STEEL_BLOCK.getDefaultState(), properties)) + .initialProperties(() -> Blocks.IRON_BLOCK) + .blockstate((ctx, provider) -> provider.stairsBlock(ctx.get(), + AnvilCraft.of("block/cut_royal_steel_block"))) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get(), 4) + .pattern("A ") + .pattern("AA ") + .pattern("AAA") + .define('A', ModBlocks.CUT_ROYAL_STEEL_BLOCK) + .unlockedBy(AnvilCraftDatagen.hasItem(ModBlocks.CUT_ROYAL_STEEL_BLOCK.asItem()), + AnvilCraftDatagen.has(ModBlocks.CUT_ROYAL_STEEL_BLOCK)) + .save(provider, AnvilCraft.of("craft/cut_royal_steel_stairs"))) + .register(); public static final BlockEntry LAVA_CAULDRON = REGISTRATE - .block("lava_cauldron", LavaCauldronBlock::new) - .initialProperties(() -> Blocks.LAVA_CAULDRON) - .properties(properties -> properties.lightLevel(blockState -> - blockState.getValue(LayeredCauldronBlock.LEVEL) * 5)) - .blockstate((ctx, provider) -> { - }) - .loot((tables, block) -> tables.dropOther(block, Items.CAULDRON)) - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .register(); + .block("lava_cauldron", LavaCauldronBlock::new) + .initialProperties(() -> Blocks.LAVA_CAULDRON) + .properties(properties -> properties.lightLevel(blockState -> + blockState.getValue(LayeredCauldronBlock.LEVEL) * 5)) + .blockstate((ctx, provider) -> { + }) + .loot((tables, block) -> tables.dropOther(block, Items.CAULDRON)) + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .register(); public static final BlockEntry CURSED_GOLD_BLOCK = REGISTRATE - .block("cursed_gold_block", Block::new) - .initialProperties(() -> Blocks.GOLD_BLOCK) - .item(CursedBlockItem::new) - .build() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) - .pattern("AAA") - .pattern("AAA") - .pattern("AAA") - .define('A', ModItems.CURSED_GOLD_INGOT) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.CURSED_GOLD_INGOT.get()), - AnvilCraftDatagen.has(ModItems.CURSED_GOLD_INGOT)) - .save(provider)) - .register(); + .block("cursed_gold_block", Block::new) + .initialProperties(() -> Blocks.GOLD_BLOCK) + .item(CursedBlockItem::new) + .build() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) + .pattern("AAA") + .pattern("AAA") + .pattern("AAA") + .define('A', ModItems.CURSED_GOLD_INGOT) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.CURSED_GOLD_INGOT.get()), + AnvilCraftDatagen.has(ModItems.CURSED_GOLD_INGOT)) + .save(provider)) + .register(); public static final BlockEntry TOPAZ_BLOCK = REGISTRATE - .block("topaz_block", Block::new) - .initialProperties(() -> Blocks.EMERALD_BLOCK) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) - .pattern("AAA") - .pattern("AAA") - .pattern("AAA") - .define('A', ModItems.TOPAZ) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.TOPAZ.get()), AnvilCraftDatagen.has(ModItems.TOPAZ)) - .save(provider)) - .register(); + .block("topaz_block", Block::new) + .initialProperties(() -> Blocks.EMERALD_BLOCK) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) + .pattern("AAA") + .pattern("AAA") + .pattern("AAA") + .define('A', ModItems.TOPAZ) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.TOPAZ.get()), AnvilCraftDatagen.has(ModItems.TOPAZ)) + .save(provider)) + .register(); public static final BlockEntry RUBY_BLOCK = REGISTRATE - .block("ruby_block", Block::new) - .initialProperties(() -> Blocks.EMERALD_BLOCK) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) - .pattern("AAA") - .pattern("AAA") - .pattern("AAA") - .define('A', ModItems.RUBY) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.RUBY.get()), AnvilCraftDatagen.has(ModItems.RUBY)) - .save(provider)) - .register(); + .block("ruby_block", Block::new) + .initialProperties(() -> Blocks.EMERALD_BLOCK) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) + .pattern("AAA") + .pattern("AAA") + .pattern("AAA") + .define('A', ModItems.RUBY) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.RUBY.get()), AnvilCraftDatagen.has(ModItems.RUBY)) + .save(provider)) + .register(); public static final BlockEntry SAPPHIRE_BLOCK = REGISTRATE - .block("sapphire_block", Block::new) - .initialProperties(() -> Blocks.EMERALD_BLOCK) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) - .pattern("AAA") - .pattern("AAA") - .pattern("AAA") - .define('A', ModItems.SAPPHIRE) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.SAPPHIRE.get()), - AnvilCraftDatagen.has(ModItems.SAPPHIRE)) - .save(provider)) - .register(); + .block("sapphire_block", Block::new) + .initialProperties(() -> Blocks.EMERALD_BLOCK) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.BEACON_BASE_BLOCKS) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) + .pattern("AAA") + .pattern("AAA") + .pattern("AAA") + .define('A', ModItems.SAPPHIRE) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.SAPPHIRE.get()), + AnvilCraftDatagen.has(ModItems.SAPPHIRE)) + .save(provider)) + .register(); public static final BlockEntry RESIN_BLOCK = REGISTRATE - .block("resin_block", SlimeBlock::new) - .initialProperties(() -> Blocks.SLIME_BLOCK) - .blockstate((ctx, provider) -> { - }) - .properties(properties -> properties.sound(SoundType.HONEY_BLOCK)) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) - .pattern("AAA") - .pattern("AAA") - .pattern("AAA") - .define('A', ModItems.RESIN) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.RESIN.get()), - AnvilCraftDatagen.has(ModItems.RESIN)) - .save(provider)) - .register(); + .block("resin_block", SlimeBlock::new) + .initialProperties(() -> Blocks.SLIME_BLOCK) + .blockstate((ctx, provider) -> { + }) + .properties(properties -> properties.sound(SoundType.HONEY_BLOCK)) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) + .pattern("AAA") + .pattern("AAA") + .pattern("AAA") + .define('A', ModItems.RESIN) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.RESIN.get()), + AnvilCraftDatagen.has(ModItems.RESIN)) + .save(provider)) + .register(); public static final BlockEntry AMBER_BLOCK = REGISTRATE - .block("amber_block", HalfTransparentBlock::new) - .initialProperties(() -> Blocks.EMERALD_BLOCK) - .blockstate((ctx, provider) -> { - provider.simpleBlock(ctx.get()); - provider.models().cubeAll(ctx.getName(), provider.modLoc("block/" + ctx.getName())) - .renderType("translucent"); - }) - .properties(BlockBehaviour.Properties::noOcclusion) - .simpleItem() - .defaultLoot() - .tag(BlockTags.MINEABLE_WITH_PICKAXE) - .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) - .pattern("AAA") - .pattern("AAA") - .pattern("AAA") - .define('A', ModItems.AMBER) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.AMBER.get()), AnvilCraftDatagen.has(ModItems.AMBER)) - .save(provider)) - .register(); + .block("amber_block", HalfTransparentBlock::new) + .initialProperties(() -> Blocks.EMERALD_BLOCK) + .blockstate((ctx, provider) -> { + provider.simpleBlock(ctx.get()); + provider.models().cubeAll(ctx.getName(), provider.modLoc("block/" + ctx.getName())) + .renderType("translucent"); + }) + .properties(BlockBehaviour.Properties::noOcclusion) + .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) + .pattern("AAA") + .pattern("AAA") + .pattern("AAA") + .define('A', ModItems.AMBER) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.AMBER.get()), AnvilCraftDatagen.has(ModItems.AMBER)) + .save(provider)) + .register(); + public static final BlockEntry CREATIVE_DYNAMO = REGISTRATE + .block("creative_dynamo", CreativeDynamoBlock::new) + .initialProperties(ModBlocks.MAGNET_BLOCK) + .properties(BlockBehaviour.Properties::noOcclusion) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .register(); public static void register() { } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java index cc29de131..64047bfcf 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java @@ -61,6 +61,7 @@ public class ModItemGroups { entries.accept(Items.CAMPFIRE.getDefaultInstance()); entries.accept(ModBlocks.STAMPING_PLATFORM.asStack()); entries.accept(ModBlocks.CORRUPTED_BEACON.asStack()); + entries.accept(ModBlocks.CREATIVE_DYNAMO.asStack()); entries.accept(Items.ANVIL.getDefaultInstance()); entries.accept(Items.CHIPPED_ANVIL.getDefaultInstance()); entries.accept(Items.DAMAGED_ANVIL.getDefaultInstance()); diff --git a/common/src/main/resources/assets/anvilcraft/blockstates/creative_dynamo.json b/common/src/main/resources/assets/anvilcraft/blockstates/creative_dynamo.json new file mode 100644 index 000000000..e4e2dcaae --- /dev/null +++ b/common/src/main/resources/assets/anvilcraft/blockstates/creative_dynamo.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "anvilcraft:block/creative_dynamo" + } + } +} \ No newline at end of file diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json index a70745cbd..37286169c 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -3,6 +3,7 @@ "block.anvilcraft.auto_crafter": "ɹǝʇɟɐɹƆ oʇnⱯ", "block.anvilcraft.chute": "ǝʇnɥƆ", "block.anvilcraft.corrupted_beacon": "uoɔɐǝᗺ pǝʇdnɹɹoƆ", + "block.anvilcraft.creative_dynamo": "oɯɐuʎᗡ ǝʌıʇɐǝɹƆ", "block.anvilcraft.cursed_gold_block": "ʞɔoןᗺ pןo⅁ pǝsɹnƆ", "block.anvilcraft.cut_royal_steel_block": "ʞɔoןᗺ ןǝǝʇS ןɐʎoᴚ ʇnƆ", "block.anvilcraft.cut_royal_steel_slab": "qɐןS ןǝǝʇS ןɐʎoᴚ ʇnƆ", @@ -111,6 +112,10 @@ "text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ ɐ ǝɔuɐʇsıp ɯnɯıxɐW", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "snıpɐᴚ sʇɔɐɹʇʇⱯ ɯǝʇI ʇǝubɐW", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ pןǝɥpuɐɥ ɐ snıpɐɹ ɯnɯıxɐW", + "text.autoconfig.anvilcraft.option.powerComponentRange": "sʇuǝuodɯoƆ ɹǝʍoԀ ɟo ǝbuɐᴚ", + "text.autoconfig.anvilcraft.option.powerComponentRange.@Tooltip": "sʇuǝuodɯoɔ ɹǝʍod ɟo ǝbuɐɹ ǝɥʇ ʎɟıʇuǝpı uɐɔ ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥ⟘", + "text.autoconfig.anvilcraft.option.powerTransmitterRange": "ɹǝʇʇıɯsuɐɹ⟘ ɹǝʍoԀ ɟo ǝbuɐᴚ", + "text.autoconfig.anvilcraft.option.powerTransmitterRange.@Tooltip": "ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥʇ ɟo ǝbuɐɹ ǝɥʇ ʎɟıʇuǝpı uɐɔ ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥ⟘", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "snıpɐᴚ xɐW dɯƎ ǝuoʇspǝᴚ", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius.@Tooltip": "ԀWƎ ǝuoʇspǝɹ ɟo ǝɔuɐʇsıp ɯnɯıxɐW", "text.autoconfig.anvilcraft.option.redstoneEmpRadius": "ʞɔoןᗺ ɹǝԀ snıpɐᴚ ԀWƎ ǝuoʇspǝᴚ", diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json index 2c16bbc13..14f73cd24 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -3,6 +3,7 @@ "block.anvilcraft.auto_crafter": "Auto Crafter", "block.anvilcraft.chute": "Chute", "block.anvilcraft.corrupted_beacon": "Corrupted Beacon", + "block.anvilcraft.creative_dynamo": "Creative Dynamo", "block.anvilcraft.cursed_gold_block": "Cursed Gold Block", "block.anvilcraft.cut_royal_steel_block": "Cut Royal Steel Block", "block.anvilcraft.cut_royal_steel_slab": "Cut Royal Steel Slab", @@ -111,6 +112,10 @@ "text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "Maximum distance a magnet attracts", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "Magnet Item Attracts Radius", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "Maximum radius a handheld magnet attracts", + "text.autoconfig.anvilcraft.option.powerComponentRange": "Range of Power Components", + "text.autoconfig.anvilcraft.option.powerComponentRange.@Tooltip": "The power transmitter can identify the range of power components", + "text.autoconfig.anvilcraft.option.powerTransmitterRange": "Range of Power Transmitter", + "text.autoconfig.anvilcraft.option.powerTransmitterRange.@Tooltip": "The power transmitter can identify the range of the power transmitter", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "Redstone Emp Max Radius", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius.@Tooltip": "Maximum distance of redstone EMP", "text.autoconfig.anvilcraft.option.redstoneEmpRadius": "Redstone EMP Radius Per Block", diff --git a/fabric/src/generated/resources/assets/anvilcraft/models/item/creative_dynamo.json b/fabric/src/generated/resources/assets/anvilcraft/models/item/creative_dynamo.json new file mode 100644 index 000000000..14133ea10 --- /dev/null +++ b/fabric/src/generated/resources/assets/anvilcraft/models/item/creative_dynamo.json @@ -0,0 +1,3 @@ +{ + "parent": "anvilcraft:block/creative_dynamo" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/creative_dynamo.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/creative_dynamo.json new file mode 100644 index 000000000..e42b9a45b --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/creative_dynamo.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "anvilcraft:creative_dynamo" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:blocks/creative_dynamo" +} \ No newline at end of file diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ModFabricEvents.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ModFabricEvents.java index 405ff50f2..8d5207f5e 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ModFabricEvents.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ModFabricEvents.java @@ -10,6 +10,7 @@ public static void init() { LootTableEvent.init(); LightningEvent.init(); AnvilEntityEvent.init(); + ServerBlockEntityEvent.init(); CommandEvent.init(); } } diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerBlockEntityEvent.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerBlockEntityEvent.java new file mode 100644 index 000000000..b719bc882 --- /dev/null +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerBlockEntityEvent.java @@ -0,0 +1,29 @@ +package dev.dubhe.anvilcraft.event.fabric; + +import dev.dubhe.anvilcraft.api.power.IPowerComponent; +import dev.dubhe.anvilcraft.api.power.PowerGrid; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerBlockEntityEvents; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.block.entity.BlockEntity; + +public class ServerBlockEntityEvent { + public static void init() { + ServerBlockEntityEvents.BLOCK_ENTITY_LOAD.register(ServerBlockEntityEvent::onLoad); + ServerBlockEntityEvents.BLOCK_ENTITY_UNLOAD.register(ServerBlockEntityEvent::onUnload); + } + + private static void onLoad(BlockEntity entity, ServerLevel level) { + if (entity instanceof IPowerComponent component) { + PowerGrid.addComponent(component); + } + } + + private static void onUnload(BlockEntity entity, ServerLevel level) { + if (entity instanceof IPowerComponent component) { + PowerGrid grid = component.getGrid(); + if (grid == null) return; + grid.remove(component); + component.setGrid(grid); + } + } +} diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java index c605e78c2..a792897d5 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java @@ -3,9 +3,12 @@ import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.api.event.server.ServerEndDataPackReloadEvent; import dev.dubhe.anvilcraft.api.event.server.ServerStartedEvent; +import dev.dubhe.anvilcraft.api.power.PowerGrid; import dev.dubhe.anvilcraft.utils.fabric.ServerHooks; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.packs.resources.CloseableResourceManager; public class ServerLifecycleEvent { @@ -15,6 +18,7 @@ public class ServerLifecycleEvent { public static void init() { ServerLifecycleEvents.SERVER_STARTED.register(ServerLifecycleEvent::serverStarted); ServerLifecycleEvents.END_DATA_PACK_RELOAD.register(ServerLifecycleEvent::endDataPackReload); + ServerTickEvents.START_WORLD_TICK.register(ServerLifecycleEvent::startWorldTick); } public static void serverStarted(MinecraftServer server) { @@ -27,4 +31,8 @@ public static void endDataPackReload( ) { AnvilCraft.EVENT_BUS.post(new ServerEndDataPackReloadEvent(server, resourceManager)); } + + public static void startWorldTick(ServerLevel world) { + PowerGrid.tickGrid(); + } } diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json index a70745cbd..37286169c 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -3,6 +3,7 @@ "block.anvilcraft.auto_crafter": "ɹǝʇɟɐɹƆ oʇnⱯ", "block.anvilcraft.chute": "ǝʇnɥƆ", "block.anvilcraft.corrupted_beacon": "uoɔɐǝᗺ pǝʇdnɹɹoƆ", + "block.anvilcraft.creative_dynamo": "oɯɐuʎᗡ ǝʌıʇɐǝɹƆ", "block.anvilcraft.cursed_gold_block": "ʞɔoןᗺ pןo⅁ pǝsɹnƆ", "block.anvilcraft.cut_royal_steel_block": "ʞɔoןᗺ ןǝǝʇS ןɐʎoᴚ ʇnƆ", "block.anvilcraft.cut_royal_steel_slab": "qɐןS ןǝǝʇS ןɐʎoᴚ ʇnƆ", @@ -111,6 +112,10 @@ "text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ ɐ ǝɔuɐʇsıp ɯnɯıxɐW", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "snıpɐᴚ sʇɔɐɹʇʇⱯ ɯǝʇI ʇǝubɐW", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ pןǝɥpuɐɥ ɐ snıpɐɹ ɯnɯıxɐW", + "text.autoconfig.anvilcraft.option.powerComponentRange": "sʇuǝuodɯoƆ ɹǝʍoԀ ɟo ǝbuɐᴚ", + "text.autoconfig.anvilcraft.option.powerComponentRange.@Tooltip": "sʇuǝuodɯoɔ ɹǝʍod ɟo ǝbuɐɹ ǝɥʇ ʎɟıʇuǝpı uɐɔ ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥ⟘", + "text.autoconfig.anvilcraft.option.powerTransmitterRange": "ɹǝʇʇıɯsuɐɹ⟘ ɹǝʍoԀ ɟo ǝbuɐᴚ", + "text.autoconfig.anvilcraft.option.powerTransmitterRange.@Tooltip": "ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥʇ ɟo ǝbuɐɹ ǝɥʇ ʎɟıʇuǝpı uɐɔ ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥ⟘", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "snıpɐᴚ xɐW dɯƎ ǝuoʇspǝᴚ", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius.@Tooltip": "ԀWƎ ǝuoʇspǝɹ ɟo ǝɔuɐʇsıp ɯnɯıxɐW", "text.autoconfig.anvilcraft.option.redstoneEmpRadius": "ʞɔoןᗺ ɹǝԀ snıpɐᴚ ԀWƎ ǝuoʇspǝᴚ", diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json index 2c16bbc13..14f73cd24 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -3,6 +3,7 @@ "block.anvilcraft.auto_crafter": "Auto Crafter", "block.anvilcraft.chute": "Chute", "block.anvilcraft.corrupted_beacon": "Corrupted Beacon", + "block.anvilcraft.creative_dynamo": "Creative Dynamo", "block.anvilcraft.cursed_gold_block": "Cursed Gold Block", "block.anvilcraft.cut_royal_steel_block": "Cut Royal Steel Block", "block.anvilcraft.cut_royal_steel_slab": "Cut Royal Steel Slab", @@ -111,6 +112,10 @@ "text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "Maximum distance a magnet attracts", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "Magnet Item Attracts Radius", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "Maximum radius a handheld magnet attracts", + "text.autoconfig.anvilcraft.option.powerComponentRange": "Range of Power Components", + "text.autoconfig.anvilcraft.option.powerComponentRange.@Tooltip": "The power transmitter can identify the range of power components", + "text.autoconfig.anvilcraft.option.powerTransmitterRange": "Range of Power Transmitter", + "text.autoconfig.anvilcraft.option.powerTransmitterRange.@Tooltip": "The power transmitter can identify the range of the power transmitter", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "Redstone Emp Max Radius", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius.@Tooltip": "Maximum distance of redstone EMP", "text.autoconfig.anvilcraft.option.redstoneEmpRadius": "Redstone EMP Radius Per Block", diff --git a/forge/src/generated/resources/assets/anvilcraft/models/item/creative_dynamo.json b/forge/src/generated/resources/assets/anvilcraft/models/item/creative_dynamo.json new file mode 100644 index 000000000..14133ea10 --- /dev/null +++ b/forge/src/generated/resources/assets/anvilcraft/models/item/creative_dynamo.json @@ -0,0 +1,3 @@ +{ + "parent": "anvilcraft:block/creative_dynamo" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/creative_dynamo.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/creative_dynamo.json new file mode 100644 index 000000000..e42b9a45b --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/creative_dynamo.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "anvilcraft:creative_dynamo" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:blocks/creative_dynamo" +} \ No newline at end of file diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java b/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/forge/ItemDepositoryHelperImpl.java similarity index 98% rename from forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java rename to forge/src/main/java/dev/dubhe/anvilcraft/api/depository/forge/ItemDepositoryHelperImpl.java index 9ce5514a9..5701469b0 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/item/forge/ItemDepositoryHelperImpl.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/api/depository/forge/ItemDepositoryHelperImpl.java @@ -1,4 +1,4 @@ -package dev.dubhe.anvilcraft.api.depository.item.forge; +package dev.dubhe.anvilcraft.api.depository.forge; import dev.dubhe.anvilcraft.api.depository.IItemDepository; import net.minecraft.core.BlockPos; diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/api/event/forge/BlockEntityEvent.java b/forge/src/main/java/dev/dubhe/anvilcraft/api/event/forge/BlockEntityEvent.java new file mode 100644 index 000000000..9d8805703 --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/api/event/forge/BlockEntityEvent.java @@ -0,0 +1,29 @@ +package dev.dubhe.anvilcraft.api.event.forge; + +import lombok.Getter; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraftforge.eventbus.api.Event; + +@Getter +public class BlockEntityEvent extends Event { + private final Level level; + private final BlockEntity entity; + + public BlockEntityEvent(Level level, BlockEntity entity) { + this.level = level; + this.entity = entity; + } + + public static class ServerLoad extends BlockEntityEvent { + public ServerLoad(Level level, BlockEntity entity) { + super(level, entity); + } + } + + public static class ServerUnload extends BlockEntityEvent { + public ServerUnload(Level level, BlockEntity entity) { + super(level, entity); + } + } +} diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/AutoCrafterBlockEntityImpl.java b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/AutoCrafterBlockEntityImpl.java index 49b766009..64ffa4a99 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/AutoCrafterBlockEntityImpl.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/AutoCrafterBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.forge; -import dev.dubhe.anvilcraft.api.depository.item.forge.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.forge.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.AutoCrafterBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/ChuteBlockEntityImpl.java b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/ChuteBlockEntityImpl.java index 61ba3e7e6..f0c82e141 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/ChuteBlockEntityImpl.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/ChuteBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.forge; -import dev.dubhe.anvilcraft.api.depository.item.forge.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.forge.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/SimpleChuteBlockEntityImpl.java b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/SimpleChuteBlockEntityImpl.java index 40404876e..37f7b5dd5 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/SimpleChuteBlockEntityImpl.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/block/entity/forge/SimpleChuteBlockEntityImpl.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block.entity.forge; -import dev.dubhe.anvilcraft.api.depository.item.forge.ItemDepositoryHelperImpl; +import dev.dubhe.anvilcraft.api.depository.forge.ItemDepositoryHelperImpl; import dev.dubhe.anvilcraft.block.entity.SimpleChuteBlockEntity; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEvent.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEvent.java new file mode 100644 index 000000000..87d64c172 --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEvent.java @@ -0,0 +1,35 @@ +package dev.dubhe.anvilcraft.event.forge; + +import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.api.event.forge.BlockEntityEvent; +import dev.dubhe.anvilcraft.api.power.IPowerComponent; +import dev.dubhe.anvilcraft.api.power.PowerGrid; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.jetbrains.annotations.NotNull; + +@Mod.EventBusSubscriber(modid = AnvilCraft.MOD_ID) +public class ServerBlockEntityEvent { + /** + * @param event 服务端方块实体加载事件 + */ + @SubscribeEvent + public static void onLoad(@NotNull BlockEntityEvent.ServerLoad event) { + if (event.getEntity() instanceof IPowerComponent component) { + PowerGrid.addComponent(component); + } + } + + /** + * @param event 服务端方块实体卸载事件 + */ + @SubscribeEvent + public static void onUnload(@NotNull BlockEntityEvent.ServerUnload event) { + if (event.getEntity() instanceof IPowerComponent component) { + PowerGrid grid = component.getGrid(); + if (grid == null) return; + grid.remove(component); + component.setGrid(null); + } + } +} diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java index 15463056d..dd7c7f639 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java @@ -3,8 +3,10 @@ import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.api.event.forge.DataPackReloadedEvent; import dev.dubhe.anvilcraft.api.event.server.ServerEndDataPackReloadEvent; +import dev.dubhe.anvilcraft.api.power.PowerGrid; import net.minecraft.server.MinecraftServer; import net.minecraft.server.packs.resources.CloseableResourceManager; +import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.server.ServerStartedEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @@ -24,9 +26,19 @@ public static void serverStarted(@NotNull ServerStartedEvent event) { * @param event 数据包重载事件 */ @SubscribeEvent - public void onDataPackReloaded(@NotNull DataPackReloadedEvent event) { + public static void onDataPackReloaded(@NotNull DataPackReloadedEvent event) { MinecraftServer server = event.getServer(); CloseableResourceManager resourceManager = event.getResourceManager(); AnvilCraft.EVENT_BUS.post(new ServerEndDataPackReloadEvent(server, resourceManager)); } + + /** + * @param event 世界刻事件 + */ + @SubscribeEvent + public static void onWordTick(@NotNull TickEvent.LevelTickEvent event) { + if (event.level.isClientSide) return; + if (event.phase != TickEvent.Phase.START) return; + PowerGrid.tickGrid(); + } } diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/mixin/forge/LevelChunkMixin.java b/forge/src/main/java/dev/dubhe/anvilcraft/mixin/forge/LevelChunkMixin.java new file mode 100644 index 000000000..77f9f4add --- /dev/null +++ b/forge/src/main/java/dev/dubhe/anvilcraft/mixin/forge/LevelChunkMixin.java @@ -0,0 +1,89 @@ +package dev.dubhe.anvilcraft.mixin.forge; + +import dev.dubhe.anvilcraft.api.event.forge.BlockEntityEvent; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraftforge.common.MinecraftForge; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +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.Slice; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.Map; + +@Mixin(LevelChunk.class) +public abstract class LevelChunkMixin { + @Shadow + public abstract Level getLevel(); + + @Inject( + method = "setBlockEntity", + at = @At( + value = "INVOKE", + target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;" + ) + ) + private void onLoadBlockEntity(BlockEntity entity, CallbackInfo ci) { + if (this.getLevel().isClientSide) return; + MinecraftForge.EVENT_BUS.post(new BlockEntityEvent.ServerLoad(this.getLevel(), entity)); + } + + @Inject( + method = "setBlockEntity", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/block/entity/BlockEntity;setRemoved()V" + ), + locals = LocalCapture.CAPTURE_FAILEXCEPTION + ) + private void onRemoveBlockEntity(BlockEntity entity, CallbackInfo ci, BlockPos blockPos, BlockEntity entity2) { + if (this.getLevel().isClientSide) return; + MinecraftForge.EVENT_BUS.post(new BlockEntityEvent.ServerUnload(this.getLevel(), entity2)); + } + + @Redirect( + method = "getBlockEntity(" + + "Lnet/minecraft/core/BlockPos;" + + "Lnet/minecraft/world/level/chunk/LevelChunk$EntityCreationType;" + + ")" + + "Lnet/minecraft/world/level/block/entity/BlockEntity;", + at = @At( + value = "INVOKE", + target = "Ljava/util/Map;remove(Ljava/lang/Object;)Ljava/lang/Object;", + ordinal = 1 + ) + ) + private V onRemoveBlockEntity(@NotNull Map map, K key) { + @Nullable final V removed = map.remove(key); + if (!this.getLevel().isClientSide && removed != null) { + if (removed instanceof BlockEntity entity) { + MinecraftForge.EVENT_BUS.post(new BlockEntityEvent.ServerUnload(this.getLevel(), entity)); + } + } + return removed; + } + + @Inject( + method = "removeBlockEntity", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/level/block/entity/BlockEntity;setRemoved()V" + ), + locals = LocalCapture.CAPTURE_FAILEXCEPTION + ) + private void onRemoveBlockEntity(BlockPos pos, CallbackInfo ci, BlockEntity removed) { + if (this.getLevel().isClientSide) return; + if (removed != null) { + MinecraftForge.EVENT_BUS.post(new BlockEntityEvent.ServerUnload(this.getLevel(), removed)); + } + } +} diff --git a/forge/src/main/resources/anvilcraft.mixins.json b/forge/src/main/resources/anvilcraft.mixins.json index 746de7061..bea8fec8d 100644 --- a/forge/src/main/resources/anvilcraft.mixins.json +++ b/forge/src/main/resources/anvilcraft.mixins.json @@ -7,7 +7,8 @@ "CraftingHelperMixin", "FallingBlockEntityMixin", "LightningBoltMixin", - "MinecraftServerMixin" + "MinecraftServerMixin", + "LevelChunkMixin" ], "client": [ ], From 0253185c7c604a59f6f4a4c6332000d19e3cd685 Mon Sep 17 00:00:00 2001 From: Gugle Date: Mon, 15 Apr 2024 03:42:12 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E5=8A=A0=E7=83=AD=E5=99=A8=E4=B8=8E?= =?UTF-8?q?=E7=94=B5=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolved #28 resolved #23 --- .../dubhe/anvilcraft/api/power/PowerGrid.java | 21 +++--- .../dubhe/anvilcraft/block/ChuteBlock.java | 2 +- .../anvilcraft/block/CreativeDynamoBlock.java | 14 ++++ .../dubhe/anvilcraft/block/HeaterBlock.java | 62 ++++++++++++++++++ .../anvilcraft/block/SimpleChuteBlock.java | 2 +- .../entity/CreativeDynamoBlockEntity.java | 14 ---- .../block/entity/HeaterBlockEntity.java | 65 +++++++++++++++++++ .../data/generator/AnvilCraftDatagen.java | 4 +- .../anvilcraft/init/ModBlockEntities.java | 38 ++++++----- .../dev/dubhe/anvilcraft/init/ModBlocks.java | 32 +++++++-- .../dubhe/anvilcraft/init/ModItemGroups.java | 5 +- .../dev/dubhe/anvilcraft/init/ModItems.java | 23 ++++++- .../anvilcraft/inventory/RoyalAnvilMenu.java | 4 +- .../dubhe/anvilcraft/item/CapacitorItem.java | 23 +++++++ .../anvilcraft/item/CursedBlockItem.java | 4 +- .../dev/dubhe/anvilcraft/item/CursedItem.java | 9 ++- .../item/{Cursed.java => ICursed.java} | 6 +- .../assets/anvilcraft/blockstates/heater.json | 10 +++ .../anvilcraft/models/block/heater.json | 2 + .../anvilcraft/models/block/heater_lit.json | 2 + .../anvilcraft/models/item/capacitor.json | 14 ++++ .../models/item/capacitor_empty.json | 6 ++ .../assets/anvilcraft/lang/en_ud.json | 2 + .../assets/anvilcraft/lang/en_us.json | 2 + .../assets/anvilcraft/models/item/heater.json | 3 + .../advancements/recipes/misc/heater.json | 61 +++++++++++++++++ .../advancements/recipes/tools/capacitor.json | 61 +++++++++++++++++ .../anvilcraft/loot_tables/blocks/heater.json | 21 ++++++ .../data/anvilcraft/recipes/capacitor.json | 25 +++++++ .../data/anvilcraft/recipes/heater.json | 24 +++++++ ...lient.java => AnvilCraftFabricClient.java} | 3 +- fabric/src/main/resources/fabric.mod.json | 2 +- .../assets/anvilcraft/lang/en_ud.json | 2 + .../assets/anvilcraft/lang/en_us.json | 2 + .../assets/anvilcraft/models/item/heater.json | 3 + .../advancements/recipes/misc/heater.json | 61 +++++++++++++++++ .../advancements/recipes/tools/capacitor.json | 61 +++++++++++++++++ .../anvilcraft/loot_tables/blocks/heater.json | 21 ++++++ .../data/anvilcraft/recipes/capacitor.json | 25 +++++++ .../data/anvilcraft/recipes/heater.json | 24 +++++++ .../anvilcraft/forge/AnvilCraftForge.java | 1 - 41 files changed, 702 insertions(+), 64 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/block/HeaterBlock.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/block/entity/HeaterBlockEntity.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/item/CapacitorItem.java rename common/src/main/java/dev/dubhe/anvilcraft/item/{Cursed.java => ICursed.java} (92%) create mode 100644 common/src/main/resources/assets/anvilcraft/blockstates/heater.json create mode 100644 common/src/main/resources/assets/anvilcraft/models/item/capacitor.json create mode 100644 common/src/main/resources/assets/anvilcraft/models/item/capacitor_empty.json create mode 100644 fabric/src/generated/resources/assets/anvilcraft/models/item/heater.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/heater.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/recipes/capacitor.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/recipes/heater.json rename fabric/src/main/java/dev/dubhe/anvilcraft/client/fabric/{AnvilCraftClient.java => AnvilCraftFabricClient.java} (87%) create mode 100644 forge/src/generated/resources/assets/anvilcraft/models/item/heater.json create mode 100644 forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json create mode 100644 forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json create mode 100644 forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/heater.json create mode 100644 forge/src/generated/resources/data/anvilcraft/recipes/capacitor.json create mode 100644 forge/src/generated/resources/data/anvilcraft/recipes/heater.json diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java index de81e66f0..3af26ba6c 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java @@ -43,14 +43,7 @@ public static void tickGrid() { * 电力刻 */ protected void tick() { - this.generate = 0; - this.consume = 0; - for (IPowerProducer producer : this.producers) { - this.generate += producer.getOutputPower(); - } - for (IPowerConsumer consumer : this.consumers) { - this.consume += consumer.getInputPower(); - } + this.flush(); if (this.isWork()) { int remainder = this.generate - this.consume; for (IPowerStorage storage : storages) { @@ -72,6 +65,17 @@ protected void tick() { } } + private void flush() { + this.generate = 0; + this.consume = 0; + for (IPowerProducer producer : this.producers) { + this.generate += producer.getOutputPower(); + } + for (IPowerConsumer consumer : this.consumers) { + this.consume += consumer.getInputPower(); + } + } + public boolean isWork() { return this.generate >= this.consume; } @@ -94,6 +98,7 @@ public void add(IPowerComponent @NotNull ... components) { } component.setGrid(this); } + this.flush(); } /** diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java index f444086bf..036942fec 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/ChuteBlock.java @@ -133,7 +133,7 @@ public void neighborChanged( } if (!neighborPos.equals(pos.relative(state.getValue(FACING)))) return; BlockState blockState = level.getBlockState(neighborPos); - if (blockState.is(ModBlocks.CHUTE.get())) return; + if (!blockState.is(ModBlocks.CHUTE.get())) return; if (hasChuteFacing(level, neighborPos)) { BlockState newState = ModBlocks.SIMPLE_CHUTE.getDefaultState(); newState = newState.setValue(SimpleChuteBlock.FACING, blockState.getValue(FACING)) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java index 9ab4b97de..b31138553 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java @@ -2,16 +2,22 @@ import dev.dubhe.anvilcraft.block.entity.CreativeDynamoBlockEntity; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; public class CreativeDynamoBlock extends BaseEntityBlock { + public static final VoxelShape AABB = Block.box(0, 0, 0, 16, 4, 16); + public CreativeDynamoBlock(Properties properties) { super(properties); } @@ -26,4 +32,12 @@ public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState sta public @Nonnull RenderShape getRenderShape(@Nonnull BlockState state) { return RenderShape.MODEL; } + + @Override + @SuppressWarnings("deprecation") + public @NotNull VoxelShape getShape( + @NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull CollisionContext context + ) { + return CreativeDynamoBlock.AABB; + } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/HeaterBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/HeaterBlock.java new file mode 100644 index 000000000..ab6d8d55e --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/HeaterBlock.java @@ -0,0 +1,62 @@ +package dev.dubhe.anvilcraft.block; + +import dev.dubhe.anvilcraft.block.entity.HeaterBlockEntity; +import dev.dubhe.anvilcraft.init.ModBlockEntities; +import net.minecraft.core.BlockPos; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RedstoneTorchBlock; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityTicker; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nonnull; + +public class HeaterBlock extends BaseEntityBlock { + public static final BooleanProperty LIT = RedstoneTorchBlock.LIT; + + public HeaterBlock(Properties properties) { + super(properties); + this.registerDefaultState(this.stateDefinition.any().setValue(LIT, false)); + } + + @Override + @Nullable + public BlockState getStateForPlacement(@NotNull BlockPlaceContext context) { + return this.defaultBlockState().setValue(LIT, false); + } + + @Nullable + @Override + public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { + return new HeaterBlockEntity(pos, state); + } + + @Override + protected void createBlockStateDefinition(@NotNull StateDefinition.Builder builder) { + builder.add(LIT); + } + + @Override + public @Nonnull RenderShape getRenderShape(@Nonnull BlockState state) { + return RenderShape.MODEL; + } + + @Nullable + @Override + public BlockEntityTicker getTicker( + @NotNull Level level, @NotNull BlockState state, @NotNull BlockEntityType type + ) { + if (level.isClientSide) return null; + return createTickerHelper(type, ModBlockEntities.HEATER.get(), + (level1, pos, state1, entity) -> entity.tick(level1, pos)); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java index 22478a3a6..b982d6924 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/SimpleChuteBlock.java @@ -102,7 +102,7 @@ public void neighborChanged( } if (!neighborPos.equals(pos.relative(state.getValue(FACING)))) return; BlockState blockState = level.getBlockState(neighborPos); - if (blockState.is(ModBlocks.CHUTE.get())) return; + if (!blockState.is(ModBlocks.CHUTE.get())) return; if (ChuteBlock.hasChuteFacing(level, neighborPos)) { BlockState newState = ModBlocks.SIMPLE_CHUTE.getDefaultState(); newState = newState.setValue(SimpleChuteBlock.FACING, blockState.getValue(FACING)) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java index 737ac2ff0..abc519a78 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java @@ -30,20 +30,6 @@ private CreativeDynamoBlockEntity(BlockEntityType type, BlockPos pos, BlockSt super(type, pos, blockState); } - @Override - public void setRemoved() { - super.setRemoved(); - if (this.grid != null) { - this.grid.remove(this); - this.grid = null; - } - } - - @Override - public void clearRemoved() { - super.clearRemoved(); - } - @Override protected void saveAdditional(@NotNull CompoundTag tag) { super.saveAdditional(tag); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/HeaterBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/HeaterBlockEntity.java new file mode 100644 index 000000000..95698dc28 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/HeaterBlockEntity.java @@ -0,0 +1,65 @@ +package dev.dubhe.anvilcraft.block.entity; + +import dev.dubhe.anvilcraft.api.power.IPowerConsumer; +import dev.dubhe.anvilcraft.api.power.PowerGrid; +import dev.dubhe.anvilcraft.block.HeaterBlock; +import dev.dubhe.anvilcraft.init.ModBlockEntities; +import dev.dubhe.anvilcraft.init.ModBlocks; +import lombok.Getter; +import net.minecraft.core.BlockPos; +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 org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Getter +public class HeaterBlockEntity extends BlockEntity implements IPowerConsumer { + private static final int POWER = 8; + private PowerGrid grid = null; + + public HeaterBlockEntity(BlockPos pos, BlockState blockState) { + this(ModBlockEntities.HEATER.get(), pos, blockState); + } + + public static @NotNull HeaterBlockEntity createBlockEntity( + BlockEntityType type, BlockPos pos, BlockState blockState + ) { + return new HeaterBlockEntity(type, pos, blockState); + } + + private HeaterBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { + super(type, pos, blockState); + } + + @Override + public int getInputPower() { + return HeaterBlockEntity.POWER; + } + + @Override + public @NotNull BlockPos getPos() { + return this.getBlockPos(); + } + + @Override + public void setGrid(@Nullable PowerGrid grid) { + this.grid = grid; + } + + /** + * @param level 世界 + * @param pos 位置 + */ + public void tick(Level level, BlockPos pos) { + if (this.grid == null) return; + BlockState state = level.getBlockState(pos); + if (!state.is(ModBlocks.HEATER.get())) return; + if (this.grid.isWork() && !state.getValue(HeaterBlock.LIT)) { + level.setBlockAndUpdate(pos, state.setValue(HeaterBlock.LIT, true)); + } else if (state.getValue(HeaterBlock.LIT)) { + level.setBlockAndUpdate(pos, state.setValue(HeaterBlock.LIT, false)); + } + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/AnvilCraftDatagen.java b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/AnvilCraftDatagen.java index 5282f40b6..9902bc3ac 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/AnvilCraftDatagen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/AnvilCraftDatagen.java @@ -33,7 +33,7 @@ public static void init() { return RegistrateRecipeProvider.has(tag); } - public static @NotNull String hasItem(@NotNull Item item) { - return "has_" + BuiltInRegistries.ITEM.getKey(item).getPath(); + public static @NotNull String hasItem(@NotNull ItemLike item) { + return "has_" + BuiltInRegistries.ITEM.getKey(item.asItem()).getPath(); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java index 10b31cdcb..2bcb36cdf 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java @@ -5,6 +5,7 @@ import dev.dubhe.anvilcraft.block.entity.ChuteBlockEntity; import dev.dubhe.anvilcraft.block.entity.CorruptedBeaconBlockEntity; import dev.dubhe.anvilcraft.block.entity.CreativeDynamoBlockEntity; +import dev.dubhe.anvilcraft.block.entity.HeaterBlockEntity; import dev.dubhe.anvilcraft.block.entity.SimpleChuteBlockEntity; import dev.dubhe.anvilcraft.client.renderer.blockentity.CorruptedBeaconRenderer; @@ -12,34 +13,39 @@ public class ModBlockEntities { public static final BlockEntityEntry AUTO_CRAFTER = REGISTRATE - .blockEntity("auto_crafter", AutoCrafterBlockEntity::createBlockEntity) - .onRegister(AutoCrafterBlockEntity::onBlockEntityRegister) - .validBlock(ModBlocks.AUTO_CRAFTER) - .register(); + .blockEntity("auto_crafter", AutoCrafterBlockEntity::createBlockEntity) + .onRegister(AutoCrafterBlockEntity::onBlockEntityRegister) + .validBlock(ModBlocks.AUTO_CRAFTER) + .register(); public static final BlockEntityEntry CHUTE = REGISTRATE - .blockEntity("chute", ChuteBlockEntity::createBlockEntity) - .onRegister(ChuteBlockEntity::onBlockEntityRegister) - .validBlock(ModBlocks.CHUTE) - .register(); + .blockEntity("chute", ChuteBlockEntity::createBlockEntity) + .onRegister(ChuteBlockEntity::onBlockEntityRegister) + .validBlock(ModBlocks.CHUTE) + .register(); public static final BlockEntityEntry SIMPLE_CHUTE = REGISTRATE - .blockEntity("simple_chute", SimpleChuteBlockEntity::createBlockEntity) - .onRegister(SimpleChuteBlockEntity::onBlockEntityRegister) - .validBlock(ModBlocks.SIMPLE_CHUTE) - .register(); + .blockEntity("simple_chute", SimpleChuteBlockEntity::createBlockEntity) + .onRegister(SimpleChuteBlockEntity::onBlockEntityRegister) + .validBlock(ModBlocks.SIMPLE_CHUTE) + .register(); public static final BlockEntityEntry CORRUPTED_BEACON = REGISTRATE - .blockEntity("corrupted_beacon", CorruptedBeaconBlockEntity::createBlockEntity) - .validBlock(ModBlocks.CORRUPTED_BEACON) - .renderer(() -> CorruptedBeaconRenderer::new) - .register(); + .blockEntity("corrupted_beacon", CorruptedBeaconBlockEntity::createBlockEntity) + .validBlock(ModBlocks.CORRUPTED_BEACON) + .renderer(() -> CorruptedBeaconRenderer::new) + .register(); public static final BlockEntityEntry CREATIVE_DYNAMO = REGISTRATE .blockEntity("creative_dynamo", CreativeDynamoBlockEntity::createBlockEntity) .validBlock(ModBlocks.CREATIVE_DYNAMO) .register(); + public static final BlockEntityEntry HEATER = REGISTRATE + .blockEntity("heater", HeaterBlockEntity::createBlockEntity) + .validBlock(ModBlocks.HEATER) + .register(); + public static void register() { } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java index 7b282dadb..26ab4be0f 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java @@ -8,6 +8,7 @@ import dev.dubhe.anvilcraft.block.CorruptedBeaconBlock; import dev.dubhe.anvilcraft.block.CreativeDynamoBlock; import dev.dubhe.anvilcraft.block.FerriteCoreMagnetBlock; +import dev.dubhe.anvilcraft.block.HeaterBlock; import dev.dubhe.anvilcraft.block.HollowMagnetBlock; import dev.dubhe.anvilcraft.block.LavaCauldronBlock; import dev.dubhe.anvilcraft.block.MagnetBlock; @@ -291,7 +292,7 @@ public class ModBlocks { .pattern("AAA") .pattern("AAA") .define('A', ModItems.CURSED_GOLD_INGOT) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.CURSED_GOLD_INGOT.get()), + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.CURSED_GOLD_INGOT), AnvilCraftDatagen.has(ModItems.CURSED_GOLD_INGOT)) .save(provider)) .register(); @@ -306,7 +307,7 @@ public class ModBlocks { .pattern("AAA") .pattern("AAA") .define('A', ModItems.TOPAZ) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.TOPAZ.get()), AnvilCraftDatagen.has(ModItems.TOPAZ)) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.TOPAZ), AnvilCraftDatagen.has(ModItems.TOPAZ)) .save(provider)) .register(); public static final BlockEntry RUBY_BLOCK = REGISTRATE @@ -320,7 +321,7 @@ public class ModBlocks { .pattern("AAA") .pattern("AAA") .define('A', ModItems.RUBY) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.RUBY.get()), AnvilCraftDatagen.has(ModItems.RUBY)) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.RUBY), AnvilCraftDatagen.has(ModItems.RUBY)) .save(provider)) .register(); public static final BlockEntry SAPPHIRE_BLOCK = REGISTRATE @@ -334,7 +335,7 @@ public class ModBlocks { .pattern("AAA") .pattern("AAA") .define('A', ModItems.SAPPHIRE) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.SAPPHIRE.get()), + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.SAPPHIRE), AnvilCraftDatagen.has(ModItems.SAPPHIRE)) .save(provider)) .register(); @@ -352,7 +353,7 @@ public class ModBlocks { .pattern("AAA") .pattern("AAA") .define('A', ModItems.RESIN) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.RESIN.get()), + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.RESIN), AnvilCraftDatagen.has(ModItems.RESIN)) .save(provider)) .register(); @@ -373,7 +374,7 @@ public class ModBlocks { .pattern("AAA") .pattern("AAA") .define('A', ModItems.AMBER) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.AMBER.get()), AnvilCraftDatagen.has(ModItems.AMBER)) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.AMBER), AnvilCraftDatagen.has(ModItems.AMBER)) .save(provider)) .register(); public static final BlockEntry CREATIVE_DYNAMO = REGISTRATE @@ -384,6 +385,25 @@ public class ModBlocks { }) .simpleItem() .register(); + public static final BlockEntry HEATER = REGISTRATE + .block("heater", HeaterBlock::new) + .initialProperties(ModBlocks.MAGNET_BLOCK) + .properties(BlockBehaviour.Properties::noOcclusion) + .blockstate((ctx, provider) -> { + }) + .simpleItem() + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) + .pattern("ABA") + .pattern("BCB") + .pattern("BBB") + .define('A', Items.TERRACOTTA) + .define('B', Items.IRON_INGOT) + .define('C', ModItems.CAPACITOR) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.TERRACOTTA), AnvilCraftDatagen.has(Items.TERRACOTTA)) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), AnvilCraftDatagen.has(Items.IRON_INGOT)) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.CAPACITOR), AnvilCraftDatagen.has(ModItems.CAPACITOR)) + .save(provider)) + .register(); public static void register() { } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java index 64047bfcf..9bff4a896 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java @@ -47,6 +47,8 @@ public class ModItemGroups { entries.accept(ModItems.COCOA_LIQUOR.get().getDefaultInstance()); entries.accept(ModItems.COCOA_BUTTER.get().getDefaultInstance()); entries.accept(ModItems.COCOA_POWDER.get().getDefaultInstance()); + entries.accept(ModItems.CAPACITOR.get().getDefaultInstance()); + entries.accept(ModItems.CAPACITOR.get()); }) .build() ) @@ -61,13 +63,14 @@ public class ModItemGroups { entries.accept(Items.CAMPFIRE.getDefaultInstance()); entries.accept(ModBlocks.STAMPING_PLATFORM.asStack()); entries.accept(ModBlocks.CORRUPTED_BEACON.asStack()); - entries.accept(ModBlocks.CREATIVE_DYNAMO.asStack()); entries.accept(Items.ANVIL.getDefaultInstance()); entries.accept(Items.CHIPPED_ANVIL.getDefaultInstance()); entries.accept(Items.DAMAGED_ANVIL.getDefaultInstance()); entries.accept(ModBlocks.ROYAL_ANVIL.asStack()); entries.accept(ModBlocks.ROYAL_GRINDSTONE.asStack()); entries.accept(ModBlocks.ROYAL_SMITHING_TABLE.asStack()); + entries.accept(ModBlocks.CREATIVE_DYNAMO.asStack()); + entries.accept(ModBlocks.HEATER.asStack()); entries.accept(ModBlocks.MAGNET_BLOCK.asStack()); entries.accept(ModBlocks.HOLLOW_MAGNET_BLOCK.asStack()); entries.accept(ModBlocks.FERRITE_CORE_MAGNET_BLOCK.asStack()); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java index c2c8c0fa7..19343cf17 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java @@ -6,6 +6,7 @@ import dev.dubhe.anvilcraft.data.generator.AnvilCraftDatagen; import dev.dubhe.anvilcraft.data.recipe.crafting.ShapedTagRecipeBuilder; import dev.dubhe.anvilcraft.item.AnvilHammerItem; +import dev.dubhe.anvilcraft.item.CapacitorItem; import dev.dubhe.anvilcraft.item.CursedItem; import dev.dubhe.anvilcraft.item.GeodeItem; import dev.dubhe.anvilcraft.item.MagnetItem; @@ -452,8 +453,26 @@ public void appendHoverText( public static final ItemEntry SEA_HEART_SHELL_SHARD = REGISTRATE .item("sea_heart_shell_shard", Item::new) .register(); + public static final ItemEntry CAPACITOR = REGISTRATE + .item("capacitor", CapacitorItem::new) + .properties(properties -> properties.durability(1)) + .model((ctx, provider) -> { + }) + .recipe((ctx, provider) -> ShapedTagRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get().getDefaultInstance()) + .pattern("ABA") + .pattern("ACA") + .pattern("ABA") + .define('A', Items.IRON_INGOT) + .define('B', Items.COPPER_INGOT) + .define('C', Items.TERRACOTTA) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), RegistrateRecipeProvider.has(Items.IRON_INGOT)) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.COPPER_INGOT), RegistrateRecipeProvider.has(Items.COPPER_INGOT)) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.TERRACOTTA), RegistrateRecipeProvider.has(Items.TERRACOTTA)) + .save(provider)) + .register(); public static final ItemEntry ANVIL_HAMMER = REGISTRATE - .item("anvil_hammer", properties -> new AnvilHammerItem(properties.durability(35))) + .item("anvil_hammer", AnvilHammerItem::new) + .properties(properties -> properties.durability(35)) .model((ctx, provider) -> { }) .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get()) @@ -464,7 +483,7 @@ public void appendHoverText( .define('B', Items.LIGHTNING_ROD) .define('C', Items.IRON_INGOT) .unlockedBy(AnvilCraftDatagen.hasItem(Items.ANVIL), RegistrateRecipeProvider.has(Items.ANVIL)) - .unlockedBy(AnvilCraftDatagen.hasItem(Items.LIGHTNING_ROD), + .unlockedBy(AnvilCraftDatagen.hasItem(Items.LIGHTNING_ROD), RegistrateRecipeProvider.has(Items.LIGHTNING_ROD)) .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), RegistrateRecipeProvider.has(Items.IRON_INGOT)) .save(provider)) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/inventory/RoyalAnvilMenu.java b/common/src/main/java/dev/dubhe/anvilcraft/inventory/RoyalAnvilMenu.java index 845df84aa..0418bd3c2 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/inventory/RoyalAnvilMenu.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/inventory/RoyalAnvilMenu.java @@ -1,7 +1,7 @@ package dev.dubhe.anvilcraft.inventory; import dev.dubhe.anvilcraft.init.ModMenuTypes; -import dev.dubhe.anvilcraft.item.Cursed; +import dev.dubhe.anvilcraft.item.ICursed; import net.minecraft.Util; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.EntityType; @@ -161,7 +161,7 @@ protected void onTake(@NotNull Player player, @NotNull ItemStack stack) { super.onTake(player, stack); Level level = player.level(); if (level.isClientSide()) return; - int curedNumber = Cursed.hasCuredNumber(player); + int curedNumber = ICursed.hasCuredNumber(player); if (curedNumber <= 0) return; LightningBolt bolt = new LightningBolt(EntityType.LIGHTNING_BOLT, level); bolt.setPos(player.getX(), player.getY(), player.getZ()); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/item/CapacitorItem.java b/common/src/main/java/dev/dubhe/anvilcraft/item/CapacitorItem.java new file mode 100644 index 000000000..98e300139 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/item/CapacitorItem.java @@ -0,0 +1,23 @@ +package dev.dubhe.anvilcraft.item; + +import dev.dubhe.anvilcraft.init.ModItems; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; + +public class CapacitorItem extends Item { + public CapacitorItem(Properties properties) { + super(properties); + } + + @Override + public @NotNull ItemStack getDefaultInstance() { + ItemStack stack = new ItemStack(ModItems.CAPACITOR); + stack.setDamageValue(1); + return stack; + } + + public static boolean isFull(@NotNull ItemStack stack) { + return stack.getDamageValue() < stack.getMaxDamage(); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/item/CursedBlockItem.java b/common/src/main/java/dev/dubhe/anvilcraft/item/CursedBlockItem.java index c8b82e0b3..ae638b752 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/item/CursedBlockItem.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/item/CursedBlockItem.java @@ -6,7 +6,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -public class CursedBlockItem extends BlockItem implements Cursed { +public class CursedBlockItem extends BlockItem implements ICursed { public CursedBlockItem(Block block, Properties properties) { super(block, properties); @@ -15,6 +15,6 @@ public CursedBlockItem(Block block, Properties properties) { @Override public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { super.inventoryTick(stack, level, entity, slotId, isSelected); - Cursed.super.inventoryTick(stack, level, entity, slotId, isSelected); + ICursed.super.inventoryTick(stack, level, entity, slotId, isSelected); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/item/CursedItem.java b/common/src/main/java/dev/dubhe/anvilcraft/item/CursedItem.java index 380c6cd25..6461cbcc0 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/item/CursedItem.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/item/CursedItem.java @@ -4,15 +4,18 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; +import org.jetbrains.annotations.NotNull; -public class CursedItem extends Item implements Cursed { +public class CursedItem extends Item implements ICursed { public CursedItem(Properties properties) { super(properties); } @Override - public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) { + public void inventoryTick( + @NotNull ItemStack stack, @NotNull Level level, @NotNull Entity entity, int slotId, boolean isSelected + ) { super.inventoryTick(stack, level, entity, slotId, isSelected); - Cursed.super.inventoryTick(stack, level, entity, slotId, isSelected); + ICursed.super.inventoryTick(stack, level, entity, slotId, isSelected); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/item/Cursed.java b/common/src/main/java/dev/dubhe/anvilcraft/item/ICursed.java similarity index 92% rename from common/src/main/java/dev/dubhe/anvilcraft/item/Cursed.java rename to common/src/main/java/dev/dubhe/anvilcraft/item/ICursed.java index d1da7cbae..d936b0add 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/item/Cursed.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/item/ICursed.java @@ -12,7 +12,7 @@ /** * 诅咒物品 */ -public interface Cursed { +public interface ICursed { /** * 执行效果 * @@ -29,7 +29,7 @@ default void inventoryTick(ItemStack stack, Level level, Entity entity, int slot MobEffectInstance slowness = new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 200, 1, false, true); MobEffectInstance hungry = new MobEffectInstance(MobEffects.HUNGER, 200, 1, false, true); player.addEffect((weakness)); - int curedNumber = Cursed.hasCuredNumber(player); + int curedNumber = ICursed.hasCuredNumber(player); if (curedNumber > 8) { player.addEffect((slowness)); } @@ -49,7 +49,7 @@ static int hasCuredNumber(@NotNull Player player) { int i = 0; for (int j = 0; j < inventory.getContainerSize(); ++j) { ItemStack itemStack = inventory.getItem(j); - if (!(itemStack.getItem() instanceof Cursed)) continue; + if (!(itemStack.getItem() instanceof ICursed)) continue; i += itemStack.getCount(); } return i; diff --git a/common/src/main/resources/assets/anvilcraft/blockstates/heater.json b/common/src/main/resources/assets/anvilcraft/blockstates/heater.json new file mode 100644 index 000000000..170350ba1 --- /dev/null +++ b/common/src/main/resources/assets/anvilcraft/blockstates/heater.json @@ -0,0 +1,10 @@ +{ + "variants": { + "lit=false": { + "model": "anvilcraft:block/heater" + }, + "lit=true": { + "model": "anvilcraft:block/heater_lit" + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/anvilcraft/models/block/heater.json b/common/src/main/resources/assets/anvilcraft/models/block/heater.json index a4029dc2b..a888db904 100644 --- a/common/src/main/resources/assets/anvilcraft/models/block/heater.json +++ b/common/src/main/resources/assets/anvilcraft/models/block/heater.json @@ -1,5 +1,7 @@ { "credit": "Made by XeKr with Blockbench", + "parent": "minecraft:block/block", + "render_type": "minecraft:translucent", "ambientocclusion": false, "textures": { "particle": "anvilcraft:block/heater", diff --git a/common/src/main/resources/assets/anvilcraft/models/block/heater_lit.json b/common/src/main/resources/assets/anvilcraft/models/block/heater_lit.json index 891281c7f..c67050cc1 100644 --- a/common/src/main/resources/assets/anvilcraft/models/block/heater_lit.json +++ b/common/src/main/resources/assets/anvilcraft/models/block/heater_lit.json @@ -1,5 +1,7 @@ { "credit": "Made by XeKr with Blockbench", + "parent": "minecraft:block/block", + "render_type": "minecraft:translucent", "ambientocclusion": false, "textures": { "particle": "anvilcraft:block/heater_lit", diff --git a/common/src/main/resources/assets/anvilcraft/models/item/capacitor.json b/common/src/main/resources/assets/anvilcraft/models/item/capacitor.json new file mode 100644 index 000000000..876a28d78 --- /dev/null +++ b/common/src/main/resources/assets/anvilcraft/models/item/capacitor.json @@ -0,0 +1,14 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "anvilcraft:item/capacitor" + }, + "overrides": [ + { + "predicate": { + "damaged": 1 + }, + "model": "anvilcraft:item/capacitor_empty" + } + ] +} diff --git a/common/src/main/resources/assets/anvilcraft/models/item/capacitor_empty.json b/common/src/main/resources/assets/anvilcraft/models/item/capacitor_empty.json new file mode 100644 index 000000000..54eaefaf2 --- /dev/null +++ b/common/src/main/resources/assets/anvilcraft/models/item/capacitor_empty.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "anvilcraft:item/capacitor_empty" + } +} diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 37286169c..a59de1ff0 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -9,6 +9,7 @@ "block.anvilcraft.cut_royal_steel_slab": "qɐןS ןǝǝʇS ןɐʎoᴚ ʇnƆ", "block.anvilcraft.cut_royal_steel_stairs": "sɹıɐʇS ןǝǝʇS ןɐʎoᴚ ʇnƆ", "block.anvilcraft.ferrite_core_magnet_block": "ʞɔoןᗺ ʇǝubɐW ǝɹoƆ ǝʇıɹɹǝℲ", + "block.anvilcraft.heater": "ɹǝʇɐǝH", "block.anvilcraft.hollow_magnet_block": "ʞɔoןᗺ ʇǝubɐW ʍoןןoH", "block.anvilcraft.lava_cauldron": "uoɹpןnɐƆ ɐʌɐꞀ", "block.anvilcraft.magnet_block": "ʞɔoןᗺ ʇǝubɐW", @@ -34,6 +35,7 @@ "item.anvilcraft.bark": "ʞɹɐᗺ", "item.anvilcraft.beef_mushroom_stew": "ʍǝʇS ɯooɹɥsnW ɟǝǝᗺ", "item.anvilcraft.beef_mushroom_stew_raw": "ʍɐᴚ ʍǝʇS ɯooɹɥsnW ɟǝǝᗺ", + "item.anvilcraft.capacitor": "ɹoʇıɔɐdɐƆ", "item.anvilcraft.chocolate": "ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_black": "ʞɔɐןᗺ ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_white": "ǝʇıɥM ǝʇɐןoɔoɥƆ", diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json index 14f73cd24..389b12f80 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -9,6 +9,7 @@ "block.anvilcraft.cut_royal_steel_slab": "Cut Royal Steel Slab", "block.anvilcraft.cut_royal_steel_stairs": "Cut Royal Steel Stairs", "block.anvilcraft.ferrite_core_magnet_block": "Ferrite Core Magnet Block", + "block.anvilcraft.heater": "Heater", "block.anvilcraft.hollow_magnet_block": "Hollow Magnet Block", "block.anvilcraft.lava_cauldron": "Lava Cauldron", "block.anvilcraft.magnet_block": "Magnet Block", @@ -34,6 +35,7 @@ "item.anvilcraft.bark": "Bark", "item.anvilcraft.beef_mushroom_stew": "Beef Mushroom Stew", "item.anvilcraft.beef_mushroom_stew_raw": "Beef Mushroom Stew Raw", + "item.anvilcraft.capacitor": "Capacitor", "item.anvilcraft.chocolate": "Chocolate", "item.anvilcraft.chocolate_black": "Chocolate Black", "item.anvilcraft.chocolate_white": "Chocolate White", diff --git a/fabric/src/generated/resources/assets/anvilcraft/models/item/heater.json b/fabric/src/generated/resources/assets/anvilcraft/models/item/heater.json new file mode 100644 index 000000000..cd6191eee --- /dev/null +++ b/fabric/src/generated/resources/assets/anvilcraft/models/item/heater.json @@ -0,0 +1,3 @@ +{ + "parent": "anvilcraft:block/heater" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json new file mode 100644 index 000000000..865c61ca8 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json @@ -0,0 +1,61 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_capacitor": { + "conditions": { + "items": [ + { + "items": [ + "anvilcraft:capacitor" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_iron_ingot": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:iron_ingot" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_terracotta": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:terracotta" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "anvilcraft:heater" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_terracotta", + "has_iron_ingot", + "has_capacitor", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "anvilcraft:heater" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json new file mode 100644 index 000000000..0495ebb62 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json @@ -0,0 +1,61 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_copper_ingot": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:copper_ingot" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_iron_ingot": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:iron_ingot" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_terracotta": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:terracotta" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "anvilcraft:capacitor" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_iron_ingot", + "has_copper_ingot", + "has_terracotta", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "anvilcraft:capacitor" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/heater.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/heater.json new file mode 100644 index 000000000..b52eb06c6 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/heater.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "anvilcraft:heater" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:blocks/heater" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/capacitor.json b/fabric/src/generated/resources/data/anvilcraft/recipes/capacitor.json new file mode 100644 index 000000000..5c88ce9e6 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/capacitor.json @@ -0,0 +1,25 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "equipment", + "key": { + "A": { + "item": "minecraft:iron_ingot" + }, + "B": { + "item": "minecraft:copper_ingot" + }, + "C": { + "item": "minecraft:terracotta" + } + }, + "pattern": [ + "ABA", + "ACA", + "ABA" + ], + "result": { + "data": "{Damage:1}", + "item": "anvilcraft:capacitor" + }, + "show_notification": true +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/heater.json b/fabric/src/generated/resources/data/anvilcraft/recipes/heater.json new file mode 100644 index 000000000..fcfa098b7 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/heater.json @@ -0,0 +1,24 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "A": { + "item": "minecraft:terracotta" + }, + "B": { + "item": "minecraft:iron_ingot" + }, + "C": { + "item": "anvilcraft:capacitor" + } + }, + "pattern": [ + "ABA", + "BCB", + "BBB" + ], + "result": { + "item": "anvilcraft:heater" + }, + "show_notification": true +} \ No newline at end of file diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/client/fabric/AnvilCraftClient.java b/fabric/src/main/java/dev/dubhe/anvilcraft/client/fabric/AnvilCraftFabricClient.java similarity index 87% rename from fabric/src/main/java/dev/dubhe/anvilcraft/client/fabric/AnvilCraftClient.java rename to fabric/src/main/java/dev/dubhe/anvilcraft/client/fabric/AnvilCraftFabricClient.java index cf1efa361..a729fd22b 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/client/fabric/AnvilCraftClient.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/client/fabric/AnvilCraftFabricClient.java @@ -8,12 +8,13 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; -public class AnvilCraftClient implements ClientModInitializer { +public class AnvilCraftFabricClient implements ClientModInitializer { @Override public void onInitializeClient() { BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.CORRUPTED_BEACON.get(), RenderType.translucent()); BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.RESIN_BLOCK.get(), RenderType.translucent()); BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.AMBER_BLOCK.get(), RenderType.translucent()); + BlockRenderLayerMap.INSTANCE.putBlock(ModBlocks.HEATER.get(), RenderType.translucent()); WorldRenderEvents.AFTER_ENTITIES.register(context -> { if (IBlockHighlightUtil.SUBCHUNKS.isEmpty()) return; MultiBufferSource consumers = context.consumers(); diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 32be2b56a..488853b33 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -20,7 +20,7 @@ "environment": "*", "entrypoints": { "client": [ - "dev.dubhe.anvilcraft.client.fabric.AnvilCraftClient" + "dev.dubhe.anvilcraft.client.fabric.AnvilCraftFabricClient" ], "main": [ "dev.dubhe.anvilcraft.fabric.AnvilCraftFabric" diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 37286169c..a59de1ff0 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -9,6 +9,7 @@ "block.anvilcraft.cut_royal_steel_slab": "qɐןS ןǝǝʇS ןɐʎoᴚ ʇnƆ", "block.anvilcraft.cut_royal_steel_stairs": "sɹıɐʇS ןǝǝʇS ןɐʎoᴚ ʇnƆ", "block.anvilcraft.ferrite_core_magnet_block": "ʞɔoןᗺ ʇǝubɐW ǝɹoƆ ǝʇıɹɹǝℲ", + "block.anvilcraft.heater": "ɹǝʇɐǝH", "block.anvilcraft.hollow_magnet_block": "ʞɔoןᗺ ʇǝubɐW ʍoןןoH", "block.anvilcraft.lava_cauldron": "uoɹpןnɐƆ ɐʌɐꞀ", "block.anvilcraft.magnet_block": "ʞɔoןᗺ ʇǝubɐW", @@ -34,6 +35,7 @@ "item.anvilcraft.bark": "ʞɹɐᗺ", "item.anvilcraft.beef_mushroom_stew": "ʍǝʇS ɯooɹɥsnW ɟǝǝᗺ", "item.anvilcraft.beef_mushroom_stew_raw": "ʍɐᴚ ʍǝʇS ɯooɹɥsnW ɟǝǝᗺ", + "item.anvilcraft.capacitor": "ɹoʇıɔɐdɐƆ", "item.anvilcraft.chocolate": "ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_black": "ʞɔɐןᗺ ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_white": "ǝʇıɥM ǝʇɐןoɔoɥƆ", diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json index 14f73cd24..389b12f80 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -9,6 +9,7 @@ "block.anvilcraft.cut_royal_steel_slab": "Cut Royal Steel Slab", "block.anvilcraft.cut_royal_steel_stairs": "Cut Royal Steel Stairs", "block.anvilcraft.ferrite_core_magnet_block": "Ferrite Core Magnet Block", + "block.anvilcraft.heater": "Heater", "block.anvilcraft.hollow_magnet_block": "Hollow Magnet Block", "block.anvilcraft.lava_cauldron": "Lava Cauldron", "block.anvilcraft.magnet_block": "Magnet Block", @@ -34,6 +35,7 @@ "item.anvilcraft.bark": "Bark", "item.anvilcraft.beef_mushroom_stew": "Beef Mushroom Stew", "item.anvilcraft.beef_mushroom_stew_raw": "Beef Mushroom Stew Raw", + "item.anvilcraft.capacitor": "Capacitor", "item.anvilcraft.chocolate": "Chocolate", "item.anvilcraft.chocolate_black": "Chocolate Black", "item.anvilcraft.chocolate_white": "Chocolate White", diff --git a/forge/src/generated/resources/assets/anvilcraft/models/item/heater.json b/forge/src/generated/resources/assets/anvilcraft/models/item/heater.json new file mode 100644 index 000000000..cd6191eee --- /dev/null +++ b/forge/src/generated/resources/assets/anvilcraft/models/item/heater.json @@ -0,0 +1,3 @@ +{ + "parent": "anvilcraft:block/heater" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json new file mode 100644 index 000000000..865c61ca8 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json @@ -0,0 +1,61 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_capacitor": { + "conditions": { + "items": [ + { + "items": [ + "anvilcraft:capacitor" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_iron_ingot": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:iron_ingot" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_terracotta": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:terracotta" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "anvilcraft:heater" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_terracotta", + "has_iron_ingot", + "has_capacitor", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "anvilcraft:heater" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json new file mode 100644 index 000000000..0495ebb62 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json @@ -0,0 +1,61 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_copper_ingot": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:copper_ingot" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_iron_ingot": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:iron_ingot" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_terracotta": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:terracotta" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "anvilcraft:capacitor" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_iron_ingot", + "has_copper_ingot", + "has_terracotta", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "anvilcraft:capacitor" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/heater.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/heater.json new file mode 100644 index 000000000..b52eb06c6 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/heater.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "anvilcraft:heater" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:blocks/heater" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/capacitor.json b/forge/src/generated/resources/data/anvilcraft/recipes/capacitor.json new file mode 100644 index 000000000..5c88ce9e6 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/recipes/capacitor.json @@ -0,0 +1,25 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "equipment", + "key": { + "A": { + "item": "minecraft:iron_ingot" + }, + "B": { + "item": "minecraft:copper_ingot" + }, + "C": { + "item": "minecraft:terracotta" + } + }, + "pattern": [ + "ABA", + "ACA", + "ABA" + ], + "result": { + "data": "{Damage:1}", + "item": "anvilcraft:capacitor" + }, + "show_notification": true +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/heater.json b/forge/src/generated/resources/data/anvilcraft/recipes/heater.json new file mode 100644 index 000000000..fcfa098b7 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/recipes/heater.json @@ -0,0 +1,24 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "A": { + "item": "minecraft:terracotta" + }, + "B": { + "item": "minecraft:iron_ingot" + }, + "C": { + "item": "anvilcraft:capacitor" + } + }, + "pattern": [ + "ABA", + "BCB", + "BBB" + ], + "result": { + "item": "anvilcraft:heater" + }, + "show_notification": true +} \ No newline at end of file diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/forge/AnvilCraftForge.java b/forge/src/main/java/dev/dubhe/anvilcraft/forge/AnvilCraftForge.java index 127c19e91..062febe27 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/forge/AnvilCraftForge.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/forge/AnvilCraftForge.java @@ -37,7 +37,6 @@ public AnvilCraftForge() { IBlockHighlightUtil.render(level, Minecraft.getInstance().renderBuffers().bufferSource(), event.getPoseStack(), event.getCamera()); }); - ModLoadingContext.get().registerExtensionPoint( ConfigScreenHandler.ConfigScreenFactory.class, () -> new ConfigScreenHandler.ConfigScreenFactory( From 03e0d4571ad1def6f93644f8996476c927869893 Mon Sep 17 00:00:00 2001 From: Gugle Date: Mon, 15 Apr 2024 22:11:54 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E7=94=B5=E7=BD=91=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anvilcraft/api/power/IPowerComponent.java | 7 ++ .../api/power/IPowerTransmitter.java | 14 +++ .../api/power/PowerComponentType.java | 1 + .../dubhe/anvilcraft/api/power/PowerGrid.java | 108 ++++++++++++------ .../block/entity/HeaterBlockEntity.java | 11 +- .../data/generator/AnvilCraftDatagen.java | 4 + .../dev/dubhe/anvilcraft/init/ModBlocks.java | 4 +- .../dubhe/anvilcraft/init/ModItemGroups.java | 2 +- .../dubhe/anvilcraft/init/ModItemTags.java | 8 +- .../dev/dubhe/anvilcraft/init/ModItems.java | 8 +- .../dubhe/anvilcraft/item/CapacitorItem.java | 14 --- .../anvilcraft/models/item/capacitor.json | 14 --- .../models/item/capacitor_empty.json | 6 - .../assets/anvilcraft/lang/en_ud.json | 1 + .../assets/anvilcraft/lang/en_us.json | 1 + .../anvilcraft/models/item/capacitor.json | 6 + .../models/item/capacitor_empty.json | 6 + .../advancements/recipes/misc/heater.json | 4 +- .../recipes/tools/capacitor_empty.json | 4 +- .../anvilcraft/recipes/capacitor_empty.json | 3 +- .../data/anvilcraft/recipes/heater.json | 2 +- .../data/anvilcraft/tags/items/capacitor.json | 7 ++ .../event/fabric/ServerLifecycleEvent.java | 14 ++- .../assets/anvilcraft/lang/en_ud.json | 1 + .../assets/anvilcraft/lang/en_us.json | 1 + .../anvilcraft/models/item/capacitor.json | 6 + .../models/item/capacitor_empty.json | 6 + .../advancements/recipes/misc/heater.json | 4 +- .../recipes/tools/capacitor_empty.json | 4 +- .../anvilcraft/recipes/capacitor_empty.json | 3 +- .../data/anvilcraft/recipes/heater.json | 2 +- .../data/anvilcraft/tags/items/capacitor.json | 7 ++ .../event/forge/ServerLifecycleEvent.java | 14 ++- 33 files changed, 191 insertions(+), 106 deletions(-) delete mode 100644 common/src/main/resources/assets/anvilcraft/models/item/capacitor.json delete mode 100644 common/src/main/resources/assets/anvilcraft/models/item/capacitor_empty.json create mode 100644 fabric/src/generated/resources/assets/anvilcraft/models/item/capacitor.json create mode 100644 fabric/src/generated/resources/assets/anvilcraft/models/item/capacitor_empty.json rename forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json => fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor_empty.json (93%) rename forge/src/generated/resources/data/anvilcraft/recipes/capacitor.json => fabric/src/generated/resources/data/anvilcraft/recipes/capacitor_empty.json (85%) create mode 100644 fabric/src/generated/resources/data/anvilcraft/tags/items/capacitor.json create mode 100644 forge/src/generated/resources/assets/anvilcraft/models/item/capacitor.json create mode 100644 forge/src/generated/resources/assets/anvilcraft/models/item/capacitor_empty.json rename fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json => forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor_empty.json (93%) rename fabric/src/generated/resources/data/anvilcraft/recipes/capacitor.json => forge/src/generated/resources/data/anvilcraft/recipes/capacitor_empty.json (85%) create mode 100644 forge/src/generated/resources/data/anvilcraft/tags/items/capacitor.json diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java index dc04976f0..62c74dca5 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java @@ -1,6 +1,8 @@ package dev.dubhe.anvilcraft.api.power; import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,6 +17,11 @@ public interface IPowerComponent { @NotNull BlockPos getPos(); + default VoxelShape getRange() { + return Shapes.box(-0.2, -0.2, -0.2, 1.2, 1.2, 1.2); + // return Shapes.block(); + } + /** * 设置电网 * diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java index 4893ab1b3..504a4c773 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java @@ -1,11 +1,25 @@ package dev.dubhe.anvilcraft.api.power; +import dev.dubhe.anvilcraft.AnvilCraft; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; /** * 电力中继器 */ public interface IPowerTransmitter extends IPowerComponent { + @Override + default VoxelShape getRange() { + int range = AnvilCraft.config.powerTransmitterRange; + Vec3 vec3 = getPos().getCenter(); + return Shapes.box( + vec3.x - range, vec3.y - range, vec3.z - range, + vec3.x + range, vec3.y + range, vec3.z + range + ); + } + @Override default @NotNull PowerComponentType getComponentType() { return PowerComponentType.TRANSMITTER; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerComponentType.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerComponentType.java index 34a899038..501475f5e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerComponentType.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerComponentType.java @@ -4,6 +4,7 @@ * 电力元件类型 */ public enum PowerComponentType { + INVALID, PRODUCER, CONSUMER, STORAGE, diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java index 3af26ba6c..0d00b93d2 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java @@ -1,29 +1,36 @@ package dev.dubhe.anvilcraft.api.power; -import dev.dubhe.anvilcraft.AnvilCraft; import lombok.Getter; import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.shapes.BooleanOp; +import net.minecraft.world.phys.shapes.Shapes; +import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; /** * 电网 */ @SuppressWarnings("unused") public class PowerGrid { - public static final List GRID_LIST = new ArrayList<>(); + public static final Set GRID_SET = new HashSet<>(); public static final int GRID_TICK = 40; public static int cooldown = 0; @Getter private int generate = 0; // 发电功率 @Getter private int consume = 0; // 耗电功率 - private final List producers = new ArrayList<>(); // 发电机 - private final List consumers = new ArrayList<>(); // 用电器 - private final List storages = new ArrayList<>(); // 储电 - private final List transmitters = new ArrayList<>(); // 中继 + private final Set producers = new HashSet<>(); // 发电机 + private final Set consumers = new HashSet<>(); // 用电器 + private final Set storages = new HashSet<>(); // 储电 + private final Set transmitters = new HashSet<>(); // 中继 + @Getter + private VoxelShape range = null; + @Getter + private BlockPos pos = null; /** * 总电力刻 @@ -33,7 +40,7 @@ public static void tickGrid() { cooldown--; return; } - for (PowerGrid grid : PowerGrid.GRID_LIST) { + for (PowerGrid grid : PowerGrid.GRID_SET) { grid.tick(); } cooldown = GRID_TICK; @@ -52,7 +59,7 @@ protected void tick() { } } else { int need = this.consume - this.generate; - List storages = new ArrayList<>(); + Set storages = new HashSet<>(); for (IPowerStorage storage : this.storages) { need -= storage.getOutputPower(); storages.add(storage); @@ -87,6 +94,7 @@ public boolean isWork() { */ public void add(IPowerComponent @NotNull ... components) { for (IPowerComponent component : components) { + if (component.getComponentType() == PowerComponentType.INVALID) continue; if (component instanceof IPowerStorage storage) { this.storages.add(storage); } else if (component instanceof IPowerProducer producer) { @@ -97,26 +105,52 @@ public void add(IPowerComponent @NotNull ... components) { this.transmitters.add(transmitter); } component.setGrid(this); + this.addRange(component); } this.flush(); } + private void addRange(IPowerComponent component) { + if (this.range == null) { + this.range = component.getRange(); + this.pos = component.getPos(); + return; + } + BlockPos center = this.pos; + BlockPos vec3 = component.getPos(); + VoxelShape range = component.getRange().move( + vec3.getX() - center.getX(), + vec3.getY() - center.getY(), + vec3.getZ() - center.getZ() + ); + this.range = Shapes.join(this.range, range, BooleanOp.OR); + } + /** * 移除电力元件 * * @param components 电力元件 */ public void remove(IPowerComponent @NotNull ... components) { - List list = new ArrayList<>(); - list.addAll(this.storages); - list.addAll(this.producers); - list.addAll(this.consumers); - list.addAll(this.transmitters); + Set set = new HashSet<>(); + this.storages.stream().filter(this::clearGrid).forEach(set::add); + this.storages.clear(); + this.producers.stream().filter(this::clearGrid).forEach(set::add); + this.producers.clear(); + this.consumers.stream().filter(this::clearGrid).forEach(set::add); + this.consumers.clear(); + this.transmitters.stream().filter(this::clearGrid).forEach(set::add); + this.transmitters.clear(); for (IPowerComponent component : components) { - list.remove(component); + set.remove(component); } - PowerGrid.GRID_LIST.remove(this); - PowerGrid.addComponent(list.toArray(IPowerComponent[]::new)); + PowerGrid.GRID_SET.remove(this); + PowerGrid.addComponent(set.toArray(IPowerComponent[]::new)); + } + + private boolean clearGrid(@NotNull IPowerComponent component) { + component.setGrid(null); + return true; } /** @@ -129,7 +163,6 @@ public void merge(@NotNull PowerGrid grid) { this.consumers.addAll(grid.consumers); this.storages.addAll(grid.storages); this.transmitters.addAll(grid.transmitters); - PowerGrid.GRID_LIST.remove(grid); } /** @@ -137,17 +170,14 @@ public void merge(@NotNull PowerGrid grid) { * @return 元件是否在电网范围内 */ public boolean isInRange(@NotNull IPowerComponent component) { - int range; - BlockPos pos = component.getPos(); - if (component instanceof IPowerTransmitter) { - range = AnvilCraft.config.powerTransmitterRange; - } else range = AnvilCraft.config.powerComponentRange; - for (IPowerTransmitter transmitter : this.transmitters) { - pos = pos.subtract(transmitter.getPos()); - if (pos.getX() > range || pos.getY() > range || pos.getZ() > range) continue; - return true; - } - return false; + BlockPos vec3 = component.getPos(); + BlockPos center = this.getPos(); + VoxelShape range = Shapes.join( + this.range.move(center.getX(), center.getY(), center.getZ()), + component.getRange().move(vec3.getX(), vec3.getY(), vec3.getZ()), + BooleanOp.AND + ); + return !range.isEmpty(); } /** @@ -158,14 +188,26 @@ public boolean isInRange(@NotNull IPowerComponent component) { public static void addComponent(IPowerComponent @NotNull ... components) { for (IPowerComponent component : components) { PowerGrid grid = null; - for (PowerGrid grid1 : PowerGrid.GRID_LIST) { + Iterator iterator = PowerGrid.GRID_SET.iterator(); + while (iterator.hasNext()) { + PowerGrid grid1 = iterator.next(); if (!grid1.isInRange(component)) continue; if (grid == null) grid = grid1; - else grid.merge(grid1); + else { + grid.merge(grid1); + iterator.remove(); + } } if (grid == null) grid = new PowerGrid(); grid.add(component); - PowerGrid.GRID_LIST.add(grid); + PowerGrid.GRID_SET.add(grid); } } + + /** + * 清空电网 + */ + public static void clear() { + PowerGrid.GRID_SET.clear(); + } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/HeaterBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/HeaterBlockEntity.java index 95698dc28..f75d080a2 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/HeaterBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/HeaterBlockEntity.java @@ -52,13 +52,18 @@ public void setGrid(@Nullable PowerGrid grid) { * @param level 世界 * @param pos 位置 */ - public void tick(Level level, BlockPos pos) { - if (this.grid == null) return; + public void tick(@NotNull Level level, @NotNull BlockPos pos) { BlockState state = level.getBlockState(pos); if (!state.is(ModBlocks.HEATER.get())) return; + if (this.grid == null) { + if (state.getValue(HeaterBlock.LIT)) { + level.setBlockAndUpdate(pos, state.setValue(HeaterBlock.LIT, false)); + } + return; + } if (this.grid.isWork() && !state.getValue(HeaterBlock.LIT)) { level.setBlockAndUpdate(pos, state.setValue(HeaterBlock.LIT, true)); - } else if (state.getValue(HeaterBlock.LIT)) { + } else if (!this.grid.isWork() && state.getValue(HeaterBlock.LIT)) { level.setBlockAndUpdate(pos, state.setValue(HeaterBlock.LIT, false)); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/AnvilCraftDatagen.java b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/AnvilCraftDatagen.java index 9902bc3ac..b9275b4ce 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/generator/AnvilCraftDatagen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/generator/AnvilCraftDatagen.java @@ -33,6 +33,10 @@ public static void init() { return RegistrateRecipeProvider.has(tag); } + public static @NotNull String hasItem(@NotNull TagKey item) { + return "has_" + item.location().getPath(); + } + public static @NotNull String hasItem(@NotNull ItemLike item) { return "has_" + BuiltInRegistries.ITEM.getKey(item.asItem()).getPath(); } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java index 26ab4be0f..481f6c2ca 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java @@ -398,10 +398,10 @@ public class ModBlocks { .pattern("BBB") .define('A', Items.TERRACOTTA) .define('B', Items.IRON_INGOT) - .define('C', ModItems.CAPACITOR) + .define('C', ModItemTags.CAPACITOR) .unlockedBy(AnvilCraftDatagen.hasItem(Items.TERRACOTTA), AnvilCraftDatagen.has(Items.TERRACOTTA)) .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_INGOT), AnvilCraftDatagen.has(Items.IRON_INGOT)) - .unlockedBy(AnvilCraftDatagen.hasItem(ModItems.CAPACITOR), AnvilCraftDatagen.has(ModItems.CAPACITOR)) + .unlockedBy(AnvilCraftDatagen.hasItem(ModItemTags.CAPACITOR), AnvilCraftDatagen.has(ModItemTags.CAPACITOR)) .save(provider)) .register(); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java index 9bff4a896..35c6107eb 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java @@ -48,7 +48,7 @@ public class ModItemGroups { entries.accept(ModItems.COCOA_BUTTER.get().getDefaultInstance()); entries.accept(ModItems.COCOA_POWDER.get().getDefaultInstance()); entries.accept(ModItems.CAPACITOR.get().getDefaultInstance()); - entries.accept(ModItems.CAPACITOR.get()); + entries.accept(ModItems.CAPACITOR_EMPTY.get().getDefaultInstance()); }) .build() ) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemTags.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemTags.java index 2be560ef1..699fc0647 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemTags.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemTags.java @@ -22,18 +22,14 @@ public class ModItemTags { public static final TagKey PLATES = bindC("plates"); public static final TagKey GOLD_PLATES = bindC("gold_plates"); public static final TagKey IRON_PLATES = bindC("iron_plates"); - public static final TagKey ROYAL_STEEL_PICKAXE_BASE = bindMod("royal_steel_pickaxe_base"); + public static final TagKey ROYAL_STEEL_PICKAXE_BASE = bind("royal_steel_pickaxe_base"); + public static final TagKey CAPACITOR = bind("capacitor"); private static @NotNull TagKey bindC(String id) { return TagKey.create(Registries.ITEM, new ResourceLocation("c", id)); } - @SuppressWarnings("SameParameterValue") - private static @NotNull TagKey bindMod(String id) { - return TagKey.create(Registries.ITEM, new ResourceLocation("anvilcraft", id)); - } - private static @NotNull TagKey bind(String id) { return TagKey.create(Registries.ITEM, AnvilCraft.of(id)); } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java index 19343cf17..6677e8d2e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java @@ -455,9 +455,11 @@ public void appendHoverText( .register(); public static final ItemEntry CAPACITOR = REGISTRATE .item("capacitor", CapacitorItem::new) - .properties(properties -> properties.durability(1)) - .model((ctx, provider) -> { - }) + .tag(ModItemTags.CAPACITOR) + .register(); + public static final ItemEntry CAPACITOR_EMPTY = REGISTRATE + .item("capacitor_empty", CapacitorItem::new) + .tag(ModItemTags.CAPACITOR) .recipe((ctx, provider) -> ShapedTagRecipeBuilder.shaped(RecipeCategory.TOOLS, ctx.get().getDefaultInstance()) .pattern("ABA") .pattern("ACA") diff --git a/common/src/main/java/dev/dubhe/anvilcraft/item/CapacitorItem.java b/common/src/main/java/dev/dubhe/anvilcraft/item/CapacitorItem.java index 98e300139..9f92250f7 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/item/CapacitorItem.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/item/CapacitorItem.java @@ -1,23 +1,9 @@ package dev.dubhe.anvilcraft.item; -import dev.dubhe.anvilcraft.init.ModItems; import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.NotNull; public class CapacitorItem extends Item { public CapacitorItem(Properties properties) { super(properties); } - - @Override - public @NotNull ItemStack getDefaultInstance() { - ItemStack stack = new ItemStack(ModItems.CAPACITOR); - stack.setDamageValue(1); - return stack; - } - - public static boolean isFull(@NotNull ItemStack stack) { - return stack.getDamageValue() < stack.getMaxDamage(); - } } diff --git a/common/src/main/resources/assets/anvilcraft/models/item/capacitor.json b/common/src/main/resources/assets/anvilcraft/models/item/capacitor.json deleted file mode 100644 index 876a28d78..000000000 --- a/common/src/main/resources/assets/anvilcraft/models/item/capacitor.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "anvilcraft:item/capacitor" - }, - "overrides": [ - { - "predicate": { - "damaged": 1 - }, - "model": "anvilcraft:item/capacitor_empty" - } - ] -} diff --git a/common/src/main/resources/assets/anvilcraft/models/item/capacitor_empty.json b/common/src/main/resources/assets/anvilcraft/models/item/capacitor_empty.json deleted file mode 100644 index 54eaefaf2..000000000 --- a/common/src/main/resources/assets/anvilcraft/models/item/capacitor_empty.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "parent": "item/generated", - "textures": { - "layer0": "anvilcraft:item/capacitor_empty" - } -} diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json index a59de1ff0..7b0ba568d 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -36,6 +36,7 @@ "item.anvilcraft.beef_mushroom_stew": "ʍǝʇS ɯooɹɥsnW ɟǝǝᗺ", "item.anvilcraft.beef_mushroom_stew_raw": "ʍɐᴚ ʍǝʇS ɯooɹɥsnW ɟǝǝᗺ", "item.anvilcraft.capacitor": "ɹoʇıɔɐdɐƆ", + "item.anvilcraft.capacitor_empty": "ʎʇdɯƎ ɹoʇıɔɐdɐƆ", "item.anvilcraft.chocolate": "ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_black": "ʞɔɐןᗺ ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_white": "ǝʇıɥM ǝʇɐןoɔoɥƆ", diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json index 389b12f80..6b8a0a96a 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -36,6 +36,7 @@ "item.anvilcraft.beef_mushroom_stew": "Beef Mushroom Stew", "item.anvilcraft.beef_mushroom_stew_raw": "Beef Mushroom Stew Raw", "item.anvilcraft.capacitor": "Capacitor", + "item.anvilcraft.capacitor_empty": "Capacitor Empty", "item.anvilcraft.chocolate": "Chocolate", "item.anvilcraft.chocolate_black": "Chocolate Black", "item.anvilcraft.chocolate_white": "Chocolate White", diff --git a/fabric/src/generated/resources/assets/anvilcraft/models/item/capacitor.json b/fabric/src/generated/resources/assets/anvilcraft/models/item/capacitor.json new file mode 100644 index 000000000..2c835c265 --- /dev/null +++ b/fabric/src/generated/resources/assets/anvilcraft/models/item/capacitor.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "anvilcraft:item/capacitor" + } +} \ No newline at end of file diff --git a/fabric/src/generated/resources/assets/anvilcraft/models/item/capacitor_empty.json b/fabric/src/generated/resources/assets/anvilcraft/models/item/capacitor_empty.json new file mode 100644 index 000000000..918a2326f --- /dev/null +++ b/fabric/src/generated/resources/assets/anvilcraft/models/item/capacitor_empty.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "anvilcraft:item/capacitor_empty" + } +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json index 865c61ca8..2e92dd13e 100644 --- a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json +++ b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "anvilcraft:capacitor" - ] + "tag": "anvilcraft:capacitor" } ] }, diff --git a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor_empty.json similarity index 93% rename from forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json rename to fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor_empty.json index 0495ebb62..c744d1652 100644 --- a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json +++ b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor_empty.json @@ -39,7 +39,7 @@ }, "has_the_recipe": { "conditions": { - "recipe": "anvilcraft:capacitor" + "recipe": "anvilcraft:capacitor_empty" }, "trigger": "minecraft:recipe_unlocked" } @@ -54,7 +54,7 @@ ], "rewards": { "recipes": [ - "anvilcraft:capacitor" + "anvilcraft:capacitor_empty" ] }, "sends_telemetry_event": false diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/capacitor.json b/fabric/src/generated/resources/data/anvilcraft/recipes/capacitor_empty.json similarity index 85% rename from forge/src/generated/resources/data/anvilcraft/recipes/capacitor.json rename to fabric/src/generated/resources/data/anvilcraft/recipes/capacitor_empty.json index 5c88ce9e6..5b80905be 100644 --- a/forge/src/generated/resources/data/anvilcraft/recipes/capacitor.json +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/capacitor_empty.json @@ -18,8 +18,7 @@ "ABA" ], "result": { - "data": "{Damage:1}", - "item": "anvilcraft:capacitor" + "item": "anvilcraft:capacitor_empty" }, "show_notification": true } \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/heater.json b/fabric/src/generated/resources/data/anvilcraft/recipes/heater.json index fcfa098b7..9ae50f2d4 100644 --- a/fabric/src/generated/resources/data/anvilcraft/recipes/heater.json +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/heater.json @@ -9,7 +9,7 @@ "item": "minecraft:iron_ingot" }, "C": { - "item": "anvilcraft:capacitor" + "tag": "anvilcraft:capacitor" } }, "pattern": [ diff --git a/fabric/src/generated/resources/data/anvilcraft/tags/items/capacitor.json b/fabric/src/generated/resources/data/anvilcraft/tags/items/capacitor.json new file mode 100644 index 000000000..20bbc5532 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/tags/items/capacitor.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "anvilcraft:capacitor", + "anvilcraft:capacitor_empty" + ] +} \ No newline at end of file diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java index a792897d5..5e268897d 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java @@ -8,7 +8,6 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.level.ServerLevel; import net.minecraft.server.packs.resources.CloseableResourceManager; public class ServerLifecycleEvent { @@ -18,21 +17,26 @@ public class ServerLifecycleEvent { public static void init() { ServerLifecycleEvents.SERVER_STARTED.register(ServerLifecycleEvent::serverStarted); ServerLifecycleEvents.END_DATA_PACK_RELOAD.register(ServerLifecycleEvent::endDataPackReload); - ServerTickEvents.START_WORLD_TICK.register(ServerLifecycleEvent::startWorldTick); + ServerLifecycleEvents.SERVER_STOPPED.register(ServerLifecycleEvent::onServerStopped); + ServerTickEvents.START_SERVER_TICK.register(ServerLifecycleEvent::startTick); } - public static void serverStarted(MinecraftServer server) { + private static void serverStarted(MinecraftServer server) { ServerHooks.setServer(server); AnvilCraft.EVENT_BUS.post(new ServerStartedEvent(server)); } - public static void endDataPackReload( + private static void endDataPackReload( MinecraftServer server, CloseableResourceManager resourceManager, boolean success ) { AnvilCraft.EVENT_BUS.post(new ServerEndDataPackReloadEvent(server, resourceManager)); } - public static void startWorldTick(ServerLevel world) { + private static void startTick(MinecraftServer server) { PowerGrid.tickGrid(); } + + private static void onServerStopped(MinecraftServer server) { + PowerGrid.clear(); + } } diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json index a59de1ff0..7b0ba568d 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -36,6 +36,7 @@ "item.anvilcraft.beef_mushroom_stew": "ʍǝʇS ɯooɹɥsnW ɟǝǝᗺ", "item.anvilcraft.beef_mushroom_stew_raw": "ʍɐᴚ ʍǝʇS ɯooɹɥsnW ɟǝǝᗺ", "item.anvilcraft.capacitor": "ɹoʇıɔɐdɐƆ", + "item.anvilcraft.capacitor_empty": "ʎʇdɯƎ ɹoʇıɔɐdɐƆ", "item.anvilcraft.chocolate": "ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_black": "ʞɔɐןᗺ ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_white": "ǝʇıɥM ǝʇɐןoɔoɥƆ", diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json index 389b12f80..6b8a0a96a 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -36,6 +36,7 @@ "item.anvilcraft.beef_mushroom_stew": "Beef Mushroom Stew", "item.anvilcraft.beef_mushroom_stew_raw": "Beef Mushroom Stew Raw", "item.anvilcraft.capacitor": "Capacitor", + "item.anvilcraft.capacitor_empty": "Capacitor Empty", "item.anvilcraft.chocolate": "Chocolate", "item.anvilcraft.chocolate_black": "Chocolate Black", "item.anvilcraft.chocolate_white": "Chocolate White", diff --git a/forge/src/generated/resources/assets/anvilcraft/models/item/capacitor.json b/forge/src/generated/resources/assets/anvilcraft/models/item/capacitor.json new file mode 100644 index 000000000..2c835c265 --- /dev/null +++ b/forge/src/generated/resources/assets/anvilcraft/models/item/capacitor.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "anvilcraft:item/capacitor" + } +} \ No newline at end of file diff --git a/forge/src/generated/resources/assets/anvilcraft/models/item/capacitor_empty.json b/forge/src/generated/resources/assets/anvilcraft/models/item/capacitor_empty.json new file mode 100644 index 000000000..918a2326f --- /dev/null +++ b/forge/src/generated/resources/assets/anvilcraft/models/item/capacitor_empty.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "anvilcraft:item/capacitor_empty" + } +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json index 865c61ca8..2e92dd13e 100644 --- a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json +++ b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/heater.json @@ -5,9 +5,7 @@ "conditions": { "items": [ { - "items": [ - "anvilcraft:capacitor" - ] + "tag": "anvilcraft:capacitor" } ] }, diff --git a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor_empty.json similarity index 93% rename from fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json rename to forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor_empty.json index 0495ebb62..c744d1652 100644 --- a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor.json +++ b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/tools/capacitor_empty.json @@ -39,7 +39,7 @@ }, "has_the_recipe": { "conditions": { - "recipe": "anvilcraft:capacitor" + "recipe": "anvilcraft:capacitor_empty" }, "trigger": "minecraft:recipe_unlocked" } @@ -54,7 +54,7 @@ ], "rewards": { "recipes": [ - "anvilcraft:capacitor" + "anvilcraft:capacitor_empty" ] }, "sends_telemetry_event": false diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/capacitor.json b/forge/src/generated/resources/data/anvilcraft/recipes/capacitor_empty.json similarity index 85% rename from fabric/src/generated/resources/data/anvilcraft/recipes/capacitor.json rename to forge/src/generated/resources/data/anvilcraft/recipes/capacitor_empty.json index 5c88ce9e6..5b80905be 100644 --- a/fabric/src/generated/resources/data/anvilcraft/recipes/capacitor.json +++ b/forge/src/generated/resources/data/anvilcraft/recipes/capacitor_empty.json @@ -18,8 +18,7 @@ "ABA" ], "result": { - "data": "{Damage:1}", - "item": "anvilcraft:capacitor" + "item": "anvilcraft:capacitor_empty" }, "show_notification": true } \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/heater.json b/forge/src/generated/resources/data/anvilcraft/recipes/heater.json index fcfa098b7..9ae50f2d4 100644 --- a/forge/src/generated/resources/data/anvilcraft/recipes/heater.json +++ b/forge/src/generated/resources/data/anvilcraft/recipes/heater.json @@ -9,7 +9,7 @@ "item": "minecraft:iron_ingot" }, "C": { - "item": "anvilcraft:capacitor" + "tag": "anvilcraft:capacitor" } }, "pattern": [ diff --git a/forge/src/generated/resources/data/anvilcraft/tags/items/capacitor.json b/forge/src/generated/resources/data/anvilcraft/tags/items/capacitor.json new file mode 100644 index 000000000..20bbc5532 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/tags/items/capacitor.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "anvilcraft:capacitor", + "anvilcraft:capacitor_empty" + ] +} \ No newline at end of file diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java index dd7c7f639..45d2eacb7 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java @@ -8,6 +8,7 @@ import net.minecraft.server.packs.resources.CloseableResourceManager; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.server.ServerStartedEvent; +import net.minecraftforge.event.server.ServerStoppedEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.jetbrains.annotations.NotNull; @@ -33,12 +34,19 @@ public static void onDataPackReloaded(@NotNull DataPackReloadedEvent event) { } /** - * @param event 世界刻事件 + * @param event 服务器刻事件 */ @SubscribeEvent - public static void onWordTick(@NotNull TickEvent.LevelTickEvent event) { - if (event.level.isClientSide) return; + public static void onTick(@NotNull TickEvent.ServerTickEvent event) { if (event.phase != TickEvent.Phase.START) return; PowerGrid.tickGrid(); } + + /** + * @param event 服务器关闭事件 + */ + @SubscribeEvent + public static void onServerStopped(@NotNull ServerStoppedEvent event) { + PowerGrid.clear(); + } } From 216b50893e061d0e8ffe4f655e760da650e2ca6c Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 01:28:29 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E7=AE=80=E5=8D=95=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E4=B8=80=E4=B8=8B=E6=8B=96=E6=8B=BD=E6=9D=A1=E7=9A=84GUI?= =?UTF-8?q?=EF=BC=88=E6=8B=96=E6=8B=BD=E4=B8=8D=E4=BA=86=E7=9A=84=E6=8B=96?= =?UTF-8?q?=E6=8B=BD=E6=9D=A1=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/dubhe/anvilcraft/AnvilCraft.java | 4 +- .../anvilcraft/block/CreativeDynamoBlock.java | 28 +++ .../entity/CreativeDynamoBlockEntity.java | 39 ++++- .../gui/component/EnableFilterButton.java | 4 +- .../gui/component/OutputDirectionButton.java | 12 +- .../client/gui/component/Slider.java | 159 ++++++++++++++++++ .../screen/inventory/AutoCrafterScreen.java | 3 +- .../gui/screen/inventory/ChuteScreen.java | 3 +- .../gui/screen/inventory/IFilterScreen.java | 2 +- .../screen/inventory/RoyalAnvilScreen.java | 10 +- .../inventory/RoyalGrindstoneScreen.java | 2 +- .../screen/inventory/RoyalSmithingScreen.java | 5 +- .../gui/screen/inventory/SliderScreen.java | 121 +++++++++++++ .../dubhe/anvilcraft/init/ModMenuTypes.java | 30 +++- .../dubhe/anvilcraft/init/ModNetworks.java | 10 +- .../anvilcraft/inventory/SliderMenu.java | 60 +++++++ .../anvilcraft/network/SliderInitPack.java | 61 +++++++ .../anvilcraft/network/SliderUpdatePack.java | 42 +++++ .../{ => machine/background}/auto_crafter.png | Bin .../{ => machine/background}/chute.png | Bin .../gui/container/{ => machine}/button_d.png | Bin .../gui/container/{ => machine}/button_e.png | Bin .../gui/container/{ => machine}/button_n.png | Bin .../gui/container/{ => machine}/button_no.png | Bin .../gui/container/{ => machine}/button_s.png | Bin .../gui/container/{ => machine}/button_u.png | Bin .../gui/container/{ => machine}/button_w.png | Bin .../container/{ => machine}/button_yes.png | Bin .../container/{ => machine}/disabled_slot.png | Bin .../{slider.png => slider/background.png} | Bin .../button_add.png} | Bin .../button_max.png} | Bin .../button_min.png} | Bin .../button_minus.png} | Bin .../{slider_slider.png => slider/slider.png} | Bin .../{ => smithing/background}/royal_anvil.png | Bin .../background}/royal_grindstone.png | Bin .../background}/royal_smithing_table.png | Bin .../gui/container/{ => smithing}/error.png | Bin .../container/{ => smithing}/text_field.png | Bin .../{ => smithing}/text_field_disabled.png | Bin .../gui/container/warning_material.png | Bin 385 -> 0 bytes .../textures/gui/container/warning_none.png | Bin 380 -> 0 bytes .../gui/container/warning_protocol.png | Bin 379 -> 0 bytes 44 files changed, 565 insertions(+), 30 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/Slider.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/inventory/SliderMenu.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/network/SliderInitPack.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/network/SliderUpdatePack.java rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine/background}/auto_crafter.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine/background}/chute.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine}/button_d.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine}/button_e.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine}/button_n.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine}/button_no.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine}/button_s.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine}/button_u.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine}/button_w.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine}/button_yes.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => machine}/disabled_slot.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{slider.png => slider/background.png} (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{slider_button_add.png => slider/button_add.png} (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{slider_button_max.png => slider/button_max.png} (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{slider_button_min.png => slider/button_min.png} (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{slider_button_minus.png => slider/button_minus.png} (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{slider_slider.png => slider/slider.png} (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => smithing/background}/royal_anvil.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => smithing/background}/royal_grindstone.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => smithing/background}/royal_smithing_table.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => smithing}/error.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => smithing}/text_field.png (100%) rename common/src/main/resources/assets/anvilcraft/textures/gui/container/{ => smithing}/text_field_disabled.png (100%) delete mode 100644 common/src/main/resources/assets/anvilcraft/textures/gui/container/warning_material.png delete mode 100644 common/src/main/resources/assets/anvilcraft/textures/gui/container/warning_none.png delete mode 100644 common/src/main/resources/assets/anvilcraft/textures/gui/container/warning_protocol.png diff --git a/common/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java b/common/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java index f4a9f2165..21aec145b 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/AnvilCraft.java @@ -52,7 +52,7 @@ public static void init() { REGISTRATE.registerRegistrate(); } - public static @NotNull ResourceLocation of(String id) { - return new ResourceLocation(MOD_ID, id); + public static @NotNull ResourceLocation of(String path) { + return new ResourceLocation(MOD_ID, path); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java index b31138553..f05ebff5e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java @@ -1,13 +1,21 @@ package dev.dubhe.anvilcraft.block; import dev.dubhe.anvilcraft.block.entity.CreativeDynamoBlockEntity; +import dev.dubhe.anvilcraft.init.ModMenuTypes; +import dev.dubhe.anvilcraft.network.SliderInitPack; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; @@ -22,6 +30,26 @@ public CreativeDynamoBlock(Properties properties) { super(properties); } + @Override + @SuppressWarnings({"deprecation", "UnreachableCode"}) + public @NotNull InteractionResult use( + @NotNull BlockState state, @NotNull Level level, + @NotNull BlockPos pos, @NotNull Player player, + @NotNull InteractionHand hand, @NotNull BlockHitResult hit + ) { + if (level.isClientSide) { + return InteractionResult.SUCCESS; + } + if ( + level.getBlockEntity(pos) instanceof CreativeDynamoBlockEntity entity + && player instanceof ServerPlayer serverPlayer + ) { + ModMenuTypes.open(serverPlayer, entity, pos); + new SliderInitPack(entity.getPower(), -1024, 1024).send(serverPlayer); + } + return InteractionResult.SUCCESS; + } + @Nullable @Override public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java index abc519a78..a8b80be4f 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java @@ -1,19 +1,31 @@ package dev.dubhe.anvilcraft.block.entity; +import dev.dubhe.anvilcraft.api.power.IPowerConsumer; import dev.dubhe.anvilcraft.api.power.IPowerProducer; +import dev.dubhe.anvilcraft.api.power.PowerComponentType; import dev.dubhe.anvilcraft.api.power.PowerGrid; import dev.dubhe.anvilcraft.init.ModBlockEntities; +import dev.dubhe.anvilcraft.init.ModBlocks; +import dev.dubhe.anvilcraft.inventory.SliderMenu; import lombok.Getter; +import lombok.Setter; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; 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 org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public class CreativeDynamoBlockEntity extends BlockEntity implements IPowerProducer { - @Getter +@Getter +public class CreativeDynamoBlockEntity extends BlockEntity implements IPowerProducer, IPowerConsumer, MenuProvider { private PowerGrid grid = null; + @Setter private int power = 16; public static @NotNull CreativeDynamoBlockEntity createBlockEntity( @@ -44,7 +56,17 @@ public void load(@NotNull CompoundTag tag) { @Override public int getOutputPower() { - return this.power; + return this.power > 0 ? this.power : 0; + } + + @Override + public int getInputPower() { + return this.power < 0 ? -this.power : 0; + } + + @Override + public @NotNull PowerComponentType getComponentType() { + return this.power > 0 ? PowerComponentType.PRODUCER : PowerComponentType.CONSUMER; } @Override @@ -56,4 +78,15 @@ public int getOutputPower() { public void setGrid(PowerGrid grid) { this.grid = grid; } + + @Override + public @NotNull Component getDisplayName() { + return ModBlocks.CREATIVE_DYNAMO.get().getName(); + } + + @Nullable + @Override + public AbstractContainerMenu createMenu(int i, @NotNull Inventory inventory, @NotNull Player player) { + return new SliderMenu(i, -1024, 1024, this::setPower); + } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/EnableFilterButton.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/EnableFilterButton.java index b1cd92372..534a0e904 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/EnableFilterButton.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/EnableFilterButton.java @@ -18,8 +18,8 @@ @Getter public class EnableFilterButton extends Button { private final Supplier filterEnabled; - private static final ResourceLocation YES = AnvilCraft.of("textures/gui/container/button_yes.png"); - private static final ResourceLocation NO = AnvilCraft.of("textures/gui/container/button_no.png"); + private static final ResourceLocation YES = AnvilCraft.of("textures/gui/container/machine/button_yes.png"); + private static final ResourceLocation NO = AnvilCraft.of("textures/gui/container/machine/button_no.png"); private static final MutableComponent defaultMessage = Component .translatable("screen.anvilcraft.button.record", Component.translatable("screen.anvilcraft.button.off")); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/OutputDirectionButton.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/OutputDirectionButton.java index 29babd838..777250b51 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/OutputDirectionButton.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/OutputDirectionButton.java @@ -18,12 +18,12 @@ public class OutputDirectionButton extends Button { private Direction direction; private final List skip = new ArrayList<>(); - private static final ResourceLocation UP = AnvilCraft.of("textures/gui/container/button_u.png"); - private static final ResourceLocation DOWN = AnvilCraft.of("textures/gui/container/button_d.png"); - private static final ResourceLocation EAST = AnvilCraft.of("textures/gui/container/button_e.png"); - private static final ResourceLocation WEST = AnvilCraft.of("textures/gui/container/button_w.png"); - private static final ResourceLocation SOUTH = AnvilCraft.of("textures/gui/container/button_s.png"); - private static final ResourceLocation NORTH = AnvilCraft.of("textures/gui/container/button_n.png"); + private static final ResourceLocation UP = AnvilCraft.of("textures/gui/container/machine/button_u.png"); + private static final ResourceLocation DOWN = AnvilCraft.of("textures/gui/container/machine/button_d.png"); + private static final ResourceLocation EAST = AnvilCraft.of("textures/gui/container/machine/button_e.png"); + private static final ResourceLocation WEST = AnvilCraft.of("textures/gui/container/machine/button_w.png"); + private static final ResourceLocation SOUTH = AnvilCraft.of("textures/gui/container/machine/button_s.png"); + private static final ResourceLocation NORTH = AnvilCraft.of("textures/gui/container/machine/button_n.png"); private static final MutableComponent defaultMessage = Component.translatable("screen.anvilcraft.button.direction", Component.translatable("screen.anvilcraft.button.direction.up")); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/Slider.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/Slider.java new file mode 100644 index 000000000..b8d310dee --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/component/Slider.java @@ -0,0 +1,159 @@ +package dev.dubhe.anvilcraft.client.gui.component; + +import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.inventory.SliderMenu; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.Util; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; + +public class Slider extends AbstractWidget { + public static final ResourceLocation SLIDER = AnvilCraft.of("textures/gui/container/slider/slider.png"); + @Setter + @Getter + private int min; + @Setter + @Getter + private int max; + @Getter + private int value; + private final int posX; + private final int posY; + private final int length; + public final SliderMenu.Update update; + private int tooltipMsDelay; + private long hoverOrFocusedStartTime; + private boolean wasHoveredOrFocused; + + /** + * @param x X + * @param y Y + * @param min 最小值 + * @param max 最大值 + * @param length 长度 + * @param update 更新回调 + */ + public Slider(int x, int y, int min, int max, int length, SliderMenu.Update update) { + super(x, y, length, 8, Component.literal("Slider")); + this.posX = x; + this.posY = y; + this.min = min; + this.max = max; + this.length = length; + this.update = update; + } + + public double getProportion() { + return Math.max(0.0, Math.min(1.0, (double) (value - this.min) / (this.max - this.min))); + } + + public void setProportion(double proportion) { + this.value = (int) ((max - min) * proportion + min); + } + + public void setValue(int value) { + this.value = Math.max(this.min, Math.min(this.max, value)); + } + + /** + * @param value 设置 Value 并更新 + */ + public void setValueWithUpdate(int value) { + if (this.value == value) return; + this.setValue(value); + this.update(); + } + + private void update() { + if (this.update != null) this.update.update(this.value); + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY) { + if (button == 0) { + this.onDrag(mouseX, mouseY, dragX, dragY); + return true; + } + return false; + } + + @Override + public void onClick(double mouseX, double mouseY) { + super.onClick(mouseX, mouseY); + if (!isInRange(mouseX, mouseY)) return; + if (isInSlider(mouseX, mouseY)) { + super.onClick(mouseX, mouseY); + return; + } + double offset = 16.0 / this.length; + int offsetX = posX + (int) ((length - 16) * this.getProportion()); + if (mouseX < offsetX) this.setProportion(Math.max(0.0, this.getProportion() - offset)); + else this.setProportion(Math.min(1.0, this.getProportion() + offset)); + this.update(); + } + + @Override + protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) { + super.onDrag(mouseX, mouseY, dragX, dragY); + if (!isInSlider(mouseX, mouseY)) return; + double offset = dragX - mouseX / this.length; + this.setProportion(Math.max(0.0, Math.min(1.0, this.getProportion() + offset))); + this.update(); + } + + protected boolean isInSlider(double mouseX, double mouseY) { + int offsetX = posX + (int) ((length - 16) * this.getProportion()); + return mouseX > offsetX && mouseX < offsetX + 16 && mouseY > posY && mouseY < posY + 8; + } + + protected boolean isInRange(double mouseX, double mouseY) { + return mouseX > posX && mouseX < posX + length && mouseY > posY && mouseY < posY + 8; + } + + @Override + public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + if (!this.visible) return; + this.isHovered = this.isInRange(mouseX, mouseY); + this.renderWidget(guiGraphics, mouseX, mouseY, partialTick); + this.updateTooltip(); + } + + @Override + protected void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) { + int offsetX = posX + (int) ((length - 16) * this.getProportion()); + guiGraphics.blit(SLIDER, offsetX, posY, 0, this.isHovered ? 8 : 0, 16, 8, 16, 16); + } + + @Override + protected void updateWidgetNarration(@NotNull NarrationElementOutput narrationElementOutput) { + } + + private void updateTooltip() { + if (this.getTooltip() == null) return; + boolean bl = this.isHovered || this.isFocused() && Minecraft.getInstance().getLastInputType().isKeyboard(); + if (bl != this.wasHoveredOrFocused) { + if (bl) this.hoverOrFocusedStartTime = Util.getMillis(); + this.wasHoveredOrFocused = bl; + } + Screen screen; + if (bl + && Util.getMillis() - this.hoverOrFocusedStartTime > (long) this.tooltipMsDelay + && (screen = Minecraft.getInstance().screen) != null + ) { + screen.setTooltipForNextRenderPass(this.getTooltip(), this.createTooltipPositioner(), this.isFocused()); + } + } + + @Override + public void setTooltipDelay(int tooltipMsDelay) { + super.setTooltipDelay(tooltipMsDelay); + this.tooltipMsDelay = tooltipMsDelay; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java index 8348a9d2f..be5c396ee 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/AutoCrafterScreen.java @@ -18,7 +18,8 @@ import java.util.function.BiFunction; public class AutoCrafterScreen extends BaseMachineScreen implements IFilterScreen { - private static final ResourceLocation CONTAINER_LOCATION = AnvilCraft.of("textures/gui/container/auto_crafter.png"); + private static final ResourceLocation CONTAINER_LOCATION = + AnvilCraft.of("textures/gui/container/machine/background/auto_crafter.png"); BiFunction enableFilterButtonSupplier = this .getEnableFilterButtonSupplier(116, 18); @Getter diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java index f9913cb6b..3c192b9cb 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ChuteScreen.java @@ -20,7 +20,8 @@ import java.util.function.BiFunction; public class ChuteScreen extends BaseMachineScreen implements IFilterScreen { - private static final ResourceLocation CONTAINER_LOCATION = AnvilCraft.of("textures/gui/container/chute.png"); + private static final ResourceLocation CONTAINER_LOCATION = + AnvilCraft.of("textures/gui/container/machine/background/chute.png"); BiFunction enableFilterButtonSupplier = this diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java index bb3bae113..7b9874f23 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/IFilterScreen.java @@ -18,7 +18,7 @@ * 有过滤的 GUI */ public interface IFilterScreen { - ResourceLocation DISABLED_SLOT = AnvilCraft.of("textures/gui/container/disabled_slot.png"); + ResourceLocation DISABLED_SLOT = AnvilCraft.of("textures/gui/container/machine/disabled_slot.png"); IFilterMenu getFilterMenu(); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalAnvilScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalAnvilScreen.java index 3234a5711..dadd2561b 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalAnvilScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalAnvilScreen.java @@ -17,10 +17,12 @@ import org.jetbrains.annotations.NotNull; public class RoyalAnvilScreen extends ItemCombinerScreen { - private static final ResourceLocation ANVIL_LOCATION = AnvilCraft.of("textures/gui/container/royal_anvil.png"); - private static final ResourceLocation TEXT_LOCATION = AnvilCraft.of("textures/gui/container/text_field.png"); - private static final ResourceLocation TEXT_DISABLE_LOCATION = AnvilCraft - .of("textures/gui/container/text_field_disabled.png"); + private static final ResourceLocation ANVIL_LOCATION = + AnvilCraft.of("textures/gui/container/smithing/background/royal_anvil.png"); + private static final ResourceLocation TEXT_LOCATION = + AnvilCraft.of("textures/gui/container/smithing/text_field.png"); + private static final ResourceLocation TEXT_DISABLE_LOCATION = + AnvilCraft.of("textures/gui/container/smithing/text_field_disabled.png"); private EditBox name; private final Player player; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalGrindstoneScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalGrindstoneScreen.java index c002d67eb..fa6f1fcc8 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalGrindstoneScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalGrindstoneScreen.java @@ -11,7 +11,7 @@ public class RoyalGrindstoneScreen extends AbstractContainerScreen { private static final ResourceLocation GRINDSTONE_LOCATION = - AnvilCraft.of("textures/gui/container/royal_grindstone.png"); + AnvilCraft.of("textures/gui/container/smithing/background/royal_grindstone.png"); public RoyalGrindstoneScreen( RoyalGrindstoneMenu menu, Inventory playerInventory, @SuppressWarnings("unused") Component title diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalSmithingScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalSmithingScreen.java index a77d112c6..3849401b8 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalSmithingScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/RoyalSmithingScreen.java @@ -25,8 +25,9 @@ public class RoyalSmithingScreen extends ItemCombinerScreen { private static final ResourceLocation SMITHING_LOCATION = - AnvilCraft.of("textures/gui/container/royal_smithing_table.png"); - private static final ResourceLocation ERROR = AnvilCraft.of("textures/gui/container/error.png"); + AnvilCraft.of("textures/gui/container/smithing/background/royal_smithing_table.png"); + private static final ResourceLocation ERROR = + AnvilCraft.of("textures/gui/container/smithing/error.png"); private static final ResourceLocation EMPTY_SLOT_SMITHING_TEMPLATE_ARMOR_TRIM = new ResourceLocation("item/empty_slot_smithing_template_armor_trim"); private static final ResourceLocation EMPTY_SLOT_SMITHING_TEMPLATE_NETHERITE_UPGRADE = diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java new file mode 100644 index 000000000..288d77065 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java @@ -0,0 +1,121 @@ +package dev.dubhe.anvilcraft.client.gui.screen.inventory; + +import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.client.gui.component.Slider; +import dev.dubhe.anvilcraft.inventory.SliderMenu; +import dev.dubhe.anvilcraft.network.SliderUpdatePack; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.components.ImageButton; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; +import org.jetbrains.annotations.NotNull; + +public class SliderScreen extends AbstractContainerScreen { + public static final ResourceLocation LOCATION = AnvilCraft.of("textures/gui/container/slider/background.png"); + public static final ResourceLocation BUTTON_MAX = AnvilCraft.of("textures/gui/container/slider/button_max.png"); + public static final ResourceLocation BUTTON_ADD = AnvilCraft.of("textures/gui/container/slider/button_add.png"); + public static final ResourceLocation BUTTON_MINUS = AnvilCraft.of("textures/gui/container/slider/button_minus.png"); + public static final ResourceLocation BUTTON_MIN = AnvilCraft.of("textures/gui/container/slider/button_min.png"); + private Slider slider = null; + private EditBox value; + + /** + * @param menu 菜单 + * @param inventory 背包 + * @param title 标题 + */ + public SliderScreen(SliderMenu menu, Inventory inventory, Component title) { + super(menu, inventory, title); + this.imageWidth = 176; + this.imageHeight = 77; + } + + @Override + protected void init() { + super.init(); + this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2; + int offsetX = (this.width - this.imageWidth) / 2; + int offsetY = (this.height - this.imageHeight) / 2; + this.slider = new Slider(8 + offsetX, 31 + offsetY, 0, 16, 160, this::update); + this.value = new EditBox(this.font, offsetX + 50, offsetY + 47, 76, 8, Component.literal("value")); + this.value.setCanLoseFocus(false); + this.value.setTextColor(-1); + this.value.setTextColorUneditable(-1); + this.value.setBordered(false); + this.value.setMaxLength(50); + this.value.setResponder(this::onValueInput); + this.value.setValue(""); + ImageButton max = new ImageButton( + 152 + offsetX, 43 + offsetY, + 16, 16, 0, 0, 16, BUTTON_MAX, 16, 32, + (btn) -> this.slider.setValueWithUpdate(slider.getMax()) + ); + ImageButton add = new ImageButton( + 134 + offsetX, 43 + offsetY, + 16, 16, 0, 0, 16, BUTTON_ADD, 16, 32, + (btn) -> this.slider.setValueWithUpdate(Math.min(slider.getMax(), slider.getValue() + 1)) + ); + ImageButton min = new ImageButton( + 8 + offsetX, 43 + offsetY, + 16, 16, 0, 0, 16, BUTTON_MIN, 16, 32, + (btn) -> this.slider.setValueWithUpdate(slider.getMin()) + ); + ImageButton minus = new ImageButton( + 26 + offsetX, 43 + offsetY, + 16, 16, 0, 0, 16, BUTTON_MINUS, 16, 32, + (btn) -> this.slider.setValueWithUpdate(Math.max(slider.getMin(), slider.getValue() - 1)) + ); + this.addRenderableWidget(max); + this.addRenderableWidget(add); + this.addRenderableWidget(min); + this.addRenderableWidget(minus); + this.addRenderableWidget(this.slider); + this.addRenderableWidget(this.value); + this.setInitialFocus(this.value); + } + + public void setValue(int value) { + if (this.slider != null) slider.setValue(value); + this.value.setValue("" + value); + } + + private void onValueInput(@NotNull String value) { + String regex = "^[+-]?[0-9]+$"; + if (value.matches(regex)) { + int v = Integer.parseInt(value); + this.slider.setValueWithUpdate(v); + } else if (value.isEmpty()) { + this.slider.setValueWithUpdate(0); + } else { + this.value.setValue("" + this.slider.getValue()); + } + } + + public void setMin(int min) { + if (this.slider != null) slider.setMin(min); + } + + public void setMax(int max) { + if (this.slider != null) slider.setMax(max); + } + + @Override + protected void renderLabels(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY) { + guiGraphics.drawString(this.font, this.title, this.titleLabelX, this.titleLabelY, 0x404040, false); + } + + @Override + protected void renderBg(@NotNull GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) { + int offsetX = (this.width - this.imageWidth) / 2; + int offsetY = (this.height - this.imageHeight) / 2; + guiGraphics.blit(LOCATION, offsetX, offsetY, 0, 0, this.imageWidth, this.imageHeight, 256, 128); + } + + private void update(int value) { + new SliderUpdatePack(value).send(); + this.value.setValue("" + value); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModMenuTypes.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModMenuTypes.java index 39667e376..19ec035d6 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModMenuTypes.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModMenuTypes.java @@ -7,11 +7,13 @@ import dev.dubhe.anvilcraft.client.gui.screen.inventory.RoyalAnvilScreen; import dev.dubhe.anvilcraft.client.gui.screen.inventory.RoyalGrindstoneScreen; import dev.dubhe.anvilcraft.client.gui.screen.inventory.RoyalSmithingScreen; +import dev.dubhe.anvilcraft.client.gui.screen.inventory.SliderScreen; import dev.dubhe.anvilcraft.inventory.AutoCrafterMenu; import dev.dubhe.anvilcraft.inventory.ChuteMenu; import dev.dubhe.anvilcraft.inventory.RoyalAnvilMenu; import dev.dubhe.anvilcraft.inventory.RoyalGrindstoneMenu; import dev.dubhe.anvilcraft.inventory.RoyalSmithingMenu; +import dev.dubhe.anvilcraft.inventory.SliderMenu; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.MenuProvider; @@ -28,17 +30,33 @@ public class ModMenuTypes { .menu("chute", ChuteMenu::new, () -> ChuteScreen::new) .register(); public static final MenuEntry ROYAL_GRINDSTONE = REGISTRATE - .menu("royal_grindstone", (type, id, inventory) -> - new RoyalGrindstoneMenu(type, id, inventory), () -> RoyalGrindstoneScreen::new) + .menu( + "royal_grindstone", + (type, id, inv) -> new RoyalGrindstoneMenu(type, id, inv), + () -> RoyalGrindstoneScreen::new + ) .register(); public static final MenuEntry ROYAL_ANVIL = REGISTRATE - .menu("royal_anvil", (type, id, inventory) -> - new RoyalAnvilMenu(id, inventory), () -> RoyalAnvilScreen::new) + .menu( + "royal_anvil", + (type, id, inv) -> new RoyalAnvilMenu(id, inv), + () -> RoyalAnvilScreen::new + ) .register(); public static final MenuEntry ROYAL_SMITHING = REGISTRATE - .menu("royal_smithing_table", (type, id, inventory) -> - new RoyalSmithingMenu(type, id, inventory), () -> RoyalSmithingScreen::new) + .menu( + "royal_smithing_table", + (type, id, inv) -> new RoyalSmithingMenu(type, id, inv), + () -> RoyalSmithingScreen::new + ) .register(); + public static final MenuEntry SLIDER = REGISTRATE + .menu( + "slider", + (menuType, containerId, inventory) -> new SliderMenu(menuType, containerId), + () -> SliderScreen::new + ) + .register(); public static void register() { } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModNetworks.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModNetworks.java index 718fea6e2..06671e151 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModNetworks.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModNetworks.java @@ -2,8 +2,10 @@ import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.api.network.Network; -import dev.dubhe.anvilcraft.network.MachineOutputDirectionPack; import dev.dubhe.anvilcraft.network.MachineEnableFilterPack; +import dev.dubhe.anvilcraft.network.MachineOutputDirectionPack; +import dev.dubhe.anvilcraft.network.SliderInitPack; +import dev.dubhe.anvilcraft.network.SliderUpdatePack; import dev.dubhe.anvilcraft.network.SlotDisableChangePack; import dev.dubhe.anvilcraft.network.SlotFilterChangePack; import net.minecraft.resources.ResourceLocation; @@ -21,6 +23,12 @@ public class ModNetworks { public static final ResourceLocation SLOT_FILTER_CHANGE_PACKET = Network .register(AnvilCraft.of("slot_filter_change"), SlotFilterChangePack.class, SlotFilterChangePack::new); + public static final ResourceLocation SLIDER_UPDATE = Network + .register(AnvilCraft.of("slider_update"), + SliderUpdatePack.class, SliderUpdatePack::new); + public static final ResourceLocation SLIDER_INIT = Network + .register(AnvilCraft.of("slider_init"), + SliderInitPack.class, SliderInitPack::new); public static void register() { } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/inventory/SliderMenu.java b/common/src/main/java/dev/dubhe/anvilcraft/inventory/SliderMenu.java new file mode 100644 index 000000000..5c214ffcc --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/inventory/SliderMenu.java @@ -0,0 +1,60 @@ +package dev.dubhe.anvilcraft.inventory; + +import dev.dubhe.anvilcraft.init.ModMenuTypes; +import lombok.Getter; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@Getter +public class SliderMenu extends AbstractContainerMenu { + private final int min; + private final int max; + private final Update update; + + /** + * @param menuType 菜单类型 + * @param containerId 容器ID + */ + public SliderMenu(@Nullable MenuType menuType, int containerId) { + super(menuType, containerId); + this.min = 0; + this.max = 160; + this.update = null; + } + + /** + * @param containerId 容器ID + * @param update 更新回调 + */ + public SliderMenu(int containerId, int min, int max, Update update) { + super(ModMenuTypes.SLIDER.get(), containerId); + this.min = min; + this.max = max; + this.update = update; + } + + @Override + public @NotNull ItemStack quickMoveStack(@NotNull Player player, int index) { + Slot sourceSlot = slots.get(index); + //noinspection ConstantValue + if (sourceSlot == null || !sourceSlot.hasItem()) return ItemStack.EMPTY; + return sourceSlot.getItem(); + } + + @Override + public boolean stillValid(@NotNull Player player) { + return true; + } + + /** + * 滑条回调 + */ + public interface Update { + void update(int value); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/network/SliderInitPack.java b/common/src/main/java/dev/dubhe/anvilcraft/network/SliderInitPack.java new file mode 100644 index 000000000..04726549e --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/network/SliderInitPack.java @@ -0,0 +1,61 @@ +package dev.dubhe.anvilcraft.network; + +import dev.dubhe.anvilcraft.api.network.Packet; +import dev.dubhe.anvilcraft.client.gui.screen.inventory.SliderScreen; +import dev.dubhe.anvilcraft.init.ModNetworks; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; + +public class SliderInitPack implements Packet { + private final int value; + private final int min; + private final int max; + + /** + * @param value 当前值 + * @param min 最小值 + * @param max 最大值 + */ + public SliderInitPack(int value, int min, int max) { + this.value = value; + this.min = min; + this.max = max; + } + + /** + * @param buf 缓冲区 + */ + public SliderInitPack(@NotNull FriendlyByteBuf buf) { + this.value = buf.readInt(); + this.min = buf.readInt(); + this.max = buf.readInt(); + } + + @Override + public ResourceLocation getType() { + return ModNetworks.SLIDER_INIT; + } + + @Override + public void encode(@NotNull FriendlyByteBuf buf) { + buf.writeInt(this.value); + buf.writeInt(this.min); + buf.writeInt(this.max); + } + + @Override + @Environment(EnvType.CLIENT) + public void handler() { + Minecraft client = Minecraft.getInstance(); + client.execute(() -> { + if (!(client.screen instanceof SliderScreen screen)) return; + screen.setMin(this.min); + screen.setMax(this.max); + screen.setValue(this.value); + }); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/network/SliderUpdatePack.java b/common/src/main/java/dev/dubhe/anvilcraft/network/SliderUpdatePack.java new file mode 100644 index 000000000..c46e2f20f --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/network/SliderUpdatePack.java @@ -0,0 +1,42 @@ +package dev.dubhe.anvilcraft.network; + +import dev.dubhe.anvilcraft.api.network.Packet; +import dev.dubhe.anvilcraft.init.ModNetworks; +import dev.dubhe.anvilcraft.inventory.SliderMenu; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import org.jetbrains.annotations.NotNull; + +public class SliderUpdatePack implements Packet { + private final int value; + + public SliderUpdatePack(int value) { + this.value = value; + } + + public SliderUpdatePack(@NotNull FriendlyByteBuf buf) { + this.value = buf.readInt(); + } + + @Override + public ResourceLocation getType() { + return ModNetworks.SLIDER_UPDATE; + } + + @Override + public void encode(@NotNull FriendlyByteBuf buf) { + buf.writeInt(this.value); + } + + @Override + public void handler(@NotNull MinecraftServer server, ServerPlayer player) { + server.execute(() -> { + if (!player.hasContainerOpen()) return; + if (!(player.containerMenu instanceof SliderMenu menu)) return; + SliderMenu.Update update = menu.getUpdate(); + if (update != null) update.update(value); + }); + } +} diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/auto_crafter.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/background/auto_crafter.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/auto_crafter.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/background/auto_crafter.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/chute.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/background/chute.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/chute.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/background/chute.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/button_d.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_d.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/button_d.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_d.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/button_e.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_e.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/button_e.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_e.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/button_n.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_n.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/button_n.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_n.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/button_no.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_no.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/button_no.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_no.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/button_s.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_s.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/button_s.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_s.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/button_u.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_u.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/button_u.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_u.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/button_w.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_w.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/button_w.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_w.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/button_yes.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_yes.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/button_yes.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/button_yes.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/disabled_slot.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/disabled_slot.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/disabled_slot.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/machine/disabled_slot.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/background.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/slider.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/background.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_button_add.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/button_add.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_button_add.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/button_add.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_button_max.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/button_max.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_button_max.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/button_max.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_button_min.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/button_min.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_button_min.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/button_min.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_button_minus.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/button_minus.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_button_minus.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/button_minus.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_slider.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/slider.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/slider_slider.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/slider/slider.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/royal_anvil.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/background/royal_anvil.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/royal_anvil.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/background/royal_anvil.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/royal_grindstone.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/background/royal_grindstone.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/royal_grindstone.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/background/royal_grindstone.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/royal_smithing_table.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/background/royal_smithing_table.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/royal_smithing_table.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/background/royal_smithing_table.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/error.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/error.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/error.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/error.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/text_field.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/text_field.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/text_field.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/text_field.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/text_field_disabled.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/text_field_disabled.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/gui/container/text_field_disabled.png rename to common/src/main/resources/assets/anvilcraft/textures/gui/container/smithing/text_field_disabled.png diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/warning_material.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/warning_material.png deleted file mode 100644 index da98667a3b886d2f3b2ea2a9bcb0136222cf54c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 385 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5!3-pI!a4o{DajJoh?3y^w370~qErUQl>DSr z1<%~X^wgl##FWaylc_d9MXmupA+C|pF&2I`>6sahQT>AAs#4N2(yG=PT6*#diXt*P z{Gy8D;*ttFt_DV?Dn|b1mNxc|E}E86hA!DYegR^$F8@Eu4>ZZt=%Fo;y5#BN7*cU7 z=6pBbVFeD>fGc*}!w#o6L=!lPvcpkD{FT9s50*p_NLx1t(yB@rOjN% dc|5#DSr z1<%~X^wgl##FWaylc_d9MNR=eA+91aI`RsN7JfC6(J|?n8IDo?(yG=PT6*H*lKi5I zg5s)D(lQDD6S7?eq%L^6IEGZ*3Yico z)}p|}qTGFM!KUZ`!sqh2x&3BeC1-PKLh-pkiDJMPEmU;LRS`1^+Tb>8!Qi(_2Q{5DczIo2Ggr@o74aZKof z2S)`KpX$uHt;SvXzPD2-x##=DnjBs4sO$|h|8y&!ncq26L9XYc(NXnsJB_-Tho3Mg zvL8PCR%mX%nBcSehTC1~&Hvg9#0=k`?hugRce9j#VboI;+}I@U+@r<5Y29iadqy?} YZ6&#Qz24popx+ogUHx3vIVCg!0O9(GwEzGB diff --git a/common/src/main/resources/assets/anvilcraft/textures/gui/container/warning_protocol.png b/common/src/main/resources/assets/anvilcraft/textures/gui/container/warning_protocol.png deleted file mode 100644 index 486626d6a6781987defac258d158d755d2f96b36..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 379 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5!3-pI!a4o{DajJoh?3y^w370~qErUQl>DSr z1<%~X^wgl##FWaylc_d9MIHe@A+C|pF&2I`>6sahQT>AAs#4N2(yG=PT6*#diXt*P z{Gy8D;*ttFt_DV?d|8uJjQq_lZR{OgG%cgVW?lY&l;6-L+s7{eXqaN>xuZbpq^FBx zNX4y~3z0&H6?m8fm?L+ouAEQ`@*w%q29o+eNlK z<;gwAl6s{B+zU%8a&B*9z9o1~_yy+_gLnK-xPQHSYf!EG`*v%-Cc`^ve-Q`k1Ftq4 z+;X(PkiTzn>*96uD(7wV@X~DQY7q!pHEC6(+nF<_-kTcVOYJD<`1ZSBTk$_H`wI66 zzXWxILmz(gH|?#q_K7?Fuj*;EQN!<3!jb{}8-D2Yly2bvGCM!x;fn6`S!z1^jBE_< XpOswR{bG{=dWyl*)z4*}Q$iB}(ItsX From 33cb9d7f0050bcf27a68c449837e2a3995e701e2 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 01:37:53 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/dubhe/anvilcraft/api/power/IPowerStorage.java | 2 +- .../java/dev/dubhe/anvilcraft/api/power/PowerGrid.java | 10 +++++++--- .../dubhe/anvilcraft/block/CreativeDynamoBlock.java | 2 +- .../block/entity/CreativeDynamoBlockEntity.java | 2 +- .../client/gui/screen/inventory/SliderScreen.java | 3 +++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java index 3d2c90cf4..e36973cf7 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerStorage.java @@ -5,7 +5,7 @@ /** * 储电 */ -public interface IPowerStorage extends IPowerProducer { +public interface IPowerStorage extends IPowerProducer, IPowerConsumer { /** * 输入电量 * diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java index 0d00b93d2..694a5c5c3 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java @@ -97,11 +97,15 @@ public void add(IPowerComponent @NotNull ... components) { if (component.getComponentType() == PowerComponentType.INVALID) continue; if (component instanceof IPowerStorage storage) { this.storages.add(storage); - } else if (component instanceof IPowerProducer producer) { + continue; + } + if (component instanceof IPowerProducer producer) { this.producers.add(producer); - } else if (component instanceof IPowerConsumer consumer) { + } + if (component instanceof IPowerConsumer consumer) { this.consumers.add(consumer); - } else if (component instanceof IPowerTransmitter transmitter) { + } + if (component instanceof IPowerTransmitter transmitter) { this.transmitters.add(transmitter); } component.setGrid(this); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java index f05ebff5e..3ddd0cd38 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java @@ -45,7 +45,7 @@ public CreativeDynamoBlock(Properties properties) { && player instanceof ServerPlayer serverPlayer ) { ModMenuTypes.open(serverPlayer, entity, pos); - new SliderInitPack(entity.getPower(), -1024, 1024).send(serverPlayer); + new SliderInitPack(entity.getPower(), -8192, 8192).send(serverPlayer); } return InteractionResult.SUCCESS; } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java index a8b80be4f..5eb00ac22 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/CreativeDynamoBlockEntity.java @@ -87,6 +87,6 @@ public void setGrid(PowerGrid grid) { @Nullable @Override public AbstractContainerMenu createMenu(int i, @NotNull Inventory inventory, @NotNull Player player) { - return new SliderMenu(i, -1024, 1024, this::setPower); + return new SliderMenu(i, -8192, 8192, this::setPower); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java index 288d77065..6424c9b6c 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java @@ -89,6 +89,9 @@ private void onValueInput(@NotNull String value) { this.slider.setValueWithUpdate(v); } else if (value.isEmpty()) { this.slider.setValueWithUpdate(0); + } else if (value.equals("-") || value.equals("0-")) { + this.slider.setValueWithUpdate(0); + this.value.setValue("-"); } else { this.value.setValue("" + this.slider.getValue()); } From 80b0d7d0da7cc1ef6fc547ddcdacc9c8fc927801 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 01:45:10 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E5=BE=AE=E8=B0=83=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/gui/screen/inventory/SliderScreen.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java index 6424c9b6c..44c5ac5c2 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/SliderScreen.java @@ -84,17 +84,21 @@ public void setValue(int value) { private void onValueInput(@NotNull String value) { String regex = "^[+-]?[0-9]+$"; + int v; if (value.matches(regex)) { - int v = Integer.parseInt(value); - this.slider.setValueWithUpdate(v); + v = Integer.parseInt(value); } else if (value.isEmpty()) { - this.slider.setValueWithUpdate(0); - } else if (value.equals("-") || value.equals("0-")) { - this.slider.setValueWithUpdate(0); + v = 0; + } else if (value.equals("-")) { + return; + } else if (value.equals("0-")) { this.value.setValue("-"); + return; } else { this.value.setValue("" + this.slider.getValue()); + return; } + this.slider.setValueWithUpdate(v); } public void setMin(int min) { From 6891bd0dec088f251f307ed1ec94c984c34c9112 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 03:25:35 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E8=BE=93=E7=94=B5=E6=9F=B1=E4=B8=8E?= =?UTF-8?q?=E7=A3=81=E7=94=B5=E6=A0=B8=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolved #26 --- .../anvilcraft/api/power/IPowerComponent.java | 3 +- .../api/power/IPowerTransmitter.java | 7 +- .../dubhe/anvilcraft/api/power/PowerGrid.java | 1 + .../block/RemoteTransmissionPoleBlock.java | 142 ++++++++++++++++++ .../RemoteTransmissionPoleBlockEntity.java | 50 ++++++ .../dubhe/anvilcraft/block/state/Half.java | 26 ++++ .../anvilcraft/config/AnvilCraftConfig.java | 10 +- .../anvilcraft/init/ModBlockEntities.java | 6 + .../dev/dubhe/anvilcraft/init/ModBlocks.java | 26 ++++ .../dubhe/anvilcraft/init/ModItemGroups.java | 1 + .../dev/dubhe/anvilcraft/init/ModItems.java | 3 + .../blockstates/remote_transmission_pole.json | 13 ++ .../models/item/remote_transmission_pole.json | 3 + .../assets/anvilcraft/lang/en_ud.json | 2 + .../assets/anvilcraft/lang/en_us.json | 2 + .../models/item/magnetoelectric_core.json | 6 + .../misc/remote_transmission_pole.json | 61 ++++++++ .../blocks/remote_transmission_pole.json | 21 +++ .../recipes/remote_transmission_pole.json | 24 +++ .../assets/anvilcraft/lang/en_ud.json | 2 + .../assets/anvilcraft/lang/en_us.json | 2 + .../models/item/magnetoelectric_core.json | 6 + .../misc/remote_transmission_pole.json | 61 ++++++++ .../blocks/remote_transmission_pole.json | 21 +++ .../recipes/remote_transmission_pole.json | 24 +++ 25 files changed, 507 insertions(+), 16 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/block/RemoteTransmissionPoleBlock.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/block/entity/RemoteTransmissionPoleBlockEntity.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/block/state/Half.java create mode 100644 common/src/main/resources/assets/anvilcraft/blockstates/remote_transmission_pole.json create mode 100644 common/src/main/resources/assets/anvilcraft/models/item/remote_transmission_pole.json create mode 100644 fabric/src/generated/resources/assets/anvilcraft/models/item/magnetoelectric_core.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json create mode 100644 fabric/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json create mode 100644 forge/src/generated/resources/assets/anvilcraft/models/item/magnetoelectric_core.json create mode 100644 forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json create mode 100644 forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json create mode 100644 forge/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java index 62c74dca5..8855795cd 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerComponent.java @@ -18,8 +18,7 @@ public interface IPowerComponent { BlockPos getPos(); default VoxelShape getRange() { - return Shapes.box(-0.2, -0.2, -0.2, 1.2, 1.2, 1.2); - // return Shapes.block(); + return Shapes.block(); } /** diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java index 504a4c773..bfaaac984 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java @@ -1,7 +1,6 @@ package dev.dubhe.anvilcraft.api.power; import dev.dubhe.anvilcraft.AnvilCraft; -import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; @@ -13,11 +12,7 @@ public interface IPowerTransmitter extends IPowerComponent { @Override default VoxelShape getRange() { int range = AnvilCraft.config.powerTransmitterRange; - Vec3 vec3 = getPos().getCenter(); - return Shapes.box( - vec3.x - range, vec3.y - range, vec3.z - range, - vec3.x + range, vec3.y + range, vec3.z + range - ); + return Shapes.box(-range, -range, -range, range, range, range); } @Override diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java index 694a5c5c3..b6227fb4d 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java @@ -191,6 +191,7 @@ public boolean isInRange(@NotNull IPowerComponent component) { */ public static void addComponent(IPowerComponent @NotNull ... components) { for (IPowerComponent component : components) { + if (component.getComponentType() == PowerComponentType.INVALID) continue; PowerGrid grid = null; Iterator iterator = PowerGrid.GRID_SET.iterator(); while (iterator.hasNext()) { diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/RemoteTransmissionPoleBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/RemoteTransmissionPoleBlock.java new file mode 100644 index 000000000..fca487f40 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/RemoteTransmissionPoleBlock.java @@ -0,0 +1,142 @@ +package dev.dubhe.anvilcraft.block; + +import dev.dubhe.anvilcraft.block.entity.RemoteTransmissionPoleBlockEntity; +import dev.dubhe.anvilcraft.block.state.Half; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelReader; +import net.minecraft.world.level.block.BaseEntityBlock; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.Nonnull; + +public class RemoteTransmissionPoleBlock extends BaseEntityBlock { + public static final EnumProperty HALF = EnumProperty.create("half", Half.class); + + public RemoteTransmissionPoleBlock(Properties properties) { + super(properties); + this.registerDefaultState(this.stateDefinition.any().setValue(HALF, Half.BOTTOM)); + } + + @Override + @Nullable + public BlockState getStateForPlacement(@NotNull BlockPlaceContext context) { + return this.defaultBlockState().setValue(HALF, Half.BOTTOM); + } + + @Override + protected void createBlockStateDefinition(@NotNull StateDefinition.Builder builder) { + builder.add(HALF); + } + + @Override + public @Nonnull RenderShape getRenderShape(@Nonnull BlockState state) { + return RenderShape.MODEL; + } + + @Override + public void setPlacedBy( + @NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, + LivingEntity placer, @NotNull ItemStack stack + ) { + BlockPos above = pos.above(); + level.setBlockAndUpdate(above, state.setValue(HALF, Half.MID)); + above = above.above(); + level.setBlockAndUpdate(above, state.setValue(HALF, Half.TOP)); + } + + @Override + public void playerWillDestroy( + @NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull Player player + ) { + if (!level.isClientSide && player.isCreative()) { + RemoteTransmissionPoleBlock.preventCreativeDropFromOtherPart(level, pos, state, player); + } + super.playerWillDestroy(level, pos, state, player); + } + + private static void preventCreativeDropFromOtherPart( + Level level, BlockPos pos, @NotNull BlockState state, Player player + ) { + BlockPos blockPos; + BlockState blockState; + BlockPos blockPos1; + BlockState blockState1; + Half half = state.getValue(HALF); + block: + if ( + half == Half.TOP + && (blockState = level.getBlockState(blockPos = pos.below())).is(state.getBlock()) + && blockState.getValue(HALF) == Half.MID + && (blockState1 = level.getBlockState(blockPos1 = blockPos.below())).is(state.getBlock()) + && blockState1.getValue(HALF) == Half.BOTTOM + ) { + breakOtherPart(level, blockPos, blockState, blockPos1, blockState1, player); + } else if ( + half == Half.MID + && (blockState = level.getBlockState(blockPos = pos.above())).is(state.getBlock()) + && blockState.getValue(HALF) == Half.TOP + && (blockState1 = level.getBlockState(blockPos1 = pos.below())).is(state.getBlock()) + && blockState1.getValue(HALF) == Half.BOTTOM + ) { + breakOtherPart(level, blockPos, blockState, blockPos1, blockState1, player); + } else if ( + half == Half.BOTTOM + && (blockState = level.getBlockState(blockPos = pos.above())).is(state.getBlock()) + && blockState.getValue(HALF) == Half.MID + && (blockState1 = level.getBlockState(blockPos1 = blockPos.above())).is(state.getBlock()) + && blockState1.getValue(HALF) == Half.TOP + ) { + breakOtherPart(level, blockPos, blockState, blockPos1, blockState1, player); + } + } + + private static void breakOtherPart( + @NotNull Level level, BlockPos blockPos, @NotNull BlockState blockState, + BlockPos blockPos1, @NotNull BlockState blockState1, Player player + ) { + BlockState blockState2 = Blocks.AIR.defaultBlockState(); + level.setBlock(blockPos, blockState2, 35); + level.levelEvent(player, 2001, blockPos, Block.getId(blockState)); + level.setBlock(blockPos1, blockState2, 35); + level.levelEvent(player, 2001, blockPos1, Block.getId(blockState1)); + } + + @Nullable + @Override + public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { + return new RemoteTransmissionPoleBlockEntity(pos, state); + } + + @Override + @SuppressWarnings("deprecation") + public boolean canSurvive(@NotNull BlockState state, @NotNull LevelReader level, @NotNull BlockPos pos) { + switch (state.getValue(HALF)) { + case TOP -> { + BlockState state1 = level.getBlockState(pos.below()); + BlockState state2 = level.getBlockState(pos.below(2)); + return state1.is(this) && state2.is(this); + } + case MID -> { + BlockState state2 = level.getBlockState(pos.below()); + return state2.is(this); + } + default -> { + return state.isFaceSturdy(level, pos.below(), Direction.UP); + } + } + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/RemoteTransmissionPoleBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/RemoteTransmissionPoleBlockEntity.java new file mode 100644 index 000000000..446d06af0 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/RemoteTransmissionPoleBlockEntity.java @@ -0,0 +1,50 @@ +package dev.dubhe.anvilcraft.block.entity; + +import dev.dubhe.anvilcraft.api.power.IPowerTransmitter; +import dev.dubhe.anvilcraft.api.power.PowerComponentType; +import dev.dubhe.anvilcraft.api.power.PowerGrid; +import dev.dubhe.anvilcraft.block.RemoteTransmissionPoleBlock; +import dev.dubhe.anvilcraft.block.state.Half; +import dev.dubhe.anvilcraft.init.ModBlockEntities; +import dev.dubhe.anvilcraft.init.ModBlocks; +import lombok.Getter; +import lombok.Setter; +import net.minecraft.core.BlockPos; +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 org.jetbrains.annotations.NotNull; + +@Getter +@Setter +public class RemoteTransmissionPoleBlockEntity extends BlockEntity implements IPowerTransmitter { + private PowerGrid grid; + + public RemoteTransmissionPoleBlockEntity(BlockPos pos, BlockState blockState) { + this(ModBlockEntities.REMOTE_TRANSMISSION_POLE.get(), pos, blockState); + } + + public static @NotNull RemoteTransmissionPoleBlockEntity createBlockEntity( + BlockEntityType type, BlockPos pos, BlockState blockState + ) { + return new RemoteTransmissionPoleBlockEntity(type, pos, blockState); + } + + private RemoteTransmissionPoleBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { + super(type, pos, blockState); + } + + @Override + public @NotNull BlockPos getPos() { + return this.getBlockPos(); + } + + @Override + public @NotNull PowerComponentType getComponentType() { + if (this.getLevel() == null) return PowerComponentType.INVALID; + BlockState state = this.getLevel().getBlockState(this.getPos()); + if (!state.is(ModBlocks.REMOTE_TRANSMISSION_POLE.get())) return PowerComponentType.INVALID; + if (state.getValue(RemoteTransmissionPoleBlock.HALF) != Half.TOP) return PowerComponentType.INVALID; + return PowerComponentType.TRANSMITTER; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/state/Half.java b/common/src/main/java/dev/dubhe/anvilcraft/block/state/Half.java new file mode 100644 index 000000000..90ea11fb3 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/state/Half.java @@ -0,0 +1,26 @@ +package dev.dubhe.anvilcraft.block.state; + +import net.minecraft.util.StringRepresentable; +import org.jetbrains.annotations.NotNull; + +public enum Half implements StringRepresentable { + TOP("top"), + MID("mid"), + BOTTOM("bottom"); + + + private final String name; + + Half(String name) { + this.name = name; + } + + public String toString() { + return this.name; + } + + @Override + public @NotNull String getSerializedName() { + return this.name; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java index 968d7b75e..f374c32ad 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java @@ -75,15 +75,9 @@ public class AnvilCraftConfig implements ConfigData { @SerializedName("Geode Search Cooldown") public int geodeCooldown = 5; - @Comment("The power transmitter can identify the range of power components") - @ConfigEntry.Gui.Tooltip - @ConfigEntry.BoundedDiscrete(max = 64, min = 1) - @SerializedName("Range of Power Components") - public int powerComponentRange = 8; - @Comment("The power transmitter can identify the range of the power transmitter") @ConfigEntry.Gui.Tooltip - @ConfigEntry.BoundedDiscrete(max = 64, min = 4) + @ConfigEntry.BoundedDiscrete(max = 64, min = 1) @SerializedName("Range of Power Transmitter") - public int powerTransmitterRange = 16; + public int powerTransmitterRange = 8; } \ No newline at end of file diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java index 2bcb36cdf..6e1677f49 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java @@ -6,6 +6,7 @@ import dev.dubhe.anvilcraft.block.entity.CorruptedBeaconBlockEntity; import dev.dubhe.anvilcraft.block.entity.CreativeDynamoBlockEntity; import dev.dubhe.anvilcraft.block.entity.HeaterBlockEntity; +import dev.dubhe.anvilcraft.block.entity.RemoteTransmissionPoleBlockEntity; import dev.dubhe.anvilcraft.block.entity.SimpleChuteBlockEntity; import dev.dubhe.anvilcraft.client.renderer.blockentity.CorruptedBeaconRenderer; @@ -46,6 +47,11 @@ public class ModBlockEntities { .validBlock(ModBlocks.HEATER) .register(); + public static final BlockEntityEntry REMOTE_TRANSMISSION_POLE = REGISTRATE + .blockEntity("remote_transmission_pole", RemoteTransmissionPoleBlockEntity::createBlockEntity) + .validBlock(ModBlocks.REMOTE_TRANSMISSION_POLE) + .register(); + public static void register() { } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java index 481f6c2ca..83eb0bb34 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java @@ -12,6 +12,7 @@ import dev.dubhe.anvilcraft.block.HollowMagnetBlock; import dev.dubhe.anvilcraft.block.LavaCauldronBlock; import dev.dubhe.anvilcraft.block.MagnetBlock; +import dev.dubhe.anvilcraft.block.RemoteTransmissionPoleBlock; import dev.dubhe.anvilcraft.block.RoyalAnvilBlock; import dev.dubhe.anvilcraft.block.RoyalGrindstone; import dev.dubhe.anvilcraft.block.RoyalSmithingTableBlock; @@ -404,6 +405,31 @@ public class ModBlocks { .unlockedBy(AnvilCraftDatagen.hasItem(ModItemTags.CAPACITOR), AnvilCraftDatagen.has(ModItemTags.CAPACITOR)) .save(provider)) .register(); + public static final BlockEntry REMOTE_TRANSMISSION_POLE = REGISTRATE + .block("remote_transmission_pole", RemoteTransmissionPoleBlock::new) + .initialProperties(ModBlocks.MAGNET_BLOCK) + .properties(BlockBehaviour.Properties::noOcclusion) + .blockstate((ctx, provider) -> { + }) + .item() + .model((ctx, provider) -> { + }) + .build() + .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) + .pattern("A") + .pattern("B") + .pattern("C") + .define('A', ModItems.MAGNETOELECTRIC_CORE) + .define('B', Items.LIGHTNING_ROD) + .define('C', Items.IRON_BLOCK) + .unlockedBy( + AnvilCraftDatagen.hasItem(ModItems.MAGNETOELECTRIC_CORE), + AnvilCraftDatagen.has(ModItems.MAGNETOELECTRIC_CORE) + ) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.LIGHTNING_ROD), AnvilCraftDatagen.has(Items.LIGHTNING_ROD)) + .unlockedBy(AnvilCraftDatagen.hasItem(Items.IRON_BLOCK), AnvilCraftDatagen.has(Items.IRON_BLOCK)) + .save(provider)) + .register(); public static void register() { } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java index 35c6107eb..69e58dfb9 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java @@ -71,6 +71,7 @@ public class ModItemGroups { entries.accept(ModBlocks.ROYAL_SMITHING_TABLE.asStack()); entries.accept(ModBlocks.CREATIVE_DYNAMO.asStack()); entries.accept(ModBlocks.HEATER.asStack()); + entries.accept(ModBlocks.REMOTE_TRANSMISSION_POLE.asStack()); entries.accept(ModBlocks.MAGNET_BLOCK.asStack()); entries.accept(ModBlocks.HOLLOW_MAGNET_BLOCK.asStack()); entries.accept(ModBlocks.FERRITE_CORE_MAGNET_BLOCK.asStack()); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java index 6677e8d2e..bbc6b29c8 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItems.java @@ -457,6 +457,9 @@ public void appendHoverText( .item("capacitor", CapacitorItem::new) .tag(ModItemTags.CAPACITOR) .register(); + public static final ItemEntry MAGNETOELECTRIC_CORE = REGISTRATE + .item("magnetoelectric_core", Item::new) + .register(); public static final ItemEntry CAPACITOR_EMPTY = REGISTRATE .item("capacitor_empty", CapacitorItem::new) .tag(ModItemTags.CAPACITOR) diff --git a/common/src/main/resources/assets/anvilcraft/blockstates/remote_transmission_pole.json b/common/src/main/resources/assets/anvilcraft/blockstates/remote_transmission_pole.json new file mode 100644 index 000000000..d0ec72aff --- /dev/null +++ b/common/src/main/resources/assets/anvilcraft/blockstates/remote_transmission_pole.json @@ -0,0 +1,13 @@ +{ + "variants": { + "half=bottom": { + "model": "anvilcraft:block/remote_transmission_pole_base" + }, + "half=mid": { + "model": "anvilcraft:block/remote_transmission_pole_mid" + }, + "half=top": { + "model": "anvilcraft:block/remote_transmission_pole_top" + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/anvilcraft/models/item/remote_transmission_pole.json b/common/src/main/resources/assets/anvilcraft/models/item/remote_transmission_pole.json new file mode 100644 index 000000000..fb4473e8e --- /dev/null +++ b/common/src/main/resources/assets/anvilcraft/models/item/remote_transmission_pole.json @@ -0,0 +1,3 @@ +{ + "parent": "anvilcraft:block/remote_transmission_pole_overall" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 7b0ba568d..03dd552ce 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -13,6 +13,7 @@ "block.anvilcraft.hollow_magnet_block": "ʞɔoןᗺ ʇǝubɐW ʍoןןoH", "block.anvilcraft.lava_cauldron": "uoɹpןnɐƆ ɐʌɐꞀ", "block.anvilcraft.magnet_block": "ʞɔoןᗺ ʇǝubɐW", + "block.anvilcraft.remote_transmission_pole": "ǝןoԀ uoıssıɯsuɐɹ⟘ ǝʇoɯǝᴚ", "block.anvilcraft.resin_block": "ʞɔoןᗺ uısǝᴚ", "block.anvilcraft.royal_anvil": "ןıʌuⱯ ןɐʎoᴚ", "block.anvilcraft.royal_grindstone": "ǝuoʇspuıɹ⅁ ןɐʎoᴚ", @@ -56,6 +57,7 @@ "item.anvilcraft.geode.find": "%s pǝʇɐɔoן 'ǝpoǝb ʇsʎɥʇǝɯɐ pǝʇɔǝdsnS", "item.anvilcraft.magnet": "ʇǝubɐW", "item.anvilcraft.magnet_ingot": "ʇobuI ʇǝubɐW", + "item.anvilcraft.magnetoelectric_core": "ǝɹoƆ ɔıɹʇɔǝןǝoʇǝubɐW", "item.anvilcraft.nether_star_shard": "pɹɐɥS ɹɐʇS ɹǝɥʇǝN", "item.anvilcraft.netherite_coil": "ןıoƆ ǝʇıɹǝɥʇǝN", "item.anvilcraft.netherite_core": "ǝɹoƆ ǝʇıɹǝɥʇǝN", diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json index 6b8a0a96a..93ce6076c 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -13,6 +13,7 @@ "block.anvilcraft.hollow_magnet_block": "Hollow Magnet Block", "block.anvilcraft.lava_cauldron": "Lava Cauldron", "block.anvilcraft.magnet_block": "Magnet Block", + "block.anvilcraft.remote_transmission_pole": "Remote Transmission Pole", "block.anvilcraft.resin_block": "Resin Block", "block.anvilcraft.royal_anvil": "Royal Anvil", "block.anvilcraft.royal_grindstone": "Royal Grindstone", @@ -56,6 +57,7 @@ "item.anvilcraft.geode.find": "Suspected amethyst geode, located %s", "item.anvilcraft.magnet": "Magnet", "item.anvilcraft.magnet_ingot": "Magnet Ingot", + "item.anvilcraft.magnetoelectric_core": "Magnetoelectric Core", "item.anvilcraft.nether_star_shard": "Nether Star Shard", "item.anvilcraft.netherite_coil": "Netherite Coil", "item.anvilcraft.netherite_core": "Netherite Core", diff --git a/fabric/src/generated/resources/assets/anvilcraft/models/item/magnetoelectric_core.json b/fabric/src/generated/resources/assets/anvilcraft/models/item/magnetoelectric_core.json new file mode 100644 index 000000000..d737a7181 --- /dev/null +++ b/fabric/src/generated/resources/assets/anvilcraft/models/item/magnetoelectric_core.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "anvilcraft:item/magnetoelectric_core" + } +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json new file mode 100644 index 000000000..898ec92e4 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json @@ -0,0 +1,61 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_iron_block": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:iron_block" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_lightning_rod": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:lightning_rod" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_magnetoelectric_core": { + "conditions": { + "items": [ + { + "items": [ + "anvilcraft:magnetoelectric_core" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "anvilcraft:remote_transmission_pole" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_magnetoelectric_core", + "has_lightning_rod", + "has_iron_block", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "anvilcraft:remote_transmission_pole" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json new file mode 100644 index 000000000..5a8de0812 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "anvilcraft:remote_transmission_pole" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:blocks/remote_transmission_pole" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json b/fabric/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json new file mode 100644 index 000000000..0bece4856 --- /dev/null +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json @@ -0,0 +1,24 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "A": { + "item": "anvilcraft:magnetoelectric_core" + }, + "B": { + "item": "minecraft:lightning_rod" + }, + "C": { + "item": "minecraft:iron_block" + } + }, + "pattern": [ + "A", + "B", + "C" + ], + "result": { + "item": "anvilcraft:remote_transmission_pole" + }, + "show_notification": true +} \ No newline at end of file diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 7b0ba568d..03dd552ce 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -13,6 +13,7 @@ "block.anvilcraft.hollow_magnet_block": "ʞɔoןᗺ ʇǝubɐW ʍoןןoH", "block.anvilcraft.lava_cauldron": "uoɹpןnɐƆ ɐʌɐꞀ", "block.anvilcraft.magnet_block": "ʞɔoןᗺ ʇǝubɐW", + "block.anvilcraft.remote_transmission_pole": "ǝןoԀ uoıssıɯsuɐɹ⟘ ǝʇoɯǝᴚ", "block.anvilcraft.resin_block": "ʞɔoןᗺ uısǝᴚ", "block.anvilcraft.royal_anvil": "ןıʌuⱯ ןɐʎoᴚ", "block.anvilcraft.royal_grindstone": "ǝuoʇspuıɹ⅁ ןɐʎoᴚ", @@ -56,6 +57,7 @@ "item.anvilcraft.geode.find": "%s pǝʇɐɔoן 'ǝpoǝb ʇsʎɥʇǝɯɐ pǝʇɔǝdsnS", "item.anvilcraft.magnet": "ʇǝubɐW", "item.anvilcraft.magnet_ingot": "ʇobuI ʇǝubɐW", + "item.anvilcraft.magnetoelectric_core": "ǝɹoƆ ɔıɹʇɔǝןǝoʇǝubɐW", "item.anvilcraft.nether_star_shard": "pɹɐɥS ɹɐʇS ɹǝɥʇǝN", "item.anvilcraft.netherite_coil": "ןıoƆ ǝʇıɹǝɥʇǝN", "item.anvilcraft.netherite_core": "ǝɹoƆ ǝʇıɹǝɥʇǝN", diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json index 6b8a0a96a..93ce6076c 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -13,6 +13,7 @@ "block.anvilcraft.hollow_magnet_block": "Hollow Magnet Block", "block.anvilcraft.lava_cauldron": "Lava Cauldron", "block.anvilcraft.magnet_block": "Magnet Block", + "block.anvilcraft.remote_transmission_pole": "Remote Transmission Pole", "block.anvilcraft.resin_block": "Resin Block", "block.anvilcraft.royal_anvil": "Royal Anvil", "block.anvilcraft.royal_grindstone": "Royal Grindstone", @@ -56,6 +57,7 @@ "item.anvilcraft.geode.find": "Suspected amethyst geode, located %s", "item.anvilcraft.magnet": "Magnet", "item.anvilcraft.magnet_ingot": "Magnet Ingot", + "item.anvilcraft.magnetoelectric_core": "Magnetoelectric Core", "item.anvilcraft.nether_star_shard": "Nether Star Shard", "item.anvilcraft.netherite_coil": "Netherite Coil", "item.anvilcraft.netherite_core": "Netherite Core", diff --git a/forge/src/generated/resources/assets/anvilcraft/models/item/magnetoelectric_core.json b/forge/src/generated/resources/assets/anvilcraft/models/item/magnetoelectric_core.json new file mode 100644 index 000000000..d737a7181 --- /dev/null +++ b/forge/src/generated/resources/assets/anvilcraft/models/item/magnetoelectric_core.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/generated", + "textures": { + "layer0": "anvilcraft:item/magnetoelectric_core" + } +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json new file mode 100644 index 000000000..898ec92e4 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json @@ -0,0 +1,61 @@ +{ + "parent": "minecraft:recipes/root", + "criteria": { + "has_iron_block": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:iron_block" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_lightning_rod": { + "conditions": { + "items": [ + { + "items": [ + "minecraft:lightning_rod" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_magnetoelectric_core": { + "conditions": { + "items": [ + { + "items": [ + "anvilcraft:magnetoelectric_core" + ] + } + ] + }, + "trigger": "minecraft:inventory_changed" + }, + "has_the_recipe": { + "conditions": { + "recipe": "anvilcraft:remote_transmission_pole" + }, + "trigger": "minecraft:recipe_unlocked" + } + }, + "requirements": [ + [ + "has_magnetoelectric_core", + "has_lightning_rod", + "has_iron_block", + "has_the_recipe" + ] + ], + "rewards": { + "recipes": [ + "anvilcraft:remote_transmission_pole" + ] + }, + "sends_telemetry_event": false +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json new file mode 100644 index 000000000..5a8de0812 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json @@ -0,0 +1,21 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "bonus_rolls": 0.0, + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ], + "entries": [ + { + "type": "minecraft:item", + "name": "anvilcraft:remote_transmission_pole" + } + ], + "rolls": 1.0 + } + ], + "random_sequence": "anvilcraft:blocks/remote_transmission_pole" +} \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json b/forge/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json new file mode 100644 index 000000000..0bece4856 --- /dev/null +++ b/forge/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json @@ -0,0 +1,24 @@ +{ + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "A": { + "item": "anvilcraft:magnetoelectric_core" + }, + "B": { + "item": "minecraft:lightning_rod" + }, + "C": { + "item": "minecraft:iron_block" + } + }, + "pattern": [ + "A", + "B", + "C" + ], + "result": { + "item": "anvilcraft:remote_transmission_pole" + }, + "show_notification": true +} \ No newline at end of file From 567991e4090331d5b8ef86d9183f9db2ab400e87 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 15:59:21 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9A=87=E5=AE=B6?= =?UTF-8?q?=E9=92=A2=E9=94=BB=E9=80=A0=E6=A8=A1=E6=9D=BF=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E9=94=AE=E8=A6=86=E7=9B=96=E4=BA=86=E5=8E=9F=E7=89=88=E9=94=BB?= =?UTF-8?q?=E9=80=A0=E6=A8=A1=E6=9D=BF=E7=BF=BB=E8=AF=91=E9=94=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed #291 --- ...PoleBlock.java => TransmissionPoleBlock.java} | 14 +++++++------- ...ity.java => TransmissionPoleBlockEntity.java} | 16 ++++++++-------- .../dubhe/anvilcraft/init/ModBlockEntities.java | 8 ++++---- .../dev/dubhe/anvilcraft/init/ModBlocks.java | 12 +++++++++--- .../dev/dubhe/anvilcraft/init/ModItemGroups.java | 2 +- .../item/RoyalUpgradeTemplateItem.java | 6 ++++++ .../blockstates/remote_transmission_pole.json | 13 ------------- .../blockstates/transmission_pole.json | 13 +++++++++++++ .../resources/assets/anvilcraft/lang/es_es.json | 2 +- .../resources/assets/anvilcraft/lang/fr_fr.json | 2 +- .../resources/assets/anvilcraft/lang/ja_jp.json | 2 +- .../resources/assets/anvilcraft/lang/ko_kr.json | 2 +- .../resources/assets/anvilcraft/lang/lzh.json | 2 +- .../resources/assets/anvilcraft/lang/ru_ru.json | 2 +- .../resources/assets/anvilcraft/lang/zh_cn.json | 2 +- .../resources/assets/anvilcraft/lang/zh_hk.json | 2 +- .../resources/assets/anvilcraft/lang/zh_tw.json | 2 +- .../models/item/remote_transmission_pole.json | 3 --- .../models/item/transmission_pole.json | 3 +++ .../resources/assets/anvilcraft/lang/en_ud.json | 6 ++---- .../resources/assets/anvilcraft/lang/en_us.json | 6 ++---- ...smission_pole.json => transmission_pole.json} | 4 ++-- ...smission_pole.json => transmission_pole.json} | 4 ++-- .../anvilcraft/recipes/transmission_pole.json | 2 +- .../minecraft/tags/blocks/mineable/pickaxe.json | 5 ++++- .../resources/assets/anvilcraft/lang/en_ud.json | 6 ++---- .../resources/assets/anvilcraft/lang/en_us.json | 6 ++---- ...smission_pole.json => transmission_pole.json} | 4 ++-- ...smission_pole.json => transmission_pole.json} | 4 ++-- .../anvilcraft/recipes/transmission_pole.json | 2 +- .../minecraft/tags/blocks/mineable/pickaxe.json | 5 ++++- 31 files changed, 86 insertions(+), 76 deletions(-) rename common/src/main/java/dev/dubhe/anvilcraft/block/{RemoteTransmissionPoleBlock.java => TransmissionPoleBlock.java} (91%) rename common/src/main/java/dev/dubhe/anvilcraft/block/entity/{RemoteTransmissionPoleBlockEntity.java => TransmissionPoleBlockEntity.java} (64%) delete mode 100644 common/src/main/resources/assets/anvilcraft/blockstates/remote_transmission_pole.json create mode 100644 common/src/main/resources/assets/anvilcraft/blockstates/transmission_pole.json delete mode 100644 common/src/main/resources/assets/anvilcraft/models/item/remote_transmission_pole.json create mode 100644 common/src/main/resources/assets/anvilcraft/models/item/transmission_pole.json rename fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/{remote_transmission_pole.json => transmission_pole.json} (91%) rename fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/{remote_transmission_pole.json => transmission_pole.json} (70%) rename forge/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json => fabric/src/generated/resources/data/anvilcraft/recipes/transmission_pole.json (87%) rename forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/{remote_transmission_pole.json => transmission_pole.json} (91%) rename forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/{remote_transmission_pole.json => transmission_pole.json} (70%) rename fabric/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json => forge/src/generated/resources/data/anvilcraft/recipes/transmission_pole.json (87%) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/RemoteTransmissionPoleBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/TransmissionPoleBlock.java similarity index 91% rename from common/src/main/java/dev/dubhe/anvilcraft/block/RemoteTransmissionPoleBlock.java rename to common/src/main/java/dev/dubhe/anvilcraft/block/TransmissionPoleBlock.java index fca487f40..9a169f8a9 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/RemoteTransmissionPoleBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/TransmissionPoleBlock.java @@ -1,6 +1,6 @@ package dev.dubhe.anvilcraft.block; -import dev.dubhe.anvilcraft.block.entity.RemoteTransmissionPoleBlockEntity; +import dev.dubhe.anvilcraft.block.entity.TransmissionPoleBlockEntity; import dev.dubhe.anvilcraft.block.state.Half; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -23,10 +23,10 @@ import javax.annotation.Nonnull; -public class RemoteTransmissionPoleBlock extends BaseEntityBlock { +public class TransmissionPoleBlock extends BaseEntityBlock { public static final EnumProperty HALF = EnumProperty.create("half", Half.class); - public RemoteTransmissionPoleBlock(Properties properties) { + public TransmissionPoleBlock(Properties properties) { super(properties); this.registerDefaultState(this.stateDefinition.any().setValue(HALF, Half.BOTTOM)); } @@ -62,13 +62,13 @@ public void setPlacedBy( public void playerWillDestroy( @NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull Player player ) { - if (!level.isClientSide && player.isCreative()) { - RemoteTransmissionPoleBlock.preventCreativeDropFromOtherPart(level, pos, state, player); + if (!level.isClientSide) { + TransmissionPoleBlock.preventDropFromOtherPart(level, pos, state, player); } super.playerWillDestroy(level, pos, state, player); } - private static void preventCreativeDropFromOtherPart( + private static void preventDropFromOtherPart( Level level, BlockPos pos, @NotNull BlockState state, Player player ) { BlockPos blockPos; @@ -118,7 +118,7 @@ private static void breakOtherPart( @Nullable @Override public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) { - return new RemoteTransmissionPoleBlockEntity(pos, state); + return new TransmissionPoleBlockEntity(pos, state); } @Override diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/RemoteTransmissionPoleBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/TransmissionPoleBlockEntity.java similarity index 64% rename from common/src/main/java/dev/dubhe/anvilcraft/block/entity/RemoteTransmissionPoleBlockEntity.java rename to common/src/main/java/dev/dubhe/anvilcraft/block/entity/TransmissionPoleBlockEntity.java index 446d06af0..8cc4f69cb 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/RemoteTransmissionPoleBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/TransmissionPoleBlockEntity.java @@ -3,7 +3,7 @@ import dev.dubhe.anvilcraft.api.power.IPowerTransmitter; import dev.dubhe.anvilcraft.api.power.PowerComponentType; import dev.dubhe.anvilcraft.api.power.PowerGrid; -import dev.dubhe.anvilcraft.block.RemoteTransmissionPoleBlock; +import dev.dubhe.anvilcraft.block.TransmissionPoleBlock; import dev.dubhe.anvilcraft.block.state.Half; import dev.dubhe.anvilcraft.init.ModBlockEntities; import dev.dubhe.anvilcraft.init.ModBlocks; @@ -17,20 +17,20 @@ @Getter @Setter -public class RemoteTransmissionPoleBlockEntity extends BlockEntity implements IPowerTransmitter { +public class TransmissionPoleBlockEntity extends BlockEntity implements IPowerTransmitter { private PowerGrid grid; - public RemoteTransmissionPoleBlockEntity(BlockPos pos, BlockState blockState) { + public TransmissionPoleBlockEntity(BlockPos pos, BlockState blockState) { this(ModBlockEntities.REMOTE_TRANSMISSION_POLE.get(), pos, blockState); } - public static @NotNull RemoteTransmissionPoleBlockEntity createBlockEntity( + public static @NotNull TransmissionPoleBlockEntity createBlockEntity( BlockEntityType type, BlockPos pos, BlockState blockState ) { - return new RemoteTransmissionPoleBlockEntity(type, pos, blockState); + return new TransmissionPoleBlockEntity(type, pos, blockState); } - private RemoteTransmissionPoleBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { + private TransmissionPoleBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { super(type, pos, blockState); } @@ -43,8 +43,8 @@ private RemoteTransmissionPoleBlockEntity(BlockEntityType type, BlockPos pos, public @NotNull PowerComponentType getComponentType() { if (this.getLevel() == null) return PowerComponentType.INVALID; BlockState state = this.getLevel().getBlockState(this.getPos()); - if (!state.is(ModBlocks.REMOTE_TRANSMISSION_POLE.get())) return PowerComponentType.INVALID; - if (state.getValue(RemoteTransmissionPoleBlock.HALF) != Half.TOP) return PowerComponentType.INVALID; + if (!state.is(ModBlocks.TRANSMISSION_POLE.get())) return PowerComponentType.INVALID; + if (state.getValue(TransmissionPoleBlock.HALF) != Half.TOP) return PowerComponentType.INVALID; return PowerComponentType.TRANSMITTER; } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java index 6e1677f49..bd610a2b5 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlockEntities.java @@ -6,7 +6,7 @@ import dev.dubhe.anvilcraft.block.entity.CorruptedBeaconBlockEntity; import dev.dubhe.anvilcraft.block.entity.CreativeDynamoBlockEntity; import dev.dubhe.anvilcraft.block.entity.HeaterBlockEntity; -import dev.dubhe.anvilcraft.block.entity.RemoteTransmissionPoleBlockEntity; +import dev.dubhe.anvilcraft.block.entity.TransmissionPoleBlockEntity; import dev.dubhe.anvilcraft.block.entity.SimpleChuteBlockEntity; import dev.dubhe.anvilcraft.client.renderer.blockentity.CorruptedBeaconRenderer; @@ -47,9 +47,9 @@ public class ModBlockEntities { .validBlock(ModBlocks.HEATER) .register(); - public static final BlockEntityEntry REMOTE_TRANSMISSION_POLE = REGISTRATE - .blockEntity("remote_transmission_pole", RemoteTransmissionPoleBlockEntity::createBlockEntity) - .validBlock(ModBlocks.REMOTE_TRANSMISSION_POLE) + public static final BlockEntityEntry REMOTE_TRANSMISSION_POLE = REGISTRATE + .blockEntity("transmission_pole", TransmissionPoleBlockEntity::createBlockEntity) + .validBlock(ModBlocks.TRANSMISSION_POLE) .register(); public static void register() { diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java index 83eb0bb34..b45abe94c 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java @@ -12,7 +12,7 @@ import dev.dubhe.anvilcraft.block.HollowMagnetBlock; import dev.dubhe.anvilcraft.block.LavaCauldronBlock; import dev.dubhe.anvilcraft.block.MagnetBlock; -import dev.dubhe.anvilcraft.block.RemoteTransmissionPoleBlock; +import dev.dubhe.anvilcraft.block.TransmissionPoleBlock; import dev.dubhe.anvilcraft.block.RoyalAnvilBlock; import dev.dubhe.anvilcraft.block.RoyalGrindstone; import dev.dubhe.anvilcraft.block.RoyalSmithingTableBlock; @@ -385,6 +385,8 @@ public class ModBlocks { .blockstate((ctx, provider) -> { }) .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) .register(); public static final BlockEntry HEATER = REGISTRATE .block("heater", HeaterBlock::new) @@ -393,6 +395,8 @@ public class ModBlocks { .blockstate((ctx, provider) -> { }) .simpleItem() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) .pattern("ABA") .pattern("BCB") @@ -405,8 +409,8 @@ public class ModBlocks { .unlockedBy(AnvilCraftDatagen.hasItem(ModItemTags.CAPACITOR), AnvilCraftDatagen.has(ModItemTags.CAPACITOR)) .save(provider)) .register(); - public static final BlockEntry REMOTE_TRANSMISSION_POLE = REGISTRATE - .block("remote_transmission_pole", RemoteTransmissionPoleBlock::new) + public static final BlockEntry TRANSMISSION_POLE = REGISTRATE + .block("transmission_pole", TransmissionPoleBlock::new) .initialProperties(ModBlocks.MAGNET_BLOCK) .properties(BlockBehaviour.Properties::noOcclusion) .blockstate((ctx, provider) -> { @@ -415,6 +419,8 @@ public class ModBlocks { .model((ctx, provider) -> { }) .build() + .defaultLoot() + .tag(BlockTags.MINEABLE_WITH_PICKAXE) .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ctx.get()) .pattern("A") .pattern("B") diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java index 69e58dfb9..bff050726 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModItemGroups.java @@ -71,7 +71,7 @@ public class ModItemGroups { entries.accept(ModBlocks.ROYAL_SMITHING_TABLE.asStack()); entries.accept(ModBlocks.CREATIVE_DYNAMO.asStack()); entries.accept(ModBlocks.HEATER.asStack()); - entries.accept(ModBlocks.REMOTE_TRANSMISSION_POLE.asStack()); + entries.accept(ModBlocks.TRANSMISSION_POLE.asStack()); entries.accept(ModBlocks.MAGNET_BLOCK.asStack()); entries.accept(ModBlocks.HOLLOW_MAGNET_BLOCK.asStack()); entries.accept(ModBlocks.FERRITE_CORE_MAGNET_BLOCK.asStack()); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/item/RoyalUpgradeTemplateItem.java b/common/src/main/java/dev/dubhe/anvilcraft/item/RoyalUpgradeTemplateItem.java index c17474fce..90512534e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/item/RoyalUpgradeTemplateItem.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/item/RoyalUpgradeTemplateItem.java @@ -4,6 +4,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.SmithingTemplateItem; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -31,4 +32,9 @@ public RoyalUpgradeTemplateItem(@SuppressWarnings("unused") Properties propertie super(APPLIES_TO, UPGRADE_INGREDIENTS, UPGRADE, UPGRADE_BASE_SLOT_DESCRIPTION, UPGRADE_ADDITIONS_SLOT_DESCRIPTION, List.of(EMPTY_SLOT_PICKAXE), List.of(EMPTY_SLOT_INGOT)); } + + @Override + public @NotNull String getDescriptionId() { + return this.getOrCreateDescriptionId(); + } } diff --git a/common/src/main/resources/assets/anvilcraft/blockstates/remote_transmission_pole.json b/common/src/main/resources/assets/anvilcraft/blockstates/remote_transmission_pole.json deleted file mode 100644 index d0ec72aff..000000000 --- a/common/src/main/resources/assets/anvilcraft/blockstates/remote_transmission_pole.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "variants": { - "half=bottom": { - "model": "anvilcraft:block/remote_transmission_pole_base" - }, - "half=mid": { - "model": "anvilcraft:block/remote_transmission_pole_mid" - }, - "half=top": { - "model": "anvilcraft:block/remote_transmission_pole_top" - } - } -} \ No newline at end of file diff --git a/common/src/main/resources/assets/anvilcraft/blockstates/transmission_pole.json b/common/src/main/resources/assets/anvilcraft/blockstates/transmission_pole.json new file mode 100644 index 000000000..192787d4b --- /dev/null +++ b/common/src/main/resources/assets/anvilcraft/blockstates/transmission_pole.json @@ -0,0 +1,13 @@ +{ + "variants": { + "half=bottom": { + "model": "anvilcraft:block/transmission_pole_base" + }, + "half=mid": { + "model": "anvilcraft:block/transmission_pole_mid" + }, + "half=top": { + "model": "anvilcraft:block/transmission_pole_top" + } + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/anvilcraft/lang/es_es.json b/common/src/main/resources/assets/anvilcraft/lang/es_es.json index f3e00b72b..af01c3399 100644 --- a/common/src/main/resources/assets/anvilcraft/lang/es_es.json +++ b/common/src/main/resources/assets/anvilcraft/lang/es_es.json @@ -70,7 +70,7 @@ "item.anvilcraft.topaz": "Topacio", "item.anvilcraft.utusan": "Polvo Wudu", "item.anvilcraft.utusan_raw": "Polvo Wudu crudo", - "item.minecraft.smithing_template": "Plantilla de mejora de acero real", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "Plantilla de mejora de acero real", "itemGroup.anvilcraft.block": "Artesanía de yunque - Bloque", "itemGroup.anvilcraft.item": "Artesanía de yunque - Ítem", "screen.anvilcraft.button.direction": "Dirección de salida: %s", diff --git a/common/src/main/resources/assets/anvilcraft/lang/fr_fr.json b/common/src/main/resources/assets/anvilcraft/lang/fr_fr.json index 72e38a006..e0d8646e7 100644 --- a/common/src/main/resources/assets/anvilcraft/lang/fr_fr.json +++ b/common/src/main/resources/assets/anvilcraft/lang/fr_fr.json @@ -70,7 +70,7 @@ "item.anvilcraft.topaz": "Topaze", "item.anvilcraft.utusan": "Poudre wudu", "item.anvilcraft.utusan_raw": "Poudre wudu (cru)", - "item.minecraft.smithing_template": "Modèle de forge d'acier royal", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "Modèle de forge d'acier royal", "itemGroup.anvilcraft.block": "Artisanat d'enclume - Blocs", "itemGroup.anvilcraft.item": "Artisanat d'enclume - Objet", "screen.anvilcraft.button.direction": "Output Direction: %s", diff --git a/common/src/main/resources/assets/anvilcraft/lang/ja_jp.json b/common/src/main/resources/assets/anvilcraft/lang/ja_jp.json index 876f28d47..ee6b09515 100644 --- a/common/src/main/resources/assets/anvilcraft/lang/ja_jp.json +++ b/common/src/main/resources/assets/anvilcraft/lang/ja_jp.json @@ -70,7 +70,7 @@ "item.anvilcraft.topaz": "トパーズ", "item.anvilcraft.utusan": "ウドゥパウダー", "item.anvilcraft.utusan_raw": "ウードゥーパウダー(生)", - "item.minecraft.smithing_template": "王室鋼の鍛冶型", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "王室鋼の鍛冶型", "itemGroup.anvilcraft.block": "金床工芸 - ブロック", "itemGroup.anvilcraft.item": "金床工芸 - アイテム", "screen.anvilcraft.button.direction": "出力方向:%s", diff --git a/common/src/main/resources/assets/anvilcraft/lang/ko_kr.json b/common/src/main/resources/assets/anvilcraft/lang/ko_kr.json index 811eb1610..5667a6285 100644 --- a/common/src/main/resources/assets/anvilcraft/lang/ko_kr.json +++ b/common/src/main/resources/assets/anvilcraft/lang/ko_kr.json @@ -70,7 +70,7 @@ "item.anvilcraft.topaz": "황옥", "item.anvilcraft.utusan": "오독가루", "item.anvilcraft.utusan_raw": "오독가루 (생)", - "item.minecraft.smithing_template": "로얄 스틸 단조 거푸집 공사", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "로얄 스틸 단조 거푸집 공사", "itemGroup.anvilcraft.block": "모루 공예 - 블록", "itemGroup.anvilcraft.item": "모루 공예 - 물건", "screen.anvilcraft.button.direction": "출력 방향: %s", diff --git a/common/src/main/resources/assets/anvilcraft/lang/lzh.json b/common/src/main/resources/assets/anvilcraft/lang/lzh.json index 8f0564be8..814ca45f9 100644 --- a/common/src/main/resources/assets/anvilcraft/lang/lzh.json +++ b/common/src/main/resources/assets/anvilcraft/lang/lzh.json @@ -70,7 +70,7 @@ "item.anvilcraft.topaz": "黃玉", "item.anvilcraft.utusan": "五毒散", "item.anvilcraft.utusan_raw": "五毒散(生)", - "item.minecraft.smithing_template": "皇家鋼鍛模", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "皇家鋼鍛模", "itemGroup.anvilcraft.block": "鐵砧匠藝 - 塊", "itemGroup.anvilcraft.item": "鐵砧匠藝 - 物", "screen.anvilcraft.button.direction": "趋之向:%s", diff --git a/common/src/main/resources/assets/anvilcraft/lang/ru_ru.json b/common/src/main/resources/assets/anvilcraft/lang/ru_ru.json index b33c95588..9dfa27694 100644 --- a/common/src/main/resources/assets/anvilcraft/lang/ru_ru.json +++ b/common/src/main/resources/assets/anvilcraft/lang/ru_ru.json @@ -70,7 +70,7 @@ "item.anvilcraft.topaz": "Topaz", "item.anvilcraft.utusan": "Порошок У Ду", "item.anvilcraft.utusan_raw": "Порошок У Ду (сырой)", - "item.minecraft.smithing_template": "Шаблон улучшения королевской стали", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "Шаблон улучшения королевской стали", "itemGroup.anvilcraft.block": "Anvilcraft — Блок", "itemGroup.anvilcraft.item": "Anvilcraft — Предмет", "screen.anvilcraft.button.direction": "Направление вывода: %s", diff --git a/common/src/main/resources/assets/anvilcraft/lang/zh_cn.json b/common/src/main/resources/assets/anvilcraft/lang/zh_cn.json index b73854aca..fc606eaf3 100644 --- a/common/src/main/resources/assets/anvilcraft/lang/zh_cn.json +++ b/common/src/main/resources/assets/anvilcraft/lang/zh_cn.json @@ -70,7 +70,7 @@ "item.anvilcraft.topaz": "黄玉", "item.anvilcraft.utusan": "五毒散", "item.anvilcraft.utusan_raw": "五毒散(生)", - "item.minecraft.smithing_template": "皇家钢锻造模板", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "皇家钢锻造模板", "itemGroup.anvilcraft.block": "铁砧工艺 - 方块", "itemGroup.anvilcraft.item": "铁砧工艺 - 物品", "screen.anvilcraft.button.direction": "输出方向:%s", diff --git a/common/src/main/resources/assets/anvilcraft/lang/zh_hk.json b/common/src/main/resources/assets/anvilcraft/lang/zh_hk.json index 8ba74c355..516dc861a 100644 --- a/common/src/main/resources/assets/anvilcraft/lang/zh_hk.json +++ b/common/src/main/resources/assets/anvilcraft/lang/zh_hk.json @@ -70,7 +70,7 @@ "item.anvilcraft.topaz": "黃玉", "item.anvilcraft.utusan": "五毒散", "item.anvilcraft.utusan_raw": "五毒散(生)", - "item.minecraft.smithing_template": "皇家鋼鍛造模板", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "皇家鋼鍛造模板", "itemGroup.anvilcraft.block": "鐵砧工藝 - 方塊", "itemGroup.anvilcraft.item": "鐵砧工藝 - 物品", "screen.anvilcraft.button.direction": "輸出方向:%s", diff --git a/common/src/main/resources/assets/anvilcraft/lang/zh_tw.json b/common/src/main/resources/assets/anvilcraft/lang/zh_tw.json index 7dbfd7704..c181a5246 100644 --- a/common/src/main/resources/assets/anvilcraft/lang/zh_tw.json +++ b/common/src/main/resources/assets/anvilcraft/lang/zh_tw.json @@ -70,7 +70,7 @@ "item.anvilcraft.topaz": "黃玉", "item.anvilcraft.utusan": "五毒散", "item.anvilcraft.utusan_raw": "五毒散(生)", - "item.minecraft.smithing_template": "皇家鍛造模板", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "皇家鍛造模板", "itemGroup.anvilcraft.block": "鐵砧工藝 - 方塊", "itemGroup.anvilcraft.item": "鐵砧工藝 - 物品", "screen.anvilcraft.button.direction": "輸出方向:%s", diff --git a/common/src/main/resources/assets/anvilcraft/models/item/remote_transmission_pole.json b/common/src/main/resources/assets/anvilcraft/models/item/remote_transmission_pole.json deleted file mode 100644 index fb4473e8e..000000000 --- a/common/src/main/resources/assets/anvilcraft/models/item/remote_transmission_pole.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "anvilcraft:block/remote_transmission_pole_overall" -} \ No newline at end of file diff --git a/common/src/main/resources/assets/anvilcraft/models/item/transmission_pole.json b/common/src/main/resources/assets/anvilcraft/models/item/transmission_pole.json new file mode 100644 index 000000000..7bed1e652 --- /dev/null +++ b/common/src/main/resources/assets/anvilcraft/models/item/transmission_pole.json @@ -0,0 +1,3 @@ +{ + "parent": "anvilcraft:block/transmission_pole_overall" +} \ No newline at end of file diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 03dd552ce..12b15bd45 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -13,7 +13,6 @@ "block.anvilcraft.hollow_magnet_block": "ʞɔoןᗺ ʇǝubɐW ʍoןןoH", "block.anvilcraft.lava_cauldron": "uoɹpןnɐƆ ɐʌɐꞀ", "block.anvilcraft.magnet_block": "ʞɔoןᗺ ʇǝubɐW", - "block.anvilcraft.remote_transmission_pole": "ǝןoԀ uoıssıɯsuɐɹ⟘ ǝʇoɯǝᴚ", "block.anvilcraft.resin_block": "ʞɔoןᗺ uısǝᴚ", "block.anvilcraft.royal_anvil": "ןıʌuⱯ ןɐʎoᴚ", "block.anvilcraft.royal_grindstone": "ǝuoʇspuıɹ⅁ ןɐʎoᴚ", @@ -25,6 +24,7 @@ "block.anvilcraft.smooth_royal_steel_block": "ʞɔoןᗺ ןǝǝʇS ןɐʎoᴚ ɥʇooɯS", "block.anvilcraft.stamping_platform": "ɯɹoɟʇɐןԀ buıdɯɐʇS", "block.anvilcraft.topaz_block": "ʞɔoןᗺ zɐdo⟘", + "block.anvilcraft.transmission_pole": "ǝןoԀ uoıssıɯsuɐɹ⟘", "item.anvilcraft.amber": "ɹǝqɯⱯ", "item.anvilcraft.amethyst_axe": "ǝxⱯ ʇsʎɥʇǝɯⱯ", "item.anvilcraft.amethyst_hoe": "ǝoH ʇsʎɥʇǝɯⱯ", @@ -68,6 +68,7 @@ "item.anvilcraft.royal_steel_ingot": "ʇobuI ןǝǝʇS ןɐʎoᴚ", "item.anvilcraft.royal_steel_nugget": "ʇǝbbnN ןǝǝʇS ןɐʎoᴚ", "item.anvilcraft.royal_steel_pickaxe": "ǝxɐʞɔıԀ ןǝǝʇS ןɐʎoᴚ", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "ǝʇɐןdɯǝ⟘ buıɥʇıɯS ǝpɐɹbd∩ ןǝǝʇS ןɐʎoᴚ", "item.anvilcraft.ruby": "ʎqnᴚ", "item.anvilcraft.sapphire": "ǝɹıɥddɐS", "item.anvilcraft.sea_heart_shell": "ןןǝɥS ʇɹɐǝH ɐǝS", @@ -76,7 +77,6 @@ "item.anvilcraft.topaz": "zɐdo⟘", "item.anvilcraft.utusan": "uɐsnʇ∩", "item.anvilcraft.utusan_raw": "ʍɐᴚ uɐsnʇ∩", - "item.minecraft.smithing_template": "ǝʇɐןdɯǝ⟘ buıɥʇıɯS ǝpɐɹbd∩ ןǝǝʇS ןɐʎoᴚ", "itemGroup.anvilcraft.block": "ʞɔoןᗺ", "itemGroup.anvilcraft.item": "ɯǝʇI", "screen.anvilcraft.button.direction": "%s :uoıʇɔǝɹıᗡ ʇndʇnO", @@ -117,8 +117,6 @@ "text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ ɐ ǝɔuɐʇsıp ɯnɯıxɐW", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "snıpɐᴚ sʇɔɐɹʇʇⱯ ɯǝʇI ʇǝubɐW", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ pןǝɥpuɐɥ ɐ snıpɐɹ ɯnɯıxɐW", - "text.autoconfig.anvilcraft.option.powerComponentRange": "sʇuǝuodɯoƆ ɹǝʍoԀ ɟo ǝbuɐᴚ", - "text.autoconfig.anvilcraft.option.powerComponentRange.@Tooltip": "sʇuǝuodɯoɔ ɹǝʍod ɟo ǝbuɐɹ ǝɥʇ ʎɟıʇuǝpı uɐɔ ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥ⟘", "text.autoconfig.anvilcraft.option.powerTransmitterRange": "ɹǝʇʇıɯsuɐɹ⟘ ɹǝʍoԀ ɟo ǝbuɐᴚ", "text.autoconfig.anvilcraft.option.powerTransmitterRange.@Tooltip": "ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥʇ ɟo ǝbuɐɹ ǝɥʇ ʎɟıʇuǝpı uɐɔ ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥ⟘", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "snıpɐᴚ xɐW dɯƎ ǝuoʇspǝᴚ", diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json index 93ce6076c..5bc7615b5 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -13,7 +13,6 @@ "block.anvilcraft.hollow_magnet_block": "Hollow Magnet Block", "block.anvilcraft.lava_cauldron": "Lava Cauldron", "block.anvilcraft.magnet_block": "Magnet Block", - "block.anvilcraft.remote_transmission_pole": "Remote Transmission Pole", "block.anvilcraft.resin_block": "Resin Block", "block.anvilcraft.royal_anvil": "Royal Anvil", "block.anvilcraft.royal_grindstone": "Royal Grindstone", @@ -25,6 +24,7 @@ "block.anvilcraft.smooth_royal_steel_block": "Smooth Royal Steel Block", "block.anvilcraft.stamping_platform": "Stamping Platform", "block.anvilcraft.topaz_block": "Topaz Block", + "block.anvilcraft.transmission_pole": "Transmission Pole", "item.anvilcraft.amber": "Amber", "item.anvilcraft.amethyst_axe": "Amethyst Axe", "item.anvilcraft.amethyst_hoe": "Amethyst Hoe", @@ -68,6 +68,7 @@ "item.anvilcraft.royal_steel_ingot": "Royal Steel Ingot", "item.anvilcraft.royal_steel_nugget": "Royal Steel Nugget", "item.anvilcraft.royal_steel_pickaxe": "Royal Steel Pickaxe", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "Royal Steel Upgrade Smithing Template", "item.anvilcraft.ruby": "Ruby", "item.anvilcraft.sapphire": "Sapphire", "item.anvilcraft.sea_heart_shell": "Sea Heart Shell", @@ -76,7 +77,6 @@ "item.anvilcraft.topaz": "Topaz", "item.anvilcraft.utusan": "Utusan", "item.anvilcraft.utusan_raw": "Utusan Raw", - "item.minecraft.smithing_template": "Royal Steel Upgrade Smithing Template", "itemGroup.anvilcraft.block": "Block", "itemGroup.anvilcraft.item": "Item", "screen.anvilcraft.button.direction": "Output Direction: %s", @@ -117,8 +117,6 @@ "text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "Maximum distance a magnet attracts", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "Magnet Item Attracts Radius", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "Maximum radius a handheld magnet attracts", - "text.autoconfig.anvilcraft.option.powerComponentRange": "Range of Power Components", - "text.autoconfig.anvilcraft.option.powerComponentRange.@Tooltip": "The power transmitter can identify the range of power components", "text.autoconfig.anvilcraft.option.powerTransmitterRange": "Range of Power Transmitter", "text.autoconfig.anvilcraft.option.powerTransmitterRange.@Tooltip": "The power transmitter can identify the range of the power transmitter", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "Redstone Emp Max Radius", diff --git a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/transmission_pole.json similarity index 91% rename from fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json rename to fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/transmission_pole.json index 898ec92e4..abe92012d 100644 --- a/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json +++ b/fabric/src/generated/resources/data/anvilcraft/advancements/recipes/misc/transmission_pole.json @@ -39,7 +39,7 @@ }, "has_the_recipe": { "conditions": { - "recipe": "anvilcraft:remote_transmission_pole" + "recipe": "anvilcraft:transmission_pole" }, "trigger": "minecraft:recipe_unlocked" } @@ -54,7 +54,7 @@ ], "rewards": { "recipes": [ - "anvilcraft:remote_transmission_pole" + "anvilcraft:transmission_pole" ] }, "sends_telemetry_event": false diff --git a/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json b/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/transmission_pole.json similarity index 70% rename from fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json rename to fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/transmission_pole.json index 5a8de0812..a9851c7d3 100644 --- a/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json +++ b/fabric/src/generated/resources/data/anvilcraft/loot_tables/blocks/transmission_pole.json @@ -11,11 +11,11 @@ "entries": [ { "type": "minecraft:item", - "name": "anvilcraft:remote_transmission_pole" + "name": "anvilcraft:transmission_pole" } ], "rolls": 1.0 } ], - "random_sequence": "anvilcraft:blocks/remote_transmission_pole" + "random_sequence": "anvilcraft:blocks/transmission_pole" } \ No newline at end of file diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json b/fabric/src/generated/resources/data/anvilcraft/recipes/transmission_pole.json similarity index 87% rename from forge/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json rename to fabric/src/generated/resources/data/anvilcraft/recipes/transmission_pole.json index 0bece4856..f61b8caee 100644 --- a/forge/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/transmission_pole.json @@ -18,7 +18,7 @@ "C" ], "result": { - "item": "anvilcraft:remote_transmission_pole" + "item": "anvilcraft:transmission_pole" }, "show_notification": true } \ No newline at end of file diff --git a/fabric/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/fabric/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 4eb682c20..ad0c2f909 100644 --- a/fabric/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/fabric/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -23,6 +23,9 @@ "anvilcraft:ruby_block", "anvilcraft:sapphire_block", "anvilcraft:resin_block", - "anvilcraft:amber_block" + "anvilcraft:amber_block", + "anvilcraft:creative_dynamo", + "anvilcraft:heater", + "anvilcraft:transmission_pole" ] } \ No newline at end of file diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 03dd552ce..12b15bd45 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -13,7 +13,6 @@ "block.anvilcraft.hollow_magnet_block": "ʞɔoןᗺ ʇǝubɐW ʍoןןoH", "block.anvilcraft.lava_cauldron": "uoɹpןnɐƆ ɐʌɐꞀ", "block.anvilcraft.magnet_block": "ʞɔoןᗺ ʇǝubɐW", - "block.anvilcraft.remote_transmission_pole": "ǝןoԀ uoıssıɯsuɐɹ⟘ ǝʇoɯǝᴚ", "block.anvilcraft.resin_block": "ʞɔoןᗺ uısǝᴚ", "block.anvilcraft.royal_anvil": "ןıʌuⱯ ןɐʎoᴚ", "block.anvilcraft.royal_grindstone": "ǝuoʇspuıɹ⅁ ןɐʎoᴚ", @@ -25,6 +24,7 @@ "block.anvilcraft.smooth_royal_steel_block": "ʞɔoןᗺ ןǝǝʇS ןɐʎoᴚ ɥʇooɯS", "block.anvilcraft.stamping_platform": "ɯɹoɟʇɐןԀ buıdɯɐʇS", "block.anvilcraft.topaz_block": "ʞɔoןᗺ zɐdo⟘", + "block.anvilcraft.transmission_pole": "ǝןoԀ uoıssıɯsuɐɹ⟘", "item.anvilcraft.amber": "ɹǝqɯⱯ", "item.anvilcraft.amethyst_axe": "ǝxⱯ ʇsʎɥʇǝɯⱯ", "item.anvilcraft.amethyst_hoe": "ǝoH ʇsʎɥʇǝɯⱯ", @@ -68,6 +68,7 @@ "item.anvilcraft.royal_steel_ingot": "ʇobuI ןǝǝʇS ןɐʎoᴚ", "item.anvilcraft.royal_steel_nugget": "ʇǝbbnN ןǝǝʇS ןɐʎoᴚ", "item.anvilcraft.royal_steel_pickaxe": "ǝxɐʞɔıԀ ןǝǝʇS ןɐʎoᴚ", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "ǝʇɐןdɯǝ⟘ buıɥʇıɯS ǝpɐɹbd∩ ןǝǝʇS ןɐʎoᴚ", "item.anvilcraft.ruby": "ʎqnᴚ", "item.anvilcraft.sapphire": "ǝɹıɥddɐS", "item.anvilcraft.sea_heart_shell": "ןןǝɥS ʇɹɐǝH ɐǝS", @@ -76,7 +77,6 @@ "item.anvilcraft.topaz": "zɐdo⟘", "item.anvilcraft.utusan": "uɐsnʇ∩", "item.anvilcraft.utusan_raw": "ʍɐᴚ uɐsnʇ∩", - "item.minecraft.smithing_template": "ǝʇɐןdɯǝ⟘ buıɥʇıɯS ǝpɐɹbd∩ ןǝǝʇS ןɐʎoᴚ", "itemGroup.anvilcraft.block": "ʞɔoןᗺ", "itemGroup.anvilcraft.item": "ɯǝʇI", "screen.anvilcraft.button.direction": "%s :uoıʇɔǝɹıᗡ ʇndʇnO", @@ -117,8 +117,6 @@ "text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ ɐ ǝɔuɐʇsıp ɯnɯıxɐW", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "snıpɐᴚ sʇɔɐɹʇʇⱯ ɯǝʇI ʇǝubɐW", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "sʇɔɐɹʇʇɐ ʇǝubɐɯ pןǝɥpuɐɥ ɐ snıpɐɹ ɯnɯıxɐW", - "text.autoconfig.anvilcraft.option.powerComponentRange": "sʇuǝuodɯoƆ ɹǝʍoԀ ɟo ǝbuɐᴚ", - "text.autoconfig.anvilcraft.option.powerComponentRange.@Tooltip": "sʇuǝuodɯoɔ ɹǝʍod ɟo ǝbuɐɹ ǝɥʇ ʎɟıʇuǝpı uɐɔ ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥ⟘", "text.autoconfig.anvilcraft.option.powerTransmitterRange": "ɹǝʇʇıɯsuɐɹ⟘ ɹǝʍoԀ ɟo ǝbuɐᴚ", "text.autoconfig.anvilcraft.option.powerTransmitterRange.@Tooltip": "ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥʇ ɟo ǝbuɐɹ ǝɥʇ ʎɟıʇuǝpı uɐɔ ɹǝʇʇıɯsuɐɹʇ ɹǝʍod ǝɥ⟘", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "snıpɐᴚ xɐW dɯƎ ǝuoʇspǝᴚ", diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json index 93ce6076c..5bc7615b5 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -13,7 +13,6 @@ "block.anvilcraft.hollow_magnet_block": "Hollow Magnet Block", "block.anvilcraft.lava_cauldron": "Lava Cauldron", "block.anvilcraft.magnet_block": "Magnet Block", - "block.anvilcraft.remote_transmission_pole": "Remote Transmission Pole", "block.anvilcraft.resin_block": "Resin Block", "block.anvilcraft.royal_anvil": "Royal Anvil", "block.anvilcraft.royal_grindstone": "Royal Grindstone", @@ -25,6 +24,7 @@ "block.anvilcraft.smooth_royal_steel_block": "Smooth Royal Steel Block", "block.anvilcraft.stamping_platform": "Stamping Platform", "block.anvilcraft.topaz_block": "Topaz Block", + "block.anvilcraft.transmission_pole": "Transmission Pole", "item.anvilcraft.amber": "Amber", "item.anvilcraft.amethyst_axe": "Amethyst Axe", "item.anvilcraft.amethyst_hoe": "Amethyst Hoe", @@ -68,6 +68,7 @@ "item.anvilcraft.royal_steel_ingot": "Royal Steel Ingot", "item.anvilcraft.royal_steel_nugget": "Royal Steel Nugget", "item.anvilcraft.royal_steel_pickaxe": "Royal Steel Pickaxe", + "item.anvilcraft.royal_steel_upgrade_smithing_template": "Royal Steel Upgrade Smithing Template", "item.anvilcraft.ruby": "Ruby", "item.anvilcraft.sapphire": "Sapphire", "item.anvilcraft.sea_heart_shell": "Sea Heart Shell", @@ -76,7 +77,6 @@ "item.anvilcraft.topaz": "Topaz", "item.anvilcraft.utusan": "Utusan", "item.anvilcraft.utusan_raw": "Utusan Raw", - "item.minecraft.smithing_template": "Royal Steel Upgrade Smithing Template", "itemGroup.anvilcraft.block": "Block", "itemGroup.anvilcraft.item": "Item", "screen.anvilcraft.button.direction": "Output Direction: %s", @@ -117,8 +117,6 @@ "text.autoconfig.anvilcraft.option.magnetAttractsDistance.@Tooltip": "Maximum distance a magnet attracts", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius": "Magnet Item Attracts Radius", "text.autoconfig.anvilcraft.option.magnetItemAttractsRadius.@Tooltip": "Maximum radius a handheld magnet attracts", - "text.autoconfig.anvilcraft.option.powerComponentRange": "Range of Power Components", - "text.autoconfig.anvilcraft.option.powerComponentRange.@Tooltip": "The power transmitter can identify the range of power components", "text.autoconfig.anvilcraft.option.powerTransmitterRange": "Range of Power Transmitter", "text.autoconfig.anvilcraft.option.powerTransmitterRange.@Tooltip": "The power transmitter can identify the range of the power transmitter", "text.autoconfig.anvilcraft.option.redstoneEmpMaxRadius": "Redstone Emp Max Radius", diff --git a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/transmission_pole.json similarity index 91% rename from forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json rename to forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/transmission_pole.json index 898ec92e4..abe92012d 100644 --- a/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/remote_transmission_pole.json +++ b/forge/src/generated/resources/data/anvilcraft/advancements/recipes/misc/transmission_pole.json @@ -39,7 +39,7 @@ }, "has_the_recipe": { "conditions": { - "recipe": "anvilcraft:remote_transmission_pole" + "recipe": "anvilcraft:transmission_pole" }, "trigger": "minecraft:recipe_unlocked" } @@ -54,7 +54,7 @@ ], "rewards": { "recipes": [ - "anvilcraft:remote_transmission_pole" + "anvilcraft:transmission_pole" ] }, "sends_telemetry_event": false diff --git a/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json b/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/transmission_pole.json similarity index 70% rename from forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json rename to forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/transmission_pole.json index 5a8de0812..a9851c7d3 100644 --- a/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/remote_transmission_pole.json +++ b/forge/src/generated/resources/data/anvilcraft/loot_tables/blocks/transmission_pole.json @@ -11,11 +11,11 @@ "entries": [ { "type": "minecraft:item", - "name": "anvilcraft:remote_transmission_pole" + "name": "anvilcraft:transmission_pole" } ], "rolls": 1.0 } ], - "random_sequence": "anvilcraft:blocks/remote_transmission_pole" + "random_sequence": "anvilcraft:blocks/transmission_pole" } \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json b/forge/src/generated/resources/data/anvilcraft/recipes/transmission_pole.json similarity index 87% rename from fabric/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json rename to forge/src/generated/resources/data/anvilcraft/recipes/transmission_pole.json index 0bece4856..f61b8caee 100644 --- a/fabric/src/generated/resources/data/anvilcraft/recipes/remote_transmission_pole.json +++ b/forge/src/generated/resources/data/anvilcraft/recipes/transmission_pole.json @@ -18,7 +18,7 @@ "C" ], "result": { - "item": "anvilcraft:remote_transmission_pole" + "item": "anvilcraft:transmission_pole" }, "show_notification": true } \ No newline at end of file diff --git a/forge/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json b/forge/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json index 4eb682c20..ad0c2f909 100644 --- a/forge/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json +++ b/forge/src/generated/resources/data/minecraft/tags/blocks/mineable/pickaxe.json @@ -23,6 +23,9 @@ "anvilcraft:ruby_block", "anvilcraft:sapphire_block", "anvilcraft:resin_block", - "anvilcraft:amber_block" + "anvilcraft:amber_block", + "anvilcraft:creative_dynamo", + "anvilcraft:heater", + "anvilcraft:transmission_pole" ] } \ No newline at end of file From 69bf4f145b3f27a3292e65121dc8975a91bce061 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 18:15:40 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E9=93=81=E7=A0=A7=E9=94=A4=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=88=B4=E5=9C=A8=E5=A4=B4=E4=B8=8A=EF=BC=8C=E5=85=85?= =?UTF-8?q?=E5=BD=93=E7=B1=BB=E4=BC=BC=E5=B7=A5=E7=A8=8B=E5=B8=88=E6=8A=A4?= =?UTF-8?q?=E7=9B=AE=E9=95=9C=E7=9A=84=E4=BD=9C=E7=94=A8=EF=BC=8C=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E7=94=B5=E7=BD=91=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolved #293 --- .../anvilcraft/block/CreativeDynamoBlock.java | 3 +- .../dubhe/anvilcraft/block/HeaterBlock.java | 3 +- .../block/TransmissionPoleBlock.java | 3 +- .../client/renderer/PowerGridRenderer.java | 66 ++++++++++++++++++ .../anvilcraft/item/AnvilHammerItem.java | 8 ++- .../anvilcraft/mixin/LevelRendererMixin.java | 69 +++++++++++++++++++ .../resources/anvilcraft-common.mixins.json | 1 + 7 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/client/renderer/PowerGridRenderer.java create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/mixin/LevelRendererMixin.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java index 3ddd0cd38..26d3e833a 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/CreativeDynamoBlock.java @@ -1,5 +1,6 @@ package dev.dubhe.anvilcraft.block; +import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.block.entity.CreativeDynamoBlockEntity; import dev.dubhe.anvilcraft.init.ModMenuTypes; import dev.dubhe.anvilcraft.network.SliderInitPack; @@ -23,7 +24,7 @@ import javax.annotation.Nonnull; -public class CreativeDynamoBlock extends BaseEntityBlock { +public class CreativeDynamoBlock extends BaseEntityBlock implements IHammerRemovable { public static final VoxelShape AABB = Block.box(0, 0, 0, 16, 4, 16); public CreativeDynamoBlock(Properties properties) { diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/HeaterBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/HeaterBlock.java index ab6d8d55e..73eea8452 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/HeaterBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/HeaterBlock.java @@ -1,5 +1,6 @@ package dev.dubhe.anvilcraft.block; +import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.block.entity.HeaterBlockEntity; import dev.dubhe.anvilcraft.init.ModBlockEntities; import net.minecraft.core.BlockPos; @@ -20,7 +21,7 @@ import javax.annotation.Nonnull; -public class HeaterBlock extends BaseEntityBlock { +public class HeaterBlock extends BaseEntityBlock implements IHammerRemovable { public static final BooleanProperty LIT = RedstoneTorchBlock.LIT; public HeaterBlock(Properties properties) { diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/TransmissionPoleBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/TransmissionPoleBlock.java index 9a169f8a9..8cd1c496c 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/TransmissionPoleBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/TransmissionPoleBlock.java @@ -1,5 +1,6 @@ package dev.dubhe.anvilcraft.block; +import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.block.entity.TransmissionPoleBlockEntity; import dev.dubhe.anvilcraft.block.state.Half; import net.minecraft.core.BlockPos; @@ -23,7 +24,7 @@ import javax.annotation.Nonnull; -public class TransmissionPoleBlock extends BaseEntityBlock { +public class TransmissionPoleBlock extends BaseEntityBlock implements IHammerRemovable { public static final EnumProperty HALF = EnumProperty.create("half", Half.class); public TransmissionPoleBlock(Properties properties) { diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/renderer/PowerGridRenderer.java b/common/src/main/java/dev/dubhe/anvilcraft/client/renderer/PowerGridRenderer.java new file mode 100644 index 000000000..e6f8237cc --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/renderer/PowerGridRenderer.java @@ -0,0 +1,66 @@ +package dev.dubhe.anvilcraft.client.renderer; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import dev.dubhe.anvilcraft.api.power.PowerGrid; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; +import net.minecraft.util.Mth; +import net.minecraft.util.RandomSource; +import net.minecraft.world.phys.shapes.VoxelShape; +import org.jetbrains.annotations.NotNull; + +@Environment(EnvType.CLIENT) +public class PowerGridRenderer { + /** + * 渲染 + */ + public static void render(PoseStack poseStack, VertexConsumer consumer, double camX, double camY, double camZ) { + if (Minecraft.getInstance().level == null) return; + RandomSource random = Minecraft.getInstance().level.random; + for (PowerGrid grid : PowerGrid.GRID_SET) { + random.setSeed(grid.hashCode()); + PowerGridRenderer.renderOutline( + poseStack, consumer, camX, camY, camZ, + grid.getPos(), grid.getRange(), + random.nextFloat(), random.nextFloat(), random.nextFloat(), 0.4f + ); + } + } + + @SuppressWarnings("SameParameterValue") + private static void renderOutline( + PoseStack poseStack, VertexConsumer consumer, + double camX, double camY, double camZ, @NotNull BlockPos pos, @NotNull VoxelShape shape, + float red, float green, float blue, float alpha + ) { + PowerGridRenderer.renderShape( + poseStack, consumer, shape, + (double) pos.getX() - camX, (double) pos.getY() - camY, (double) pos.getZ() - camZ, + red, green, blue, alpha + ); + } + + private static void renderShape( + @NotNull PoseStack poseStack, VertexConsumer consumer, @NotNull VoxelShape shape, + double x, double y, double z, float red, float green, float blue, float alpha + ) { + PoseStack.Pose pose = poseStack.last(); + shape.forAllEdges((minX, minY, minZ, maxX, maxY, maxZ) -> { + float k = (float) (maxX - minX); + float l = (float) (maxY - minY); + float m = (float) (maxZ - minZ); + float n = Mth.sqrt(k * k + l * l + m * m); + consumer.vertex(pose.pose(), (float) (minX + x), (float) (minY + y), (float) (minZ + z)) + .color(red, green, blue, alpha) + .normal(pose.normal(), k /= n, l /= n, m /= n) + .endVertex(); + consumer.vertex(pose.pose(), (float) (maxX + x), (float) (maxY + y), (float) (maxZ + z)) + .color(red, green, blue, alpha) + .normal(pose.normal(), k, l, m) + .endVertex(); + }); + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/item/AnvilHammerItem.java b/common/src/main/java/dev/dubhe/anvilcraft/item/AnvilHammerItem.java index d6b6af927..5f250f546 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/item/AnvilHammerItem.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/item/AnvilHammerItem.java @@ -20,6 +20,7 @@ import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.item.FallingBlockEntity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Equipable; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Vanishable; @@ -29,7 +30,7 @@ import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; -public class AnvilHammerItem extends Item implements Vanishable { +public class AnvilHammerItem extends Item implements Vanishable, Equipable { private long lastDropAnvilTime = 0; private final Multimap defaultModifiers; @@ -168,4 +169,9 @@ public boolean isCorrectToolForDrops(@NotNull BlockState block) { } return super.getDefaultAttributeModifiers(slot); } + + @Override + public @NotNull EquipmentSlot getEquipmentSlot() { + return EquipmentSlot.HEAD; + } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/mixin/LevelRendererMixin.java b/common/src/main/java/dev/dubhe/anvilcraft/mixin/LevelRendererMixin.java new file mode 100644 index 000000000..8bf381777 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/mixin/LevelRendererMixin.java @@ -0,0 +1,69 @@ +package dev.dubhe.anvilcraft.mixin; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import dev.dubhe.anvilcraft.client.renderer.PowerGridRenderer; +import dev.dubhe.anvilcraft.init.ModItems; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Camera; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderBuffers; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; +import org.joml.Matrix4f; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(LevelRenderer.class) +@Environment(EnvType.CLIENT) +public abstract class LevelRendererMixin { + @Shadow + @Final + private RenderBuffers renderBuffers; + + @Inject( + method = "renderLevel", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/debug/DebugRenderer;render(Lcom/mojang/blaze3d/vertex/PoseStack;" + + "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;DDD)V" + ), + locals = LocalCapture.CAPTURE_FAILEXCEPTION + ) + private void renderLevel( + PoseStack poseStack, float partialTick, long finishNanoTime, + boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, + LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci, + @NotNull ProfilerFiller profilerFiller, @NotNull Vec3 vec3 + ) { + Entity entity = camera.getEntity(); + boolean bl = true; + for (ItemStack slot : entity.getArmorSlots()) { + if (slot.is(ModItems.ANVIL_HAMMER.get())) { + bl = false; + break; + } + } + if (bl) return; + MultiBufferSource.BufferSource bufferSource = this.renderBuffers.bufferSource(); + VertexConsumer vertexConsumer3 = bufferSource.getBuffer(RenderType.lines()); + double camX = vec3.x(); + double camY = vec3.y(); + double camZ = vec3.z(); + profilerFiller.popPush("grid"); + PowerGridRenderer.render(poseStack, vertexConsumer3, camX, camY, camZ); + } +} diff --git a/common/src/main/resources/anvilcraft-common.mixins.json b/common/src/main/resources/anvilcraft-common.mixins.json index 9fc891070..3214ddeb3 100644 --- a/common/src/main/resources/anvilcraft-common.mixins.json +++ b/common/src/main/resources/anvilcraft-common.mixins.json @@ -17,6 +17,7 @@ "SolidBucketItemMixin" ], "client": [ + "LevelRendererMixin" ], "injectors": { "defaultRequire": 1 From d083b6f1e47ffeb1c69b59d6289639da70c462e2 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 21:10:03 +0800 Subject: [PATCH 13/17] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .idea/icon.svg | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .idea/icon.svg diff --git a/.gitignore b/.gitignore index e6f1a16ec..8cd1abd2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # User-specific stuff .idea/ +!.idea/icon.svg *.iml *.ipr diff --git a/.idea/icon.svg b/.idea/icon.svg new file mode 100644 index 000000000..6c3268648 --- /dev/null +++ b/.idea/icon.svg @@ -0,0 +1,47 @@ + + + + From 5c1486f7edceb385e284d351609b2ea9bbb318d8 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 21:50:20 +0800 Subject: [PATCH 14/17] =?UTF-8?q?=E7=94=9F=E6=88=90=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anvilcraft/textures/icon.png => pack.png} | Bin .../resources/assets/anvilcraft/lang/en_ud.json | 3 +++ .../resources/assets/anvilcraft/lang/en_us.json | 3 +++ fabric/src/main/resources/fabric.mod.json | 2 +- .../resources/assets/anvilcraft/lang/en_ud.json | 3 +++ .../resources/assets/anvilcraft/lang/en_us.json | 3 +++ forge/src/main/resources/META-INF/mods.toml | 2 +- 7 files changed, 14 insertions(+), 2 deletions(-) rename common/src/main/resources/{assets/anvilcraft/textures/icon.png => pack.png} (100%) diff --git a/common/src/main/resources/assets/anvilcraft/textures/icon.png b/common/src/main/resources/pack.png similarity index 100% rename from common/src/main/resources/assets/anvilcraft/textures/icon.png rename to common/src/main/resources/pack.png diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 12b15bd45..175cc6276 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -41,6 +41,7 @@ "item.anvilcraft.chocolate": "ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_black": "ʞɔɐןᗺ ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_white": "ǝʇıɥM ǝʇɐןoɔoɥƆ", + "item.anvilcraft.circuit_board": "pɹɐoᗺ ʇınɔɹıƆ", "item.anvilcraft.cocoa_butter": "ɹǝʇʇnᗺ ɐoɔoƆ", "item.anvilcraft.cocoa_liquor": "ɹonbıꞀ ɐoɔoƆ", "item.anvilcraft.cocoa_powder": "ɹǝpʍoԀ ɐoɔoƆ", @@ -55,6 +56,7 @@ "item.anvilcraft.flour": "ɹnoןℲ", "item.anvilcraft.geode": "ǝpoǝ⅁", "item.anvilcraft.geode.find": "%s pǝʇɐɔoן 'ǝpoǝb ʇsʎɥʇǝɯɐ pǝʇɔǝdsnS", + "item.anvilcraft.hardend_resin": "uısǝᴚ puǝpɹɐH", "item.anvilcraft.magnet": "ʇǝubɐW", "item.anvilcraft.magnet_ingot": "ʇobuI ʇǝubɐW", "item.anvilcraft.magnetoelectric_core": "ǝɹoƆ ɔıɹʇɔǝןǝoʇǝubɐW", @@ -77,6 +79,7 @@ "item.anvilcraft.topaz": "zɐdo⟘", "item.anvilcraft.utusan": "uɐsnʇ∩", "item.anvilcraft.utusan_raw": "ʍɐᴚ uɐsnʇ∩", + "item.anvilcraft.wood_fiber": "ɹǝqıℲ pooM", "itemGroup.anvilcraft.block": "ʞɔoןᗺ", "itemGroup.anvilcraft.item": "ɯǝʇI", "screen.anvilcraft.button.direction": "%s :uoıʇɔǝɹıᗡ ʇndʇnO", diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json index 5bc7615b5..078b89b09 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -41,6 +41,7 @@ "item.anvilcraft.chocolate": "Chocolate", "item.anvilcraft.chocolate_black": "Chocolate Black", "item.anvilcraft.chocolate_white": "Chocolate White", + "item.anvilcraft.circuit_board": "Circuit Board", "item.anvilcraft.cocoa_butter": "Cocoa Butter", "item.anvilcraft.cocoa_liquor": "Cocoa Liquor", "item.anvilcraft.cocoa_powder": "Cocoa Powder", @@ -55,6 +56,7 @@ "item.anvilcraft.flour": "Flour", "item.anvilcraft.geode": "Geode", "item.anvilcraft.geode.find": "Suspected amethyst geode, located %s", + "item.anvilcraft.hardend_resin": "Hardend Resin", "item.anvilcraft.magnet": "Magnet", "item.anvilcraft.magnet_ingot": "Magnet Ingot", "item.anvilcraft.magnetoelectric_core": "Magnetoelectric Core", @@ -77,6 +79,7 @@ "item.anvilcraft.topaz": "Topaz", "item.anvilcraft.utusan": "Utusan", "item.anvilcraft.utusan_raw": "Utusan Raw", + "item.anvilcraft.wood_fiber": "Wood Fiber", "itemGroup.anvilcraft.block": "Block", "itemGroup.anvilcraft.item": "Item", "screen.anvilcraft.button.direction": "Output Direction: %s", diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 488853b33..e3c86e4d9 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -15,7 +15,7 @@ }, "license": "${mod_license}", - "icon": "assets/anvilcraft/textures/icon.png", + "icon": "pack.png", "environment": "*", "entrypoints": { diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 12b15bd45..175cc6276 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -41,6 +41,7 @@ "item.anvilcraft.chocolate": "ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_black": "ʞɔɐןᗺ ǝʇɐןoɔoɥƆ", "item.anvilcraft.chocolate_white": "ǝʇıɥM ǝʇɐןoɔoɥƆ", + "item.anvilcraft.circuit_board": "pɹɐoᗺ ʇınɔɹıƆ", "item.anvilcraft.cocoa_butter": "ɹǝʇʇnᗺ ɐoɔoƆ", "item.anvilcraft.cocoa_liquor": "ɹonbıꞀ ɐoɔoƆ", "item.anvilcraft.cocoa_powder": "ɹǝpʍoԀ ɐoɔoƆ", @@ -55,6 +56,7 @@ "item.anvilcraft.flour": "ɹnoןℲ", "item.anvilcraft.geode": "ǝpoǝ⅁", "item.anvilcraft.geode.find": "%s pǝʇɐɔoן 'ǝpoǝb ʇsʎɥʇǝɯɐ pǝʇɔǝdsnS", + "item.anvilcraft.hardend_resin": "uısǝᴚ puǝpɹɐH", "item.anvilcraft.magnet": "ʇǝubɐW", "item.anvilcraft.magnet_ingot": "ʇobuI ʇǝubɐW", "item.anvilcraft.magnetoelectric_core": "ǝɹoƆ ɔıɹʇɔǝןǝoʇǝubɐW", @@ -77,6 +79,7 @@ "item.anvilcraft.topaz": "zɐdo⟘", "item.anvilcraft.utusan": "uɐsnʇ∩", "item.anvilcraft.utusan_raw": "ʍɐᴚ uɐsnʇ∩", + "item.anvilcraft.wood_fiber": "ɹǝqıℲ pooM", "itemGroup.anvilcraft.block": "ʞɔoןᗺ", "itemGroup.anvilcraft.item": "ɯǝʇI", "screen.anvilcraft.button.direction": "%s :uoıʇɔǝɹıᗡ ʇndʇnO", diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json index 5bc7615b5..078b89b09 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -41,6 +41,7 @@ "item.anvilcraft.chocolate": "Chocolate", "item.anvilcraft.chocolate_black": "Chocolate Black", "item.anvilcraft.chocolate_white": "Chocolate White", + "item.anvilcraft.circuit_board": "Circuit Board", "item.anvilcraft.cocoa_butter": "Cocoa Butter", "item.anvilcraft.cocoa_liquor": "Cocoa Liquor", "item.anvilcraft.cocoa_powder": "Cocoa Powder", @@ -55,6 +56,7 @@ "item.anvilcraft.flour": "Flour", "item.anvilcraft.geode": "Geode", "item.anvilcraft.geode.find": "Suspected amethyst geode, located %s", + "item.anvilcraft.hardend_resin": "Hardend Resin", "item.anvilcraft.magnet": "Magnet", "item.anvilcraft.magnet_ingot": "Magnet Ingot", "item.anvilcraft.magnetoelectric_core": "Magnetoelectric Core", @@ -77,6 +79,7 @@ "item.anvilcraft.topaz": "Topaz", "item.anvilcraft.utusan": "Utusan", "item.anvilcraft.utusan_raw": "Utusan Raw", + "item.anvilcraft.wood_fiber": "Wood Fiber", "itemGroup.anvilcraft.block": "Block", "itemGroup.anvilcraft.item": "Item", "screen.anvilcraft.button.direction": "Output Direction: %s", diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index d9fe5b512..b6d9365f8 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -9,7 +9,7 @@ displayName="${mod_name}" displayURL="${mod_url}" authors="" description="${mod_description}" -logoFile="icon.png" #optional +logoFile="pack.png" #optional #credits="Thanks for this example mod goes to Java" [[dependencies.${mod_id}]] From c7193476b52bf81e211500662a9e9b7a52b271a7 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 22:20:00 +0800 Subject: [PATCH 15/17] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/dubhe/anvilcraft/api/power/PowerGrid.java | 13 +++++++++++++ .../event/fabric/ServerBlockEntityEvent.java | 5 +---- .../event/forge/ServerBlockEntityEvent.java | 5 +---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java index b6227fb4d..fc7382960 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java @@ -130,6 +130,19 @@ private void addRange(IPowerComponent component) { this.range = Shapes.join(this.range, range, BooleanOp.OR); } + /** + * 移除除电网元件 + * + * @param components 元件 + */ + public static void removeComponent(IPowerComponent @NotNull ... components) { + for (IPowerComponent component : components) { + PowerGrid grid = component.getGrid(); + if (grid == null) return; + grid.remove(component); + } + } + /** * 移除电力元件 * diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerBlockEntityEvent.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerBlockEntityEvent.java index b719bc882..ac5c6d7f2 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerBlockEntityEvent.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerBlockEntityEvent.java @@ -20,10 +20,7 @@ private static void onLoad(BlockEntity entity, ServerLevel level) { private static void onUnload(BlockEntity entity, ServerLevel level) { if (entity instanceof IPowerComponent component) { - PowerGrid grid = component.getGrid(); - if (grid == null) return; - grid.remove(component); - component.setGrid(grid); + PowerGrid.removeComponent(component); } } } diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEvent.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEvent.java index 87d64c172..164c0e1e1 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEvent.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerBlockEntityEvent.java @@ -26,10 +26,7 @@ public static void onLoad(@NotNull BlockEntityEvent.ServerLoad event) { @SubscribeEvent public static void onUnload(@NotNull BlockEntityEvent.ServerUnload event) { if (event.getEntity() instanceof IPowerComponent component) { - PowerGrid grid = component.getGrid(); - if (grid == null) return; - grid.remove(component); - component.setGrid(null); + PowerGrid.removeComponent(component); } } } From a7310a9e368452d0892157a8c3882f421af770c6 Mon Sep 17 00:00:00 2001 From: Gugle Date: Tue, 16 Apr 2024 23:19:07 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/power/IPowerTransmitter.java | 2 +- .../dubhe/anvilcraft/api/power/PowerGrid.java | 25 ++++++++++++++++--- .../event/fabric/ServerLifecycleEvent.java | 6 +++++ .../event/forge/ServerLifecycleEvent.java | 10 ++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java index bfaaac984..0a1c7a67e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/IPowerTransmitter.java @@ -12,7 +12,7 @@ public interface IPowerTransmitter extends IPowerComponent { @Override default VoxelShape getRange() { int range = AnvilCraft.config.powerTransmitterRange; - return Shapes.box(-range, -range, -range, range, range, range); + return Shapes.box(-range, -range, -range, range + 1, range + 1, range + 1); } @Override diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java index fc7382960..6023cca63 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java @@ -2,11 +2,13 @@ import lombok.Getter; import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.phys.shapes.BooleanOp; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -16,7 +18,8 @@ */ @SuppressWarnings("unused") public class PowerGrid { - public static final Set GRID_SET = new HashSet<>(); + public static boolean isServerClosing = false; + public static final Set GRID_SET = Collections.synchronizedSet(new HashSet<>()); public static final int GRID_TICK = 40; public static int cooldown = 0; @Getter @@ -50,10 +53,11 @@ public static void tickGrid() { * 电力刻 */ protected void tick() { - this.flush(); + if (this.flush()) return; if (this.isWork()) { int remainder = this.generate - this.consume; for (IPowerStorage storage : storages) { + if (checkRemove(storage)) return; remainder = storage.insert(remainder); if (remainder <= 0) break; } @@ -72,15 +76,29 @@ protected void tick() { } } - private void flush() { + private boolean checkRemove(IPowerComponent component) { + if (component instanceof BlockEntity entity && entity.isRemoved()) { + PowerGrid.removeComponent(component); + return true; + } + return false; + } + + private boolean flush() { this.generate = 0; this.consume = 0; + for (IPowerTransmitter transmitter : transmitters) { + if (checkRemove(transmitter)) return true; + } for (IPowerProducer producer : this.producers) { + if (checkRemove(producer)) return true; this.generate += producer.getOutputPower(); } for (IPowerConsumer consumer : this.consumers) { + if (checkRemove(consumer)) return true; this.consume += consumer.getInputPower(); } + return false; } public boolean isWork() { @@ -136,6 +154,7 @@ private void addRange(IPowerComponent component) { * @param components 元件 */ public static void removeComponent(IPowerComponent @NotNull ... components) { + if (PowerGrid.isServerClosing) return; for (IPowerComponent component : components) { PowerGrid grid = component.getGrid(); if (grid == null) return; diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java index 5e268897d..3804dff1e 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEvent.java @@ -17,6 +17,7 @@ public class ServerLifecycleEvent { public static void init() { ServerLifecycleEvents.SERVER_STARTED.register(ServerLifecycleEvent::serverStarted); ServerLifecycleEvents.END_DATA_PACK_RELOAD.register(ServerLifecycleEvent::endDataPackReload); + ServerLifecycleEvents.SERVER_STOPPING.register(ServerLifecycleEvent::onServerStopping); ServerLifecycleEvents.SERVER_STOPPED.register(ServerLifecycleEvent::onServerStopped); ServerTickEvents.START_SERVER_TICK.register(ServerLifecycleEvent::startTick); } @@ -36,7 +37,12 @@ private static void startTick(MinecraftServer server) { PowerGrid.tickGrid(); } + private static void onServerStopping(MinecraftServer server) { + PowerGrid.isServerClosing = true; + } + private static void onServerStopped(MinecraftServer server) { + PowerGrid.isServerClosing = false; PowerGrid.clear(); } } diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java index 45d2eacb7..d7b6da46d 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEvent.java @@ -9,6 +9,7 @@ import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.server.ServerStartedEvent; import net.minecraftforge.event.server.ServerStoppedEvent; +import net.minecraftforge.event.server.ServerStoppingEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.jetbrains.annotations.NotNull; @@ -47,6 +48,15 @@ public static void onTick(@NotNull TickEvent.ServerTickEvent event) { */ @SubscribeEvent public static void onServerStopped(@NotNull ServerStoppedEvent event) { + PowerGrid.isServerClosing = false; PowerGrid.clear(); } + + /** + * @param event 服务器关闭事件 + */ + @SubscribeEvent + public static void onServerStopping(ServerStoppingEvent event) { + PowerGrid.isServerClosing = true; + } } From aa5a1320d07845244ad073bc852989c24a7771b1 Mon Sep 17 00:00:00 2001 From: Gugle Date: Wed, 17 Apr 2024 22:32:59 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/api/power/PowerGrid.java | 55 ++++++++++++++----- .../entity/TransmissionPoleBlockEntity.java | 5 +- .../client/renderer/PowerGridRenderer.java | 2 +- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java index 6023cca63..ee4803afd 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/power/PowerGrid.java @@ -1,5 +1,6 @@ package dev.dubhe.anvilcraft.api.power; +import dev.dubhe.anvilcraft.AnvilCraft; import lombok.Getter; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.entity.BlockEntity; @@ -11,6 +12,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.Set; /** @@ -19,7 +21,9 @@ @SuppressWarnings("unused") public class PowerGrid { public static boolean isServerClosing = false; - public static final Set GRID_SET = Collections.synchronizedSet(new HashSet<>()); + @Getter + private static Set gridSetClient = Collections.synchronizedSet(new HashSet<>()); + public static final Set GRID_SET = new HashSet<>(); public static final int GRID_TICK = 40; public static int cooldown = 0; @Getter @@ -35,6 +39,20 @@ public class PowerGrid { @Getter private BlockPos pos = null; + /** + * @return 获取电网中的元件数量 + */ + public int getComponentCount() { + return this.transmitters.size() + this.producers.size() + this.consumers.size() + this.storages.size(); + } + + /** + * @return 该电网是否为空电网 + */ + public boolean isEmpty() { + return this.getComponentCount() <= 0; + } + /** * 总电力刻 */ @@ -43,10 +61,14 @@ public static void tickGrid() { cooldown--; return; } - for (PowerGrid grid : PowerGrid.GRID_SET) { + Iterator iterator = PowerGrid.GRID_SET.iterator(); + while (iterator.hasNext()) { + PowerGrid grid = iterator.next(); + if (grid.isEmpty()) iterator.remove(); grid.tick(); } cooldown = GRID_TICK; + gridSetClient = Set.copyOf(GRID_SET); } /** @@ -154,11 +176,15 @@ private void addRange(IPowerComponent component) { * @param components 元件 */ public static void removeComponent(IPowerComponent @NotNull ... components) { - if (PowerGrid.isServerClosing) return; - for (IPowerComponent component : components) { - PowerGrid grid = component.getGrid(); - if (grid == null) return; - grid.remove(component); + try { + if (PowerGrid.isServerClosing) return; + for (IPowerComponent component : components) { + PowerGrid grid = component.getGrid(); + if (grid == null) return; + grid.remove(component); + } + } catch (Exception e) { + AnvilCraft.LOGGER.error(e.getMessage(), e); } } @@ -168,15 +194,15 @@ public static void removeComponent(IPowerComponent @NotNull ... components) { * @param components 电力元件 */ public void remove(IPowerComponent @NotNull ... components) { - Set set = new HashSet<>(); + Set set = new LinkedHashSet<>(); + this.transmitters.stream().filter(this::clearGrid).forEach(set::add); + this.transmitters.clear(); this.storages.stream().filter(this::clearGrid).forEach(set::add); this.storages.clear(); this.producers.stream().filter(this::clearGrid).forEach(set::add); this.producers.clear(); this.consumers.stream().filter(this::clearGrid).forEach(set::add); this.consumers.clear(); - this.transmitters.stream().filter(this::clearGrid).forEach(set::add); - this.transmitters.clear(); for (IPowerComponent component : components) { set.remove(component); } @@ -195,9 +221,13 @@ private boolean clearGrid(@NotNull IPowerComponent component) { * @param grid 电网 */ public void merge(@NotNull PowerGrid grid) { + grid.producers.forEach(producer -> producer.setGrid(this)); this.producers.addAll(grid.producers); + grid.consumers.forEach(producer -> producer.setGrid(this)); this.consumers.addAll(grid.consumers); + grid.storages.forEach(producer -> producer.setGrid(this)); this.storages.addAll(grid.storages); + grid.transmitters.forEach(producer -> producer.setGrid(this)); this.transmitters.addAll(grid.transmitters); } @@ -206,10 +236,9 @@ public void merge(@NotNull PowerGrid grid) { * @return 元件是否在电网范围内 */ public boolean isInRange(@NotNull IPowerComponent component) { - BlockPos vec3 = component.getPos(); - BlockPos center = this.getPos(); + BlockPos vec3 = component.getPos().subtract(this.getPos()); VoxelShape range = Shapes.join( - this.range.move(center.getX(), center.getY(), center.getZ()), + this.range, component.getRange().move(vec3.getX(), vec3.getY(), vec3.getZ()), BooleanOp.AND ); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/TransmissionPoleBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/TransmissionPoleBlockEntity.java index 8cc4f69cb..8b631a0be 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/TransmissionPoleBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/TransmissionPoleBlockEntity.java @@ -42,9 +42,8 @@ private TransmissionPoleBlockEntity(BlockEntityType type, BlockPos pos, Block @Override public @NotNull PowerComponentType getComponentType() { if (this.getLevel() == null) return PowerComponentType.INVALID; - BlockState state = this.getLevel().getBlockState(this.getPos()); - if (!state.is(ModBlocks.TRANSMISSION_POLE.get())) return PowerComponentType.INVALID; - if (state.getValue(TransmissionPoleBlock.HALF) != Half.TOP) return PowerComponentType.INVALID; + if (!this.getBlockState().is(ModBlocks.TRANSMISSION_POLE.get())) return PowerComponentType.INVALID; + if (this.getBlockState().getValue(TransmissionPoleBlock.HALF) != Half.TOP) return PowerComponentType.INVALID; return PowerComponentType.TRANSMITTER; } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/renderer/PowerGridRenderer.java b/common/src/main/java/dev/dubhe/anvilcraft/client/renderer/PowerGridRenderer.java index e6f8237cc..2388545ea 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/renderer/PowerGridRenderer.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/renderer/PowerGridRenderer.java @@ -20,7 +20,7 @@ public class PowerGridRenderer { public static void render(PoseStack poseStack, VertexConsumer consumer, double camX, double camY, double camZ) { if (Minecraft.getInstance().level == null) return; RandomSource random = Minecraft.getInstance().level.random; - for (PowerGrid grid : PowerGrid.GRID_SET) { + for (PowerGrid grid : PowerGrid.getGridSetClient()) { random.setSeed(grid.hashCode()); PowerGridRenderer.renderOutline( poseStack, consumer, camX, camY, camZ,