From cf36092f94d6413ea0e8d17f6779497465de28c4 Mon Sep 17 00:00:00 2001 From: TheMCLoveMan Date: Mon, 26 Feb 2024 21:26:29 +0100 Subject: [PATCH] finish up jade plugin Co-authored-by: TheMCCrazyMan --- gradle.properties | 2 +- .../entity/AbstractMachineBlockEntity.java | 17 +----- .../entity/CoalGeneratorBlockEntity.java | 4 +- .../block/entity/CompactorBlockEntity.java | 4 +- .../block/entity/CrusherBlockEntity.java | 4 +- .../entity/ElectricSmelterBlockEntity.java | 4 +- .../entity/LavaGeneratorBlockEntity.java | 5 +- .../compat/jade/MachineProvider.java | 59 +++++++++++++++---- .../compat/jade/MachineryJadePlugin.java | 1 + .../jade/RemoveVanillaStuffProvider.java | 38 ++++++++++++ .../datagen/MachineryLanguageProvider.java | 1 + 11 files changed, 99 insertions(+), 40 deletions(-) create mode 100644 src/main/java/net/themcbrothers/usefulmachinery/compat/jade/RemoveVanillaStuffProvider.java diff --git a/gradle.properties b/gradle.properties index 6066c47..944d09a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ minecraft_version_range=[1.20.4,1.21) # NeoForge neo_version=20.4.167 -neo_version_range=[20.4,) +neo_version_range=[20.4.167,) loader_version_range=[2,) # Mappings diff --git a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/AbstractMachineBlockEntity.java b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/AbstractMachineBlockEntity.java index 5cde8e5..4790be8 100644 --- a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/AbstractMachineBlockEntity.java +++ b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/AbstractMachineBlockEntity.java @@ -31,7 +31,6 @@ import org.apache.commons.lang3.ArrayUtils; import javax.annotation.Nullable; -import java.util.Arrays; import java.util.function.Function; public abstract class AbstractMachineBlockEntity extends BlockEntity implements WorldlyContainer, MenuProvider { @@ -158,9 +157,9 @@ public void clearContent() { this.stacks.clear(); } - protected abstract int[] getInputSlots(); + public abstract int[] getInputSlots(); - protected abstract int[] getOutputSlots(); + public abstract int[] getOutputSlots(); protected abstract boolean canRun(); @@ -350,16 +349,4 @@ public void setRedstoneMode(RedstoneMode redstoneMode) { public Container getUpgradeContainer() { return this.upgradeContainer; } - - public int[] getInputsForJade() { - return this.getInputSlots(); - } - - public int[] getOutputsForJade() { - return this.getOutputSlots(); - } - - public boolean showJadeProgress() { - return Arrays.stream(ArrayUtils.addAll(this.getInputSlots(), this.getOutputSlots())).mapToObj(this::getItem).anyMatch(itemStack -> !itemStack.isEmpty()); - } } diff --git a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CoalGeneratorBlockEntity.java b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CoalGeneratorBlockEntity.java index 5704aac..e40c920 100644 --- a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CoalGeneratorBlockEntity.java +++ b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CoalGeneratorBlockEntity.java @@ -58,12 +58,12 @@ public CoalGeneratorBlockEntity(BlockPos pos, BlockState state) { } @Override - protected int[] getInputSlots() { + public int[] getInputSlots() { return new int[]{0}; } @Override - protected int[] getOutputSlots() { + public int[] getOutputSlots() { return new int[0]; } diff --git a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CompactorBlockEntity.java b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CompactorBlockEntity.java index e7964b2..b36c3ec 100644 --- a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CompactorBlockEntity.java +++ b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CompactorBlockEntity.java @@ -63,12 +63,12 @@ public CompactorBlockEntity(BlockPos pos, BlockState state) { } @Override - protected int[] getInputSlots() { + public int[] getInputSlots() { return new int[]{0}; } @Override - protected int[] getOutputSlots() { + public int[] getOutputSlots() { return new int[]{1}; } diff --git a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CrusherBlockEntity.java b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CrusherBlockEntity.java index 41de171..aefc072 100644 --- a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CrusherBlockEntity.java +++ b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/CrusherBlockEntity.java @@ -59,12 +59,12 @@ public CrusherBlockEntity(BlockPos pos, BlockState state) { } @Override - protected int[] getInputSlots() { + public int[] getInputSlots() { return new int[]{0}; } @Override - protected int[] getOutputSlots() { + public int[] getOutputSlots() { return new int[]{1, 2}; } diff --git a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/ElectricSmelterBlockEntity.java b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/ElectricSmelterBlockEntity.java index 414e9e3..1c5a036 100644 --- a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/ElectricSmelterBlockEntity.java +++ b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/ElectricSmelterBlockEntity.java @@ -56,12 +56,12 @@ public ElectricSmelterBlockEntity(BlockPos pos, BlockState state) { } @Override - protected int[] getInputSlots() { + public int[] getInputSlots() { return new int[]{0}; } @Override - protected int[] getOutputSlots() { + public int[] getOutputSlots() { return new int[]{1}; } diff --git a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/LavaGeneratorBlockEntity.java b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/LavaGeneratorBlockEntity.java index 145c637..daa7efd 100644 --- a/src/main/java/net/themcbrothers/usefulmachinery/block/entity/LavaGeneratorBlockEntity.java +++ b/src/main/java/net/themcbrothers/usefulmachinery/block/entity/LavaGeneratorBlockEntity.java @@ -18,7 +18,6 @@ import net.neoforged.neoforge.fluids.FluidUtil; import net.neoforged.neoforge.fluids.capability.IFluidHandler; import net.neoforged.neoforge.fluids.capability.templates.FluidTank; -import net.themcbrothers.usefulmachinery.block.AbstractMachineBlock; import net.themcbrothers.usefulmachinery.core.MachineryBlockEntities; import net.themcbrothers.usefulmachinery.core.MachineryItems; import net.themcbrothers.usefulmachinery.machine.RedstoneMode; @@ -76,12 +75,12 @@ public LavaGeneratorBlockEntity(BlockPos pos, BlockState state) { } @Override - protected int[] getInputSlots() { + public int[] getInputSlots() { return new int[]{0}; } @Override - protected int[] getOutputSlots() { + public int[] getOutputSlots() { return new int[0]; } diff --git a/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/MachineProvider.java b/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/MachineProvider.java index a68bf0c..e742eb0 100644 --- a/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/MachineProvider.java +++ b/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/MachineProvider.java @@ -3,11 +3,14 @@ import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.Vec2; import net.themcbrothers.usefulmachinery.UsefulMachinery; import net.themcbrothers.usefulmachinery.block.entity.AbstractMachineBlockEntity; +import net.themcbrothers.usefulmachinery.core.MachineryItems; +import net.themcbrothers.usefulmachinery.machine.MachineTier; import snownee.jade.api.BlockAccessor; import snownee.jade.api.IBlockComponentProvider; import snownee.jade.api.IServerDataProvider; @@ -15,6 +18,10 @@ import snownee.jade.api.config.IPluginConfig; import snownee.jade.api.ui.IElementHelper; +import java.util.Arrays; +import java.util.Optional; +import java.util.stream.IntStream; + public enum MachineProvider implements IBlockComponentProvider, IServerDataProvider { INSTANCE; @@ -23,6 +30,8 @@ public enum MachineProvider implements IBlockComponentProvider, IServerDataProvi @Override public void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfig pluginConfig) { CompoundTag data = accessor.getServerData(); + IElementHelper helper = IElementHelper.get(); + if (data.contains("progress")) { ListTag machineItems = data.getList("machine", ListTag.TAG_COMPOUND); NonNullList inventory = NonNullList.withSize(data.getInt("size"), ItemStack.EMPTY); @@ -31,12 +40,11 @@ public void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfi inventory.set(i, ItemStack.of(machineItems.getCompound(i))); } - IElementHelper helper = IElementHelper.get(); - int progress = data.getInt("progress"); int total = data.getInt("total"); int count = 0; + for (int slot : data.getIntArray("inputs")) { if (count++ == 0) { tooltip.add(helper.item(inventory.get(slot))); @@ -45,36 +53,61 @@ public void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfi } } - // progress bar + // Progress Bar tooltip.append(helper.spacer(4, 0)); - tooltip.append(helper.progress((float) progress / (float) total).translate(new Vec2(-2.0F, 0.0F))); + tooltip.append(helper.progress((float) progress / (float) total) + .translate(new Vec2(-2.0F, 0.0F))); - for (int slot : data.getIntArray("outputs")) { - tooltip.append(helper.item(inventory.get(slot))); - } + Arrays.stream(data.getIntArray("outputs")) + .mapToObj(inventory::get) + .map(helper::item) + .forEach(tooltip::append); + } + + MachineTier tier = MachineTier.byOrdinal(data.getInt("tier")); + if (accessor.getPlayer().isShiftKeyDown() && tier.ordinal() > 0) { + CompoundTag tierTag = new CompoundTag(); + tierTag.putInt("Tier", tier.ordinal()); + + // Tier + tooltip.add(helper.smallItem(new ItemStack(MachineryItems.TIER_UPGRADE.get(), 1, Optional.of(tierTag)))); + tooltip.append(helper.spacer(4, 0)); + tooltip.append(helper.text(Component.literal(tier.getSerializedName()))); } + } @Override public void appendServerData(CompoundTag data, BlockAccessor accessor) { AbstractMachineBlockEntity machine = (AbstractMachineBlockEntity) accessor.getBlockEntity(); - if (machine.showJadeProgress()) { + + boolean showJadeProgress = Arrays.stream(machine.getSlotsForFace(null)) + .mapToObj(machine::getItem) + .anyMatch(itemStack -> !itemStack.isEmpty()); + + if (showJadeProgress) { ListTag items = new ListTag(); - for (int i = 0; i < machine.getContainerSize(); ++i) { - items.add(machine.getItem(i).save(new CompoundTag())); - } + IntStream.range(0, machine.getContainerSize()) + .mapToObj(machine::getItem) + .map(stack -> stack.save(new CompoundTag())) + .forEach(items::add); - data.putIntArray("inputs", machine.getInputsForJade()); - data.putIntArray("outputs", machine.getOutputsForJade()); + data.putIntArray("inputs", machine.getInputSlots()); + data.putIntArray("outputs", machine.getOutputSlots()); data.putInt("size", machine.getContainerSize()); data.put("machine", items); + CompoundTag furnaceTag = machine.saveWithoutMetadata(); + data.putInt("progress", furnaceTag.getInt("ProcessTime")); data.putInt("total", furnaceTag.getInt("ProcessTimeTotal")); + } + + data.putInt("tier", machine.getMachineTier(accessor.getBlockState()).ordinal()); } @Override diff --git a/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/MachineryJadePlugin.java b/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/MachineryJadePlugin.java index 823c6ce..acd8394 100644 --- a/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/MachineryJadePlugin.java +++ b/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/MachineryJadePlugin.java @@ -20,5 +20,6 @@ public void register(IWailaCommonRegistration registration) { @Override public void registerClient(IWailaClientRegistration registration) { registration.registerBlockComponent(MachineProvider.INSTANCE, AbstractMachineBlock.class); + registration.registerBlockComponent(RemoveVanillaStuffProvider.INSTANCE, AbstractMachineBlock.class); } } diff --git a/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/RemoveVanillaStuffProvider.java b/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/RemoveVanillaStuffProvider.java new file mode 100644 index 0000000..f8e72b1 --- /dev/null +++ b/src/main/java/net/themcbrothers/usefulmachinery/compat/jade/RemoveVanillaStuffProvider.java @@ -0,0 +1,38 @@ +package net.themcbrothers.usefulmachinery.compat.jade; + +import net.minecraft.resources.ResourceLocation; +import net.themcbrothers.usefulmachinery.UsefulMachinery; +import net.themcbrothers.usefulmachinery.block.entity.AbstractMachineBlockEntity; +import snownee.jade.api.BlockAccessor; +import snownee.jade.api.IBlockComponentProvider; +import snownee.jade.api.ITooltip; +import snownee.jade.api.Identifiers; +import snownee.jade.api.config.IPluginConfig; + +public enum RemoveVanillaStuffProvider implements IBlockComponentProvider { + INSTANCE; + + private static final ResourceLocation UID = UsefulMachinery.rl("remove_vanilla_stuff"); + + @Override + public void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfig pluginConfig) { + if (accessor.getBlockEntity() instanceof AbstractMachineBlockEntity) { + tooltip.remove(Identifiers.UNIVERSAL_ITEM_STORAGE); + } + } + + @Override + public ResourceLocation getUid() { + return UID; + } + + @Override + public int getDefaultPriority() { + return Integer.MAX_VALUE; + } + + @Override + public boolean isRequired() { + return true; + } +} diff --git a/src/main/java/net/themcbrothers/usefulmachinery/datagen/MachineryLanguageProvider.java b/src/main/java/net/themcbrothers/usefulmachinery/datagen/MachineryLanguageProvider.java index 387f87a..ae38fc2 100644 --- a/src/main/java/net/themcbrothers/usefulmachinery/datagen/MachineryLanguageProvider.java +++ b/src/main/java/net/themcbrothers/usefulmachinery/datagen/MachineryLanguageProvider.java @@ -61,6 +61,7 @@ protected void addTranslations() { // Jade this.add("config.jade.plugin_usefulmachinery.machine", "Machine"); + this.add("config.jade.plugin_usefulmachinery.remove_vanilla_stuff", "Remove Vanilla Stuff"); // Misc this.add("misc.usefulmachinery.energy", "%s FE");