diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2020-01-16 11:33:41 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2020-01-16 11:33:41 +0000 |
commit | 72696a0dd5ca5c0cb2a1017cc1e0bb36669d0ce7 (patch) | |
tree | 01430c29601718947e0dcb758e121b135f34f26c /src/Java/gtPlusPlus/xmod/gregtech/common/tileentities | |
parent | eae5bc6995f40b9b4875fc17db9d12dad1872863 (diff) | |
download | GT5-Unofficial-72696a0dd5ca5c0cb2a1017cc1e0bb36669d0ce7.tar.gz GT5-Unofficial-72696a0dd5ca5c0cb2a1017cc1e0bb36669d0ce7.tar.bz2 GT5-Unofficial-72696a0dd5ca5c0cb2a1017cc1e0bb36669d0ce7.zip |
+ Added GT RF convertor.
$ Fixed Industrial Mixer not working with fluids.
$ Fixed COFH being a hard dependency.
$ Fixed Energy Buffers relying on the Rocket Engine config option.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common/tileentities')
3 files changed, 348 insertions, 3 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_RfConvertor.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_RfConvertor.java new file mode 100644 index 0000000000..ee37f50060 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_RfConvertor.java @@ -0,0 +1,344 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators; + +import static gregtech.api.enums.GT_Values.V; + +import cofh.api.energy.IEnergyConnection; +import cofh.api.energy.IEnergyHandler; +import cofh.api.energy.IEnergyProvider; +import cofh.api.energy.IEnergyReceiver; +import cofh.api.energy.IEnergyStorage; +import crazypants.enderio.machine.capbank.TileCapBank; +import crazypants.enderio.machine.capbank.network.ICapBankNetwork; +import crazypants.enderio.power.IPowerContainer; +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +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.lib.LoadedMods; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.tileentities.storage.GregtechMetaEnergyBuffer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * NEVER INCLUDE THIS FILE IN YOUR MOD!!! + * + * This is the main construct for my Basic Machines such as the Automatic Extractor + * Extend this class to make a simple Machine + */ +public class GT_MetaTileEntity_RfConvertor extends GregtechMetaEnergyBuffer implements IEnergyReceiver { + + + public GT_MetaTileEntity_RfConvertor(final String aName, final int aTier, + final String aDescription, final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aDescription, aTextures, aSlotCount); + } + + public GT_MetaTileEntity_RfConvertor(final int aID, final String aName, + final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aDescription, aSlotCount); + } + + @Override + public String[] getDescription() { + return new String[] {"Use Screwdriver to change voltage", "Hold Shift while using Screwdriver to change amperage", EnumChatFormatting.DARK_AQUA+"Variable Output Voltage"}; + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + ITexture[][][] rTextures = new ITexture[12][17][]; + GT_RenderedTexture aTex = new GT_RenderedTexture(TexturesGtBlock.Casing_Material_ZirconiumCarbide); + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier]}; + rTextures[1][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier]}; + rTextures[2][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT[mTier]}; + rTextures[3][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]}; + rTextures[4][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]}; + rTextures[5][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[mTier]}; + rTextures[6][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier]}; + rTextures[7][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier]}; + rTextures[8][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_IN[mTier]}; + rTextures[9][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier]}; + rTextures[10][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier]}; + rTextures[11][i + 1] = new ITexture[]{aTex, Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[mTier]}; + } + return rTextures; + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { + return mTextures[Math.min(2, aSide) + (aSide == aFacing ? 3 : 0) + (aActive ? 0 : 6)][aColorIndex + 1]; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_RfConvertor(this.mName, this.mTier, this.mDescription, + this.mTextures, this.mInventory.length); + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return Integer.MAX_VALUE; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return V[this.mTier]; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isInputFacing(byte aSide) { + return !isOutputFacing(aSide); + } + + @Override + public boolean isOutputFacing(byte aSide) { + return aSide == getBaseMetaTileEntity().getFrontFacing(); + } + + @Override public boolean isAccessAllowed(final EntityPlayer aPlayer) {return true;} + + @Override + public Object getServerGUI(final int aID, final InventoryPlayer aPlayerInventory, + final IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public Object getClientGUI(final int aID, final InventoryPlayer aPlayerInventory, + final IGregTechTileEntity aBaseMetaTileEntity) { + return null; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (!aBaseMetaTileEntity.isActive()) { + aBaseMetaTileEntity.setActive(true); + } + if (this.getEUVar() < this.maxEUStore()) { + for (byte i = 0; i < 6 && aBaseMetaTileEntity.getStoredEU() < aBaseMetaTileEntity.getEUCapacity(); i++) { + if (isInputFacing(i)) { + receiveEnergy(ForgeDirection.getOrientation(i), Integer.MAX_VALUE, false); + } + } + } + return; + } + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, final byte aSide, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + String[] infoData = super.getInfoData(); + return new String[] { + infoData[0], + "Converts RF -> GTEU | Tier: "+this.mTier, + infoData[1], + infoData[2] + }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("mTier", this.mTier); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mTier = aNBT.getByte("mTier"); + } + + @Override + public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer.isSneaking()) { + byte aTest = (byte) (aCurrentOutputAmperage + 1); + if (aTest > 16 || aTest <= 0 ) { + aTest = 1; + } + aCurrentOutputAmperage = aTest; + PlayerUtils.messagePlayer(aPlayer, "Now handling "+maxAmperesOut()+" Amps."); + } + else { + if (this.mTier < (CORE.GTNH ? GT_Values.V.length : 9)) { + this.mTier++; + } + else { + this.mTier = 0; + } + PlayerUtils.messagePlayer(aPlayer, "Now running at "+GT_Values.VOLTAGE_NAMES[this.mTier]+"."); + } + + } + + @Override + public boolean canConnectEnergy(ForgeDirection from) { + if (isOutputFacing((byte) from.ordinal())) { + return false; + } + return true; + } + + @Override + public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { + + // Cannot accept power on the output face. + if (!canConnectEnergy(from) || isOutputFacing((byte) from.ordinal())) { + return 0; + } + + TileEntity tTileEntity = this.getBaseMetaTileEntity().getTileEntityAtSide((byte) from.ordinal()); + if (tTileEntity == null) { + return 0; + } + + Logger.INFO("Someone is trying to inject RF from "+from+". Type:"+tTileEntity.getClass().getName()); + + // Calculate maximum RF we need to consume + int aInputRF = MathUtils.safeInt(this.maxEUOutput() * GregTech_API.mEUtoRF / 100); + + // Make sure we only consume the correct amount of RF that is pushed into this Tile. + if (aInputRF > maxReceive) { + aInputRF = maxReceive; + } + + int aInjectedRF = 0; + boolean aVal = false; + + long aStoredEU = this.getEUVar(); + long aMaxEU = this.maxEUStore(); + Logger.INFO("Stored: "+aStoredEU+", Capacity: "+aMaxEU+""); + if (aStoredEU < aMaxEU) { + Logger.INFO("StoredEU < MaxEU"); + long aRemainingSpace = aMaxEU - aStoredEU; + if (aRemainingSpace > 0) { + long tEU = 0; + byte aSide = (byte) from.ordinal(); + Logger.INFO("Free: "+aRemainingSpace+"EU"); + if (tTileEntity instanceof IEnergyProvider && ((IEnergyProvider) tTileEntity).extractEnergy(ForgeDirection.getOrientation(GT_Utility.getOppositeSide(aSide)), 1, true) == 1) { + tEU = (long) ((IEnergyProvider) tTileEntity).extractEnergy(ForgeDirection.getOrientation(GT_Utility.getOppositeSide(aSide)), (int) maxEUOutput() * 100 / GregTech_API.mRFtoEU, false); + Logger.INFO("Drained from IEnergyProvider Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); + tEU = tEU * GregTech_API.mRFtoEU / 100; + } + else if (tTileEntity instanceof IEnergyStorage && ((IEnergyStorage) tTileEntity).extractEnergy(1, true) == 1) { + tEU = (long) ((IEnergyStorage) tTileEntity).extractEnergy((int) maxEUOutput() * 100 / GregTech_API.mRFtoEU, false); + Logger.INFO("Drained from IEnergyStorage Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); + tEU = tEU * GregTech_API.mRFtoEU / 100; + } + else if (GregTech_API.meIOLoaded && tTileEntity instanceof IPowerContainer && ((IPowerContainer) tTileEntity).getEnergyStored() > 0) { + int storedRF = ((IPowerContainer) tTileEntity).getEnergyStored(); + int extractRF = (int) maxEUOutput() * 100 / GregTech_API.mRFtoEU; + tEU = 0; + if (tTileEntity instanceof TileCapBank) { + ICapBankNetwork network = ((TileCapBank) tTileEntity).getNetwork(); + if (network != null && network.getEnergyStoredL() > 0) { + tEU = Math.min((Math.min(Math.min(network.getEnergyStoredL(), storedRF - extractRF), network.getMaxOutput())) * GregTech_API.mRFtoEU / 100, maxEUOutput()); + Logger.INFO("Drained from EIO CapBank Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); + network.addEnergy((int) -(tEU * 100 / GregTech_API.mRFtoEU)); + } + } else { + if (storedRF > extractRF) { + ((IPowerContainer) tTileEntity).setEnergyStored(storedRF - extractRF); + tEU = maxEUOutput(); + Logger.INFO("Drained from EIO Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); + } else { + ((IPowerContainer) tTileEntity).setEnergyStored(0); + tEU = storedRF * GregTech_API.mRFtoEU / 100; + Logger.INFO("Drained from EIO Tile: "+(tEU * 100 / GregTech_API.mRFtoEU)+""); + } + } + } + Logger.INFO("EU to inject: "+tEU+"EU"); + if (!simulate) { + aVal = this.getBaseMetaTileEntity().increaseStoredEnergyUnits(tEU, true); + } + if (tEU > 0) { + Logger.INFO("Tried injecting "+tEU+" eu into self. Success? "+aVal); + } + } + } + return aInjectedRF; + } + + @Override + public int getEnergyStored(ForgeDirection from) { + long aStoredEU = this.getEUVar(); + long aMaxEU = this.maxEUStore(); + if (aStoredEU == 0) { + return 0; + } + if (aStoredEU < aMaxEU) { + long aRemainingSpace = aMaxEU - aStoredEU; + if (aRemainingSpace > 0) { + if (aRemainingSpace > (this.maxEUOutput() / (GregTech_API.mEUtoRF / 100))) { + int aCalculatedFreeSpace = 0; + int aRfPer10Eu = GregTech_API.mEUtoRF / 10; + // Calculate how many lots of '10 + aCalculatedFreeSpace = (int) Math.floor(aRemainingSpace / 10); + // Return value equal to how many lots of '10eu' packets we can fit in. + return Integer.MAX_VALUE - MathUtils.balance(aCalculatedFreeSpace * aRfPer10Eu, 0, Integer.MAX_VALUE); + } + } + } + return Integer.MAX_VALUE; + } + + @Override + public int getMaxEnergyStored(ForgeDirection from) { + return Integer.MAX_VALUE; + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java index 6e4c071ecb..0c7067b3c0 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java @@ -14,6 +14,7 @@ import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.util.data.ArrayUtils; import gtPlusPlus.core.util.minecraft.ItemUtils; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; @@ -128,7 +129,7 @@ extends GregtechMeta_MultiBlockBase { } if (inputs.length > 0) { log("Recipe. ["+inputs.length+"]["+getMaxParallelRecipes()+"]"); - if (checkRecipeGeneric(inputs, new FluidStack[]{}, getMaxParallelRecipes(), getEuDiscountForParallelism(), 250, 10000)) { + if (checkRecipeGeneric(inputs, (FluidStack[]) ArrayUtils.getArrayFromArrayList(this.getStoredFluids()), getMaxParallelRecipes(), getEuDiscountForParallelism(), 250, 10000)) { log("Recipe 2."); return true; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java index 86d02eae9a..4f0197c060 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java @@ -26,7 +26,7 @@ import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; public class GregtechMetaEnergyBuffer extends GregtechMetaTileEntity { - private byte aCurrentOutputAmperage = 4; + protected byte aCurrentOutputAmperage = 4; public GregtechMetaEnergyBuffer(final int aID, final String aName, final String aNameRegional, final int aTier, final String aDescription, final int aSlotCount) { super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); @@ -253,7 +253,7 @@ public class GregtechMetaEnergyBuffer extends GregtechMetaTileEntity { final double c = ((double) tempStorage / this.maxEUStore()) * 100; final double roundOff = Math.round(c * 100.00) / 100.00; PlayerUtils.messagePlayer(playerIn, "Energy: " + GT_Utility.formatNumbers(tempStorage) + " EU at "+V[this.mTier]+"v ("+roundOff+"%)"); - PlayerUtils.messagePlayer(playerIn, "Amperage: " + GT_Utility.formatNumbers(maxAmperesIn())+"A"); + PlayerUtils.messagePlayer(playerIn, "Amperage: " + GT_Utility.formatNumbers(maxAmperesOut())+"A"); } //Utils.LOG_WARNING("Begin Show Energy"); |