From 0f50c05a7d4e9292ecba78bc9f176f4dad255b3b Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Tue, 15 Jul 2014 02:25:03 -0500 Subject: [PATCH] Added Light P2P Tunnel --- core/features/AEFeature.java | 2 +- .../registries/P2PTunnelRegistry.java | 6 + core/localization/GuiText.java | 2 +- core/settings/TickRates.java | 4 +- items/parts/PartType.java | 3 + parts/p2p/PartP2PLight.java | 178 ++++++++++++++++++ parts/p2p/PartP2PTunnel.java | 3 + 7 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 parts/p2p/PartP2PLight.java diff --git a/core/features/AEFeature.java b/core/features/AEFeature.java index 7e476932..a756a086 100644 --- a/core/features/AEFeature.java +++ b/core/features/AEFeature.java @@ -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"), diff --git a/core/features/registries/P2PTunnelRegistry.java b/core/features/registries/P2PTunnelRegistry.java index 9be00bbc..2635150e 100644 --- a/core/features/registries/P2PTunnelRegistry.java +++ b/core/features/registries/P2PTunnelRegistry.java @@ -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. */ diff --git a/core/localization/GuiText.java b/core/localization/GuiText.java index 4e33332a..462146a8 100644 --- a/core/localization/GuiText.java +++ b/core/localization/GuiText.java @@ -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; diff --git a/core/settings/TickRates.java b/core/settings/TickRates.java index 7e9fa1fe..cec48ba9 100644 --- a/core/settings/TickRates.java +++ b/core/settings/TickRates.java @@ -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; diff --git a/items/parts/PartType.java b/items/parts/PartType.java index 089c772d..d0e1130c 100644 --- a/items/parts/PartType.java +++ b/items/parts/PartType.java @@ -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 features; diff --git a/parts/p2p/PartP2PLight.java b/parts/p2p/PartP2PLight.java new file mode 100644 index 00000000..37fd6c3a --- /dev/null +++ b/parts/p2p/PartP2PLight.java @@ -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 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; + } +} diff --git a/parts/p2p/PartP2PTunnel.java b/parts/p2p/PartP2PTunnel.java index c8ea2159..b207a04d 100644 --- a/parts/p2p/PartP2PTunnel.java +++ b/parts/p2p/PartP2PTunnel.java @@ -121,6 +121,9 @@ public class 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 );