Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charging bus for Tree Growth Simulator #3225

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
3 changes: 2 additions & 1 deletion src/main/java/gregtech/api/enums/MetaTileEntityIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,8 @@ public enum MetaTileEntityIDs {
ComponentAssemblyLine(32026),
AntimatterForge(32027),
WireLumiium(32737),
WireSignalium(32749),;
WireSignalium(32749),
ChargingBus(31785);

public final int ID;

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/gtPlusPlus/core/recipe/RecipesMachines.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ public enum GregtechItemList implements IGregtechItemContainer {
// Reservoir Hatch
Hatch_Reservoir,

// ChargingBus
ChargingBus,

// XL Turbine Rotor Hatch
Hatch_Turbine_Rotor,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -82,13 +88,17 @@
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<MTETreeFarm> implements ISurvivalConstructable {

public static int CASING_TEXTURE_ID;
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";
Expand Down Expand Up @@ -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<String> 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/gregtech/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading