Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void setBuffer(@Nullable BlockPos pos) {
if (level == null || pos == null) {
this.buffer = null;
} else if (MetaMachine.getMachine(level, pos) instanceof ExpandedPatternBufferPartMachine machine) {
this.bufferPos = pos;
this.buffer = machine;
bufferPos = pos;
buffer = machine;
machine.addProxy(this);
if (!isRemote()) proxySlotRecipeHandler.updateProxy(machine);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public double getTotalContentAmount() {
return proxy == null ? 0 : proxy.getTotalContentAmount();
}

@Override
public int getPriority() {
return proxy == null ? IFilteredHandler.LOW : proxy.getPriority();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package net.neganote.gtutilities.integration.jade;

import com.gregtechceu.gtceu.GTCEu;

import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.neganote.gtutilities.integration.jade.provider.ExpandedMEPatternBufferProvider;
import net.neganote.gtutilities.integration.jade.provider.ExpandedMEPatternBufferProxyProvider;
import net.neganote.gtutilities.integration.jade.provider.PTERBInformationProvider;

import snownee.jade.api.IWailaClientRegistration;
Expand All @@ -16,10 +20,18 @@ public class UtilJadePlugin implements IWailaPlugin {
@Override
public void register(IWailaCommonRegistration registration) {
registration.registerBlockDataProvider(new PTERBInformationProvider(), BlockEntity.class);
if (GTCEu.Mods.isAE2Loaded()) {
registration.registerBlockDataProvider(new ExpandedMEPatternBufferProvider(), BlockEntity.class);
registration.registerBlockDataProvider(new ExpandedMEPatternBufferProxyProvider(), BlockEntity.class);
}
}

@Override
public void registerClient(IWailaClientRegistration registration) {
registration.registerBlockComponent(new PTERBInformationProvider(), Block.class);
if (GTCEu.Mods.isAE2Loaded()) {
registration.registerBlockComponent(new ExpandedMEPatternBufferProvider(), Block.class);
registration.registerBlockComponent(new ExpandedMEPatternBufferProxyProvider(), Block.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package net.neganote.gtutilities.integration.jade.provider;

import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.client.util.TooltipHelper;
import com.gregtechceu.gtceu.integration.jade.GTElementHelper;
import com.gregtechceu.gtceu.utils.FormattingUtil;

import net.minecraft.ChatFormatting;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.neganote.gtutilities.GregTechModernUtilities;
import net.neganote.gtutilities.integration.ae2.machine.ExpandedPatternBufferPartMachine;

import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
import snownee.jade.api.IServerDataProvider;
import snownee.jade.api.ITooltip;
import snownee.jade.api.config.IPluginConfig;
import snownee.jade.api.fluid.JadeFluidObject;
import snownee.jade.api.ui.IElementHelper;

public class ExpandedMEPatternBufferProvider implements IBlockComponentProvider, IServerDataProvider<BlockAccessor> {

@Override
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) {
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
if (blockEntity.getMetaMachine() instanceof ExpandedPatternBufferPartMachine) {
CompoundTag serverData = blockAccessor.getServerData();
if (!serverData.getBoolean("formed")) return;

iTooltip.add(Component.translatable("gtceu.top.proxies_bound", serverData.getInt("proxies"))
.withStyle(TooltipHelper.RAINBOW_HSL_SLOW));
readBufferTag(iTooltip, serverData);
}
}
}

@Override
public void appendServerData(CompoundTag compoundTag, BlockAccessor blockAccessor) {
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
if (blockEntity.getMetaMachine() instanceof ExpandedPatternBufferPartMachine buffer) {
if (!buffer.isFormed()) {
compoundTag.putBoolean("formed", false);
return;
}
compoundTag.putBoolean("formed", true);
compoundTag.putInt("proxies", buffer.getProxies().size());
writeBufferTag(compoundTag, buffer);
}
}
}

@Override
public ResourceLocation getUid() {
return GregTechModernUtilities.id("me_expanded_pattern_buffer");
}

public static void writeBufferTag(CompoundTag compoundTag, ExpandedPatternBufferPartMachine buffer) {
var merged = buffer.mergeInternalSlots();
var items = merged.items();
var fluids = merged.fluids();

ListTag itemsTag = new ListTag();
for (var entry : items.object2LongEntrySet()) {
var ct = entry.getKey().serializeNBT();
ct.putLong("real", entry.getLongValue());
itemsTag.add(ct);
}
if (!itemsTag.isEmpty()) compoundTag.put("items", itemsTag);

ListTag fluidsTag = new ListTag();
for (var entry : fluids.object2LongEntrySet()) {
var ct = entry.getKey().writeToNBT(new CompoundTag());
ct.putLong("real", entry.getLongValue());
fluidsTag.add(ct);
}
if (!fluidsTag.isEmpty()) compoundTag.put("fluids", fluidsTag);
}

public static void readBufferTag(ITooltip iTooltip, CompoundTag serverData) {
IElementHelper helper = iTooltip.getElementHelper();

ListTag itemsTag = serverData.getList("items", Tag.TAG_COMPOUND);
for (Tag t : itemsTag) {
if (!(t instanceof CompoundTag ct)) continue;
var stack = ItemStack.of(ct);
var count = ct.getLong("real");
if (!stack.isEmpty() && count > 0) {
iTooltip.add(helper.smallItem(stack));
Component text = Component.literal(" ")
.append(Component.literal(FormattingUtil.formatNumbers(count))
.withStyle(ChatFormatting.DARK_PURPLE))
.append(Component.literal("× ").withStyle(ChatFormatting.WHITE))
.append(stack.getHoverName().copy().withStyle(ChatFormatting.GOLD));
iTooltip.append(text);
}
}
ListTag fluidsTag = serverData.getList("fluids", Tag.TAG_COMPOUND);
for (Tag t : fluidsTag) {
if (!(t instanceof CompoundTag ct)) continue;
var stack = FluidStack.loadFluidStackFromNBT(ct);
var amount = ct.getLong("real");
if (!stack.isEmpty() && amount > 0) {
iTooltip.add(GTElementHelper.smallFluid(JadeFluidObject.of(stack.getFluid())));
Component text = Component.literal(" ")
.append(Component.literal(FormattingUtil.formatBuckets(amount)))
.withStyle(ChatFormatting.DARK_PURPLE)
.append(Component.literal(" ").withStyle(ChatFormatting.WHITE))
.append(stack.getDisplayName().copy().withStyle(ChatFormatting.DARK_AQUA));
iTooltip.append(text);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package net.neganote.gtutilities.integration.jade.provider;

import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.client.util.TooltipHelper;
import com.gregtechceu.gtceu.integration.jade.provider.MEPatternBufferProvider;

import net.minecraft.ChatFormatting;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.neganote.gtutilities.GregTechModernUtilities;
import net.neganote.gtutilities.integration.ae2.machine.ExpandedPatternBufferProxyPartMachine;

import snownee.jade.api.BlockAccessor;
import snownee.jade.api.IBlockComponentProvider;
import snownee.jade.api.IServerDataProvider;
import snownee.jade.api.ITooltip;
import snownee.jade.api.config.IPluginConfig;

public class ExpandedMEPatternBufferProxyProvider implements IBlockComponentProvider,
IServerDataProvider<BlockAccessor> {

@Override
public void appendTooltip(ITooltip iTooltip, BlockAccessor blockAccessor, IPluginConfig iPluginConfig) {
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
if (blockEntity.getMetaMachine() instanceof ExpandedPatternBufferProxyPartMachine) {
CompoundTag serverData = blockAccessor.getServerData();
if (!serverData.getBoolean("formed")) return;
if (!serverData.getBoolean("bound")) {
iTooltip.add(Component.translatable("gtceu.top.buffer_not_bound").withStyle(ChatFormatting.RED));
return;
}

int[] pos = serverData.getIntArray("pos");
iTooltip.add(Component.translatable("gtceu.top.buffer_bound_pos", pos[0], pos[1], pos[2])
.withStyle(TooltipHelper.RAINBOW_HSL_SLOW));

MEPatternBufferProvider.readBufferTag(iTooltip,
serverData);
}
}
}

@Override
public void appendServerData(CompoundTag compoundTag, BlockAccessor blockAccessor) {
if (blockAccessor.getBlockEntity() instanceof IMachineBlockEntity blockEntity) {
if (blockEntity.getMetaMachine() instanceof ExpandedPatternBufferProxyPartMachine proxy) {
if (!proxy.isFormed()) {
compoundTag.putBoolean("formed", false);
return;
}
compoundTag.putBoolean("formed", true);
var buffer = proxy.getBuffer();
if (buffer == null) {
compoundTag.putBoolean("bound", false);
return;
}
compoundTag.putBoolean("bound", true);

var pos = buffer.getPos();
compoundTag.putIntArray("pos", new int[] { pos.getX(), pos.getY(), pos.getZ() });
ExpandedMEPatternBufferProvider.writeBufferTag(compoundTag, buffer);
}
}
}

@Override
public ResourceLocation getUid() {
return GregTechModernUtilities.id("me_expanded_pattern_buffer_proxy");
}
}