diff --git a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java index 836856c793b..f5d0bf422f3 100644 --- a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java +++ b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java @@ -1944,7 +1944,8 @@ public enum MetaTileEntityIDs { ComponentAssemblyLine(32026), AntimatterForge(32027), WireLumiium(32737), - WireSignalium(32749),; + WireSignalium(32749), + 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 new file mode 100644 index 00000000000..aa7e7fb9307 --- /dev/null +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchChargingBus.java @@ -0,0 +1,151 @@ +package gregtech.common.tileentities.machines; + +import static gregtech.api.enums.GTValues.AuthorEvgenWarGold; +import static gregtech.api.enums.GTValues.V; +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; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.MTEHatchInputBus; +import gregtech.api.objects.GTRenderedTexture; +import gregtech.api.util.GTModHandler; +import gregtech.api.util.GTUtility; +import gtPlusPlus.xmod.gregtech.api.gui.widget.ElectricSlotWidget; + +public class MTEHatchChargingBus extends MTEHatchInputBus { + + public MTEHatchChargingBus(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, getSlots(aTier)); + } + + public MTEHatchChargingBus(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, getSlots(aTier), aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new MTEHatchChargingBus(this.mName, this.mTier, mDescriptionArray, this.mTextures); + } + + @Override + public String[] getDescription() { + return new String[] { "Item Charger Bus for Tree Growth Simulator", getSlots(this.mTier) + " Slots", + "Transfer EU : MaxInputEU - ActualUsage", "Author: " + AuthorEvgenWarGold }; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (aBaseMetaTileEntity.isServerSide() && aBaseMetaTileEntity.hasInventoryBeenModified()) { + fillStacksIntoFirstSlots(); + } + + if (aBaseMetaTileEntity.isServerSide()) { + 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 { + this.onSetActive(false); + } + } + } + + super.onPostTick(aBaseMetaTileEntity, aTimer); + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public long maxEUInput() { + return 8192; + } + + @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 boolean allowSelectCircuit() { + return false; + } + + @Override + public ITexture[] getTexturesActive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GTRenderedTexture(Overlay_Charging) }; + } + + @Override + public ITexture[] getTexturesInactive(ITexture aBaseTexture) { + return new ITexture[] { aBaseTexture, new GTRenderedTexture(Overlay_Charging) }; + } + + 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() { + 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 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)); + } + } +} diff --git a/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java b/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java index 5f37d75c6f7..265599f923a 100644 --- a/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java +++ b/src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java @@ -2882,6 +2882,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(7, 2), + CI.getEnergyCore(7, 4), + CI.getTieredComponent(OrePrefixes.circuit, 7, 8)) + .itemOutputs(GregtechItemList.ChargingBus.get(1)) + .duration(100 * SECONDS) + .eut(TierEU.RECIPE_UV) + .addTo(assemblerRecipes); // Mystic Frame GTValues.RA.stdBuilder() .itemInputs( 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 4858b555831..532e6e2659f 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/common/blocks/textures/TexturesGtBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtBlock.java index 2f87a3b6fb9..4f8cd35fbac 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 @@ -506,6 +506,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/common/tileentities/machines/multi/production/MTETreeFarm.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/MTETreeFarm.java index c93caaffe9c..35b58eb1f95 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 @@ -37,11 +37,16 @@ import javax.annotation.Nonnull; +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; @@ -72,6 +77,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.pollution.PollutionConfig; import gregtech.common.tileentities.machines.MTEHatchInputBusME; import gtPlusPlus.api.objects.Logger; @@ -82,6 +88,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 { @@ -89,6 +97,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"; @@ -530,6 +540,54 @@ 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 chargingBus) { + isChargingBus = true; + transferEU = getMaxInputEu() - getActualEnergyUsage(); + + long busMaxEU = chargingBus.maxEUStore(); + long euUsage = transferEU + getActualEnergyUsage(); + + if (mProgresstime != 0) { + 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/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java b/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechCustomHatches.java index 58d1abc73b7..7ebc663d24f 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.GT_MetaTileEntity_ChiselBus_HV; import static gregtech.api.enums.MetaTileEntityIDs.GT_MetaTileEntity_ChiselBus_LV; import static gregtech.api.enums.MetaTileEntityIDs.GT_MetaTileEntity_ChiselBus_MV; @@ -45,6 +46,7 @@ import gregtech.GTMod; 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.xmod.gregtech.api.enums.GregtechItemList; @@ -122,6 +124,10 @@ private static void run1() { "Extreme Air Intake Hatch", 6).getStackForm(1L)); + // MultiBlock ChargingBus + GregtechItemList.ChargingBus + .set(new MTEHatchChargingBus(ChargingBus.ID, "Charging Bus", "Charging Bus", 4).getStackForm(1L)); + // Multiblock Reservoir Hatch GregtechItemList.Hatch_Reservoir.set( new MTEHatchReservoir(Hatch_Reservoir.ID, "hatch.water.intake.tier.00", "Reservoir Hatch", 4) diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index edd3a8a0cc4..5175305e1de 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -1687,6 +1687,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 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 00000000000..9664f50057e Binary files /dev/null and b/src/main/resources/assets/miscutils/textures/blocks/TileEntities/adv_machine_charging.png differ