diff options
| author | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
|---|---|---|
| committer | Raven Szewczyk <git@eigenraven.me> | 2024-05-24 19:50:35 +0100 |
| commit | 6d1b2216464d4dad449ac6fcfec476832224a55e (patch) | |
| tree | 526a0c15f7056313c80e6c0386e025e9b3f61781 /src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines | |
| parent | b5d35f40afa606ed1b07061dad82e0521a59c186 (diff) | |
| download | GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.gz GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.bz2 GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.zip | |
Merge addon sources
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines')
65 files changed, 23899 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java new file mode 100644 index 0000000000..c592a68a40 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java @@ -0,0 +1,716 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizon.gtnhlib.util.map.ItemStackMap; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.gui.GTPP_UITextures; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import ic2.api.crops.CropCard; +import ic2.api.crops.ICropTile; +import ic2.core.item.DamageHandler; + +public class GT_MetaTileEntity_CropHarvestor extends GT_MetaTileEntity_BasicTank { + + private static final int SLOT_WEEDEX_1 = 1; + private static final int SLOT_WEEDEX_2 = 2; + private static final int SLOT_FERT_1 = 3; + private static final int SLOT_FERT_4 = 6; + private static final int SLOT_OUTPUT_START = 7; + + public boolean mModeAlternative = false; + public boolean mHarvestEnabled = true; + + public GT_MetaTileEntity_CropHarvestor(final int aID, final int aTier, final String aDescription) { + super( + aID, + "basicmachine.cropharvester.0" + aTier, + "Crop Manager (" + GT_Values.VN[aTier] + ")", + aTier, + 21, + aDescription); + } + + public GT_MetaTileEntity_CropHarvestor(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, 21, aDescription, aTextures); + } + + @Override + public boolean isTransformerUpgradable() { + return true; + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isInputFacing(ForgeDirection side) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public long maxAmperesIn() { + return 8; + } + + @Override + public long getMinimumStoredEU() { + return GT_Values.V[this.mTier]; + } + + @Override + public long maxEUStore() { + return GT_Values.V[this.mTier] * (this.mTier * GT_Values.V[this.mTier]); + } + + @Override + public long maxEUInput() { + return GT_Values.V[this.mTier]; + } + + @Override + public int getCapacity() { + return 32000 * this.mTier; + } + + @Override + public int getTankPressure() { + return -100; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_CropHarvestor(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public int getSizeInventory() { + return 21; + } + + private static int getRange(int aTier) { + return switch (aTier) { + case 1 -> 1; + case 2 -> 5; + case 3 -> 9; + case 4 -> 13; + case 5 -> 17; + case 6 -> 21; + case 7 -> 25; + case 8 -> 29; + case 9 -> 33; + default -> 0; + }; + } + + private HashSet<ICropTile> mCropCache = new HashSet<>(); + private boolean mInvalidCache = false; + + public boolean doesInventoryHaveSpace() { + for (int i = SLOT_OUTPUT_START; i < this.getSizeInventory(); i++) { + if (this.mInventory[i] == null || this.mInventory[i].stackSize < 64) { + return true; + } + } + return false; + } + + public long powerUsage() { + return this.maxEUInput() / 8; + } + + public long powerUsageSecondary() { + return this.maxEUInput() / 32; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (!getBaseMetaTileEntity().isServerSide() || !getBaseMetaTileEntity().isAllowedToWork() + || (!getBaseMetaTileEntity().hasWorkJustBeenEnabled() && aTick % 100 != 0)) return; + + if (this.getBaseMetaTileEntity() + .getUniversalEnergyStored() < getMinimumStoredEU()) return; + + int aTileX = this.getBaseMetaTileEntity() + .getXCoord(); + int aTileY = this.getBaseMetaTileEntity() + .getXCoord(); + int aTileZ = this.getBaseMetaTileEntity() + .getXCoord(); + + int aRadius = 10 + getRange(this.mTier); + int aSide = (aRadius - 1) / 2; + Map<ItemStack, Integer> aAllDrops = new ItemStackMap<>(true); + + if (this.mCropCache.isEmpty() || aTick % 1200 == 0 || this.mInvalidCache) { + if (!this.mCropCache.isEmpty()) { + this.mCropCache.clear(); + } + // Logger.INFO("Looking for crops."); + for (int y = -2; y <= 2; y++) { + for (int x = (-aSide); x <= aSide; x++) { + for (int z = (-aSide); z <= aSide; z++) { + TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntityOffset(x, y, z); + if (tTileEntity != null && tTileEntity instanceof ICropTile tCrop) { + this.mCropCache.add(tCrop); + } + } + } + } + } + + // Process Cache + if (!doesInventoryHaveSpace()) return; + + for (ICropTile tCrop : this.mCropCache) { + if (tCrop == null) { + this.mInvalidCache = true; + break; + } + CropCard aCrop = tCrop.getCrop(); + if (aCrop == null) continue; + + if (this.mModeAlternative) processSecondaryFunctions(tCrop); + if (!this.mHarvestEnabled) continue; + + if (aCrop.canBeHarvested(tCrop) && tCrop.getSize() == aCrop.getOptimalHavestSize(tCrop)) { + if (!getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsage(), true)) continue; + ItemStack[] aHarvest = tCrop.harvest_automated(true); + if (aHarvest == null) continue; + + for (ItemStack aStack : aHarvest) { + if (!ItemUtils.checkForInvalidItems(aStack)) continue; + if (this.mTier * 5 > MathUtils.randInt(1, 100)) { + aStack.stackSize += Math.floor(tCrop.getGain() / 10); + Logger.INFO("Bonus output given for " + aCrop.displayName()); + } + Logger.INFO("Harvested " + aCrop.displayName()); + aAllDrops.merge(aStack, aStack.stackSize, Integer::sum); + } + } + } + + if (aAllDrops.isEmpty()) return; + + Logger.INFO("Handling " + aAllDrops.size() + " Harvests"); + for (int i = SLOT_OUTPUT_START; i < this.getSizeInventory() && !aAllDrops.isEmpty(); i++) { + ItemStack invStack = mInventory[i]; + if (invStack == null || GT_Utility.isStackInvalid(invStack) || invStack.stackSize == 0) { + Iterator<Entry<ItemStack, Integer>> iter = aAllDrops.entrySet() + .iterator(); + if (!iter.hasNext()) return; + Entry< |
