Skip to content

Commit 85501be

Browse files
Missing jade providers for expanded pattern buffers. (#24)
* datagen * Fix some sync issues and added a jade provider for the expanded pattern buffer and proxy. * Idk man, just let me do the thing. * Please just work. * Please just work. * Please just work. * Requested changes. * Requested changes. * I've found the spot, and now it's less. --------- Co-authored-by: NegaNote <neganote43@gmail.com>
1 parent 7bb0d16 commit 85501be

5 files changed

Lines changed: 205 additions & 2 deletions

File tree

src/main/java/net/neganote/gtutilities/integration/ae2/machine/ExpandedPatternBufferProxyPartMachine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public void setBuffer(@Nullable BlockPos pos) {
7676
if (level == null || pos == null) {
7777
this.buffer = null;
7878
} else if (MetaMachine.getMachine(level, pos) instanceof ExpandedPatternBufferPartMachine machine) {
79-
this.bufferPos = pos;
80-
this.buffer = machine;
79+
bufferPos = pos;
80+
buffer = machine;
8181
machine.addProxy(this);
8282
if (!isRemote()) proxySlotRecipeHandler.updateProxy(machine);
8383
} else {

src/main/java/net/neganote/gtutilities/integration/ae2/machine/trait/ExpandedProxySlotRecipeHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public double getTotalContentAmount() {
191191
return proxy == null ? 0 : proxy.getTotalContentAmount();
192192
}
193193

194+
@Override
194195
public int getPriority() {
195196
return proxy == null ? IFilteredHandler.LOW : proxy.getPriority();
196197
}

src/main/java/net/neganote/gtutilities/integration/jade/UtilJadePlugin.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package net.neganote.gtutilities.integration.jade;
22

3+
import com.gregtechceu.gtceu.GTCEu;
4+
35
import net.minecraft.world.level.block.Block;
46
import net.minecraft.world.level.block.entity.BlockEntity;
7+
import net.neganote.gtutilities.integration.jade.provider.ExpandedMEPatternBufferProvider;
8+
import net.neganote.gtutilities.integration.jade.provider.ExpandedMEPatternBufferProxyProvider;
59
import net.neganote.gtutilities.integration.jade.provider.PTERBInformationProvider;
610

711
import snownee.jade.api.IWailaClientRegistration;
@@ -16,10 +20,18 @@ public class UtilJadePlugin implements IWailaPlugin {
1620
@Override
1721
public void register(IWailaCommonRegistration registration) {
1822
registration.registerBlockDataProvider(new PTERBInformationProvider(), BlockEntity.class);
23+
if (GTCEu.Mods.isAE2Loaded()) {
24+
registration.registerBlockDataProvider(new ExpandedMEPatternBufferProvider(), BlockEntity.class);
25+
registration.registerBlockDataProvider(new ExpandedMEPatternBufferProxyProvider(), BlockEntity.class);
26+
}
1927
}
2028

2129
@Override
2230
public void registerClient(IWailaClientRegistration registration) {
2331
registration.registerBlockComponent(new PTERBInformationProvider(), Block.class);
32+
if (GTCEu.Mods.isAE2Loaded()) {
33+
registration.registerBlockComponent(new ExpandedMEPatternBufferProvider(), Block.class);
34+
registration.registerBlockComponent(new ExpandedMEPatternBufferProxyProvider(), Block.class);
35+
}
2436
}
2537
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package net.neganote.gtutilities.integration.jade.provider;
2+
3+
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
4+
import com.gregtechceu.gtceu.client.util.TooltipHelper;
5+
import com.gregtechceu.gtceu.integration.jade.GTElementHelper;
6+
import com.gregtechceu.gtceu.utils.FormattingUtil;
7+
8+
import net.minecraft.ChatFormatting;
9+
import net.minecraft.nbt.CompoundTag;
10+
import net.minecraft.nbt.ListTag;
11+
import net.minecraft.nbt.Tag;
12+
import net.minecraft.network.chat.Component;
13+
import net.minecraft.resources.ResourceLocation;
14+
import net.minecraft.world.item.ItemStack;
15+
import net.minecraftforge.fluids.FluidStack;
16+
import net.neganote.gtutilities.GregTechModernUtilities;
17+
import net.neganote.gtutilities.integration.ae2.machine.ExpandedPatternBufferPartMachine;
18+
19+
import snownee.jade.api.BlockAccessor;
20+
import snownee.jade.api.IBlockComponentProvider;
21+
import snownee.jade.api.IServerDataProvider;
22+
import snownee.jade.api.ITooltip;
23+
import snownee.jade.api.config.IPluginConfig;
24+
import snownee.jade.api.fluid.JadeFluidObject;
25+
import snownee.jade.api.ui.IElementHelper;
26+
27+
public class ExpandedMEPatternBufferProvider implements IBlockComponentProvider, IServerDataProvider<BlockAccessor> {
28+
29+
@Override
30+
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) {
31+
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
32+
if (blockEntity.getMetaMachine() instanceof ExpandedPatternBufferPartMachine) {
33+
CompoundTag serverData = blockAccessor.getServerData();
34+
if (!serverData.getBoolean("formed")) return;
35+
36+
iTooltip.add(Component.translatable("gtceu.top.proxies_bound", serverData.getInt("proxies"))
37+
.withStyle(TooltipHelper.RAINBOW_HSL_SLOW));
38+
readBufferTag(iTooltip, serverData);
39+
}
40+
}
41+
}
42+
43+
@Override
44+
public void appendServerData(CompoundTag compoundTag, BlockAccessor blockAccessor) {
45+
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
46+
if (blockEntity.getMetaMachine() instanceof ExpandedPatternBufferPartMachine buffer) {
47+
if (!buffer.isFormed()) {
48+
compoundTag.putBoolean("formed", false);
49+
return;
50+
}
51+
compoundTag.putBoolean("formed", true);
52+
compoundTag.putInt("proxies", buffer.getProxies().size());
53+
writeBufferTag(compoundTag, buffer);
54+
}
55+
}
56+
}
57+
58+
@Override
59+
public ResourceLocation getUid() {
60+
return GregTechModernUtilities.id("me_expanded_pattern_buffer");
61+
}
62+
63+
public static void writeBufferTag(CompoundTag compoundTag, ExpandedPatternBufferPartMachine buffer) {
64+
var merged = buffer.mergeInternalSlots();
65+
var items = merged.items();
66+
var fluids = merged.fluids();
67+
68+
ListTag itemsTag = new ListTag();
69+
for (var entry : items.object2LongEntrySet()) {
70+
var ct = entry.getKey().serializeNBT();
71+
ct.putLong("real", entry.getLongValue());
72+
itemsTag.add(ct);
73+
}
74+
if (!itemsTag.isEmpty()) compoundTag.put("items", itemsTag);
75+
76+
ListTag fluidsTag = new ListTag();
77+
for (var entry : fluids.object2LongEntrySet()) {
78+
var ct = entry.getKey().writeToNBT(new CompoundTag());
79+
ct.putLong("real", entry.getLongValue());
80+
fluidsTag.add(ct);
81+
}
82+
if (!fluidsTag.isEmpty()) compoundTag.put("fluids", fluidsTag);
83+
}
84+
85+
public static void readBufferTag(ITooltip iTooltip, CompoundTag serverData) {
86+
IElementHelper helper = iTooltip.getElementHelper();
87+
88+
ListTag itemsTag = serverData.getList("items", Tag.TAG_COMPOUND);
89+
for (Tag t : itemsTag) {
90+
if (!(t instanceof CompoundTag ct)) continue;
91+
var stack = ItemStack.of(ct);
92+
var count = ct.getLong("real");
93+
if (!stack.isEmpty() && count > 0) {
94+
iTooltip.add(helper.smallItem(stack));
95+
Component text = Component.literal(" ")
96+
.append(Component.literal(FormattingUtil.formatNumbers(count))
97+
.withStyle(ChatFormatting.DARK_PURPLE))
98+
.append(Component.literal("× ").withStyle(ChatFormatting.WHITE))
99+
.append(stack.getHoverName().copy().withStyle(ChatFormatting.GOLD));
100+
iTooltip.append(text);
101+
}
102+
}
103+
ListTag fluidsTag = serverData.getList("fluids", Tag.TAG_COMPOUND);
104+
for (Tag t : fluidsTag) {
105+
if (!(t instanceof CompoundTag ct)) continue;
106+
var stack = FluidStack.loadFluidStackFromNBT(ct);
107+
var amount = ct.getLong("real");
108+
if (!stack.isEmpty() && amount > 0) {
109+
iTooltip.add(GTElementHelper.smallFluid(JadeFluidObject.of(stack.getFluid())));
110+
Component text = Component.literal(" ")
111+
.append(Component.literal(FormattingUtil.formatBuckets(amount)))
112+
.withStyle(ChatFormatting.DARK_PURPLE)
113+
.append(Component.literal(" ").withStyle(ChatFormatting.WHITE))
114+
.append(stack.getDisplayName().copy().withStyle(ChatFormatting.DARK_AQUA));
115+
iTooltip.append(text);
116+
}
117+
}
118+
}
119+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package net.neganote.gtutilities.integration.jade.provider;
2+
3+
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
4+
import com.gregtechceu.gtceu.client.util.TooltipHelper;
5+
import com.gregtechceu.gtceu.integration.jade.provider.MEPatternBufferProvider;
6+
7+
import net.minecraft.ChatFormatting;
8+
import net.minecraft.nbt.CompoundTag;
9+
import net.minecraft.network.chat.Component;
10+
import net.minecraft.resources.ResourceLocation;
11+
import net.neganote.gtutilities.GregTechModernUtilities;
12+
import net.neganote.gtutilities.integration.ae2.machine.ExpandedPatternBufferProxyPartMachine;
13+
14+
import snownee.jade.api.BlockAccessor;
15+
import snownee.jade.api.IBlockComponentProvider;
16+
import snownee.jade.api.IServerDataProvider;
17+
import snownee.jade.api.ITooltip;
18+
import snownee.jade.api.config.IPluginConfig;
19+
20+
public class ExpandedMEPatternBufferProxyProvider implements IBlockComponentProvider,
21+
IServerDataProvider<BlockAccessor> {
22+
23+
@Override
24+
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) {
25+
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
26+
if (blockEntity.getMetaMachine() instanceof ExpandedPatternBufferProxyPartMachine) {
27+
CompoundTag serverData = blockAccessor.getServerData();
28+
if (!serverData.getBoolean("formed")) return;
29+
if (!serverData.getBoolean("bound")) {
30+
iTooltip.add(Component.translatable("gtceu.top.buffer_not_bound").withStyle(ChatFormatting.RED));
31+
return;
32+
}
33+
34+
int[] pos = serverData.getIntArray("pos");
35+
iTooltip.add(Component.translatable("gtceu.top.buffer_bound_pos", pos[0], pos[1], pos[2])
36+
.withStyle(TooltipHelper.RAINBOW_HSL_SLOW));
37+
38+
MEPatternBufferProvider.readBufferTag(iTooltip,
39+
serverData);
40+
}
41+
}
42+
}
43+
44+
@Override
45+
public void appendServerData(CompoundTag compoundTag, BlockAccessor blockAccessor) {
46+
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
47+
if (blockEntity.getMetaMachine() instanceof ExpandedPatternBufferProxyPartMachine proxy) {
48+
if (!proxy.isFormed()) {
49+
compoundTag.putBoolean("formed", false);
50+
return;
51+
}
52+
compoundTag.putBoolean("formed", true);
53+
var buffer = proxy.getBuffer();
54+
if (buffer == null) {
55+
compoundTag.putBoolean("bound", false);
56+
return;
57+
}
58+
compoundTag.putBoolean("bound", true);
59+
60+
var pos = buffer.getPos();
61+
compoundTag.putIntArray("pos", new int[] { pos.getX(), pos.getY(), pos.getZ() });
62+
ExpandedMEPatternBufferProvider.writeBufferTag(compoundTag, buffer);
63+
}
64+
}
65+
}
66+
67+
@Override
68+
public ResourceLocation getUid() {
69+
return GregTechModernUtilities.id("me_expanded_pattern_buffer_proxy");
70+
}
71+
}

0 commit comments

Comments
 (0)