Added Light P2P Tunnel

This commit is contained in:
AlgorithmX2 2014-07-15 02:25:03 -05:00
parent e1d3fdb8d7
commit 0f50c05a7d
7 changed files with 195 additions and 3 deletions

View file

@ -42,7 +42,7 @@ public enum AEFeature
DenseEnergyCells("HigherCapacity"), DenseCables("HigherCapacity"),
P2PTunnelRF("P2PTunnels"), P2PTunnelME("P2PTunnels"), P2PTunnelItems("P2PTunnels"), P2PTunnelRedstone("P2PTunnels"), P2PTunnelEU("P2PTunnels"), P2PTunnelMJ(
"P2PTunnels"), P2PTunnelLiquids("P2PTunnels"),
"P2PTunnels"), P2PTunnelLiquids("P2PTunnels"), P2PTunnelLight("P2PTunnels"),
MassCannonBlockDamage("BlockFeatures"), TinyTNTBlockDamage("BlockFeatures"), Facades("Facades"),

View file

@ -33,6 +33,12 @@ public class P2PTunnelRegistry implements IP2PTunnelRegistry
public void configure()
{
/**
* light!
*/
addNewAttunement( new ItemStack( Blocks.torch ), TunnelType.LIGHT );
addNewAttunement( new ItemStack( Blocks.glowstone ), TunnelType.LIGHT );
/**
* attune based on most redstone base items.
*/

View file

@ -32,7 +32,7 @@ public enum GuiText
OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, ConfirmCrafting,
Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing, InterfaceTerminal, NoCraftingCPUs;
Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing, InterfaceTerminal, NoCraftingCPUs, LightTunnel;
String root;

View file

@ -25,7 +25,9 @@ public enum TickRates
StorageBus(5, 60),
ItemTunnel(5, 60);
ItemTunnel(5, 60),
LightTunnel(5, 120);
public int min;
public int max;

View file

@ -24,6 +24,7 @@ import appeng.parts.networking.PartQuartzFiber;
import appeng.parts.p2p.PartP2PBCPower;
import appeng.parts.p2p.PartP2PIC2Power;
import appeng.parts.p2p.PartP2PItems;
import appeng.parts.p2p.PartP2PLight;
import appeng.parts.p2p.PartP2PLiquids;
import appeng.parts.p2p.PartP2PRFPower;
import appeng.parts.p2p.PartP2PRedstone;
@ -104,6 +105,8 @@ public enum PartType
P2PTunnelRF(466, AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel),
P2PTunnelLight(467, AEFeature.P2PTunnelLight, PartP2PLight.class, GuiText.LightTunnel),
InterfaceTerminal(480, AEFeature.InterfaceTerminal, PartInterfaceTerminal.class);
private final EnumSet<AEFeature> features;

178
parts/p2p/PartP2PLight.java Normal file
View file

@ -0,0 +1,178 @@
package appeng.parts.p2p;
import io.netty.buffer.ByteBuf;
import java.io.IOException;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import appeng.api.config.TunnelType;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.core.settings.TickRates;
import appeng.me.GridAccessException;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTickable
{
public PartP2PLight(ItemStack is) {
super( is );
}
public TunnelType getTunnelType()
{
return TunnelType.LIGHT;
}
int lastValue = 0;
public void setLightLevel(int out)
{
lastValue = out;
getHost().markForUpdate();
}
@Override
public int getLightLevel()
{
if ( output && isPowered() )
return blockLight( lastValue );
return 0;
}
private int blockLight(int emit)
{
TileEntity te = this.getTile();
float opacity = 255 - te.getWorldObj().getBlockLightOpacity( te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
return (int) (emit * (opacity / 255.0f));
}
@Override
public void chanRender(MENetworkChannelsChanged c)
{
onTunnelNetworkChange();
super.chanRender( c );
}
@Override
public void powerRender(MENetworkPowerStatusChange c)
{
onTunnelNetworkChange();
super.powerRender( c );
}
@Override
public void onTunnelNetworkChange()
{
if ( output )
{
PartP2PLight src = getInput();
if ( src != null && src.proxy.isActive() )
setLightLevel( src.lastValue );
else
getHost().markForUpdate();
}
else
doWork();
}
@Override
public void onTunnelConfigChange()
{
onTunnelNetworkChange();
}
@Override
public void onNeighborChanged()
{
doWork();
if ( output )
getHost().markForUpdate();
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT( tag );
tag.setInteger( "lastValue", lastValue );
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT( tag );
lastValue = tag.getInteger( "lastValue" );
}
@Override
public boolean readFromStream(ByteBuf data) throws IOException
{
super.readFromStream( data );
lastValue = data.readInt();
output = lastValue > 0;
return false;
}
@Override
public void writeToStream(ByteBuf data) throws IOException
{
super.writeToStream( data );
data.writeInt( output ? lastValue : 0 );
}
@SideOnly(Side.CLIENT)
public IIcon getTypeTexture()
{
return Blocks.quartz_block.getBlockTextureFromSide( 0 );
}
@Override
public TickingRequest getTickingRequest(IGridNode node)
{
return new TickingRequest( TickRates.LightTunnel.min, TickRates.LightTunnel.max, false, false );
}
private boolean doWork()
{
if ( output )
return false;
TileEntity te = getTile();
World w = te.getWorldObj();
int newLevel = w.getBlockLightValue( te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
if ( lastValue != newLevel && proxy.isActive() )
{
lastValue = newLevel;
try
{
for (PartP2PLight out : getOutputs())
out.setLightLevel( lastValue );
}
catch (GridAccessException e)
{
// :P
}
return true;
}
return false;
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
{
return doWork() ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
}

View file

@ -121,6 +121,9 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
switch (tt)
{
case LIGHT:
newType = AEApi.instance().parts().partP2PTunnelLight.stack( 1 );
break;
case RF_POWER:
newType = AEApi.instance().parts().partP2PTunnelRF.stack( 1 );