From a3b83a8125b1afbcdbaa8ef77f2b15b0d3be3791 Mon Sep 17 00:00:00 2001 From: evgengoldwar Date: Thu, 5 Sep 2024 21:20:20 +0400 Subject: [PATCH 1/8] ChargingBus --- .../gregtech/api/enums/MetaTileEntityIDs.java | 3 +- .../machines/MTEHatchChargingBus.java | 308 ++++++++++++++++++ .../gregtech/api/enums/GregtechItemList.java | 3 + .../gregtech/GregtechCustomHatches.java | 6 + 4 files changed, 319 insertions(+), 1 deletion(-) create mode 100644 src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java diff --git a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java index 4d11475ac4b..e16f977d23a 100644 --- a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java +++ b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java @@ -1886,7 +1886,8 @@ public enum MetaTileEntityIDs { CoolantTower(32025), ComponentAssemblyLine(32026), WireLumiium(32737), - WireSignalium(32749),; + WireSignalium(32749), + ChargingBus(32750); public final int ID; diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java new file mode 100644 index 00000000000..2a61d87eba5 --- /dev/null +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java @@ -0,0 +1,308 @@ +package gregtech.common.tileentities.machines; + +import static gregtech.api.enums.Textures.BlockIcons.ITEM_IN_SIGN; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_IN; +import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizons.modularui.api.drawable.UITexture; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.api.widget.Widget; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; + +import gregtech.GTMod; +import gregtech.api.gui.modularui.GTUIInfos; +import gregtech.api.gui.modularui.GTUITextures; +import gregtech.api.interfaces.IConfigurationCircuitSupport; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.MTEHatch; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GTOreDictUnificator; +import gregtech.api.util.GTTooltipDataCache; +import gregtech.api.util.GTUtility; +import gregtech.api.util.extensions.ArrayExt; + +public class MTEHatchChargingBus extends MTEHatch implements IConfigurationCircuitSupport, IAddUIWidgets { + + private static final String SORTING_MODE_TOOLTIP = "GT5U.machines.sorting_mode.tooltip"; + private static final String ONE_STACK_LIMIT_TOOLTIP = "GT5U.machines.one_stack_limit.tooltip"; + private static final int BUTTON_SIZE = 18; + + private int uiButtonCount = 0; + + public RecipeMap mRecipeMap = null; + public boolean disableSort; + public boolean disableFilter = true; + public boolean disableLimited = true; + + public MTEHatchChargingBus(int id, String name, String nameRegional, int tier) { + this(id, name, nameRegional, tier, 4); + } + + protected MTEHatchChargingBus(int id, String name, String nameRegional, int tier, int slots, String[] description) { + super(id, name, nameRegional, tier, slots, description); + } + + public MTEHatchChargingBus(int id, String name, String nameRegional, int tier, int slots) { + super( + id, + name, + nameRegional, + tier, + slots, + ArrayExt.of( + "Item Input for Multiblocks", + "Shift + right click with screwdriver to turn Sort mode on/off", + "Capacity: " + getSlots(tier) + " stack" + (getSlots(tier) >= 2 ? "s" : ""))); + } + + public MTEHatchChargingBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + this(aName, aTier, 4, aDescription, aTextures); + } + + public MTEHatchChargingBus(String aName, int aTier, int aSlots, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aSlots, aDescription, aTextures); + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return GTMod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(ITEM_IN_SIGN) } + : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return GTMod.gregtechproxy.mRenderIndicatorsOnHatch + ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(ITEM_IN_SIGN) } + : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN) }; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return aIndex != getCircuitSlot(); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTEHatchChargingBus(mName, mTier, mDescriptionArray, mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GTUIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public int getCircuitSlotX() { + return 153; + } + + @Override + public int getCircuitSlotY() { + return 63; + } + + @Override + public boolean allowSelectCircuit() { + return true; + } + + @Override + public int getCircuitSlot() { + return getSlots(mTier); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + updateSlots(); + } + } + + public void updateSlots() { + for (int i = 0; i < mInventory.length - 1; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + if (!disableSort) fillStacksIntoFirstSlots(); + } + + protected void fillStacksIntoFirstSlots() { + final int L = mInventory.length - 1; + HashMap slots = new HashMap<>(L); + HashMap stacks = new HashMap<>(L); + List order = new ArrayList<>(L); + List validSlots = new ArrayList<>(L); + for (int i = 0; i < L; i++) { + if (!isValidSlot(i)) continue; + validSlots.add(i); + ItemStack s = mInventory[i]; + if (s == null) continue; + GTUtility.ItemId sID = GTUtility.ItemId.createNoCopy(s); + slots.merge(sID, s.stackSize, Integer::sum); + if (!stacks.containsKey(sID)) stacks.put(sID, s); + order.add(sID); + mInventory[i] = null; + } + int slotindex = 0; + for (GTUtility.ItemId sID : order) { + int toSet = slots.get(sID); + if (toSet == 0) continue; + int slot = validSlots.get(slotindex); + slotindex++; + mInventory[slot] = stacks.get(sID) + .copy(); + toSet = Math.min(toSet, mInventory[slot].getMaxStackSize()); + mInventory[slot].stackSize = toSet; + slots.merge(sID, toSet, (a, b) -> a - b); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("disableSort", disableSort); + aNBT.setBoolean("disableFilter", disableFilter); + aNBT.setBoolean("disableLimited", disableLimited); + if (mRecipeMap != null) { + aNBT.setString("recipeMap", mRecipeMap.unlocalizedName); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + disableSort = aNBT.getBoolean("disableSort"); + disableFilter = aNBT.getBoolean("disableFilter"); + if (aNBT.hasKey("disableLimited")) { + disableLimited = aNBT.getBoolean("disableLimited"); + } + mRecipeMap = RecipeMap.getFromOldIdentifier(aNBT.getString("recipeMap")); + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (!getBaseMetaTileEntity().getCoverInfoAtSide(side) + .isGUIClickable()) return; + if (aPlayer.isSneaking()) { + if (disableSort) { + disableSort = false; + } else { + if (disableLimited) { + disableLimited = false; + } else { + disableSort = true; + disableLimited = true; + } + } + GTUtility.sendChatToPlayer( + aPlayer, + StatCollector.translateToLocal("GT5U.hatch.disableSort." + disableSort) + " " + + StatCollector.translateToLocal("GT5U.hatch.disableLimited." + disableLimited)); + } else { + disableFilter = !disableFilter; + GTUtility + .sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.hatch.disableFilter." + disableFilter)); + } + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + if (aIndex == getCircuitSlot()) return false; + return side == getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return side == getBaseMetaTileEntity().getFrontFacing() && aIndex != getCircuitSlot() + && (mRecipeMap == null || disableFilter || mRecipeMap.containsInput(aStack)) + && (disableLimited || limitedAllowPutStack(aIndex, aStack)); + } + + protected boolean limitedAllowPutStack(int aIndex, ItemStack aStack) { + for (int i = 0; i < getSizeInventory(); i++) + if (GTUtility.areStacksEqual(GTOreDictUnificator.get_nocopy(aStack), mInventory[i])) return i == aIndex; + return mInventory[aIndex] == null; + } + + private void addSortStacksButton(ModularWindow.Builder builder) { + builder.widget( + createToggleButton( + () -> !disableSort, + val -> disableSort = !val, + GTUITextures.OVERLAY_BUTTON_SORTING_MODE, + () -> mTooltipCache.getData(SORTING_MODE_TOOLTIP))); + } + + private void addOneStackLimitButton(ModularWindow.Builder builder) { + builder.widget(createToggleButton(() -> !disableLimited, val -> { + disableLimited = !val; + updateSlots(); + }, GTUITextures.OVERLAY_BUTTON_ONE_STACK_LIMIT, () -> mTooltipCache.getData(ONE_STACK_LIMIT_TOOLTIP))); + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + buildContext.addCloseListener(() -> uiButtonCount = 0); + addSortStacksButton(builder); + addOneStackLimitButton(builder); + // Remove one for ghost circuit slot + int slotCount = getSizeInventory(); + if (allowSelectCircuit()) { + slotCount = slotCount - 1; + } + // We do this to decouple slot count from tier in here, since there is no reason to do so. + switch (slotCount) { + case 1 -> getBaseMetaTileEntity().add1by1Slot(builder); + case 4 -> getBaseMetaTileEntity().add2by2Slots(builder); + case 9 -> getBaseMetaTileEntity().add3by3Slots(builder); + case 16 -> getBaseMetaTileEntity().add4by4Slots(builder); + default -> {} + } + } + + private Widget createToggleButton(Supplier getter, Consumer setter, UITexture picture, + Supplier tooltipDataSupplier) { + return new CycleButtonWidget().setToggle(getter, setter) + .setStaticTexture(picture) + .setVariableBackground(GTUITextures.BUTTON_STANDARD_TOGGLE) + .setTooltipShowUpDelay(TOOLTIP_DELAY) + .setPos(7 + (uiButtonCount++ * BUTTON_SIZE), 62) + .setSize(BUTTON_SIZE, BUTTON_SIZE) + .setGTTooltip(tooltipDataSupplier); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java index e51d60834f1..d25f7437701 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java @@ -503,6 +503,9 @@ public enum GregtechItemList implements IGregtechItemContainer { // Reservoir Hatch Hatch_Reservoir, + // ChargingBus + ChargingBus, + // XL Turbine Rotor Hatch Hatch_Turbine_Rotor, diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java b/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java index 27817302299..079824136e9 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java @@ -1,5 +1,6 @@ package gtPlusPlus.xmod.gregtech.registration.gregtech; +import static gregtech.api.enums.MetaTileEntityIDs.ChargingBus; import static gregtech.api.enums.MetaTileEntityIDs.Hatch_Air_Intake; import static gregtech.api.enums.MetaTileEntityIDs.Hatch_Air_Intake_Extreme; import static gregtech.api.enums.MetaTileEntityIDs.Hatch_Input_Cryotheum; @@ -18,6 +19,7 @@ import static gregtech.api.enums.MetaTileEntityIDs.Hatch_Reservoir; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.common.tileentities.machines.MTEHatchChargingBus; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.util.minecraft.FluidUtils; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; @@ -96,6 +98,10 @@ private static void run1() { "Extreme Air Intake Hatch", 6).getStackForm(1L)); + // MultiBlock ChargingBus + GregtechItemList.ChargingBus + .set(new MTEHatchChargingBus(ChargingBus.ID, "ChargingBus", "ChargingBus", 4).getStackForm(1L)); + // Multiblock Reservoir Hatch GregtechItemList.Hatch_Reservoir.set( new MTEHatchReservoir(Hatch_Reservoir.ID, "hatch.water.intake.tier.00", "Reservoir Hatch", 4) From bff7dde21ab552884254364d150c49d6be326c26 Mon Sep 17 00:00:00 2001 From: evgengoldwar Date: Fri, 6 Sep 2024 17:17:57 +0400 Subject: [PATCH 2/8] getMultiBlock --- .../gregtech/api/enums/MetaTileEntityIDs.java | 2 +- .../machines/MTEHatchChargingBus.java | 392 +++++++----------- 2 files changed, 156 insertions(+), 238 deletions(-) diff --git a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java index e16f977d23a..4222d39b3c7 100644 --- a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java +++ b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java @@ -1887,7 +1887,7 @@ public enum MetaTileEntityIDs { ComponentAssemblyLine(32026), WireLumiium(32737), WireSignalium(32749), - ChargingBus(32750); + ChargingBus(31785); public final int ID; diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java index 2a61d87eba5..3dbf258b102 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java @@ -1,308 +1,226 @@ package gregtech.common.tileentities.machines; -import static gregtech.api.enums.Textures.BlockIcons.ITEM_IN_SIGN; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_IN; -import static gregtech.api.metatileentity.BaseTileEntity.TOOLTIP_DELAY; - import java.util.ArrayList; -import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; import java.util.List; -import java.util.function.Consumer; -import java.util.function.Supplier; +import java.util.Queue; +import java.util.Set; -import net.minecraft.entity.player.EntityPlayer; +import gregtech.api.logic.ProcessingLogic; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.StatCollector; -import net.minecraftforge.common.util.ForgeDirection; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; -import com.gtnewhorizons.modularui.api.drawable.UITexture; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; -import com.gtnewhorizons.modularui.api.widget.Widget; -import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; -import gregtech.GTMod; -import gregtech.api.gui.modularui.GTUIInfos; -import gregtech.api.gui.modularui.GTUITextures; -import gregtech.api.interfaces.IConfigurationCircuitSupport; import gregtech.api.interfaces.ITexture; -import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable; import gregtech.api.metatileentity.MetaTileEntity; -import gregtech.api.metatileentity.implementations.MTEHatch; +import gregtech.api.metatileentity.implementations.MTEHatchInputBus; +import gregtech.api.metatileentity.implementations.MTEMultiBlockBase; import gregtech.api.recipe.RecipeMap; -import gregtech.api.render.TextureFactory; -import gregtech.api.util.GTOreDictUnificator; -import gregtech.api.util.GTTooltipDataCache; +import gregtech.api.util.GTModHandler; +import gregtech.api.util.GTUtil; import gregtech.api.util.GTUtility; -import gregtech.api.util.extensions.ArrayExt; +import gtPlusPlus.core.lib.GTPPCore; +import gtPlusPlus.xmod.gregtech.api.gui.widget.ElectricSlotWidget; -public class MTEHatchChargingBus extends MTEHatch implements IConfigurationCircuitSupport, IAddUIWidgets { +public class MTEHatchChargingBus extends MTEHatchInputBus { - private static final String SORTING_MODE_TOOLTIP = "GT5U.machines.sorting_mode.tooltip"; - private static final String ONE_STACK_LIMIT_TOOLTIP = "GT5U.machines.one_stack_limit.tooltip"; - private static final int BUTTON_SIZE = 18; + public final RecipeMap mRecipeMap = null; - private int uiButtonCount = 0; + private MTEMultiBlockBase machine; - public RecipeMap mRecipeMap = null; - public boolean disableSort; - public boolean disableFilter = true; - public boolean disableLimited = true; + private ConnectionMulti connection; - public MTEHatchChargingBus(int id, String name, String nameRegional, int tier) { - this(id, name, nameRegional, tier, 4); - } + private List connectionList = new ArrayList<>(); - protected MTEHatchChargingBus(int id, String name, String nameRegional, int tier, int slots, String[] description) { - super(id, name, nameRegional, tier, slots, description); - } - - public MTEHatchChargingBus(int id, String name, String nameRegional, int tier, int slots) { - super( - id, - name, - nameRegional, - tier, - slots, - ArrayExt.of( - "Item Input for Multiblocks", - "Shift + right click with screwdriver to turn Sort mode on/off", - "Capacity: " + getSlots(tier) + " stack" + (getSlots(tier) >= 2 ? "s" : ""))); + public MTEHatchChargingBus(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, getSlots(aTier) + 1); } public MTEHatchChargingBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - this(aName, aTier, 4, aDescription, aTextures); - } - - public MTEHatchChargingBus(String aName, int aTier, int aSlots, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aSlots, aDescription, aTextures); - } - - @Override - public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return GTMod.gregtechproxy.mRenderIndicatorsOnHatch - ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(ITEM_IN_SIGN) } - : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN) }; + super(aName, aTier, getSlots(aTier) + 1, aDescription, aTextures); } @Override - public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return GTMod.gregtechproxy.mRenderIndicatorsOnHatch - ? new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN), TextureFactory.of(ITEM_IN_SIGN) } - : new ITexture[] { aBaseTexture, TextureFactory.of(OVERLAY_PIPE_IN) }; + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTEHatchChargingBus(this.mName, this.mTier, mDescriptionArray, this.mTextures); } @Override - public boolean isSimpleMachine() { - return true; + public String[] getDescription() { + return new String[] { "Item Input for Multiblocks", "" + getSlots(this.mTier) + " Slots", + GTPPCore.GT_Tooltip.get() }; } @Override - public boolean isFacingValid(ForgeDirection facing) { - return true; + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + if (aBaseMetaTileEntity.isServerSide()) { + if (hasConnection()) { + final ArrayList inputs = machine.getStoredInputs(); + final int inputsSize = inputs.size(); + long machineTier = machine.getInputVoltageTier(); + + if (machine.mProgresstime > 0) { + for (int i = inputsSize - 1; i >= 0; i--) { + ItemStack stack = inputs.get(i); + int stackTier = ((ic2.api.item.IElectricItem) stack.getItem()).getTier(stack); + + if (stackTier <= machineTier) { + if (GTModHandler.isElectricItem(stack)) { + GTModHandler.chargeElectricItem( + stack, + (int) machine.getMaxInputEu() / 4, + stackTier, + true, + false); + } + } + } + } + } else { + if (aTimer % 200 == 0) { + connection = null; + tryFindConnection(); + } + } + } + super.onPostTick(aBaseMetaTileEntity, aTimer); } - @Override - public boolean isAccessAllowed(EntityPlayer aPlayer) { - return true; + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); } @Override public boolean isValidSlot(int aIndex) { - return aIndex != getCircuitSlot(); - } - - @Override - public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new MTEHatchChargingBus(mName, mTier, mDescriptionArray, mTextures); - } - - @Override - public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { - GTUIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); - return true; - } - - @Override - public int getCircuitSlotX() { - return 153; - } - - @Override - public int getCircuitSlotY() { - return 63; + return aIndex < getSlots(this.mTier); } - @Override - public boolean allowSelectCircuit() { - return true; + public static int getSlots(int aTier) { + return (1 + aTier) * 16; } - @Override - public int getCircuitSlot() { - return getSlots(mTier); + protected void fillStacksIntoFirstSlots() { + for (int i = 0; i < mInventory.length; i++) + for (int j = i + 1; j < mInventory.length; j++) if (mInventory[j] != null + && (mInventory[i] == null || GTUtility.areStacksEqual(mInventory[i], mInventory[j]))) { + GTUtility.moveStackFromSlotAToSlotB( + getBaseMetaTileEntity(), + getBaseMetaTileEntity(), + j, + i, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1); + } } @Override - public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { - updateSlots(); + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + for (int i = 0; i < 16; i++) { + builder.widget(new ElectricSlotWidget(inventoryHandler, i).setPos(52 + (i % 4) * 18, 7 + (i / 4) * 18)); } } - public void updateSlots() { - for (int i = 0; i < mInventory.length - 1; i++) - if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; - if (!disableSort) fillStacksIntoFirstSlots(); - } - - protected void fillStacksIntoFirstSlots() { - final int L = mInventory.length - 1; - HashMap slots = new HashMap<>(L); - HashMap stacks = new HashMap<>(L); - List order = new ArrayList<>(L); - List validSlots = new ArrayList<>(L); - for (int i = 0; i < L; i++) { - if (!isValidSlot(i)) continue; - validSlots.add(i); - ItemStack s = mInventory[i]; - if (s == null) continue; - GTUtility.ItemId sID = GTUtility.ItemId.createNoCopy(s); - slots.merge(sID, s.stackSize, Integer::sum); - if (!stacks.containsKey(sID)) stacks.put(sID, s); - order.add(sID); - mInventory[i] = null; - } - int slotindex = 0; - for (GTUtility.ItemId sID : order) { - int toSet = slots.get(sID); - if (toSet == 0) continue; - int slot = validSlots.get(slotindex); - slotindex++; - mInventory[slot] = stacks.get(sID) - .copy(); - toSet = Math.min(toSet, mInventory[slot].getMaxStackSize()); - mInventory[slot].stackSize = toSet; - slots.merge(sID, toSet, (a, b) -> a - b); + private MTEMultiBlockBase tryFindCoreGTMultiBlock() { + Queue tQueue = new LinkedList<>(); + Set visited = new HashSet<>(80); + tQueue.add( + this.getBaseMetaTileEntity() + .getCoords()); + World world = this.getBaseMetaTileEntity() + .getWorld(); + while (!tQueue.isEmpty()) { + final ChunkCoordinates aCoords = tQueue.poll(); + final TileEntity tTileEntity; + + tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ); + + if (tTileEntity instanceof IGregTechTileEntity te + && te.getMetaTileEntity() instanceof MTEMultiBlockBase mte) + if (mte.mInputBusses.contains(this)) return mte; + + if (visited.size() < 5 || (tTileEntity instanceof IMachineBlockUpdateable + && ((IMachineBlockUpdateable) tTileEntity).isMachineBlockUpdateRecursive())) { + ChunkCoordinates tCoords; + + if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX + 1, aCoords.posY, aCoords.posZ))) + tQueue.add(tCoords); + if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX - 1, aCoords.posY, aCoords.posZ))) + tQueue.add(tCoords); + if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY + 1, aCoords.posZ))) + tQueue.add(tCoords); + if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY - 1, aCoords.posZ))) + tQueue.add(tCoords); + if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ + 1))) + tQueue.add(tCoords); + if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ - 1))) + tQueue.add(tCoords); + } } + return null; } - @Override - public void saveNBTData(NBTTagCompound aNBT) { - super.saveNBTData(aNBT); - aNBT.setBoolean("disableSort", disableSort); - aNBT.setBoolean("disableFilter", disableFilter); - aNBT.setBoolean("disableLimited", disableLimited); - if (mRecipeMap != null) { - aNBT.setString("recipeMap", mRecipeMap.unlocalizedName); + private void tryFindConnection() { + MTEMultiBlockBase machine = tryFindCoreGTMultiBlock(); + if (machine != null && machine.isValid()) { + this.machine = machine; + connection = new ConnectionMulti(machine); + connectionList.add(connection); } } - @Override - public void loadNBTData(NBTTagCompound aNBT) { - super.loadNBTData(aNBT); - disableSort = aNBT.getBoolean("disableSort"); - disableFilter = aNBT.getBoolean("disableFilter"); - if (aNBT.hasKey("disableLimited")) { - disableLimited = aNBT.getBoolean("disableLimited"); - } - mRecipeMap = RecipeMap.getFromOldIdentifier(aNBT.getString("recipeMap")); + private boolean hasConnection() { + if (connection == null) return false; + if (connection.isValid()) return true; + return connection.reCheckConnection(); } @Override - public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { - if (!getBaseMetaTileEntity().getCoverInfoAtSide(side) - .isGUIClickable()) return; - if (aPlayer.isSneaking()) { - if (disableSort) { - disableSort = false; - } else { - if (disableLimited) { - disableLimited = false; - } else { - disableSort = true; - disableLimited = true; - } - } - GTUtility.sendChatToPlayer( - aPlayer, - StatCollector.translateToLocal("GT5U.hatch.disableSort." + disableSort) + " " - + StatCollector.translateToLocal("GT5U.hatch.disableLimited." + disableLimited)); - } else { - disableFilter = !disableFilter; - GTUtility - .sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.hatch.disableFilter." + disableFilter)); - } + public void onRemoval() { + if (hasConnection()) connection.machine = null; } +} - @Override - public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, - ItemStack aStack) { - if (aIndex == getCircuitSlot()) return false; - return side == getBaseMetaTileEntity().getFrontFacing(); - } +class ConnectionMulti { - @Override - public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, - ItemStack aStack) { - return side == getBaseMetaTileEntity().getFrontFacing() && aIndex != getCircuitSlot() - && (mRecipeMap == null || disableFilter || mRecipeMap.containsInput(aStack)) - && (disableLimited || limitedAllowPutStack(aIndex, aStack)); - } + MTEMultiBlockBase machine; + ItemStack machineItem; + ChunkCoordinates machineCoord; - protected boolean limitedAllowPutStack(int aIndex, ItemStack aStack) { - for (int i = 0; i < getSizeInventory(); i++) - if (GTUtility.areStacksEqual(GTOreDictUnificator.get_nocopy(aStack), mInventory[i])) return i == aIndex; - return mInventory[aIndex] == null; - } + World world; - private void addSortStacksButton(ModularWindow.Builder builder) { - builder.widget( - createToggleButton( - () -> !disableSort, - val -> disableSort = !val, - GTUITextures.OVERLAY_BUTTON_SORTING_MODE, - () -> mTooltipCache.getData(SORTING_MODE_TOOLTIP))); + public ConnectionMulti(MTEMultiBlockBase machine) { + this.machine = machine; + this.machineItem = machine.getStackForm(1); + machineCoord = machine.getBaseMetaTileEntity() + .getCoords(); } - private void addOneStackLimitButton(ModularWindow.Builder builder) { - builder.widget(createToggleButton(() -> !disableLimited, val -> { - disableLimited = !val; - updateSlots(); - }, GTUITextures.OVERLAY_BUTTON_ONE_STACK_LIMIT, () -> mTooltipCache.getData(ONE_STACK_LIMIT_TOOLTIP))); + public boolean reCheckConnection() { + if (machine == null) this.machine = getLoadedGT_BaseMachineAt(machineCoord, world, true); + return isValid(); } - @Override - public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { - buildContext.addCloseListener(() -> uiButtonCount = 0); - addSortStacksButton(builder); - addOneStackLimitButton(builder); - // Remove one for ghost circuit slot - int slotCount = getSizeInventory(); - if (allowSelectCircuit()) { - slotCount = slotCount - 1; - } - // We do this to decouple slot count from tier in here, since there is no reason to do so. - switch (slotCount) { - case 1 -> getBaseMetaTileEntity().add1by1Slot(builder); - case 4 -> getBaseMetaTileEntity().add2by2Slots(builder); - case 9 -> getBaseMetaTileEntity().add3by3Slots(builder); - case 16 -> getBaseMetaTileEntity().add4by4Slots(builder); - default -> {} - } + public MTEMultiBlockBase getLoadedGT_BaseMachineAt(ChunkCoordinates coords, World world, boolean isLoaded) { + TileEntity te = GTUtil.getTileEntity(world, coords, isLoaded); + if (te == null) return null; + return (MTEMultiBlockBase) ((IGregTechTileEntity) te).getMetaTileEntity(); } - private Widget createToggleButton(Supplier getter, Consumer setter, UITexture picture, - Supplier tooltipDataSupplier) { - return new CycleButtonWidget().setToggle(getter, setter) - .setStaticTexture(picture) - .setVariableBackground(GTUITextures.BUTTON_STANDARD_TOGGLE) - .setTooltipShowUpDelay(TOOLTIP_DELAY) - .setPos(7 + (uiButtonCount++ * BUTTON_SIZE), 62) - .setSize(BUTTON_SIZE, BUTTON_SIZE) - .setGTTooltip(tooltipDataSupplier); + public boolean isValid() { + return machine != null && machine.isValid(); } - } From 7e608885a28e3a7e711c143f34dd36f7a8c61e1f Mon Sep 17 00:00:00 2001 From: evgengoldwar Date: Sat, 7 Sep 2024 22:45:17 +0400 Subject: [PATCH 3/8] Rebalanced charging bus --- .../machines/MTEHatchChargingBus.java | 377 +++++++++++------- .../multi/production/MTETreeFarm.java | 36 ++ 2 files changed, 268 insertions(+), 145 deletions(-) diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java index 3dbf258b102..58dfc8e617e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java @@ -1,43 +1,34 @@ package gregtech.common.tileentities.machines; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; -import java.util.Set; - -import gregtech.api.logic.ProcessingLogic; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.world.World; +import static gregtech.api.enums.GTValues.AuthorEvgenWarGold; +import static gregtech.api.enums.GTValues.V; +import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_IN; +import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_LOCKER; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.Overlay_UU_Matter; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.interfaces.tileentity.IMachineBlockUpdateable; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.MTEHatchInputBus; -import gregtech.api.metatileentity.implementations.MTEMultiBlockBase; -import gregtech.api.recipe.RecipeMap; +import gregtech.api.objects.GTRenderedTexture; +import gregtech.api.render.TextureFactory; import gregtech.api.util.GTModHandler; -import gregtech.api.util.GTUtil; import gregtech.api.util.GTUtility; -import gtPlusPlus.core.lib.GTPPCore; import gtPlusPlus.xmod.gregtech.api.gui.widget.ElectricSlotWidget; public class MTEHatchChargingBus extends MTEHatchInputBus { - public final RecipeMap mRecipeMap = null; - - private MTEMultiBlockBase machine; - - private ConnectionMulti connection; - - private List connectionList = new ArrayList<>(); + // public final RecipeMap mRecipeMap = null; + // + // private MTEMultiBlockBase machine; + // + // private ConnectionMulti connection; + // + // private List connectionList = new ArrayList<>(); public MTEHatchChargingBus(int aID, String aName, String aNameRegional, int aTier) { super(aID, aName, aNameRegional, aTier, getSlots(aTier) + 1); @@ -54,8 +45,21 @@ public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { @Override public String[] getDescription() { - return new String[] { "Item Input for Multiblocks", "" + getSlots(this.mTier) + " Slots", - GTPPCore.GT_Tooltip.get() }; + return new String[] { "Item Charger Bus for multi-bocks", getSlots(this.mTier) + " Slots", AuthorEvgenWarGold }; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[3][17][]; + for (byte i = -1; i < 16; i = (byte) (i + 1)) { + ITexture[] tmp0 = { MACHINE_CASINGS[this.mTier + 2][(i + 1)] }; + rTextures[0][(i + 1)] = tmp0; + ITexture[] tmp1 = { MACHINE_CASINGS[this.mTier + 2][(i + 1)], OVERLAYS_ENERGY_IN[this.mTier] }; + rTextures[1][(i + 1)] = tmp1; + ITexture[] tmp2 = { MACHINE_CASINGS[this.mTier + 2][(i + 1)], TextureFactory.of(OVERLAY_LOCKER) }; + rTextures[2][(i + 1)] = tmp2; + } + return rTextures; } @Override @@ -63,52 +67,88 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { fillStacksIntoFirstSlots(); } + if (aBaseMetaTileEntity.isServerSide()) { - if (hasConnection()) { - final ArrayList inputs = machine.getStoredInputs(); - final int inputsSize = inputs.size(); - long machineTier = machine.getInputVoltageTier(); - - if (machine.mProgresstime > 0) { - for (int i = inputsSize - 1; i >= 0; i--) { - ItemStack stack = inputs.get(i); - int stackTier = ((ic2.api.item.IElectricItem) stack.getItem()).getTier(stack); - - if (stackTier <= machineTier) { - if (GTModHandler.isElectricItem(stack)) { - GTModHandler.chargeElectricItem( - stack, - (int) machine.getMaxInputEu() / 4, - stackTier, - true, - false); + if (aBaseMetaTileEntity.getMetaTileEntity() instanceof MetaTileEntity mMetaTileEntity) { + if (mMetaTileEntity.rechargerSlotCount() > 0 && aBaseMetaTileEntity.getStoredEU() > 0) { + this.onSetActive(true); + + for (int i = mMetaTileEntity.rechargerSlotStartIndex(), + k = mMetaTileEntity.rechargerSlotCount() + i; i < k; i++) { + if (aBaseMetaTileEntity.getStoredEU() > 0 && mMetaTileEntity.mInventory[i] != null) { + for (int u = 0; u < 10; u++) { + aBaseMetaTileEntity.decreaseStoredEnergyUnits( + GTModHandler.chargeElectricItem( + mMetaTileEntity.mInventory[i], + (int) Math.min(V[this.mTier] * 16, aBaseMetaTileEntity.getStoredEU()), + Integer.MAX_VALUE, + false, + false), + true); + if (mMetaTileEntity.mInventory[i].stackSize <= 0) { + mMetaTileEntity.mInventory[i] = null; + } } } } - } - } else { - if (aTimer % 200 == 0) { - connection = null; - tryFindConnection(); + } else { + this.onSetActive(false); } } } + super.onPostTick(aBaseMetaTileEntity, aTimer); } - public void updateSlots() { - for (int i = 0; i < mInventory.length; i++) - if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; - fillStacksIntoFirstSlots(); + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public long maxEUInput() { + return mTier == 0 ? 128 : 512; + } + + @Override + public int rechargerSlotCount() { + return getSlots(this.mTier); + } + + @Override + public long maxAmperesIn() { + return getSlots(this.mTier); + } + + @Override + public long maxEUStore() { + return maxEUInput() * 16; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GTRenderedTexture(Overlay_UU_Matter) }; } @Override - public boolean isValidSlot(int aIndex) { - return aIndex < getSlots(this.mTier); + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GTRenderedTexture(Overlay_UU_Matter) }; } - public static int getSlots(int aTier) { - return (1 + aTier) * 16; + public void updateSlots() { + for (int i = 0; i < mInventory.length; i++) + if (mInventory[i] != null && mInventory[i].stackSize <= 0) mInventory[i] = null; + fillStacksIntoFirstSlots(); } protected void fillStacksIntoFirstSlots() { @@ -134,93 +174,140 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont } } - private MTEMultiBlockBase tryFindCoreGTMultiBlock() { - Queue tQueue = new LinkedList<>(); - Set visited = new HashSet<>(80); - tQueue.add( - this.getBaseMetaTileEntity() - .getCoords()); - World world = this.getBaseMetaTileEntity() - .getWorld(); - while (!tQueue.isEmpty()) { - final ChunkCoordinates aCoords = tQueue.poll(); - final TileEntity tTileEntity; - - tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ); - - if (tTileEntity instanceof IGregTechTileEntity te - && te.getMetaTileEntity() instanceof MTEMultiBlockBase mte) - if (mte.mInputBusses.contains(this)) return mte; - - if (visited.size() < 5 || (tTileEntity instanceof IMachineBlockUpdateable - && ((IMachineBlockUpdateable) tTileEntity).isMachineBlockUpdateRecursive())) { - ChunkCoordinates tCoords; - - if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX + 1, aCoords.posY, aCoords.posZ))) - tQueue.add(tCoords); - if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX - 1, aCoords.posY, aCoords.posZ))) - tQueue.add(tCoords); - if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY + 1, aCoords.posZ))) - tQueue.add(tCoords); - if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY - 1, aCoords.posZ))) - tQueue.add(tCoords); - if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ + 1))) - tQueue.add(tCoords); - if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ - 1))) - tQueue.add(tCoords); - } - } - return null; - } - - private void tryFindConnection() { - MTEMultiBlockBase machine = tryFindCoreGTMultiBlock(); - if (machine != null && machine.isValid()) { - this.machine = machine; - connection = new ConnectionMulti(machine); - connectionList.add(connection); - } - } - - private boolean hasConnection() { - if (connection == null) return false; - if (connection.isValid()) return true; - return connection.reCheckConnection(); - } - - @Override - public void onRemoval() { - if (hasConnection()) connection.machine = null; - } + // @Override + // public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + // if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + // fillStacksIntoFirstSlots(); + // } + // if (aBaseMetaTileEntity.isServerSide()) { + // if (hasConnection()) { + // final ArrayList inputs = machine.getStoredInputs(); + // final int inputsSize = inputs.size(); + // long machineTier = machine.getInputVoltageTier(); + // + // if (machine.mProgresstime > 0) { + // for (int i = inputsSize - 1; i >= 0; i--) { + // ItemStack stack = inputs.get(i); + // int stackTier = ((ic2.api.item.IElectricItem) stack.getItem()).getTier(stack); + // + // if (stackTier <= machineTier) { + // if (GTModHandler.isElectricItem(stack)) { + // GTModHandler.chargeElectricItem( + // stack, + // (int) machine.getMaxInputEu() / 4, + // stackTier, + // true, + // false); + // } + // } + // } + // } + // } else { + // if (aTimer % 200 == 0) { + // connection = null; + // tryFindConnection(); + // } + // } + // } + // super.onPostTick(aBaseMetaTileEntity, aTimer); + // } + + // @Override + // public boolean isValidSlot(int aIndex) { + // return aIndex < getSlots(this.mTier); + // } + // + // public static int getSlots(int aTier) { + // return (1 + aTier) * 16; + // } + + // private MTEMultiBlockBase tryFindCoreGTMultiBlock() { + // Queue tQueue = new LinkedList<>(); + // Set visited = new HashSet<>(80); + // tQueue.add( + // this.getBaseMetaTileEntity() + // .getCoords()); + // World world = this.getBaseMetaTileEntity() + // .getWorld(); + // while (!tQueue.isEmpty()) { + // final ChunkCoordinates aCoords = tQueue.poll(); + // final TileEntity tTileEntity; + // + // tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ); + // + // if (tTileEntity instanceof IGregTechTileEntity te + // && te.getMetaTileEntity() instanceof MTEMultiBlockBase mte) + // if (mte.mInputBusses.contains(this)) return mte; + // + // if (visited.size() < 5 || (tTileEntity instanceof IMachineBlockUpdateable + // && ((IMachineBlockUpdateable) tTileEntity).isMachineBlockUpdateRecursive())) { + // ChunkCoordinates tCoords; + // + // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX + 1, aCoords.posY, aCoords.posZ))) + // tQueue.add(tCoords); + // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX - 1, aCoords.posY, aCoords.posZ))) + // tQueue.add(tCoords); + // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY + 1, aCoords.posZ))) + // tQueue.add(tCoords); + // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY - 1, aCoords.posZ))) + // tQueue.add(tCoords); + // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ + 1))) + // tQueue.add(tCoords); + // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ - 1))) + // tQueue.add(tCoords); + // } + // } + // return null; + // } + + // private void tryFindConnection() { + // MTEMultiBlockBase machine = tryFindCoreGTMultiBlock(); + // if (machine != null && machine.isValid()) { + // this.machine = machine; + // connection = new ConnectionMulti(machine); + // connectionList.add(connection); + // } + // } + // + // private boolean hasConnection() { + // if (connection == null) return false; + // if (connection.isValid()) return true; + // return connection.reCheckConnection(); + // } + // + // @Override + // public void onRemoval() { + // if (hasConnection()) connection.machine = null; + // } } -class ConnectionMulti { - - MTEMultiBlockBase machine; - ItemStack machineItem; - ChunkCoordinates machineCoord; - - World world; - - public ConnectionMulti(MTEMultiBlockBase machine) { - this.machine = machine; - this.machineItem = machine.getStackForm(1); - machineCoord = machine.getBaseMetaTileEntity() - .getCoords(); - } - - public boolean reCheckConnection() { - if (machine == null) this.machine = getLoadedGT_BaseMachineAt(machineCoord, world, true); - return isValid(); - } - - public MTEMultiBlockBase getLoadedGT_BaseMachineAt(ChunkCoordinates coords, World world, boolean isLoaded) { - TileEntity te = GTUtil.getTileEntity(world, coords, isLoaded); - if (te == null) return null; - return (MTEMultiBlockBase) ((IGregTechTileEntity) te).getMetaTileEntity(); - } - - public boolean isValid() { - return machine != null && machine.isValid(); - } -} +// class ConnectionMulti { +// +// MTEMultiBlockBase machine; +// ItemStack machineItem; +// ChunkCoordinates machineCoord; +// +// World world; +// +// public ConnectionMulti(MTEMultiBlockBase machine) { +// this.machine = machine; +// this.machineItem = machine.getStackForm(1); +// machineCoord = machine.getBaseMetaTileEntity() +// .getCoords(); +// } +// +// public boolean reCheckConnection() { +// if (machine == null) this.machine = getLoadedGT_BaseMachineAt(machineCoord, world, true); +// return isValid(); +// } +// +// public MTEMultiBlockBase getLoadedGT_BaseMachineAt(ChunkCoordinates coords, World world, boolean isLoaded) { +// TileEntity te = GTUtil.getTileEntity(world, coords, isLoaded); +// if (te == null) return null; +// return (MTEMultiBlockBase) ((IGregTechTileEntity) te).getMetaTileEntity(); +// } +// +// public boolean isValid() { +// return machine != null && machine.isValid(); +// } +// } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java index 6f8dd28c031..8481a0c8a43 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java @@ -28,6 +28,7 @@ import static gregtech.common.items.IDMetaTool01.SAW; import static gregtech.common.items.IDMetaTool01.WIRECUTTER; import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GTPPMultiBlockBase.GTPPHatchElement.TTEnergy; +import static java.lang.Long.max; import java.util.ArrayList; import java.util.EnumMap; @@ -36,6 +37,7 @@ import javax.annotation.Nonnull; +import gregtech.common.tileentities.machines.MTEHatchChargingBus; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemShears; @@ -531,6 +533,40 @@ private ItemStack findSapling() { return null; } + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + for (MTEHatchInputBus inputBus : this.mInputBusses){ + if (inputBus instanceof MTEHatchChargingBus chargerBus){ +// long tgsCurrentEU = getStoredEnergyInAllEnergyHatches(); +// long busMaxEU = chargerBus.maxEUStore(); +// +// if (tgsCurrentEU > 0 && inputBus.getEUVar() < busMaxEU) { +// long euToTransfer = max(busMaxEU - tgsCurrentEU, chargerBus.maxEUInput()); +// drainEnergyInput(tgsCurrentEU - euToTransfer); +// chargerBus.setEUVar(chargerBus.getEUVar() + euToTransfer); +// } + long tgsCurrentEU = getStoredEnergyInAllEnergyHatches(); + long busMaxEU = chargerBus.maxEUStore(); + + if (mProgresstime != 0) { + if (getAverageInputVoltage() != 0 && getActualEnergyUsage() != 0) { + long euToTransfer = getMaxInputEu() - getActualEnergyUsage(); + long euUsage = tgsCurrentEU - euToTransfer; + + if (tgsCurrentEU > getAverageInputVoltage() * 2) { + if (chargerBus.getEUVar() <= busMaxEU) { + drainEnergyInput(euUsage); + chargerBus.setEUVar(chargerBus.getEUVar() + euToTransfer); + } + } + } + } + } + } + } + /** * In previous versions, the saw used to be placed in the controller slot and the sapling into an input bus. We do * not want to break existing setups like this, so we attempt to swap the two if possible. From 26174c59ae3362c44c50684d1bcc711f37da6911 Mon Sep 17 00:00:00 2001 From: evgengoldwar Date: Wed, 18 Sep 2024 18:44:21 +0400 Subject: [PATCH 4/8] Added Charging Bus --- .../machines/MTEHatchChargingBus.java | 188 ++---------------- .../core/recipe/RecipesMachines.java | 11 + .../blocks/textures/TexturesGtBlock.java | 1 + .../gregtech/GregtechCustomHatches.java | 2 +- .../TileEntities/adv_machine_charging.png | Bin 0 -> 194 bytes 5 files changed, 26 insertions(+), 176 deletions(-) create mode 100644 src/main/resources/assets/miscutils/textures/blocks/TileEntities/adv_machine_charging.png diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java index 58dfc8e617e..4e9fdb0ef52 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java @@ -2,10 +2,7 @@ import static gregtech.api.enums.GTValues.AuthorEvgenWarGold; import static gregtech.api.enums.GTValues.V; -import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_IN; -import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_LOCKER; -import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.Overlay_UU_Matter; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.Overlay_Charging; import com.gtnewhorizons.modularui.api.screen.ModularWindow; import com.gtnewhorizons.modularui.api.screen.UIBuildContext; @@ -15,27 +12,18 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.MTEHatchInputBus; import gregtech.api.objects.GTRenderedTexture; -import gregtech.api.render.TextureFactory; import gregtech.api.util.GTModHandler; import gregtech.api.util.GTUtility; import gtPlusPlus.xmod.gregtech.api.gui.widget.ElectricSlotWidget; public class MTEHatchChargingBus extends MTEHatchInputBus { - // public final RecipeMap mRecipeMap = null; - // - // private MTEMultiBlockBase machine; - // - // private ConnectionMulti connection; - // - // private List connectionList = new ArrayList<>(); - public MTEHatchChargingBus(int aID, String aName, String aNameRegional, int aTier) { - super(aID, aName, aNameRegional, aTier, getSlots(aTier) + 1); + super(aID, aName, aNameRegional, aTier, getSlots(aTier)); } public MTEHatchChargingBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, getSlots(aTier) + 1, aDescription, aTextures); + super(aName, aTier, getSlots(aTier), aDescription, aTextures); } @Override @@ -45,21 +33,8 @@ public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { @Override public String[] getDescription() { - return new String[] { "Item Charger Bus for multi-bocks", getSlots(this.mTier) + " Slots", AuthorEvgenWarGold }; - } - - @Override - public ITexture[][][] getTextureSet(ITexture[] aTextures) { - ITexture[][][] rTextures = new ITexture[3][17][]; - for (byte i = -1; i < 16; i = (byte) (i + 1)) { - ITexture[] tmp0 = { MACHINE_CASINGS[this.mTier + 2][(i + 1)] }; - rTextures[0][(i + 1)] = tmp0; - ITexture[] tmp1 = { MACHINE_CASINGS[this.mTier + 2][(i + 1)], OVERLAYS_ENERGY_IN[this.mTier] }; - rTextures[1][(i + 1)] = tmp1; - ITexture[] tmp2 = { MACHINE_CASINGS[this.mTier + 2][(i + 1)], TextureFactory.of(OVERLAY_LOCKER) }; - rTextures[2][(i + 1)] = tmp2; - } - return rTextures; + return new String[] { "Item Charger Bus for Tree Growth Simulator", getSlots(this.mTier) + " Slots", + "Author: " + AuthorEvgenWarGold }; } @Override @@ -110,14 +85,9 @@ public boolean isEnetInput() { return true; } - @Override - public boolean isSimpleMachine() { - return true; - } - @Override public long maxEUInput() { - return mTier == 0 ? 128 : 512; + return 8192; } @Override @@ -135,14 +105,19 @@ public long maxEUStore() { return maxEUInput() * 16; } + @Override + public boolean allowSelectCircuit() { + return false; + } + @Override public ITexture[] getTexturesActive(ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, new GTRenderedTexture(Overlay_UU_Matter) }; + return new ITexture[] { aBaseTexture, new GTRenderedTexture(Overlay_Charging) }; } @Override public ITexture[] getTexturesInactive(ITexture aBaseTexture) { - return new ITexture[] { aBaseTexture, new GTRenderedTexture(Overlay_UU_Matter) }; + return new ITexture[] { aBaseTexture, new GTRenderedTexture(Overlay_Charging) }; } public void updateSlots() { @@ -173,141 +148,4 @@ public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildCont builder.widget(new ElectricSlotWidget(inventoryHandler, i).setPos(52 + (i % 4) * 18, 7 + (i / 4) * 18)); } } - - // @Override - // public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { - // if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { - // fillStacksIntoFirstSlots(); - // } - // if (aBaseMetaTileEntity.isServerSide()) { - // if (hasConnection()) { - // final ArrayList inputs = machine.getStoredInputs(); - // final int inputsSize = inputs.size(); - // long machineTier = machine.getInputVoltageTier(); - // - // if (machine.mProgresstime > 0) { - // for (int i = inputsSize - 1; i >= 0; i--) { - // ItemStack stack = inputs.get(i); - // int stackTier = ((ic2.api.item.IElectricItem) stack.getItem()).getTier(stack); - // - // if (stackTier <= machineTier) { - // if (GTModHandler.isElectricItem(stack)) { - // GTModHandler.chargeElectricItem( - // stack, - // (int) machine.getMaxInputEu() / 4, - // stackTier, - // true, - // false); - // } - // } - // } - // } - // } else { - // if (aTimer % 200 == 0) { - // connection = null; - // tryFindConnection(); - // } - // } - // } - // super.onPostTick(aBaseMetaTileEntity, aTimer); - // } - - // @Override - // public boolean isValidSlot(int aIndex) { - // return aIndex < getSlots(this.mTier); - // } - // - // public static int getSlots(int aTier) { - // return (1 + aTier) * 16; - // } - - // private MTEMultiBlockBase tryFindCoreGTMultiBlock() { - // Queue tQueue = new LinkedList<>(); - // Set visited = new HashSet<>(80); - // tQueue.add( - // this.getBaseMetaTileEntity() - // .getCoords()); - // World world = this.getBaseMetaTileEntity() - // .getWorld(); - // while (!tQueue.isEmpty()) { - // final ChunkCoordinates aCoords = tQueue.poll(); - // final TileEntity tTileEntity; - // - // tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ); - // - // if (tTileEntity instanceof IGregTechTileEntity te - // && te.getMetaTileEntity() instanceof MTEMultiBlockBase mte) - // if (mte.mInputBusses.contains(this)) return mte; - // - // if (visited.size() < 5 || (tTileEntity instanceof IMachineBlockUpdateable - // && ((IMachineBlockUpdateable) tTileEntity).isMachineBlockUpdateRecursive())) { - // ChunkCoordinates tCoords; - // - // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX + 1, aCoords.posY, aCoords.posZ))) - // tQueue.add(tCoords); - // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX - 1, aCoords.posY, aCoords.posZ))) - // tQueue.add(tCoords); - // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY + 1, aCoords.posZ))) - // tQueue.add(tCoords); - // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY - 1, aCoords.posZ))) - // tQueue.add(tCoords); - // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ + 1))) - // tQueue.add(tCoords); - // if (visited.add(tCoords = new ChunkCoordinates(aCoords.posX, aCoords.posY, aCoords.posZ - 1))) - // tQueue.add(tCoords); - // } - // } - // return null; - // } - - // private void tryFindConnection() { - // MTEMultiBlockBase machine = tryFindCoreGTMultiBlock(); - // if (machine != null && machine.isValid()) { - // this.machine = machine; - // connection = new ConnectionMulti(machine); - // connectionList.add(connection); - // } - // } - // - // private boolean hasConnection() { - // if (connection == null) return false; - // if (connection.isValid()) return true; - // return connection.reCheckConnection(); - // } - // - // @Override - // public void onRemoval() { - // if (hasConnection()) connection.machine = null; - // } } - -// class ConnectionMulti { -// -// MTEMultiBlockBase machine; -// ItemStack machineItem; -// ChunkCoordinates machineCoord; -// -// World world; -// -// public ConnectionMulti(MTEMultiBlockBase machine) { -// this.machine = machine; -// this.machineItem = machine.getStackForm(1); -// machineCoord = machine.getBaseMetaTileEntity() -// .getCoords(); -// } -// -// public boolean reCheckConnection() { -// if (machine == null) this.machine = getLoadedGT_BaseMachineAt(machineCoord, world, true); -// return isValid(); -// } -// -// public MTEMultiBlockBase getLoadedGT_BaseMachineAt(ChunkCoordinates coords, World world, boolean isLoaded) { -// TileEntity te = GTUtil.getTileEntity(world, coords, isLoaded); -// if (te == null) return null; -// return (MTEMultiBlockBase) ((IGregTechTileEntity) te).getMetaTileEntity(); -// } -// -// public boolean isValid() { -// return machine != null && machine.isValid(); -// } -// } diff --git a/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java b/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java index ae3817f1414..2549bfd766a 100644 --- a/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java +++ b/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java @@ -2927,6 +2927,17 @@ private static void runModRecipes() { .duration(5 * SECONDS) .eut(TierEU.RECIPE_EV) .addTo(assemblerRecipes); + // Charging Bus + GTValues.RA.stdBuilder() + .itemInputs( + ItemList.Hatch_Input_Bus_IV.get(1), + CI.getRobotArm(5, 2), + CI.getEnergyCore(5, 4), + CI.getTieredComponent(OrePrefixes.circuit, 5, 8)) + .itemOutputs(GregtechItemList.ChargingBus.get(1)) + .duration(50 * SECONDS) + .eut(TierEU.RECIPE_IV) + .addTo(assemblerRecipes); // Mystic Frame GTValues.RA.stdBuilder() .itemInputs( diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtBlock.java index 57d01bcc5fe..fe9081ed0ad 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtBlock.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtBlock.java @@ -509,6 +509,7 @@ public ResourceLocation getTextureFile() { "TileEntities/adv_machine_matterfab_active_animated"); public static final CustomIcon Overlay_Water = new CustomIcon("TileEntities/adv_machine_water"); public static final CustomIcon Overlay_UU_Matter = new CustomIcon("TileEntities/adv_machine_uum"); + public static final CustomIcon Overlay_Charging = new CustomIcon("TileEntities/adv_machine_charging"); // GT++ Tiered Hulls public static final CustomIcon TEXTURE_CASING_TIERED_ULV = new CustomIcon("iconsets/TieredHulls/CASING_ULV"); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java b/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java index 079824136e9..c52fec90a34 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java @@ -100,7 +100,7 @@ private static void run1() { // MultiBlock ChargingBus GregtechItemList.ChargingBus - .set(new MTEHatchChargingBus(ChargingBus.ID, "ChargingBus", "ChargingBus", 4).getStackForm(1L)); + .set(new MTEHatchChargingBus(ChargingBus.ID, "Charging Bus", "Charging Bus", 4).getStackForm(1L)); // Multiblock Reservoir Hatch GregtechItemList.Hatch_Reservoir.set( diff --git a/src/main/resources/assets/miscutils/textures/blocks/TileEntities/adv_machine_charging.png b/src/main/resources/assets/miscutils/textures/blocks/TileEntities/adv_machine_charging.png new file mode 100644 index 0000000000000000000000000000000000000000..9664f50057efc48c489437315d71cefea7075c7f GIT binary patch literal 194 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|YCK&WLoEE0 zQx*sq1g)6QIG^!3#hyX4m*?s2W>EVoAB_x}R&ezOzn4#{%6WE_+2aLGC*&HaLt rEqv1Pm#j~&wCV4^U}7vdHIOm;lA++IAV&_MI~Y7&{an^LB{Ts5QVc{Q literal 0 HcmV?d00001 From 83c87d4fd6c85ccd201d3f2fad0fa5db7b0b8bc0 Mon Sep 17 00:00:00 2001 From: evgengoldwar Date: Wed, 18 Sep 2024 18:45:18 +0400 Subject: [PATCH 5/8] Added Charging Bus support for TGS --- .../multi/production/MTETreeFarm.java | 70 ++++++++++++------- .../resources/assets/gregtech/lang/en_US.lang | 1 + 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java index 8481a0c8a43..a34fcd90b95 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java @@ -28,7 +28,6 @@ import static gregtech.common.items.IDMetaTool01.SAW; import static gregtech.common.items.IDMetaTool01.WIRECUTTER; import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GTPPMultiBlockBase.GTPPHatchElement.TTEnergy; -import static java.lang.Long.max; import java.util.ArrayList; import java.util.EnumMap; @@ -37,12 +36,16 @@ import javax.annotation.Nonnull; -import gregtech.common.tileentities.machines.MTEHatchChargingBus; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemShears; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -73,6 +76,7 @@ import gregtech.api.util.VoidProtectionHelper; import gregtech.common.items.IDMetaTool01; import gregtech.common.items.MetaGeneratedTool01; +import gregtech.common.tileentities.machines.MTEHatchChargingBus; import gregtech.common.tileentities.machines.MTEHatchInputBusME; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.recipe.GTPPRecipeMaps; @@ -83,6 +87,8 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoaderTreeFarm; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; public class MTETreeFarm extends GTPPMultiBlockBase implements ISurvivalConstructable { @@ -90,6 +96,8 @@ public class MTETreeFarm extends GTPPMultiBlockBase implements ISur private static final int TICKS_PER_OPERATION = 100; private static final int TOOL_DAMAGE_PER_OPERATION = 1; private static final int TOOL_CHARGE_PER_OPERATION = 32; + private boolean isChargingBus; + private long transferEU; private int mCasing; public static String mCasingName = "Sterile Farm Casing"; @@ -537,36 +545,50 @@ private ItemStack findSapling() { public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPostTick(aBaseMetaTileEntity, aTick); - for (MTEHatchInputBus inputBus : this.mInputBusses){ - if (inputBus instanceof MTEHatchChargingBus chargerBus){ -// long tgsCurrentEU = getStoredEnergyInAllEnergyHatches(); -// long busMaxEU = chargerBus.maxEUStore(); -// -// if (tgsCurrentEU > 0 && inputBus.getEUVar() < busMaxEU) { -// long euToTransfer = max(busMaxEU - tgsCurrentEU, chargerBus.maxEUInput()); -// drainEnergyInput(tgsCurrentEU - euToTransfer); -// chargerBus.setEUVar(chargerBus.getEUVar() + euToTransfer); -// } - long tgsCurrentEU = getStoredEnergyInAllEnergyHatches(); - long busMaxEU = chargerBus.maxEUStore(); + for (MTEHatchInputBus inputBus : this.mInputBusses) { + if (inputBus instanceof MTEHatchChargingBus chargingBus) { + isChargingBus = true; + transferEU = getMaxInputEu() - getActualEnergyUsage(); + + long busMaxEU = chargingBus.maxEUStore(); + long euUsage = transferEU + getActualEnergyUsage(); if (mProgresstime != 0) { - if (getAverageInputVoltage() != 0 && getActualEnergyUsage() != 0) { - long euToTransfer = getMaxInputEu() - getActualEnergyUsage(); - long euUsage = tgsCurrentEU - euToTransfer; - - if (tgsCurrentEU > getAverageInputVoltage() * 2) { - if (chargerBus.getEUVar() <= busMaxEU) { - drainEnergyInput(euUsage); - chargerBus.setEUVar(chargerBus.getEUVar() + euToTransfer); - } + if (getStoredEnergyInAllEnergyHatches() >= euUsage) { + if (chargingBus.getEUVar() <= busMaxEU && transferEU > 0) { + drainEnergyInput(transferEU); + chargingBus.setEUVar(chargingBus.getEUVar() + transferEU); } } } - } + } else isChargingBus = false; + } + } + + @Override + public void getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + super.getWailaBody(itemStack, currenttip, accessor, config); + NBTTagCompound tag = accessor.getNBTData(); + + if (tag.getBoolean("isChargingBus")) { + currenttip.add( + StatCollector.translateToLocal("GTPP.machines.tgs.charging_bus") + ": " + + EnumChatFormatting.RED + + tag.getLong("transferEU") + + EnumChatFormatting.RESET); } } + @Override + public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, + int z) { + super.getWailaNBTData(player, tile, tag, world, x, y, z); + tag.setLong("transferEU", transferEU); + tag.setBoolean("isChargingBus", isChargingBus); + + } + /** * In previous versions, the saw used to be placed in the controller slot and the sapling into an input bus. We do * not want to break existing setups like this, so we attempt to swap the two if possible. diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index e4609fd52de..a3d20aca0e0 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -1630,6 +1630,7 @@ GTPP.EBF.heat=Heat capacity GTPP.machines.tier=Tier GTPP.machines.input=Input GTPP.machines.output=Output +GTPP.machines.tgs.charging_bus=Transfer EU GTPP.multiblock.pollutionreduced=Pollution reduced to GTPP.multiblock.pollution=Pollution From 1445bf4bc4a4c50657ed0bda73e1458c7534097a Mon Sep 17 00:00:00 2001 From: evgengoldwar Date: Wed, 18 Sep 2024 19:10:34 +0400 Subject: [PATCH 6/8] Change tooltip --- .../common/tileentities/machines/MTEHatchChargingBus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java index 4e9fdb0ef52..21247660d32 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java @@ -34,7 +34,7 @@ public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { @Override public String[] getDescription() { return new String[] { "Item Charger Bus for Tree Growth Simulator", getSlots(this.mTier) + " Slots", - "Author: " + AuthorEvgenWarGold }; + "Transfer EU : MaxInputEU - ActualUsage","Author: " + AuthorEvgenWarGold }; } @Override From 5405e0536aba08dd2c8f3eb46ff5265a1a90e52f Mon Sep 17 00:00:00 2001 From: evgengoldwar Date: Wed, 18 Sep 2024 19:12:23 +0400 Subject: [PATCH 7/8] Apply spotless --- .../common/tileentities/machines/MTEHatchChargingBus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java index 21247660d32..aa7e7fb9307 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java @@ -34,7 +34,7 @@ public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { @Override public String[] getDescription() { return new String[] { "Item Charger Bus for Tree Growth Simulator", getSlots(this.mTier) + " Slots", - "Transfer EU : MaxInputEU - ActualUsage","Author: " + AuthorEvgenWarGold }; + "Transfer EU : MaxInputEU - ActualUsage", "Author: " + AuthorEvgenWarGold }; } @Override From 8b4ad1df7e7aeb0ee4d61cc31475a7c0c39eb2d2 Mon Sep 17 00:00:00 2001 From: evgengoldwar Date: Wed, 18 Sep 2024 22:45:12 +0400 Subject: [PATCH 8/8] Change recipe --- .../java/gtPlusPlus/core/recipe/RecipesMachines.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java b/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java index 2549bfd766a..4032a925c5c 100644 --- a/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java +++ b/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java @@ -2931,12 +2931,12 @@ private static void runModRecipes() { GTValues.RA.stdBuilder() .itemInputs( ItemList.Hatch_Input_Bus_IV.get(1), - CI.getRobotArm(5, 2), - CI.getEnergyCore(5, 4), - CI.getTieredComponent(OrePrefixes.circuit, 5, 8)) + CI.getRobotArm(7, 2), + CI.getEnergyCore(7, 4), + CI.getTieredComponent(OrePrefixes.circuit, 7, 8)) .itemOutputs(GregtechItemList.ChargingBus.get(1)) - .duration(50 * SECONDS) - .eut(TierEU.RECIPE_IV) + .duration(100 * SECONDS) + .eut(TierEU.RECIPE_UV) .addTo(assemblerRecipes); // Mystic Frame GTValues.RA.stdBuilder()