GT EU P2P support. Partial credits to Ultramine author.

This commit is contained in:
repo_alt committed 2020-09-02 14:15:52 +03:00
1 parent 66e1fa75c7
commit b1f029c477
16 files changed
+649 -6

No files matched your search

+1
View File
@@ -37,6 +37,7 @@ nei_version=1.0.5.111
bc_version=7.0.9
opencomputers_version=1.5.12.26
pneumaticcraft_version=1.9.15-105
gt_version=5.09.33.52
#########################################################
# Self Compiled APIs #
+6
View File
@@ -79,6 +79,11 @@ repositories {
name 'gtnh_download_source'
artifactPattern "http://downloads.gtnewhorizons.com/Mods_for_Jenkins/[module]-[revision].[ext]"
}
maven {
name = "gt"
url = "https://gregtech.overminddl1.com/"
}
// CurseForge DNS for TE is not available or I am just being unlucky, code part can stay since this is applicable to any other curseforge mod though
// ivy {
// name = "CoFHLib"
@@ -127,6 +132,7 @@ dependencies {
compileOnly "codechicken:CodeChickenLib:${minecraft_version}-${code_chicken_lib_version}:dev"
compileOnly "codechicken:CodeChickenCore:${minecraft_version}-${code_chicken_core_version}:dev"
compileOnly "codechicken:NotEnoughItems:${minecraft_version}-${nei_version}:dev"
compileOnly "com.gregoriust.gregtech:gregtech:${gt_version}:dev"
compile files("lib/buildcraft-${bc_version}-dev.jar")
compile files("lib/PneumaticCraft-${minecraft_version}-${pneumaticcraft_version}-api.jar")
@@ -35,5 +35,6 @@ public enum TunnelType
LIGHT, // Light Tunnel
BUNDLED_REDSTONE, // Bundled Redstone Tunnel
COMPUTER_MESSAGE, // Computer Message Tunnel
PRESSURE // PneumaticCraft Tunnel
PRESSURE, // PneumaticCraft Tunnel
GT_POWER // GregTech EU Tunnel
}
@@ -109,4 +109,6 @@ public interface IParts
IItemDefinition conversionMonitor();
IItemDefinition patternTerminalEx();
IItemDefinition p2PTunnelGregtech();
}
+5 -3
View File
@@ -43,8 +43,7 @@ import java.util.List;
public final class AEConfig extends Configuration implements IConfigurableObject, IConfigManagerHost
{
public static final double TUNNEL_POWER_LOSS = 0.05;
public static double TUNNEL_POWER_LOSS = 0.05;
public static final String VERSION = "@version@";
public static final String CHANNEL = "@aechannel@";
public static final String PACKET_CHANNEL = "AE";
@@ -108,7 +107,6 @@ public final class AEConfig extends Configuration implements IConfigurableObject
FMLCommonHandler.instance().bus().register( this );
final double DEFAULT_MEKANISM_EXCHANGE = 0.2;
PowerUnits.MK.conversionRatio = this.get( "PowerRatios", "Mekanism", DEFAULT_MEKANISM_EXCHANGE ).getDouble( DEFAULT_MEKANISM_EXCHANGE );
final double DEFAULT_IC2_EXCHANGE = 2.0;
PowerUnits.EU.conversionRatio = this.get( "PowerRatios", "IC2", DEFAULT_IC2_EXCHANGE ).getDouble( DEFAULT_IC2_EXCHANGE );
@@ -116,6 +114,10 @@ public final class AEConfig extends Configuration implements IConfigurableObject
PowerUnits.WA.conversionRatio = this.get( "PowerRatios", "RotaryCraft", DEFAULT_RTC_EXCHANGE ).getDouble( DEFAULT_RTC_EXCHANGE );
final double DEFAULT_RF_EXCHANGE = 0.5;
PowerUnits.RF.conversionRatio = this.get( "PowerRatios", "ThermalExpansion", DEFAULT_RF_EXCHANGE ).getDouble( DEFAULT_RF_EXCHANGE );
final double DEFAULT_TUNNEL_POWER_LOSS = 0.15;
TUNNEL_POWER_LOSS = this.get("PowerRatios", "TunnelPowerLoss", DEFAULT_TUNNEL_POWER_LOSS).getDouble(DEFAULT_TUNNEL_POWER_LOSS);
if (TUNNEL_POWER_LOSS < 0 || TUNNEL_POWER_LOSS >= 1)
TUNNEL_POWER_LOSS = DEFAULT_TUNNEL_POWER_LOSS;
final double usageEffective = this.get( "PowerRatios", "UsageMultiplier", 1.0 ).getDouble( 1.0 );
PowerMultiplier.CONFIG.multiplier = Math.max( 0.01, usageEffective );
@@ -62,6 +62,7 @@ public final class ApiParts implements IParts
private final IItemDefinition p2PTunnelLight;
private final IItemDefinition p2PTunnelOpenComputers;
private final IItemDefinition p2PTunnelPneumaticCraft;
private final IItemDefinition p2PTunnelGregtech;
private final IItemDefinition cableAnchor;
private final IItemDefinition monitor;
private final IItemDefinition semiDarkMonitor;
@@ -107,6 +108,7 @@ public final class ApiParts implements IParts
this.p2PTunnelLight = new DamagedItemDefinition( itemMultiPart.createPart( PartType.P2PTunnelLight ) );
this.p2PTunnelOpenComputers = new DamagedItemDefinition( itemMultiPart.createPart( PartType.P2PTunnelOpenComputers ) );
this.p2PTunnelPneumaticCraft = new DamagedItemDefinition( itemMultiPart.createPart( PartType.P2PTunnelPressure ) );
this.p2PTunnelGregtech = new DamagedItemDefinition( itemMultiPart.createPart( PartType.P2PTunnelGT ) );
this.cableAnchor = new DamagedItemDefinition( itemMultiPart.createPart( PartType.CableAnchor ) );
this.monitor = new DamagedItemDefinition( itemMultiPart.createPart( PartType.Monitor ) );
this.semiDarkMonitor = new DamagedItemDefinition( itemMultiPart.createPart( PartType.SemiDarkMonitor ) );
@@ -292,6 +294,12 @@ public final class ApiParts implements IParts
return this.p2PTunnelPneumaticCraft;
}
@Override
public IItemDefinition p2PTunnelGregtech()
{
return this.p2PTunnelGregtech;
}
@Override
public IItemDefinition cableAnchor()
{
@@ -103,6 +103,7 @@ public enum AEFeature
P2PTunnelLight( Constants.CATEGORY_P2P_TUNNELS ),
P2PTunnelOpenComputers( Constants.CATEGORY_P2P_TUNNELS ),
P2PTunnelPressure( Constants.CATEGORY_P2P_TUNNELS ),
P2PTunnelGregtech( Constants.CATEGORY_P2P_TUNNELS ),
MassCannonBlockDamage( Constants.CATEGORY_BLOCK_FEATURES ),
TinyTNTBlockDamage( Constants.CATEGORY_BLOCK_FEATURES ),
@@ -45,7 +45,7 @@ public enum GuiText
CraftingTerminal, FormationPlane, Inscriber, QuartzCuttingKnife,
// tunnel names
METunnel, ItemTunnel, RedstoneTunnel, EUTunnel, FluidTunnel, OCTunnel, LightTunnel, RFTunnel, PressureTunnel,
METunnel, ItemTunnel, RedstoneTunnel, EUTunnel, FluidTunnel, OCTunnel, LightTunnel, RFTunnel, PressureTunnel, GTTunnel,
StoredSize, CopyMode, CopyModeDesc, PatternTerminal,
@@ -65,7 +65,9 @@ public enum IntegrationType
OpenComputers( IntegrationSide.BOTH, "OpenComputers", "OpenComputers" ),
PneumaticCraft( IntegrationSide.BOTH, "PneumaticCraft", "PneumaticCraft" );
PneumaticCraft( IntegrationSide.BOTH, "PneumaticCraft", "PneumaticCraft" ),
GT( IntegrationSide.BOTH, "GregTech", "gregtech" );
public final IntegrationSide side;
public final String dspName;
@@ -0,0 +1,35 @@
package appeng.integration.modules;
import appeng.api.AEApi;
import appeng.helpers.Reflected;
import appeng.integration.IIntegrationModule;
import appeng.integration.IntegrationHelper;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
public class GT implements IIntegrationModule {
@Reflected
public static GT instance;
@Reflected
public GT()
{
IntegrationHelper.testClassExistence( this, gregtech.api.interfaces.tileentity.IEnergyConnected.class );
}
@Override
public void init() throws Throwable {
if( IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.GT ) )
{
AEApi.instance().partHelper().registerNewLayer(
"appeng.parts.layers.LayerIEnergyConnected",
"gregtech.api.interfaces.tileentity.IEnergyConnected");
}
}
@Override
public void postInit() {
}
}
@@ -133,6 +133,8 @@ public enum PartType
P2PTunnelPressure( 469, EnumSet.of( AEFeature.P2PTunnel, AEFeature.P2PTunnelPressure ), EnumSet.of( IntegrationType.PneumaticCraft ), PartP2PPressure.class, GuiText.PressureTunnel ),
P2PTunnelGT( 470, EnumSet.of( AEFeature.P2PTunnel, AEFeature.P2PTunnelGregtech ), EnumSet.of( IntegrationType.GT ), PartP2PGT5Power.class, GuiText.GTTunnel ),
InterfaceTerminal( 480, EnumSet.of( AEFeature.InterfaceTerminal ), EnumSet.noneOf( IntegrationType.class ), PartInterfaceTerminal.class ),
PatternTerminalEx( 500, EnumSet.of( AEFeature.Patterns ), EnumSet.noneOf( IntegrationType.class ), PartPatternTerminalEx.class );
@@ -0,0 +1,346 @@
package appeng.parts.layers;
import appeng.api.parts.IPart;
import appeng.api.parts.LayerBase;
import appeng.parts.p2p.IPartGT5Power;
import gregtech.api.interfaces.tileentity.IEnergyConnected;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.util.GT_Utility;
import ic2.api.energy.tile.IEnergySink;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
public class LayerIEnergyConnected extends LayerBase implements IEnergyConnected {
public LayerIEnergyConnected() {
}
public long injectEnergyUnits(byte side, long voltage, long amperage) {
IPart part = this.getPart(ForgeDirection.getOrientation(side));
if (part instanceof IPartGT5Power) {
return ((IPartGT5Power) part).injectEnergyUnits(voltage, amperage);
} else {
ForgeDirection dir = ForgeDirection.getOrientation(side);
if (part instanceof IEnergySink) {
TileEntity source = this.getTileEntityAtSide(side);
if (source != null && ((IEnergySink) part).acceptsEnergyFrom(source, dir)) {
long rUsedAmperes;
for (rUsedAmperes = 0L; amperage > rUsedAmperes && ((IEnergySink) part).getDemandedEnergy() > 0.0D && ((IEnergySink) part).injectEnergy(dir, (double) voltage, (double) voltage) < (double) voltage; ++rUsedAmperes) {
}
return rUsedAmperes;
}
}
return 0L;
}
}
@Override
public boolean inputEnergyFrom(byte side) {
ForgeDirection dir = ForgeDirection.getOrientation(side);
IPart part = this.getPart(dir);
if (part instanceof IPartGT5Power) {
return ((IPartGT5Power) part).inputEnergy();
} else if (!(part instanceof IEnergySink)) {
return false;
} else {
TileEntity source = this.getTileEntityAtSide(side);
return source != null && ((IEnergySink) part).acceptsEnergyFrom(source, dir);
}
}
@Override
public boolean inputEnergyFrom(byte side, boolean q) {
ForgeDirection dir = ForgeDirection.getOrientation(side);
IPart part = this.getPart(dir);
if (part instanceof IPartGT5Power) {
return ((IPartGT5Power) part).inputEnergy();
} else if (!(part instanceof IEnergySink)) {
return false;
} else {
TileEntity source = this.getTileEntityAtSide(side);
return source != null && ((IEnergySink) part).acceptsEnergyFrom(source, dir);
}
}
@Override
public boolean outputsEnergyTo(byte side) {
IPart part = this.getPart(ForgeDirection.getOrientation(side));
return part instanceof IPartGT5Power && ((IPartGT5Power) part).outputsEnergy();
}
@Override
public boolean outputsEnergyTo(byte side, boolean q) {
IPart part = this.getPart(ForgeDirection.getOrientation(side));
return part instanceof IPartGT5Power && ((IPartGT5Power) part).outputsEnergy();
}
public byte getColorization() {
return -1;
}
public byte setColorization(byte b) {
return -1;
}
public final World getWorld() {
return this.worldObj;
}
public final int getXCoord() {
return this.xCoord;
}
public final short getYCoord() {
return (short) this.yCoord;
}
public final int getZCoord() {
return this.zCoord;
}
public final int getOffsetX(byte aSide, int aMultiplier) {
return this.xCoord + ForgeDirection.getOrientation(aSide).offsetX * aMultiplier;
}
public final short getOffsetY(byte aSide, int aMultiplier) {
return (short) (this.yCoord + ForgeDirection.getOrientation(aSide).offsetY * aMultiplier);
}
public final int getOffsetZ(byte aSide, int aMultiplier) {
return this.zCoord + ForgeDirection.getOrientation(aSide).offsetZ * aMultiplier;
}
public final boolean isServerSide() {
return !this.worldObj.isRemote;
}
public final boolean isClientSide() {
return this.worldObj.isRemote;
}
public final boolean openGUI(EntityPlayer aPlayer) {
return this.openGUI(aPlayer, 0);
}
public final boolean openGUI(EntityPlayer aPlayer, int aID) {
return false;
}
public final int getRandomNumber(int aRange) {
return this.worldObj.rand.nextInt(aRange);
}
public final BiomeGenBase getBiome(int aX, int aZ) {
return this.worldObj.getBiomeGenForCoords(aX, aZ);
}
public final BiomeGenBase getBiome() {
return this.getBiome(this.xCoord, this.zCoord);
}
public final Block getBlockOffset(int aX, int aY, int aZ) {
return this.getBlock(this.xCoord + aX, this.yCoord + aY, this.zCoord + aZ);
}
public final Block getBlockAtSide(byte aSide) {
return this.getBlockAtSideAndDistance(aSide, 1);
}
public final Block getBlockAtSideAndDistance(byte aSide, int aDistance) {
return this.getBlock(this.getOffsetX(aSide, aDistance), this.getOffsetY(aSide, aDistance), this.getOffsetZ(aSide, aDistance));
}
public final byte getMetaIDOffset(int aX, int aY, int aZ) {
return this.getMetaID(this.xCoord + aX, this.yCoord + aY, this.zCoord + aZ);
}
public final byte getMetaIDAtSide(byte aSide) {
return this.getMetaIDAtSideAndDistance(aSide, 1);
}
public final byte getMetaIDAtSideAndDistance(byte aSide, int aDistance) {
return this.getMetaID(this.getOffsetX(aSide, aDistance), this.getOffsetY(aSide, aDistance), this.getOffsetZ(aSide, aDistance));
}
public final byte getLightLevelOffset(int aX, int aY, int aZ) {
return this.getLightLevel(this.xCoord + aX, this.yCoord + aY, this.zCoord + aZ);
}
public final byte getLightLevelAtSide(byte aSide) {
return this.getLightLevelAtSideAndDistance(aSide, 1);
}
public final byte getLightLevelAtSideAndDistance(byte aSide, int aDistance) {
return this.getLightLevel(this.getOffsetX(aSide, aDistance), this.getOffsetY(aSide, aDistance), this.getOffsetZ(aSide, aDistance));
}
public final boolean getOpacityOffset(int aX, int aY, int aZ) {
return this.getOpacity(this.xCoord + aX, this.yCoord + aY, this.zCoord + aZ);
}
public final boolean getOpacityAtSide(byte aSide) {
return this.getOpacityAtSideAndDistance(aSide, 1);
}
public final boolean getOpacityAtSideAndDistance(byte aSide, int aDistance) {
return this.getOpacity(this.getOffsetX(aSide, aDistance), this.getOffsetY(aSide, aDistance), this.getOffsetZ(aSide, aDistance));
}
public final boolean getSkyOffset(int aX, int aY, int aZ) {
return this.getSky(this.xCoord + aX, this.yCoord + aY, this.zCoord + aZ);
}
public final boolean getSkyAtSide(byte aSide) {
return this.getSkyAtSideAndDistance(aSide, 1);
}
public final boolean getSkyAtSideAndDistance(byte aSide, int aDistance) {
return this.getSky(this.getOffsetX(aSide, aDistance), this.getOffsetY(aSide, aDistance), this.getOffsetZ(aSide, aDistance));
}
public final boolean getAirOffset(int aX, int aY, int aZ) {
return this.getAir(this.xCoord + aX, this.yCoord + aY, this.zCoord + aZ);
}
public final boolean getAirAtSide(byte aSide) {
return this.getAirAtSideAndDistance(aSide, 1);
}
public final boolean getAirAtSideAndDistance(byte aSide, int aDistance) {
return this.getAir(this.getOffsetX(aSide, aDistance), this.getOffsetY(aSide, aDistance), this.getOffsetZ(aSide, aDistance));
}
public final TileEntity getTileEntityOffset(int aX, int aY, int aZ) {
return this.getTileEntity(this.xCoord + aX, this.yCoord + aY, this.zCoord + aZ);
}
public final TileEntity getTileEntityAtSideAndDistance(byte aSide, int aDistance) {
return aDistance == 1 ? this.getTileEntityAtSide(aSide) : this.getTileEntity(this.getOffsetX(aSide, aDistance), this.getOffsetY(aSide, aDistance), this.getOffsetZ(aSide, aDistance));
}
public final IInventory getIInventory(int aX, int aY, int aZ) {
TileEntity tTileEntity = this.getTileEntity(aX, aY, aZ);
return tTileEntity instanceof IInventory ? (IInventory) tTileEntity : null;
}
public final IInventory getIInventoryOffset(int aX, int aY, int aZ) {
TileEntity tTileEntity = this.getTileEntityOffset(aX, aY, aZ);
return tTileEntity instanceof IInventory ? (IInventory) tTileEntity : null;
}
public final IInventory getIInventoryAtSide(byte aSide) {
TileEntity tTileEntity = this.getTileEntityAtSide(aSide);
return tTileEntity instanceof IInventory ? (IInventory) tTileEntity : null;
}
public final IInventory getIInventoryAtSideAndDistance(byte aSide, int aDistance) {
TileEntity tTileEntity = this.getTileEntityAtSideAndDistance(aSide, aDistance);
return tTileEntity instanceof IInventory ? (IInventory) tTileEntity : null;
}
public final IFluidHandler getITankContainer(int aX, int aY, int aZ) {
TileEntity tTileEntity = this.getTileEntity(aX, aY, aZ);
return tTileEntity instanceof IFluidHandler ? (IFluidHandler) tTileEntity : null;
}
public final IFluidHandler getITankContainerOffset(int aX, int aY, int aZ) {
TileEntity tTileEntity = this.getTileEntityOffset(aX, aY, aZ);
return tTileEntity instanceof IFluidHandler ? (IFluidHandler) tTileEntity : null;
}
public final IFluidHandler getITankContainerAtSide(byte aSide) {
TileEntity tTileEntity = this.getTileEntityAtSide(aSide);
return tTileEntity instanceof IFluidHandler ? (IFluidHandler) tTileEntity : null;
}
public final IFluidHandler getITankContainerAtSideAndDistance(byte aSide, int aDistance) {
TileEntity tTileEntity = this.getTileEntityAtSideAndDistance(aSide, aDistance);
return tTileEntity instanceof IFluidHandler ? (IFluidHandler) tTileEntity : null;
}
public final IGregTechTileEntity getIGregTechTileEntity(int aX, int aY, int aZ) {
TileEntity tTileEntity = this.getTileEntity(aX, aY, aZ);
return tTileEntity instanceof IGregTechTileEntity ? (IGregTechTileEntity) tTileEntity : null;
}
public final IGregTechTileEntity getIGregTechTileEntityOffset(int aX, int aY, int aZ) {
TileEntity tTileEntity = this.getTileEntityOffset(aX, aY, aZ);
return tTileEntity instanceof IGregTechTileEntity ? (IGregTechTileEntity) tTileEntity : null;
}
public final IGregTechTileEntity getIGregTechTileEntityAtSide(byte aSide) {
TileEntity tTileEntity = this.getTileEntityAtSide(aSide);
return tTileEntity instanceof IGregTechTileEntity ? (IGregTechTileEntity) tTileEntity : null;
}
public final IGregTechTileEntity getIGregTechTileEntityAtSideAndDistance(byte aSide, int aDistance) {
TileEntity tTileEntity = this.getTileEntityAtSideAndDistance(aSide, aDistance);
return tTileEntity instanceof IGregTechTileEntity ? (IGregTechTileEntity) tTileEntity : null;
}
private boolean crossedChunkBorder(int aX, int aZ) {
return aX >> 4 != this.xCoord >> 4 || aZ >> 4 != this.zCoord >> 4;
}
public final Block getBlock(int aX, int aY, int aZ) {
return this.crossedChunkBorder(aX, aZ) && !this.worldObj.blockExists(aX, aY, aZ) ? Blocks.air : this.worldObj.getBlock(aX, aY, aZ);
}
public final byte getMetaID(int aX, int aY, int aZ) {
return this.crossedChunkBorder(aX, aZ) && !this.worldObj.blockExists(aX, aY, aZ) ? 0 : (byte) this.worldObj.getBlockMetadata(aX, aY, aZ);
}
public final byte getLightLevel(int aX, int aY, int aZ) {
return this.crossedChunkBorder(aX, aZ) && !this.worldObj.blockExists(aX, aY, aZ) ? 0 : (byte) ((int) (this.worldObj.getLightBrightness(aX, aY, aZ) * 15.0F));
}
public final boolean getSky(int aX, int aY, int aZ) {
return this.crossedChunkBorder(aX, aZ) && !this.worldObj.blockExists(aX, aY, aZ) || this.worldObj.canBlockSeeTheSky(aX, aY, aZ);
}
public final boolean getOpacity(int aX, int aY, int aZ) {
return (!this.crossedChunkBorder(aX, aZ) || this.worldObj.blockExists(aX, aY, aZ)) && GT_Utility.isOpaqueBlock(this.worldObj, aX, aY, aZ);
}
public final boolean getAir(int aX, int aY, int aZ) {
return this.crossedChunkBorder(aX, aZ) && !this.worldObj.blockExists(aX, aY, aZ) || GT_Utility.isBlockAir(this.worldObj, aX, aY, aZ);
}
public final TileEntity getTileEntity(int aX, int aY, int aZ) {
return this.crossedChunkBorder(aX, aZ) && !this.worldObj.blockExists(aX, aY, aZ) ? null : this.worldObj.getTileEntity(aX, aY, aZ);
}
public final TileEntity getTileEntityAtSide(byte aSide) {
int tX = this.getOffsetX(aSide, 1);
int tY = this.getOffsetY(aSide, 1);
int tZ = this.getOffsetZ(aSide, 1);
return this.crossedChunkBorder(tX, tZ) && !this.worldObj.blockExists(tX, tY, tZ) ? null : this.worldObj.getTileEntity(tX, tY, tZ);
}
public boolean isDead() {
return this.isInvalidTileEntity();
}
public void sendBlockEvent(byte b, byte b1) {
}
public long getTimer() {
return 0L;
}
public void setLightValue(byte b) {
}
public boolean isInvalidTileEntity() {
return this.isInvalid();
}
}
@@ -0,0 +1,9 @@
package appeng.parts.p2p;
public interface IPartGT5Power {
long injectEnergyUnits(long voltage, long amperage);
boolean inputEnergy();
boolean outputsEnergy();
}
@@ -0,0 +1,220 @@
package appeng.parts.p2p;
import appeng.api.config.PowerUnits;
import appeng.api.networking.IGridNode;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.core.AEConfig;
import appeng.me.GridAccessException;
import cofh.api.energy.IEnergyReceiver;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.GregTech_API;
import gregtech.api.enums.GT_Values;
import gregtech.api.interfaces.tileentity.IEnergyConnected;
import gregtech.api.util.GT_Utility;
import ic2.api.energy.tile.IEnergySink;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import javax.annotation.Nullable;
import java.util.Iterator;
public class PartP2PGT5Power extends PartP2PTunnel<PartP2PGT5Power> implements IPartGT5Power, IGridTickable {
private long buffer;
private long voltage;
private TileEntity cachedTarget;
private boolean isCachedTargetValid;
public PartP2PGT5Power(ItemStack is) {
super(is);
this.getProxy().setFlags();
}
private static IChatComponent chatComponent(String title, String value) {
ChatComponentText cct = new ChatComponentText(title);
cct.getChatStyle().setColor(EnumChatFormatting.GOLD);
ChatComponentText ccv = new ChatComponentText(value);
ccv.getChatStyle().setColor(EnumChatFormatting.YELLOW);
cct.appendSibling(ccv);
return cct;
}
public void onTunnelNetworkChange() {
this.isCachedTargetValid = false;
this.cachedTarget = null;
}
public void onNeighborChanged() {
this.isCachedTargetValid = false;
this.cachedTarget = null;
}
@SideOnly(Side.CLIENT)
protected IIcon getTypeTexture() {
return Blocks.stone.getIcon(0, 0);
}
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
this.buffer = data.getLong("e");
this.voltage = data.getLong("v");
}
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setLong("e", this.buffer);
data.setLong("v", this.voltage);
}
public boolean onPartActivate(EntityPlayer player, Vec3 pos) {
if (!super.onPartActivate(player, pos) && !player.worldObj.isRemote && player.inventory.getCurrentItem() == null) {
PartP2PGT5Power input = this.getInput();
String inputLoc;
if (input == null) {
inputLoc = "no input";
} else {
TileEntity te = input.getHost().getTile();
inputLoc = "[" + te.getWorldObj().provider.dimensionId + "](" + te.xCoord + ", " + te.zCoord + ", " + te.zCoord + ")";
}
player.addChatMessage(chatComponent("------", ""));
player.addChatMessage(chatComponent("Input location: ", (input == this ? "this block " : "") + inputLoc));
player.addChatMessage(chatComponent("Name: ", input != null ? input.getCustomName() : this.getCustomName()));
player.addChatMessage(chatComponent("Freq: ", "" + this.getFrequency()));
player.addChatMessage(chatComponent("Voltage: ", input == null ? "no input" : "" + input.voltage));
return true;
} else {
return false;
}
}
private long getMaxBufferSize(long voltage) {
return voltage * 64L;
}
public long injectEnergyUnits(long voltage, long amperage) {
if (!this.isOutput() && this.isActive() && voltage > 0L && amperage > 0L && this.buffer < this.getMaxBufferSize(voltage)) {
long lastBuffer = this.buffer;
long lastVoltage = this.voltage;
this.voltage = voltage;
this.buffer += (amperage * voltage * (1 - AEConfig.TUNNEL_POWER_LOSS));
if (lastBuffer < voltage && this.buffer >= voltage || lastVoltage <= 0L) {
try {
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
} catch (GridAccessException var10) {
}
}
return amperage;
} else {
return 0L;
}
}
public boolean inputEnergy() {
return !this.isOutput();
}
public boolean outputsEnergy() {
return this.isOutput();
}
public TickingRequest getTickingRequest(IGridNode node) {
return new TickingRequest(1, 20, false, true);
}
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall) {
long voltage = this.voltage;
if (!this.isOutput() && voltage > 0L && this.buffer >= voltage) {
long amperes = this.buffer / voltage;
long amperesUsed = 0L;
try {
for (PartP2PGT5Power t: getOutputs()) {
long received = t.doOutput(voltage, amperes);
amperesUsed += received;
amperes -= received;
if (amperes <= 0L)
break;
}
} catch (GridAccessException ignored) {
}
this.buffer -= amperesUsed * voltage;
return this.buffer < voltage ? TickRateModulation.IDLE : TickRateModulation.URGENT;
} else {
return TickRateModulation.IDLE;
}
}
@Nullable
private TileEntity getTarget() {
TileEntity te;
if (this.isCachedTargetValid) {
te = this.cachedTarget;
if (te == null || !te.isInvalid()) {
return te;
}
}
this.isCachedTargetValid = true;
te = this.getTile();
ForgeDirection side = this.getSide();
return this.cachedTarget = te.getWorldObj().getTileEntity(te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ);
}
private long doOutput(long aVoltage, long aAmperage) {
if (!this.isOutput()) {
return 0L;
} else {
TileEntity te = this.getTarget();
if (te == null) {
return 0L;
} else {
ForgeDirection oppositeSide = this.getSide().getOpposite();
if (te instanceof IEnergyConnected) {
return ((IEnergyConnected) te).injectEnergyUnits((byte) oppositeSide.ordinal(), aVoltage, aAmperage);
} else {
if (te instanceof IEnergySink) {
if (((IEnergySink) te).acceptsEnergyFrom(this.getTile(), oppositeSide)) {
long rUsedAmperes;
for (rUsedAmperes = 0L; aAmperage > rUsedAmperes && ((IEnergySink) te).getDemandedEnergy() > 0.0D && ((IEnergySink) te).injectEnergy(oppositeSide, (double) aVoltage, (double) aVoltage) < (double) aVoltage; ++rUsedAmperes) {
}
return rUsedAmperes;
}
} else if (GregTech_API.mOutputRF && te instanceof IEnergyReceiver) {
int rfOut = (int) (aVoltage * (long) GregTech_API.mEUtoRF / 100L);
if (((IEnergyReceiver) te).receiveEnergy(oppositeSide, rfOut, true) == rfOut) {
((IEnergyReceiver) te).receiveEnergy(oppositeSide, rfOut, false);
return 1L;
}
if (GregTech_API.mRFExplosions && GregTech_API.sMachineExplosions && ((IEnergyReceiver) te).getMaxEnergyStored(oppositeSide) < rfOut * 600 && rfOut > 32 * GregTech_API.mEUtoRF / 100) {
float tStrength = (long) rfOut < GT_Values.V[0] ? 1.0F : ((long) rfOut < GT_Values.V[1] ? 2.0F : ((long) rfOut < GT_Values.V[2] ? 3.0F : ((long) rfOut < GT_Values.V[3] ? 4.0F : ((long) rfOut < GT_Values.V[4] ? 5.0F : ((long) rfOut < GT_Values.V[4] * 2L ? 6.0F : ((long) rfOut < GT_Values.V[5] ? 7.0F : ((long) rfOut < GT_Values.V[6] ? 8.0F : ((long) rfOut < GT_Values.V[7] ? 9.0F : 10.0F))))))));
int tX = te.xCoord;
int tY = te.yCoord;
int tZ = te.zCoord;
World tWorld = te.getWorldObj();
GT_Utility.sendSoundToPlayers(tWorld, GregTech_API.sSoundList.get(209), 1.0F, -1.0F, tX, tY, tZ);
tWorld.setBlock(tX, tY, tZ, Blocks.air);
if (GregTech_API.sMachineExplosions) {
tWorld.createExplosion(null, (double) tX + 0.5D, (double) tY + 0.5D, (double) tZ + 0.5D, tStrength, true);
}
}
}
return 0L;
}
}
}
}
}
@@ -351,6 +351,13 @@ public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicSt
}
break;
case GT_POWER:
for( final ItemStack stack : parts.p2PTunnelGregtech().maybeStack( 1 ).asSet() )
{
newType = stack;
}
break;
default:
break;
}
@@ -103,6 +103,7 @@ gui.appliedenergistics2.RFTunnel=RF
gui.appliedenergistics2.LightTunnel=Light
gui.appliedenergistics2.OCTunnel=OpenComputers
gui.appliedenergistics2.PressureTunnel=Pressure
gui.appliedenergistics2.GTTunnel=GT EU
gui.appliedenergistics2.security.extract.name=Withdraw
gui.appliedenergistics2.security.inject.name=Deposit