diff options
| author | 2024-01-27 04:57:45 +0200 | |
|---|---|---|
| committer | 2024-01-27 04:57:45 +0200 | |
| commit | 9081089c2e47a20e4108ee322204e8c8dbde4169 (patch) | |
| tree | 0449d101a614d441ed922f52b3ce26971eb7d454 /src | |
| parent | Fix the fresh build (diff) | |
| download | mc-eris-alchemy-9081089c2e47a20e4108ee322204e8c8dbde4169.tar.gz mc-eris-alchemy-9081089c2e47a20e4108ee322204e8c8dbde4169.tar.xz mc-eris-alchemy-9081089c2e47a20e4108ee322204e8c8dbde4169.zip | |
Add support for WAILA (specifically with WTHIT).
Diffstat (limited to 'src')
10 files changed, 92 insertions, 35 deletions
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/Emc.java b/src/main/java/lv/enes/mc/eris_alchemy/Emc.java index 576fdc2..d278bcc 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/Emc.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/Emc.java | |||
| @@ -2,6 +2,7 @@ package lv.enes.mc.eris_alchemy; | |||
| 2 | 2 | ||
| 3 | import jakarta.annotation.Nullable; | 3 | import jakarta.annotation.Nullable; |
| 4 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry.NetworkingConstants; | 4 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry.NetworkingConstants; |
| 5 | import lv.enes.mc.eris_alchemy.block.EmcStorageBlock; | ||
| 5 | import lv.enes.mc.eris_alchemy.recipe.BannedRecipe; | 6 | import lv.enes.mc.eris_alchemy.recipe.BannedRecipe; |
| 6 | import lv.enes.mc.eris_alchemy.recipe.SimplifiedRecipe; | 7 | import lv.enes.mc.eris_alchemy.recipe.SimplifiedRecipe; |
| 7 | import lv.enes.mc.eris_alchemy.utils.*; | 8 | import lv.enes.mc.eris_alchemy.utils.*; |
| @@ -63,17 +64,12 @@ public final class Emc { | |||
| 63 | return get(itemId) | 64 | return get(itemId) |
| 64 | .stream() | 65 | .stream() |
| 65 | .map(value -> { | 66 | .map(value -> { |
| 66 | EmcStorage storage = null; | 67 | if (item instanceof BlockItem blockItem) { |
| 67 | if (item instanceof EmcStorage emcStorage) { | 68 | if (blockItem.getBlock() instanceof EmcStorageBlock block) { |
| 68 | storage = emcStorage; | 69 | return value + block.getStoredEmc(stack); |
| 69 | } else if (item instanceof BlockItem blockItem) { | ||
| 70 | if (blockItem.getBlock() instanceof EmcStorage emcStorage) { | ||
| 71 | storage = emcStorage; | ||
| 72 | } | 70 | } |
| 73 | } | 71 | } |
| 74 | if (storage != null) { | 72 | |
| 75 | return value + storage.getStoredEmc(stack); | ||
| 76 | } | ||
| 77 | return value; | 73 | return value; |
| 78 | }) | 74 | }) |
| 79 | .findFirst(); | 75 | .findFirst(); |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/EmcStorage.java b/src/main/java/lv/enes/mc/eris_alchemy/EmcStorage.java deleted file mode 100644 index 427a887..0000000 --- a/src/main/java/lv/enes/mc/eris_alchemy/EmcStorage.java +++ /dev/null | |||
| @@ -1,17 +0,0 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy; | ||
| 2 | |||
| 3 | import net.minecraft.nbt.CompoundTag; | ||
| 4 | import net.minecraft.world.item.BlockItem; | ||
| 5 | import net.minecraft.world.item.ItemStack; | ||
| 6 | |||
| 7 | public interface EmcStorage { | ||
| 8 | double getStoredEmc(ItemStack stack, CompoundTag blockEntityData); | ||
| 9 | |||
| 10 | default double getStoredEmc(ItemStack stack) { | ||
| 11 | var blockEntityData = BlockItem.getBlockEntityData(stack); | ||
| 12 | if (blockEntityData == null) { | ||
| 13 | return 0; | ||
| 14 | } | ||
| 15 | return getStoredEmc(stack, blockEntityData); | ||
| 16 | } | ||
| 17 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/EmcStorageBlock.java b/src/main/java/lv/enes/mc/eris_alchemy/block/EmcStorageBlock.java new file mode 100644 index 0000000..8c0b93e --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/block/EmcStorageBlock.java | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.block; | ||
| 2 | |||
| 3 | import net.minecraft.nbt.CompoundTag; | ||
| 4 | import net.minecraft.world.item.BlockItem; | ||
| 5 | import net.minecraft.world.item.ItemStack; | ||
| 6 | |||
| 7 | // TODO: Somehow make this be an automatic thing depending on the EmcStorageEntity or something | ||
| 8 | public interface EmcStorageBlock { | ||
| 9 | double getStoredEmc(CompoundTag blockEntityData); | ||
| 10 | |||
| 11 | default double getStoredEmc(ItemStack stack) { | ||
| 12 | var bed = BlockItem.getBlockEntityData(stack); | ||
| 13 | if (bed == null) { | ||
| 14 | return 0; | ||
| 15 | } | ||
| 16 | return getStoredEmc(bed); | ||
| 17 | } | ||
| 18 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/EnergyCondenserBlock.java b/src/main/java/lv/enes/mc/eris_alchemy/block/EnergyCondenserBlock.java index af58fc6..19eb681 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/EnergyCondenserBlock.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/block/EnergyCondenserBlock.java | |||
| @@ -3,7 +3,6 @@ package lv.enes.mc.eris_alchemy.block; | |||
| 3 | import jakarta.annotation.Nonnull; | 3 | import jakarta.annotation.Nonnull; |
| 4 | import jakarta.annotation.Nullable; | 4 | import jakarta.annotation.Nullable; |
| 5 | import lv.enes.mc.eris_alchemy.Emc; | 5 | import lv.enes.mc.eris_alchemy.Emc; |
| 6 | import lv.enes.mc.eris_alchemy.EmcStorage; | ||
| 7 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; | 6 | import lv.enes.mc.eris_alchemy.ErisAlchemyRegistry; |
| 8 | import lv.enes.mc.eris_alchemy.block.entity.EnergyCondenserEntity; | 7 | import lv.enes.mc.eris_alchemy.block.entity.EnergyCondenserEntity; |
| 9 | import net.minecraft.core.BlockPos; | 8 | import net.minecraft.core.BlockPos; |
| @@ -17,7 +16,7 @@ import net.minecraft.world.level.block.state.BlockState; | |||
| 17 | 16 | ||
| 18 | import java.util.List; | 17 | import java.util.List; |
| 19 | 18 | ||
| 20 | public class EnergyCondenserBlock extends ChestLikeBlock<EnergyCondenserEntity> implements EmcStorage { | 19 | public class EnergyCondenserBlock extends ChestLikeBlock<EnergyCondenserEntity> implements EmcStorageBlock { |
| 21 | public static final Component CONTAINER_TITLE | 20 | public static final Component CONTAINER_TITLE |
| 22 | = Component.translatable("container.eris_alchemy.energy_condenser"); | 21 | = Component.translatable("container.eris_alchemy.energy_condenser"); |
| 23 | 22 | ||
| @@ -44,7 +43,7 @@ public class EnergyCondenserBlock extends ChestLikeBlock<EnergyCondenserEntity> | |||
| 44 | } | 43 | } |
| 45 | 44 | ||
| 46 | @Override | 45 | @Override |
| 47 | public double getStoredEmc(ItemStack stack, CompoundTag blockEntityData) { | 46 | public double getStoredEmc(CompoundTag blockEntityData) { |
| 48 | return blockEntityData.getDouble("stored_emc"); | 47 | return blockEntityData.getDouble("stored_emc"); |
| 49 | } | 48 | } |
| 50 | 49 | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/EmcStorageEntity.java b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/EmcStorageEntity.java new file mode 100644 index 0000000..465e743 --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/EmcStorageEntity.java | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.block.entity; | ||
| 2 | |||
| 3 | public interface EmcStorageEntity { | ||
| 4 | double getMaxEmc(); | ||
| 5 | double getStoredEmc(); | ||
| 6 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/EnergyCondenserEntity.java b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/EnergyCondenserEntity.java index 33a6250..105e9e3 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/block/entity/EnergyCondenserEntity.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/block/entity/EnergyCondenserEntity.java | |||
| @@ -25,7 +25,7 @@ import org.quiltmc.loader.api.minecraft.ClientOnly; | |||
| 25 | 25 | ||
| 26 | import java.util.stream.IntStream; | 26 | import java.util.stream.IntStream; |
| 27 | 27 | ||
| 28 | public class EnergyCondenserEntity extends ChestLikeEntity implements ExtendedScreenHandlerFactory { | 28 | public class EnergyCondenserEntity extends ChestLikeEntity implements EmcStorageEntity, ExtendedScreenHandlerFactory { |
| 29 | private final static int WIDTH = 13; | 29 | private final static int WIDTH = 13; |
| 30 | private final static int HEIGHT = 7; | 30 | private final static int HEIGHT = 7; |
| 31 | 31 | ||
| @@ -49,6 +49,11 @@ public class EnergyCondenserEntity extends ChestLikeEntity implements ExtendedSc | |||
| 49 | return items; | 49 | return items; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | @Override | ||
| 53 | public double getMaxEmc() { | ||
| 54 | return Emc.get(items.get(0)).orElse(Double.POSITIVE_INFINITY); | ||
| 55 | } | ||
| 56 | |||
| 52 | @ClientOnly | 57 | @ClientOnly |
| 53 | @Nonnull | 58 | @Nonnull |
| 54 | public Material getMaterial() { | 59 | public Material getMaterial() { |
| @@ -61,6 +66,7 @@ public class EnergyCondenserEntity extends ChestLikeEntity implements ExtendedSc | |||
| 61 | return Blocks.ENERGY_CONDENSER; | 66 | return Blocks.ENERGY_CONDENSER; |
| 62 | } | 67 | } |
| 63 | 68 | ||
| 69 | @Override | ||
| 64 | public double getStoredEmc() { | 70 | public double getStoredEmc() { |
| 65 | return storedEmc.getValue(); | 71 | return storedEmc.getValue(); |
| 66 | } | 72 | } |
| @@ -89,11 +95,9 @@ public class EnergyCondenserEntity extends ChestLikeEntity implements ExtendedSc | |||
| 89 | @Override | 95 | @Override |
| 90 | public void tick(Level world, BlockPos pos, BlockState state) { | 96 | public void tick(Level world, BlockPos pos, BlockState state) { |
| 91 | super.tick(world, pos, state); | 97 | super.tick(world, pos, state); |
| 92 | Emc.get(items.get(0)).ifPresent(cost -> { | 98 | var cost = getMaxEmc(); |
| 93 | tryConsumeEmc(cost); | 99 | tryConsumeEmc(cost); |
| 94 | tryCloneTemplate(cost); | 100 | tryCloneTemplate(cost); |
| 95 | }); | ||
| 96 | |||
| 97 | this.storedEmc.syncIfChanged(ContainerOpenersCounterUtil.getOpeners(openersCounter)); | 101 | this.storedEmc.syncIfChanged(ContainerOpenersCounterUtil.getOpeners(openersCounter)); |
| 98 | } | 102 | } |
| 99 | 103 | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/waila/EmcProvider.java b/src/main/java/lv/enes/mc/eris_alchemy/waila/EmcProvider.java new file mode 100644 index 0000000..190ebbe --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/waila/EmcProvider.java | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.waila; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.block.entity.EmcStorageEntity; | ||
| 4 | import mcp.mobius.waila.api.IDataProvider; | ||
| 5 | import mcp.mobius.waila.api.IDataWriter; | ||
| 6 | import mcp.mobius.waila.api.IPluginConfig; | ||
| 7 | import mcp.mobius.waila.api.IServerAccessor; | ||
| 8 | import mcp.mobius.waila.api.data.EnergyData; | ||
| 9 | import net.minecraft.world.level.block.entity.BlockEntity; | ||
| 10 | |||
| 11 | public enum EmcProvider implements IDataProvider<BlockEntity> { | ||
| 12 | INSTANCE; | ||
| 13 | |||
| 14 | @Override | ||
| 15 | public void appendData(IDataWriter data, IServerAccessor<BlockEntity> accessor, IPluginConfig config) { | ||
| 16 | data.add(EnergyData.class, res -> { | ||
| 17 | if (accessor.getTarget() instanceof EmcStorageEntity storage) { | ||
| 18 | res.add(EnergyData.of(storage.getStoredEmc(), storage.getMaxEmc())); | ||
| 19 | } | ||
| 20 | }); | ||
| 21 | } | ||
| 22 | } | ||
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/waila/WailaPlugin.java b/src/main/java/lv/enes/mc/eris_alchemy/waila/WailaPlugin.java new file mode 100644 index 0000000..db797bf --- /dev/null +++ b/src/main/java/lv/enes/mc/eris_alchemy/waila/WailaPlugin.java | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | package lv.enes.mc.eris_alchemy.waila; | ||
| 2 | |||
| 3 | import lv.enes.mc.eris_alchemy.ErisAlchemy; | ||
| 4 | import mcp.mobius.waila.api.IRegistrar; | ||
| 5 | import mcp.mobius.waila.api.IWailaPlugin; | ||
| 6 | import mcp.mobius.waila.api.data.EnergyData; | ||
| 7 | import net.minecraft.network.chat.Component; | ||
| 8 | import net.minecraft.world.level.block.entity.BlockEntity; | ||
| 9 | |||
| 10 | @SuppressWarnings("unused") | ||
| 11 | public class WailaPlugin implements IWailaPlugin { | ||
| 12 | @Override | ||
| 13 | public void register(IRegistrar registrar) { | ||
| 14 | registrar.addBlockData(EmcProvider.INSTANCE, BlockEntity.class); | ||
| 15 | |||
| 16 | EnergyData.describe(ErisAlchemy.ID) | ||
| 17 | .name(Component.translatable("gui.eris_alchemy.stored_emc")) | ||
| 18 | .unit(""); | ||
| 19 | } | ||
| 20 | } | ||
diff --git a/src/main/resources/assets/eris_alchemy/lang/en_us.json b/src/main/resources/assets/eris_alchemy/lang/en_us.json index c399a68..c797ac8 100644 --- a/src/main/resources/assets/eris_alchemy/lang/en_us.json +++ b/src/main/resources/assets/eris_alchemy/lang/en_us.json | |||
| @@ -9,6 +9,8 @@ | |||
| 9 | "container.eris_alchemy.alchemical_chest": "Alchemical Chest", | 9 | "container.eris_alchemy.alchemical_chest": "Alchemical Chest", |
| 10 | "container.eris_alchemy.energy_condenser": "Energy Condenser", | 10 | "container.eris_alchemy.energy_condenser": "Energy Condenser", |
| 11 | 11 | ||
| 12 | "gui.eris_alchemy.stored_emc": "Stored EMC", | ||
| 13 | |||
| 12 | "item.eris_alchemy.low_covalence_dust": "Low Covalence Dust", | 14 | "item.eris_alchemy.low_covalence_dust": "Low Covalence Dust", |
| 13 | "item.eris_alchemy.medium_covalence_dust": "Medium Covalence Dust", | 15 | "item.eris_alchemy.medium_covalence_dust": "Medium Covalence Dust", |
| 14 | "item.eris_alchemy.high_covalence_dust": "High Covalence Dust", | 16 | "item.eris_alchemy.high_covalence_dust": "High Covalence Dust", |
diff --git a/src/main/resources/waila_plugins.json b/src/main/resources/waila_plugins.json new file mode 100644 index 0000000..13951db --- /dev/null +++ b/src/main/resources/waila_plugins.json | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | { | ||
| 2 | "eris_alchemy:plugin": { | ||
| 3 | "initializer": "lv.enes.mc.eris_alchemy.waila.WailaPlugin", | ||
| 4 | "side": "*", | ||
| 5 | "required": [] | ||
| 6 | } | ||
| 7 | } \ No newline at end of file | ||