Created
July 27, 2024 22:34
-
-
Save Zorbatron/e1518ca5fc28854b179d5b89e60634db to your computer and use it in GitHub Desktop.
Multiple DualHandlers test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package gregtech.common.metatileentities.multi.multiblockpart; | |
| import gregtech.api.GTValues; | |
| import gregtech.api.capability.DualHandler; | |
| import gregtech.api.capability.impl.FluidTankList; | |
| import gregtech.api.capability.impl.NotifiableFluidTank; | |
| import gregtech.api.capability.impl.NotifiableItemStackHandler; | |
| import gregtech.api.gui.GuiTextures; | |
| import gregtech.api.gui.ModularUI; | |
| import gregtech.api.gui.widgets.SlotWidget; | |
| import gregtech.api.gui.widgets.TankWidget; | |
| import gregtech.api.metatileentity.MetaTileEntity; | |
| import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; | |
| import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; | |
| import gregtech.api.metatileentity.multiblock.MultiblockAbility; | |
| import gregtech.api.util.GTUtility; | |
| import net.minecraft.entity.player.EntityPlayer; | |
| import net.minecraft.nbt.NBTTagCompound; | |
| import net.minecraft.util.ResourceLocation; | |
| import net.minecraftforge.fluids.FluidTank; | |
| import net.minecraftforge.items.IItemHandlerModifiable; | |
| import org.jetbrains.annotations.NotNull; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| public class MetaTileEntityDistinctInputDual extends MetaTileEntityMultiblockNotifiablePart implements | |
| IMultiblockAbilityPart<IItemHandlerModifiable> { | |
| private final IItemHandlerModifiable[] itemHandlers = new IItemHandlerModifiable[2]; | |
| private final FluidTankList[] fluidHandlers = new FluidTankList[2]; | |
| private final DualHandler[] dualHandlers = new DualHandler[2]; | |
| public MetaTileEntityDistinctInputDual(ResourceLocation metaTileEntityId) { | |
| super(metaTileEntityId, GTValues.LuV, false); | |
| for (int i = 0; i < itemHandlers.length; i++) { | |
| itemHandlers[i] = new NotifiableItemStackHandler(this, 4, getController(), false); | |
| } | |
| for (int i = 0; i < fluidHandlers.length; i++) { | |
| FluidTank[] fluidTanks = new FluidTank[2]; | |
| for (int y = 0; y < fluidTanks.length; y++) { | |
| fluidTanks[y] = new NotifiableFluidTank(32000, this, false); | |
| } | |
| fluidHandlers[i] = new FluidTankList(false, fluidTanks); | |
| } | |
| for (int i = 0; i < dualHandlers.length; i++) { | |
| dualHandlers[i] = new DualHandler(itemHandlers[i], fluidHandlers[i], false); | |
| } | |
| } | |
| @SuppressWarnings("deprecation") | |
| @Override | |
| protected ModularUI createUI(EntityPlayer entityPlayer) { | |
| ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 18 + 54 + 94) | |
| .label(10, 5, getMetaFullName()); | |
| //First set | |
| int xStart = 7; | |
| int yStart = 20; | |
| builder.widget(new SlotWidget(itemHandlers[0], 0, xStart, yStart) | |
| .setBackgroundTexture(GuiTextures.SLOT)); | |
| builder.widget(new SlotWidget(itemHandlers[0], 1, xStart + 18, yStart). | |
| setBackgroundTexture(GuiTextures.SLOT)); | |
| builder.widget(new SlotWidget(itemHandlers[0], 2, xStart, yStart + 18) | |
| .setBackgroundTexture(GuiTextures.SLOT)); | |
| builder.widget(new SlotWidget(itemHandlers[0], 3, xStart + 18, yStart + 18) | |
| .setBackgroundTexture(GuiTextures.SLOT)); | |
| builder.widget(new TankWidget(fluidHandlers[0].getTankAt(0), xStart, yStart + 18 * 2, 18, 18) | |
| .setBackgroundTexture(GuiTextures.FLUID_SLOT) | |
| .setAlwaysShowFull(true) | |
| .setContainerClicking(true, true)); | |
| builder.widget(new TankWidget(fluidHandlers[0].getTankAt(1), xStart + 18, yStart + 18 * 2, 18, 18) | |
| .setBackgroundTexture(GuiTextures.FLUID_SLOT) | |
| .setAlwaysShowFull(true) | |
| .setContainerClicking(true, true)); | |
| //Second set | |
| int xOffset = xStart + 18 * 2 + 20; | |
| builder.widget(new SlotWidget(itemHandlers[1], 0, xOffset, yStart) | |
| .setBackgroundTexture(GuiTextures.SLOT)); | |
| builder.widget(new SlotWidget(itemHandlers[1], 1, xOffset + 18, yStart) | |
| .setBackgroundTexture(GuiTextures.SLOT)); | |
| builder.widget(new SlotWidget(itemHandlers[1], 2, xOffset, yStart + 18) | |
| .setBackgroundTexture(GuiTextures.SLOT)); | |
| builder.widget(new SlotWidget(itemHandlers[1], 3, xOffset + 18, yStart + 18) | |
| .setBackgroundTexture(GuiTextures.SLOT)); | |
| builder.widget(new TankWidget(fluidHandlers[1].getTankAt(0), xOffset, yStart + 18 * 2, 18, 18) | |
| .setBackgroundTexture(GuiTextures.FLUID_SLOT) | |
| .setAlwaysShowFull(true) | |
| .setContainerClicking(true, true)); | |
| builder.widget(new TankWidget(fluidHandlers[1].getTankAt(1), xOffset + 18, yStart + 18 * 2, 18, 18) | |
| .setBackgroundTexture(GuiTextures.FLUID_SLOT) | |
| .setAlwaysShowFull(true) | |
| .setContainerClicking(true, true)); | |
| builder.bindPlayerInventory(entityPlayer.inventory, GuiTextures.SLOT, 7, 84); | |
| return builder.build(getHolder(), entityPlayer); | |
| } | |
| @Override | |
| public MetaTileEntity createMetaTileEntity(IGregTechTileEntity tileEntity) { | |
| return new MetaTileEntityDistinctInputDual(metaTileEntityId); | |
| } | |
| @Override | |
| public MultiblockAbility<IItemHandlerModifiable> getAbility() { | |
| return MultiblockAbility.IMPORT_ITEMS; | |
| } | |
| @Override | |
| public void registerAbilities(@NotNull MultiblockAbility<IItemHandlerModifiable> key, | |
| @NotNull List<IItemHandlerModifiable> abilities) { | |
| abilities.addAll(Arrays.asList(dualHandlers)); | |
| } | |
| @Override | |
| public NBTTagCompound writeToNBT(NBTTagCompound data) { | |
| super.writeToNBT(data); | |
| for (int i = 0; i < itemHandlers.length; i++) { | |
| String tag = String.format("inputItem%d", i); | |
| GTUtility.writeItems(itemHandlers[i], tag, data); | |
| } | |
| for (int i = 0; i < fluidHandlers.length; i++) { | |
| String tag = String.format("inputTank%d", i); | |
| data.setTag(tag, fluidHandlers[i].serializeNBT()); | |
| } | |
| return data; | |
| } | |
| @Override | |
| public void readFromNBT(NBTTagCompound data) { | |
| super.readFromNBT(data); | |
| for (int i = 0; i < itemHandlers.length; i++) { | |
| String tag = String.format("inputItem%d", i); | |
| GTUtility.readItems(itemHandlers[i], tag, data); | |
| } | |
| for (int i = 0; i < fluidHandlers.length; i++) { | |
| String tag = String.format("inputTank%d", i); | |
| fluidHandlers[i].deserializeNBT(data.getCompoundTag(tag)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment