pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
+34 -41
View File
@@ -18,7 +18,6 @@
package appeng.parts.p2p;
import java.util.ArrayList;
import java.util.List;
@@ -28,54 +27,48 @@ import appeng.api.parts.IPartModel;
import appeng.core.AppEng;
import appeng.parts.PartModel;
/**
* Helper for maintaining the models used for a variant of the P2P bus.
*/
class P2PModels
{
class P2PModels {
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_off" );
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_on" );
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_has_channel" );
public static final ResourceLocation MODEL_FREQUENCY = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_frequency" );
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation(AppEng.MOD_ID,
"part/p2p/p2p_tunnel_status_off");
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation(AppEng.MOD_ID,
"part/p2p/p2p_tunnel_status_on");
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID,
"part/p2p/p2p_tunnel_status_has_channel");
public static final ResourceLocation MODEL_FREQUENCY = new ResourceLocation(AppEng.MOD_ID,
"part/p2p/p2p_tunnel_frequency");
private final IPartModel modelsOff;
private final IPartModel modelsOn;
private final IPartModel modelsHasChannel;
private final IPartModel modelsOff;
private final IPartModel modelsOn;
private final IPartModel modelsHasChannel;
public P2PModels( String frontModelPath )
{
ResourceLocation frontModel = new ResourceLocation( AppEng.MOD_ID, frontModelPath );
public P2PModels(String frontModelPath) {
ResourceLocation frontModel = new ResourceLocation(AppEng.MOD_ID, frontModelPath);
this.modelsOff = new PartModel( MODEL_STATUS_OFF, MODEL_FREQUENCY, frontModel );
this.modelsOn = new PartModel( MODEL_STATUS_ON, MODEL_FREQUENCY, frontModel );
this.modelsHasChannel = new PartModel( MODEL_STATUS_HAS_CHANNEL, MODEL_FREQUENCY, frontModel );
}
this.modelsOff = new PartModel(MODEL_STATUS_OFF, MODEL_FREQUENCY, frontModel);
this.modelsOn = new PartModel(MODEL_STATUS_ON, MODEL_FREQUENCY, frontModel);
this.modelsHasChannel = new PartModel(MODEL_STATUS_HAS_CHANNEL, MODEL_FREQUENCY, frontModel);
}
public IPartModel getModel( boolean hasPower, boolean hasChannel )
{
if( hasPower && hasChannel )
{
return this.modelsHasChannel;
}
else if( hasPower )
{
return this.modelsOn;
}
else
{
return this.modelsOff;
}
}
public IPartModel getModel(boolean hasPower, boolean hasChannel) {
if (hasPower && hasChannel) {
return this.modelsHasChannel;
} else if (hasPower) {
return this.modelsOn;
} else {
return this.modelsOff;
}
}
public List<IPartModel> getModels()
{
List<IPartModel> result = new ArrayList<>();
result.add( this.modelsOff );
result.add( this.modelsOn );
result.add( this.modelsHasChannel );
return result;
}
public List<IPartModel> getModels() {
List<IPartModel> result = new ArrayList<>();
result.add(this.modelsOff);
result.add(this.modelsOn);
result.add(this.modelsHasChannel);
return result;
}
}
+163 -212
View File
@@ -18,8 +18,8 @@
package appeng.parts.p2p;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -35,254 +35,205 @@ import appeng.capabilities.Capabilities;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower> {
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_fe");
private static final IEnergyStorage NULL_ENERGY_STORAGE = new NullEnergyStorage();
private final IEnergyStorage inputHandler = new InputEnergyStorage();
private final IEnergyStorage outputHandler = new OutputEnergyStorage();
public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower>
{
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_fe" );
private static final IEnergyStorage NULL_ENERGY_STORAGE = new NullEnergyStorage();
private final IEnergyStorage inputHandler = new InputEnergyStorage();
private final IEnergyStorage outputHandler = new OutputEnergyStorage();
public PartP2PFEPower(ItemStack is) {
super(is);
}
public PartP2PFEPower( ItemStack is )
{
super( is );
}
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.isPowered(), this.isActive());
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.isPowered(), this.isActive() );
}
@Override
public void onTunnelNetworkChange() {
this.getHost().notifyNeighbors();
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
private IEnergyStorage getAttachedEnergyStorage() {
LazyOptional<IEnergyStorage> energyStorageOpt = LazyOptional.empty();
if (this.isActive()) {
final TileEntity self = this.getTile();
final TileEntity te = self.getWorld().getTileEntity(self.getPos().offset(this.getSide().getFacing()));
private IEnergyStorage getAttachedEnergyStorage()
{
LazyOptional<IEnergyStorage> energyStorageOpt = LazyOptional.empty();
if( this.isActive() )
{
final TileEntity self = this.getTile();
final TileEntity te = self.getWorld().getTileEntity( self.getPos().offset( this.getSide().getFacing() ) );
if (te != null) {
energyStorageOpt = te.getCapability(Capabilities.FORGE_ENERGY,
this.getSide().getOpposite().getFacing());
}
}
return energyStorageOpt.orElse(NULL_ENERGY_STORAGE);
}
if( te != null )
{
energyStorageOpt = te.getCapability( Capabilities.FORGE_ENERGY, this.getSide().getOpposite().getFacing() );
}
}
return energyStorageOpt.orElse( NULL_ENERGY_STORAGE );
}
@SuppressWarnings("unchecked")
@Nullable
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability) {
if (capability == Capabilities.FORGE_ENERGY) {
if (this.isOutput()) {
return (LazyOptional<T>) LazyOptional.of(() -> this.outputHandler);
}
return (LazyOptional<T>) LazyOptional.of(() -> this.inputHandler);
}
return super.getCapability(capability);
}
@SuppressWarnings("unchecked")
@Nullable
@Override
public <T> LazyOptional<T> getCapability( @Nonnull Capability<T> capability )
{
if( capability == Capabilities.FORGE_ENERGY )
{
if( this.isOutput() )
{
return (LazyOptional<T>) LazyOptional.of(() -> this.outputHandler);
}
return (LazyOptional<T>) LazyOptional.of(() ->this.inputHandler);
}
return super.getCapability( capability );
}
private class InputEnergyStorage implements IEnergyStorage {
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
return 0;
}
private class InputEnergyStorage implements IEnergyStorage
{
@Override
public int extractEnergy( int maxExtract, boolean simulate )
{
return 0;
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
int total = 0;
@Override
public int receiveEnergy( int maxReceive, boolean simulate )
{
int total = 0;
try {
final int outputTunnels = PartP2PFEPower.this.getOutputs().size();
try
{
final int outputTunnels = PartP2PFEPower.this.getOutputs().size();
if (outputTunnels == 0 | maxReceive == 0) {
return 0;
}
if( outputTunnels == 0 | maxReceive == 0 )
{
return 0;
}
final int amountPerOutput = maxReceive / outputTunnels;
int overflow = amountPerOutput == 0 ? maxReceive : maxReceive % amountPerOutput;
final int amountPerOutput = maxReceive / outputTunnels;
int overflow = amountPerOutput == 0 ? maxReceive : maxReceive % amountPerOutput;
for (PartP2PFEPower target : PartP2PFEPower.this.getOutputs()) {
final IEnergyStorage output = target.getAttachedEnergyStorage();
final int toSend = amountPerOutput + overflow;
final int received = output.receiveEnergy(toSend, simulate);
for( PartP2PFEPower target : PartP2PFEPower.this.getOutputs() )
{
final IEnergyStorage output = target.getAttachedEnergyStorage();
final int toSend = amountPerOutput + overflow;
final int received = output.receiveEnergy( toSend, simulate );
overflow = toSend - received;
total += received;
}
overflow = toSend - received;
total += received;
}
if (!simulate) {
PartP2PFEPower.this.queueTunnelDrain(PowerUnits.RF, total);
}
} catch (GridAccessException ignored) {
}
if( !simulate )
{
PartP2PFEPower.this.queueTunnelDrain( PowerUnits.RF, total );
}
}
catch( GridAccessException ignored )
{
}
return total;
}
return total;
}
@Override
public boolean canExtract() {
return false;
}
@Override
public boolean canExtract()
{
return false;
}
@Override
public boolean canReceive() {
return true;
}
@Override
public boolean canReceive()
{
return true;
}
@Override
public int getMaxEnergyStored() {
int total = 0;
@Override
public int getMaxEnergyStored()
{
int total = 0;
try {
for (PartP2PFEPower t : PartP2PFEPower.this.getOutputs()) {
total += t.getAttachedEnergyStorage().getMaxEnergyStored();
}
} catch (GridAccessException e) {
return 0;
}
try
{
for( PartP2PFEPower t : PartP2PFEPower.this.getOutputs() )
{
total += t.getAttachedEnergyStorage().getMaxEnergyStored();
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
return total;
}
@Override
public int getEnergyStored() {
int total = 0;
@Override
public int getEnergyStored()
{
int total = 0;
try {
for (PartP2PFEPower t : PartP2PFEPower.this.getOutputs()) {
total += t.getAttachedEnergyStorage().getEnergyStored();
}
} catch (GridAccessException e) {
return 0;
}
try
{
for( PartP2PFEPower t : PartP2PFEPower.this.getOutputs() )
{
total += t.getAttachedEnergyStorage().getEnergyStored();
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
}
return total;
}
}
private class OutputEnergyStorage implements IEnergyStorage {
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
final int total = PartP2PFEPower.this.getAttachedEnergyStorage().extractEnergy(maxExtract, simulate);
if (!simulate) {
PartP2PFEPower.this.queueTunnelDrain(PowerUnits.RF, total);
}
private class OutputEnergyStorage implements IEnergyStorage
{
@Override
public int extractEnergy( int maxExtract, boolean simulate )
{
final int total = PartP2PFEPower.this.getAttachedEnergyStorage().extractEnergy( maxExtract, simulate );
return total;
}
if( !simulate )
{
PartP2PFEPower.this.queueTunnelDrain( PowerUnits.RF, total );
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
return 0;
}
return total;
}
@Override
public boolean canExtract() {
return PartP2PFEPower.this.getAttachedEnergyStorage().canExtract();
}
@Override
public int receiveEnergy( int maxReceive, boolean simulate )
{
return 0;
}
@Override
public boolean canReceive() {
return false;
}
@Override
public boolean canExtract()
{
return PartP2PFEPower.this.getAttachedEnergyStorage().canExtract();
}
@Override
public int getMaxEnergyStored() {
return PartP2PFEPower.this.getAttachedEnergyStorage().getMaxEnergyStored();
}
@Override
public boolean canReceive()
{
return false;
}
@Override
public int getEnergyStored() {
return PartP2PFEPower.this.getAttachedEnergyStorage().getEnergyStored();
}
}
@Override
public int getMaxEnergyStored()
{
return PartP2PFEPower.this.getAttachedEnergyStorage().getMaxEnergyStored();
}
private static class NullEnergyStorage implements IEnergyStorage {
@Override
public int getEnergyStored()
{
return PartP2PFEPower.this.getAttachedEnergyStorage().getEnergyStored();
}
}
@Override
public int receiveEnergy(int maxReceive, boolean simulate) {
return 0;
}
@Override
public int extractEnergy(int maxExtract, boolean simulate) {
return 0;
}
private static class NullEnergyStorage implements IEnergyStorage
{
@Override
public int getEnergyStored() {
return 0;
}
@Override
public int receiveEnergy( int maxReceive, boolean simulate )
{
return 0;
}
@Override
public int getMaxEnergyStored() {
return 0;
}
@Override
public int extractEnergy( int maxExtract, boolean simulate )
{
return 0;
}
@Override
public boolean canExtract() {
return false;
}
@Override
public int getEnergyStored()
{
return 0;
}
@Override
public int getMaxEnergyStored()
{
return 0;
}
@Override
public boolean canExtract()
{
return false;
}
@Override
public boolean canReceive()
{
return false;
}
}
@Override
public boolean canReceive() {
return false;
}
}
}
+167 -218
View File
@@ -18,7 +18,6 @@
package appeng.parts.p2p;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
@@ -42,272 +41,222 @@ import appeng.api.parts.IPartModel;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
public class PartP2PFluids extends PartP2PTunnel<PartP2PFluids> implements IFluidHandler {
public class PartP2PFluids extends PartP2PTunnel<PartP2PFluids> implements IFluidHandler
{
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_fluids");
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_fluids" );
private static final ThreadLocal<Deque<PartP2PFluids>> DEPTH = new ThreadLocal<>();;
private static final ThreadLocal<Deque<PartP2PFluids>> DEPTH = new ThreadLocal<>();;
private LazyOptional<IFluidHandler> cachedTank;
private int tmpUsed;
private LazyOptional<IFluidHandler> cachedTank;
private int tmpUsed;
public PartP2PFluids(final ItemStack is) {
super(is);
}
public PartP2PFluids( final ItemStack is )
{
super( is );
}
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
public float getPowerDrainPerTick() {
return 2.0f;
}
public float getPowerDrainPerTick()
{
return 2.0f;
}
@Override
public void onTunnelNetworkChange() {
this.cachedTank = null;
}
@Override
public void onTunnelNetworkChange()
{
this.cachedTank = null;
}
@Override
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
this.cachedTank = null;
@Override
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
{
this.cachedTank = null;
if (this.isOutput()) {
final PartP2PFluids in = this.getInput();
if (in != null) {
in.onTunnelNetworkChange();
}
}
}
if( this.isOutput() )
{
final PartP2PFluids in = this.getInput();
if( in != null )
{
in.onTunnelNetworkChange();
}
}
}
@SuppressWarnings("unchecked")
@Override
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass) {
if (capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return (LazyOptional<T>) LazyOptional.of(() -> this);
}
@SuppressWarnings("unchecked")
@Override
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass )
{
if( capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
{
return (LazyOptional<T>) LazyOptional.of(() ->this);
}
return super.getCapability(capabilityClass);
}
return super.getCapability( capabilityClass );
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.isPowered(), this.isActive());
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.isPowered(), this.isActive() );
}
@Override
public int getTanks() {
return 0;
}
@Override
public int getTanks()
{
return 0;
}
@Override
@Nonnull
public FluidStack getFluidInTank(int tank) {
return FluidStack.EMPTY;
}
@Override
@Nonnull
public FluidStack getFluidInTank( int tank )
{
return FluidStack.EMPTY;
}
@Override
public int getTankCapacity(int tank) {
return 1000;
}
@Override
public int getTankCapacity( int tank )
{
return 1000;
}
@Override
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
return false;
}
@Override
public boolean isFluidValid( int tank, @Nonnull FluidStack stack )
{
return false;
}
@Override
public int fill(FluidStack resource, FluidAction action) {
@Override
public int fill( FluidStack resource, FluidAction action )
{
final Deque<PartP2PFluids> stack = this.getDepth();
final Deque<PartP2PFluids> stack = this.getDepth();
for (final PartP2PFluids t : stack) {
if (t == this) {
return 0;
}
}
for( final PartP2PFluids t : stack )
{
if( t == this )
{
return 0;
}
}
stack.push(this);
stack.push( this );
final List<PartP2PFluids> list = this.getOutputs(resource.getFluid());
int requestTotal = 0;
final List<PartP2PFluids> list = this.getOutputs( resource.getFluid() );
int requestTotal = 0;
Iterator<PartP2PFluids> i = list.iterator();
Iterator<PartP2PFluids> i = list.iterator();
while (i.hasNext()) {
final PartP2PFluids l = i.next();
final IFluidHandler tank = l.getTarget().orElse(null);
if (tank != null) {
l.tmpUsed = tank.fill(resource.copy(), FluidAction.SIMULATE);
} else {
l.tmpUsed = 0;
}
while( i.hasNext() )
{
final PartP2PFluids l = i.next();
final IFluidHandler tank = l.getTarget().orElse( null );
if( tank != null )
{
l.tmpUsed = tank.fill( resource.copy(), FluidAction.SIMULATE );
}
else
{
l.tmpUsed = 0;
}
if (l.tmpUsed <= 0) {
i.remove();
} else {
requestTotal += l.tmpUsed;
}
}
if( l.tmpUsed <= 0 )
{
i.remove();
}
else
{
requestTotal += l.tmpUsed;
}
}
if (requestTotal <= 0) {
if (stack.pop() != this) {
throw new IllegalStateException("Invalid Recursion detected.");
}
if( requestTotal <= 0 )
{
if( stack.pop() != this )
{
throw new IllegalStateException( "Invalid Recursion detected." );
}
return 0;
}
return 0;
}
if (action == FluidAction.EXECUTE) {
if (stack.pop() != this) {
throw new IllegalStateException("Invalid Recursion detected.");
}
if( action == FluidAction.EXECUTE )
{
if( stack.pop() != this )
{
throw new IllegalStateException( "Invalid Recursion detected." );
}
return Math.min(resource.getAmount(), requestTotal);
}
return Math.min( resource.getAmount(), requestTotal );
}
int available = resource.getAmount();
int available = resource.getAmount();
i = list.iterator();
int used = 0;
i = list.iterator();
int used = 0;
while (i.hasNext() && available > 0) {
final PartP2PFluids l = i.next();
while( i.hasNext() && available > 0 )
{
final PartP2PFluids l = i.next();
final FluidStack insert = resource.copy();
insert.setAmount((int) Math.ceil(insert.getAmount() * ((double) l.tmpUsed / (double) requestTotal)));
if (insert.getAmount() > available) {
insert.setAmount(available);
}
final FluidStack insert = resource.copy();
insert.setAmount( (int) Math.ceil( insert.getAmount() * ( (double) l.tmpUsed / (double) requestTotal ) ) );
if( insert.getAmount() > available )
{
insert.setAmount( available );
}
final IFluidHandler tank = l.getTarget().orElse(null);
if (tank != null) {
l.tmpUsed = tank.fill(insert.copy(), action);
} else {
l.tmpUsed = 0;
}
final IFluidHandler tank = l.getTarget().orElse( null );
if( tank != null )
{
l.tmpUsed = tank.fill( insert.copy(), action );
}
else
{
l.tmpUsed = 0;
}
available -= insert.getAmount();
used += l.tmpUsed;
}
available -= insert.getAmount();
used += l.tmpUsed;
}
if (stack.pop() != this) {
throw new IllegalStateException("Invalid Recursion detected.");
}
if( stack.pop() != this )
{
throw new IllegalStateException( "Invalid Recursion detected." );
}
return used;
}
return used;
}
@Override
@Nonnull
public FluidStack drain(FluidStack resource, FluidAction action) {
return FluidStack.EMPTY;
}
@Override
@Nonnull
public FluidStack drain( FluidStack resource, FluidAction action )
{
return FluidStack.EMPTY;
}
@Override
@Nonnull
public FluidStack drain(int maxDrain, FluidAction action) {
return FluidStack.EMPTY;
}
@Override
@Nonnull
public FluidStack drain( int maxDrain, FluidAction action )
{
return FluidStack.EMPTY;
}
private Deque<PartP2PFluids> getDepth() {
Deque<PartP2PFluids> s = DEPTH.get();
private Deque<PartP2PFluids> getDepth()
{
Deque<PartP2PFluids> s = DEPTH.get();
if (s == null) {
DEPTH.set(s = new ArrayDeque<>());
}
if( s == null )
{
DEPTH.set( s = new ArrayDeque<>() );
}
return s;
}
return s;
}
private List<PartP2PFluids> getOutputs(final Fluid input) {
final List<PartP2PFluids> outs = new ArrayList<>();
private List<PartP2PFluids> getOutputs( final Fluid input )
{
final List<PartP2PFluids> outs = new ArrayList<>();
try {
for (final PartP2PFluids l : this.getOutputs()) {
final IFluidHandler handler = l.getTarget().orElse(null);
try
{
for( final PartP2PFluids l : this.getOutputs() )
{
final IFluidHandler handler = l.getTarget().orElse( null );
if (handler != null) {
outs.add(l);
}
}
} catch (final GridAccessException e) {
// :P
}
if( handler != null )
{
outs.add( l );
}
}
}
catch( final GridAccessException e )
{
// :P
}
return outs;
}
return outs;
}
private LazyOptional<IFluidHandler> getTarget() {
if (!this.getProxy().isActive()) {
return null;
}
private LazyOptional<IFluidHandler> getTarget()
{
if( !this.getProxy().isActive() )
{
return null;
}
if (this.cachedTank != null) {
return this.cachedTank;
}
if( this.cachedTank != null )
{
return this.cachedTank;
}
final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( this.getSide().getFacing() ) );
if( te != null && te.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite() ).isPresent() )
{
return this.cachedTank = te.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
this.getSide().getFacing().getOpposite() );
}
return null;
}
final TileEntity te = this.getTile().getWorld()
.getTileEntity(this.getTile().getPos().offset(this.getSide().getFacing()));
if (te != null && te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
this.getSide().getFacing().getOpposite()).isPresent()) {
return this.cachedTank = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
this.getSide().getFacing().getOpposite());
}
return null;
}
}
+165 -213
View File
@@ -18,10 +18,11 @@
package appeng.parts.p2p;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
@@ -49,246 +50,197 @@ import appeng.me.cache.helpers.TunnelCollection;
import appeng.util.Platform;
import appeng.util.inv.WrapperChainedItemHandler;
import javax.annotation.Nonnull;
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IItemHandler, IGridTickable {
private static final float POWER_DRAIN = 2.0f;
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_items");
private boolean partVisited = false;
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IItemHandler, IGridTickable
{
private static final float POWER_DRAIN = 2.0f;
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_items" );
private boolean partVisited = false;
private int oldSize = 0;
private boolean requested;
private IItemHandler cachedInv;
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
public PartP2PItems(final ItemStack is) {
super(is);
}
private int oldSize = 0;
private boolean requested;
private IItemHandler cachedInv;
@Override
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
this.cachedInv = null;
final PartP2PItems input = this.getInput();
if (input != null && this.isOutput()) {
input.onTunnelNetworkChange();
}
}
public PartP2PItems( final ItemStack is )
{
super( is );
}
private IItemHandler getDestination() {
this.requested = true;
@Override
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
{
this.cachedInv = null;
final PartP2PItems input = this.getInput();
if( input != null && this.isOutput() )
{
input.onTunnelNetworkChange();
}
}
if (this.cachedInv != null) {
return this.cachedInv;
}
private IItemHandler getDestination()
{
this.requested = true;
final List<IItemHandler> outs = new ArrayList<IItemHandler>();
final TunnelCollection<PartP2PItems> itemTunnels;
if( this.cachedInv != null )
{
return this.cachedInv;
}
try {
itemTunnels = this.getOutputs();
} catch (final GridAccessException e) {
return EmptyHandler.INSTANCE;
}
final List<IItemHandler> outs = new ArrayList<IItemHandler>();
final TunnelCollection<PartP2PItems> itemTunnels;
for (final PartP2PItems t : itemTunnels) {
final IItemHandler inv = t.getOutputInv();
if (inv != null && inv != this) {
if (Platform.getRandomInt() % 2 == 0) {
outs.add(inv);
} else {
outs.add(0, inv);
}
}
}
try
{
itemTunnels = this.getOutputs();
}
catch( final GridAccessException e )
{
return EmptyHandler.INSTANCE;
}
return this.cachedInv = new WrapperChainedItemHandler(outs.toArray(new IItemHandler[outs.size()]));
}
for( final PartP2PItems t : itemTunnels )
{
final IItemHandler inv = t.getOutputInv();
if( inv != null && inv != this )
{
if( Platform.getRandomInt() % 2 == 0 )
{
outs.add( inv );
}
else
{
outs.add( 0, inv );
}
}
}
private IItemHandler getOutputInv() {
IItemHandler ret = null;
if (!this.partVisited) {
this.partVisited = true;
if (this.getProxy().isActive()) {
final Direction facing = this.getSide().getFacing();
final TileEntity te = this.getTile().getWorld().getTileEntity(this.getTile().getPos().offset(facing));
return this.cachedInv = new WrapperChainedItemHandler( outs.toArray( new IItemHandler[outs.size()] ) );
}
if (te != null) {
ret = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite())
.orElse(ret);
}
}
this.partVisited = false;
}
return ret;
}
private IItemHandler getOutputInv()
{
IItemHandler ret = null;
if( !this.partVisited )
{
this.partVisited = true;
if( this.getProxy().isActive() )
{
final Direction facing = this.getSide().getFacing();
final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( facing ) );
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return new TickingRequest(TickRates.ItemTunnel.getMin(), TickRates.ItemTunnel.getMax(), false, false);
}
if( te != null )
{
ret = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() )
.orElse(ret);
}
}
this.partVisited = false;
}
return ret;
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
final boolean wasReq = this.requested;
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
return new TickingRequest( TickRates.ItemTunnel.getMin(), TickRates.ItemTunnel.getMax(), false, false );
}
if (this.requested && this.cachedInv != null) {
((WrapperChainedItemHandler) this.cachedInv).cycleOrder();
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
final boolean wasReq = this.requested;
this.requested = false;
return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
if( this.requested && this.cachedInv != null )
{
( (WrapperChainedItemHandler) this.cachedInv ).cycleOrder();
}
@MENetworkEventSubscribe
public void changeStateA(final MENetworkBootingStatusChange bs) {
if (!this.isOutput()) {
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSlots();
if (olderSize != this.oldSize) {
this.getHost().notifyNeighbors();
}
}
}
this.requested = false;
return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
}
@MENetworkEventSubscribe
public void changeStateB(final MENetworkChannelsChanged bs) {
if (!this.isOutput()) {
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSlots();
if (olderSize != this.oldSize) {
this.getHost().notifyNeighbors();
}
}
}
@MENetworkEventSubscribe
public void changeStateA( final MENetworkBootingStatusChange bs )
{
if( !this.isOutput() )
{
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSlots();
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
}
}
}
@MENetworkEventSubscribe
public void changeStateC(final MENetworkPowerStatusChange bs) {
if (!this.isOutput()) {
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSlots();
if (olderSize != this.oldSize) {
this.getHost().notifyNeighbors();
}
}
}
@MENetworkEventSubscribe
public void changeStateB( final MENetworkChannelsChanged bs )
{
if( !this.isOutput() )
{
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSlots();
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
}
}
}
@Override
public void onTunnelNetworkChange() {
if (!this.isOutput()) {
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSlots();
if (olderSize != this.oldSize) {
this.getHost().notifyNeighbors();
}
} else {
final PartP2PItems input = this.getInput();
if (input != null) {
input.getHost().notifyNeighbors();
}
}
}
@MENetworkEventSubscribe
public void changeStateC( final MENetworkPowerStatusChange bs )
{
if( !this.isOutput() )
{
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSlots();
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
}
}
}
@SuppressWarnings("unchecked")
@Override
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass) {
if (capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return (LazyOptional<T>) LazyOptional.of(() -> this);
}
@Override
public void onTunnelNetworkChange()
{
if( !this.isOutput() )
{
this.cachedInv = null;
final int olderSize = this.oldSize;
this.oldSize = this.getDestination().getSlots();
if( olderSize != this.oldSize )
{
this.getHost().notifyNeighbors();
}
}
else
{
final PartP2PItems input = this.getInput();
if( input != null )
{
input.getHost().notifyNeighbors();
}
}
}
return super.getCapability(capabilityClass);
}
@SuppressWarnings( "unchecked" )
@Override
public <T> LazyOptional<T> getCapability(Capability<T> capabilityClass )
{
if( capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
{
return (LazyOptional<T>) LazyOptional.of(() ->this);
}
@Override
public int getSlots() {
return this.getDestination().getSlots();
}
return super.getCapability( capabilityClass );
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return this.getDestination().isItemValid(slot, stack);
}
@Override
public int getSlots()
{
return this.getDestination().getSlots();
}
@Override
public ItemStack getStackInSlot(final int i) {
return this.getDestination().getStackInSlot(i);
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
return this.getDestination().isItemValid(slot, stack);
}
@Override
public ItemStack insertItem(final int slot, final ItemStack stack, boolean simulate) {
return this.getDestination().insertItem(slot, stack, simulate);
}
@Override
public ItemStack getStackInSlot( final int i )
{
return this.getDestination().getStackInSlot( i );
}
@Override
public ItemStack extractItem(final int slot, final int amount, boolean simulate) {
return this.getDestination().extractItem(slot, amount, simulate);
}
@Override
public ItemStack insertItem( final int slot, final ItemStack stack, boolean simulate )
{
return this.getDestination().insertItem( slot, stack, simulate );
}
@Override
public int getSlotLimit(int slot) {
return this.getDestination().getSlotLimit(slot);
}
@Override
public ItemStack extractItem( final int slot, final int amount, boolean simulate )
{
return this.getDestination().extractItem( slot, amount, simulate );
}
public float getPowerDrainPerTick() {
return POWER_DRAIN;
}
@Override
public int getSlotLimit( int slot )
{
return this.getDestination().getSlotLimit( slot );
}
public float getPowerDrainPerTick()
{
return POWER_DRAIN;
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.isPowered(), this.isActive() );
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.isPowered(), this.isActive());
}
}
+126 -165
View File
@@ -18,7 +18,6 @@
package appeng.parts.p2p;
import java.io.IOException;
import java.util.List;
@@ -41,197 +40,159 @@ import appeng.core.settings.TickRates;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTickable {
public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTickable
{
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_light");
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_light" );
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
private int lastValue = 0;
private int opacity = -1;
private int lastValue = 0;
private int opacity = -1;
public PartP2PLight(final ItemStack is) {
super(is);
}
public PartP2PLight( final ItemStack is )
{
super( is );
}
@Override
public void chanRender(final MENetworkChannelsChanged c) {
this.onTunnelNetworkChange();
super.chanRender(c);
}
@Override
public void chanRender( final MENetworkChannelsChanged c )
{
this.onTunnelNetworkChange();
super.chanRender( c );
}
@Override
public void powerRender(final MENetworkPowerStatusChange c) {
this.onTunnelNetworkChange();
super.powerRender(c);
}
@Override
public void powerRender( final MENetworkPowerStatusChange c )
{
this.onTunnelNetworkChange();
super.powerRender( c );
}
@Override
public void writeToStream(final PacketBuffer data) throws IOException {
super.writeToStream(data);
data.writeInt(this.isOutput() ? this.lastValue : 0);
data.writeInt(this.opacity);
}
@Override
public void writeToStream( final PacketBuffer data ) throws IOException
{
super.writeToStream( data );
data.writeInt( this.isOutput() ? this.lastValue : 0 );
data.writeInt( this.opacity );
}
@Override
public boolean readFromStream(final PacketBuffer data) throws IOException {
super.readFromStream(data);
final int oldValue = this.lastValue;
final int oldOpacity = this.opacity;
@Override
public boolean readFromStream( final PacketBuffer data ) throws IOException
{
super.readFromStream( data );
final int oldValue = this.lastValue;
final int oldOpacity = this.opacity;
this.lastValue = data.readInt();
this.opacity = data.readInt();
this.lastValue = data.readInt();
this.opacity = data.readInt();
this.setOutput(this.lastValue > 0);
return this.lastValue != oldValue || oldOpacity != this.opacity;
}
this.setOutput( this.lastValue > 0 );
return this.lastValue != oldValue || oldOpacity != this.opacity;
}
private boolean doWork() {
if (this.isOutput()) {
return false;
}
private boolean doWork()
{
if( this.isOutput() )
{
return false;
}
final TileEntity te = this.getTile();
final World w = te.getWorld();
final TileEntity te = this.getTile();
final World w = te.getWorld();
final int newLevel = w.getLight(te.getPos().offset(this.getSide().getFacing()));
final int newLevel = w.getLight( te.getPos().offset( this.getSide().getFacing() ) );
if (this.lastValue != newLevel && this.getProxy().isActive()) {
this.lastValue = newLevel;
try {
for (final PartP2PLight out : this.getOutputs()) {
out.setLightLevel(this.lastValue);
}
} catch (final GridAccessException e) {
// :P
}
return true;
}
return false;
}
if( this.lastValue != newLevel && this.getProxy().isActive() )
{
this.lastValue = newLevel;
try
{
for( final PartP2PLight out : this.getOutputs() )
{
out.setLightLevel( this.lastValue );
}
}
catch( final GridAccessException e )
{
// :P
}
return true;
}
return false;
}
@Override
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
if (this.isOutput() && pos.offset(this.getSide().getFacing()).equals(neighbor)) {
this.opacity = -1;
this.getHost().markForUpdate();
} else {
this.doWork();
}
}
@Override
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
{
if( this.isOutput() && pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
{
this.opacity = -1;
this.getHost().markForUpdate();
}
else
{
this.doWork();
}
}
@Override
public int getLightLevel() {
if (this.isOutput() && this.isPowered()) {
return this.blockLight(this.lastValue);
}
@Override
public int getLightLevel()
{
if( this.isOutput() && this.isPowered() )
{
return this.blockLight( this.lastValue );
}
return 0;
}
return 0;
}
private void setLightLevel(final int out) {
this.lastValue = out;
this.getHost().markForUpdate();
}
private void setLightLevel( final int out )
{
this.lastValue = out;
this.getHost().markForUpdate();
}
private int blockLight(final int emit) {
if (this.opacity < 0) {
final TileEntity te = this.getTile();
this.opacity = 255 - te.getWorld().getLight(te.getPos().offset(this.getSide().getFacing()));
}
private int blockLight( final int emit )
{
if( this.opacity < 0 )
{
final TileEntity te = this.getTile();
this.opacity = 255 - te.getWorld().getLight( te.getPos().offset( this.getSide().getFacing() ) );
}
return (int) (emit * (this.opacity / 255.0f));
}
return (int) ( emit * ( this.opacity / 255.0f ) );
}
@Override
public void readFromNBT(final CompoundNBT tag) {
super.readFromNBT(tag);
this.lastValue = tag.getInt("lastValue");
}
@Override
public void readFromNBT( final CompoundNBT tag )
{
super.readFromNBT( tag );
this.lastValue = tag.getInt( "lastValue" );
}
@Override
public void writeToNBT(final CompoundNBT tag) {
super.writeToNBT(tag);
tag.putInt("lastValue", this.lastValue);
}
@Override
public void writeToNBT( final CompoundNBT tag )
{
super.writeToNBT( tag );
tag.putInt( "lastValue", this.lastValue );
}
@Override
public void onTunnelConfigChange() {
this.onTunnelNetworkChange();
}
@Override
public void onTunnelConfigChange()
{
this.onTunnelNetworkChange();
}
@Override
public void onTunnelNetworkChange() {
if (this.isOutput()) {
final PartP2PLight src = this.getInput();
if (src != null && src.getProxy().isActive()) {
this.setLightLevel(src.lastValue);
} else {
this.getHost().markForUpdate();
}
} else {
this.doWork();
}
}
@Override
public void onTunnelNetworkChange()
{
if( this.isOutput() )
{
final PartP2PLight src = this.getInput();
if( src != null && src.getProxy().isActive() )
{
this.setLightLevel( src.lastValue );
}
else
{
this.getHost().markForUpdate();
}
}
else
{
this.doWork();
}
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return new TickingRequest(TickRates.LightTunnel.getMin(), TickRates.LightTunnel.getMax(), false, false);
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
return new TickingRequest( TickRates.LightTunnel.getMin(), TickRates.LightTunnel.getMax(), false, false );
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
return this.doWork() ? TickRateModulation.URGENT : TickRateModulation.SLOWER;
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
return this.doWork() ? TickRateModulation.URGENT : TickRateModulation.SLOWER;
}
public float getPowerDrainPerTick() {
return 0.5f;
}
public float getPowerDrainPerTick()
{
return 0.5f;
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.isPowered(), this.isActive() );
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.isPowered(), this.isActive());
}
}
@@ -18,7 +18,6 @@
package appeng.parts.p2p;
import java.util.List;
import net.minecraft.block.Block;
@@ -40,179 +39,144 @@ import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.util.Platform;
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone> {
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
{
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_redstone");
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_redstone" );
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
private int power;
private boolean recursive = false;
private int power;
private boolean recursive = false;
public PartP2PRedstone(final ItemStack is) {
super(is);
}
public PartP2PRedstone( final ItemStack is )
{
super( is );
}
@MENetworkEventSubscribe
public void changeStateA(final MENetworkBootingStatusChange bs) {
this.setNetworkReady();
}
@MENetworkEventSubscribe
public void changeStateA( final MENetworkBootingStatusChange bs )
{
this.setNetworkReady();
}
private void setNetworkReady() {
if (this.isOutput()) {
final PartP2PRedstone in = this.getInput();
if (in != null) {
this.putInput(in.power);
}
}
}
private void setNetworkReady()
{
if( this.isOutput() )
{
final PartP2PRedstone in = this.getInput();
if( in != null )
{
this.putInput( in.power );
}
}
}
private void putInput(final Object o) {
if (this.recursive) {
return;
}
private void putInput( final Object o )
{
if( this.recursive )
{
return;
}
this.recursive = true;
if (this.isOutput() && this.getProxy().isActive()) {
final int newPower = (Integer) o;
if (this.power != newPower) {
this.power = newPower;
this.notifyNeighbors();
}
}
this.recursive = false;
}
this.recursive = true;
if( this.isOutput() && this.getProxy().isActive() )
{
final int newPower = (Integer) o;
if( this.power != newPower )
{
this.power = newPower;
this.notifyNeighbors();
}
}
this.recursive = false;
}
private void notifyNeighbors() {
final World world = this.getTile().getWorld();
private void notifyNeighbors()
{
final World world = this.getTile().getWorld();
Platform.notifyBlocksOfNeighbors(world, this.getTile().getPos());
Platform.notifyBlocksOfNeighbors( world, this.getTile().getPos() );
// and this cause sometimes it can go thought walls.
for (final Direction face : Direction.values()) {
Platform.notifyBlocksOfNeighbors(world, this.getTile().getPos().offset(face));
}
}
// and this cause sometimes it can go thought walls.
for( final Direction face : Direction.values() )
{
Platform.notifyBlocksOfNeighbors( world, this.getTile().getPos().offset( face ) );
}
}
@MENetworkEventSubscribe
public void changeStateB(final MENetworkChannelsChanged bs) {
this.setNetworkReady();
}
@MENetworkEventSubscribe
public void changeStateB( final MENetworkChannelsChanged bs )
{
this.setNetworkReady();
}
@MENetworkEventSubscribe
public void changeStateC(final MENetworkPowerStatusChange bs) {
this.setNetworkReady();
}
@MENetworkEventSubscribe
public void changeStateC( final MENetworkPowerStatusChange bs )
{
this.setNetworkReady();
}
@Override
public void readFromNBT(final CompoundNBT tag) {
super.readFromNBT(tag);
this.power = tag.getInt("power");
}
@Override
public void readFromNBT( final CompoundNBT tag )
{
super.readFromNBT( tag );
this.power = tag.getInt( "power" );
}
@Override
public void writeToNBT(final CompoundNBT tag) {
super.writeToNBT(tag);
tag.putInt("power", this.power);
}
@Override
public void writeToNBT( final CompoundNBT tag )
{
super.writeToNBT( tag );
tag.putInt( "power", this.power );
}
@Override
public void onTunnelNetworkChange() {
this.setNetworkReady();
}
@Override
public void onTunnelNetworkChange()
{
this.setNetworkReady();
}
public float getPowerDrainPerTick() {
return 0.5f;
}
public float getPowerDrainPerTick()
{
return 0.5f;
}
@Override
public void onNeighborChanged(IBlockReader w, BlockPos pos, BlockPos neighbor) {
if (!this.isOutput()) {
final BlockPos target = this.getTile().getPos().offset(this.getSide().getFacing());
@Override
public void onNeighborChanged( IBlockReader w, BlockPos pos, BlockPos neighbor )
{
if( !this.isOutput() )
{
final BlockPos target = this.getTile().getPos().offset( this.getSide().getFacing() );
final BlockState state = this.getTile().getWorld().getBlockState(target);
final Block b = state.getBlock();
if (b != null && !this.isOutput()) {
Direction srcSide = this.getSide().getFacing();
if (b instanceof RedstoneWireBlock) {
srcSide = Direction.UP;
}
final BlockState state = this.getTile().getWorld().getBlockState( target );
final Block b = state.getBlock();
if( b != null && !this.isOutput() )
{
Direction srcSide = this.getSide().getFacing();
if( b instanceof RedstoneWireBlock )
{
srcSide = Direction.UP;
}
this.power = b.getWeakPower(state, this.getTile().getWorld(), target, srcSide);
this.power = Math.max(this.power, b.getWeakPower(state, this.getTile().getWorld(), target, srcSide));
this.sendToOutput(this.power);
} else {
this.sendToOutput(0);
}
}
}
this.power = b.getWeakPower( state, this.getTile().getWorld(), target, srcSide );
this.power = Math.max( this.power, b.getWeakPower( state, this.getTile().getWorld(), target, srcSide ) );
this.sendToOutput( this.power );
}
else
{
this.sendToOutput( 0 );
}
}
}
@Override
public boolean canConnectRedstone() {
return true;
}
@Override
public boolean canConnectRedstone()
{
return true;
}
@Override
public int isProvidingStrongPower() {
return this.isOutput() ? this.power : 0;
}
@Override
public int isProvidingStrongPower()
{
return this.isOutput() ? this.power : 0;
}
@Override
public int isProvidingWeakPower() {
return this.isOutput() ? this.power : 0;
}
@Override
public int isProvidingWeakPower()
{
return this.isOutput() ? this.power : 0;
}
private void sendToOutput(final int power) {
try {
for (final PartP2PRedstone rs : this.getOutputs()) {
rs.putInput(power);
}
} catch (final GridAccessException e) {
// :P
}
}
private void sendToOutput( final int power )
{
try
{
for( final PartP2PRedstone rs : this.getOutputs() )
{
rs.putInput( power );
}
}
catch( final GridAccessException e )
{
// :P
}
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.isPowered(), this.isActive() );
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.isPowered(), this.isActive());
}
}
+334 -401
View File
@@ -18,19 +18,20 @@
package appeng.parts.p2p;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
import appeng.client.render.cablebus.P2PTunnelFrequencyModelData;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Hand;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.data.ModelDataMap;
import net.minecraftforge.client.model.data.ModelProperty;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -47,409 +48,341 @@ import appeng.api.parts.PartItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import appeng.client.render.cablebus.P2PTunnelFrequencyModelData;
import appeng.core.AEConfig;
import appeng.me.GridAccessException;
import appeng.me.cache.P2PCache;
import appeng.me.cache.helpers.TunnelCollection;
import appeng.parts.PartBasicState;
import appeng.util.Platform;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.data.ModelDataMap;
import net.minecraftforge.client.model.data.ModelProperty;
public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
{
private final TunnelCollection type = new TunnelCollection<T>( null, this.getClass() );
private boolean output;
private short freq;
public PartP2PTunnel( final ItemStack is )
{
super( is );
}
public TunnelCollection<T> getCollection( final Collection<PartP2PTunnel> collection, final Class<? extends PartP2PTunnel> c )
{
if( this.type.matches( c ) )
{
this.type.setSource( collection );
return this.type;
}
return null;
}
public T getInput()
{
if( this.getFrequency() == 0 )
{
return null;
}
try
{
final PartP2PTunnel tunnel = this.getProxy().getP2P().getInput( this.getFrequency() );
if( this.getClass().isInstance( tunnel ) )
{
return (T) tunnel;
}
}
catch( final GridAccessException e )
{
// :P
}
return null;
}
public TunnelCollection<T> getOutputs() throws GridAccessException
{
if( this.getProxy().isActive() )
{
return (TunnelCollection<T>) this.getProxy().getP2P().getOutputs( this.getFrequency(), this.getClass() );
}
return new TunnelCollection( new ArrayList(), this.getClass() );
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
bch.addBox( 5, 5, 12, 11, 11, 13 );
bch.addBox( 3, 3, 13, 13, 13, 14 );
bch.addBox( 2, 2, 14, 14, 14, 16 );
}
@Override
public ItemStack getItemStack( final PartItemStack type )
{
if( type == PartItemStack.WORLD || type == PartItemStack.NETWORK || type == PartItemStack.WRENCH || type == PartItemStack.PICK )
{
return super.getItemStack( type );
}
final Optional<ItemStack> maybeMEStack = AEApi.instance().definitions().parts().p2PTunnelME().maybeStack( 1 );
if( maybeMEStack.isPresent() )
{
return maybeMEStack.get();
}
return super.getItemStack( type );
}
@Override
public void readFromNBT( final CompoundNBT data )
{
super.readFromNBT( data );
this.setOutput( data.getBoolean( "output" ) );
this.freq = data.getShort( "freq" );
}
@Override
public void writeToNBT( final CompoundNBT data )
{
super.writeToNBT( data );
data.putBoolean( "output", this.isOutput() );
data.putShort( "freq", this.getFrequency() );
}
@Override
public boolean readFromStream( PacketBuffer data ) throws IOException
{
final boolean c = super.readFromStream( data );
final short oldf = this.freq;
this.freq = data.readShort();
return c || oldf != this.freq;
}
@Override
public void writeToStream( PacketBuffer data ) throws IOException
{
super.writeToStream( data );
data.writeShort( this.getFrequency() );
}
@Override
public float getCableConnectionLength( AECableType cable )
{
return 1;
}
@Override
public boolean useStandardMemoryCard()
{
return false;
}
@Override
public boolean onPartActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
{
if( Platform.isClient() )
{
return true;
}
if( hand == Hand.OFF_HAND )
{
return false;
}
final ItemStack is = player.getHeldItem( hand );
// UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() );
// AELog.info( "ID:" + id.toString() + " : " + is.getItemDamage() );
final TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem( is );
if( !is.isEmpty() && is.getItem() instanceof IMemoryCard )
{
final IMemoryCard mc = (IMemoryCard) is.getItem();
final CompoundNBT data = mc.getData( is );
final ItemStack newType = ItemStack.read( data );
final short freq = data.getShort( "freq" );
if( !newType.isEmpty() )
{
if( newType.getItem() instanceof IPartItem )
{
final IPart testPart = ( (IPartItem<?>) newType.getItem() ).createPart( newType );
if( testPart instanceof PartP2PTunnel )
{
this.getHost().removePart( this.getSide(), true );
final AEPartLocation dir = this.getHost().addPart( newType, this.getSide(), player, hand );
final IPart newBus = this.getHost().getPart( dir );
if( newBus instanceof PartP2PTunnel )
{
final PartP2PTunnel<?> newTunnel = (PartP2PTunnel<?>) newBus;
newTunnel.setOutput( true );
try
{
final P2PCache p2p = newTunnel.getProxy().getP2P();
p2p.updateFreq( newTunnel, freq );
}
catch( final GridAccessException e )
{
// :P
}
newTunnel.onTunnelNetworkChange();
}
mc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
return true;
}
}
}
mc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
}
else if( tt != null ) // attunement
{
final ItemStack newType;
final IParts parts = AEApi.instance().definitions().parts();
switch( tt )
{
case LIGHT:
newType = parts.p2PTunnelLight().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case FE_POWER:
newType = parts.p2PTunnelFE().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case FLUID:
newType = parts.p2PTunnelFluids().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case IC2_POWER:
newType = parts.p2PTunnelEU().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case ITEM:
newType = parts.p2PTunnelItems().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case ME:
newType = parts.p2PTunnelME().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
case REDSTONE:
newType = parts.p2PTunnelRedstone().maybeStack( 1 ).orElse( ItemStack.EMPTY );
break;
/*
* case COMPUTER_MESSAGE:
* for( ItemStack stack : parts.p2PTunnelOpenComputers().maybeStack( 1 ).asSet() )
* {
* newType = stack;
* }
* break;
*/
default:
newType = ItemStack.EMPTY;
break;
}
if( !newType.isEmpty() && !ItemStack.areItemsEqual( newType, this.getItemStack() ) )
{
final boolean oldOutput = this.isOutput();
final short myFreq = this.getFrequency();
this.getHost().removePart( this.getSide(), false );
final AEPartLocation dir = this.getHost().addPart( newType, this.getSide(), player, hand );
final IPart newBus = this.getHost().getPart( dir );
if( newBus instanceof PartP2PTunnel )
{
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
newTunnel.setOutput( oldOutput );
newTunnel.onTunnelNetworkChange();
try
{
final P2PCache p2p = newTunnel.getProxy().getP2P();
p2p.updateFreq( newTunnel, myFreq );
}
catch( final GridAccessException e )
{
// :P
}
}
Platform.notifyBlocksOfNeighbors( this.getTile().getWorld(), this.getTile().getPos() );
return true;
}
}
return false;
}
@Override
public boolean onPartShiftActivate( final PlayerEntity player, final Hand hand, final Vec3d pos )
{
final ItemStack is = player.inventory.getCurrentItem();
if( !is.isEmpty() && is.getItem() instanceof IMemoryCard )
{
if( Platform.isClient() )
{
return true;
}
final IMemoryCard mc = (IMemoryCard) is.getItem();
final CompoundNBT data = mc.getData( is );
final short storedFrequency = data.getShort( "freq" );
short newFreq = this.getFrequency();
final boolean wasOutput = this.isOutput();
this.setOutput( false );
final boolean needsNewFrequency = wasOutput || this.getFrequency() == 0 || storedFrequency == newFreq;
try
{
if( needsNewFrequency )
{
newFreq = this.getProxy().getP2P().newFrequency();
}
this.getProxy().getP2P().updateFreq( this, newFreq );
}
catch( final GridAccessException e )
{
// :P
}
this.onTunnelConfigChange();
final ItemStack p2pItem = this.getItemStack( PartItemStack.WRENCH );
final String type = p2pItem.getTranslationKey();
p2pItem.write( data );
data.putShort( "freq", this.getFrequency() );
final AEColor[] colors = Platform.p2p().toColors( this.getFrequency() );
final int[] colorCode = new int[] {
colors[0].ordinal(), colors[0].ordinal(), colors[1].ordinal(), colors[1].ordinal(),
colors[2].ordinal(), colors[2].ordinal(), colors[3].ordinal(), colors[3].ordinal(),
};
data.putIntArray( "colorCode", colorCode );
mc.setMemoryCardContents( is, type + ".name", data );
if( needsNewFrequency )
{
mc.notifyUser( player, MemoryCardMessages.SETTINGS_RESET );
}
else
{
mc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
}
return true;
}
return false;
}
public void onTunnelConfigChange()
{
}
public void onTunnelNetworkChange()
{
}
protected void queueTunnelDrain( final PowerUnits unit, final double f )
{
final double ae_to_tax = unit.convertTo( PowerUnits.AE, f * AEConfig.TUNNEL_POWER_LOSS );
try
{
this.getProxy().getEnergy().extractAEPower( ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE );
}
catch( final GridAccessException e )
{
// :P
}
}
public short getFrequency()
{
return this.freq;
}
public void setFrequency( final short freq )
{
final short oldf = this.freq;
this.freq = freq;
if( oldf != this.freq )
{
this.getHost().markForUpdate();
}
}
public boolean isOutput()
{
return this.output;
}
void setOutput( final boolean output )
{
this.output = output;
}
@Override
public IModelData getModelData()
{
long ret = Short.toUnsignedLong( this.getFrequency() );
if( this.isActive() && this.isPowered() )
{
ret |= 0x10000L;
}
return new P2PTunnelFrequencyModelData(ret);
}
public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState {
private final TunnelCollection type = new TunnelCollection<T>(null, this.getClass());
private boolean output;
private short freq;
public PartP2PTunnel(final ItemStack is) {
super(is);
}
public TunnelCollection<T> getCollection(final Collection<PartP2PTunnel> collection,
final Class<? extends PartP2PTunnel> c) {
if (this.type.matches(c)) {
this.type.setSource(collection);
return this.type;
}
return null;
}
public T getInput() {
if (this.getFrequency() == 0) {
return null;
}
try {
final PartP2PTunnel tunnel = this.getProxy().getP2P().getInput(this.getFrequency());
if (this.getClass().isInstance(tunnel)) {
return (T) tunnel;
}
} catch (final GridAccessException e) {
// :P
}
return null;
}
public TunnelCollection<T> getOutputs() throws GridAccessException {
if (this.getProxy().isActive()) {
return (TunnelCollection<T>) this.getProxy().getP2P().getOutputs(this.getFrequency(), this.getClass());
}
return new TunnelCollection(new ArrayList(), this.getClass());
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(5, 5, 12, 11, 11, 13);
bch.addBox(3, 3, 13, 13, 13, 14);
bch.addBox(2, 2, 14, 14, 14, 16);
}
@Override
public ItemStack getItemStack(final PartItemStack type) {
if (type == PartItemStack.WORLD || type == PartItemStack.NETWORK || type == PartItemStack.WRENCH
|| type == PartItemStack.PICK) {
return super.getItemStack(type);
}
final Optional<ItemStack> maybeMEStack = AEApi.instance().definitions().parts().p2PTunnelME().maybeStack(1);
if (maybeMEStack.isPresent()) {
return maybeMEStack.get();
}
return super.getItemStack(type);
}
@Override
public void readFromNBT(final CompoundNBT data) {
super.readFromNBT(data);
this.setOutput(data.getBoolean("output"));
this.freq = data.getShort("freq");
}
@Override
public void writeToNBT(final CompoundNBT data) {
super.writeToNBT(data);
data.putBoolean("output", this.isOutput());
data.putShort("freq", this.getFrequency());
}
@Override
public boolean readFromStream(PacketBuffer data) throws IOException {
final boolean c = super.readFromStream(data);
final short oldf = this.freq;
this.freq = data.readShort();
return c || oldf != this.freq;
}
@Override
public void writeToStream(PacketBuffer data) throws IOException {
super.writeToStream(data);
data.writeShort(this.getFrequency());
}
@Override
public float getCableConnectionLength(AECableType cable) {
return 1;
}
@Override
public boolean useStandardMemoryCard() {
return false;
}
@Override
public boolean onPartActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
if (Platform.isClient()) {
return true;
}
if (hand == Hand.OFF_HAND) {
return false;
}
final ItemStack is = player.getHeldItem(hand);
// UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() );
// AELog.info( "ID:" + id.toString() + " : " + is.getItemDamage() );
final TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem(is);
if (!is.isEmpty() && is.getItem() instanceof IMemoryCard) {
final IMemoryCard mc = (IMemoryCard) is.getItem();
final CompoundNBT data = mc.getData(is);
final ItemStack newType = ItemStack.read(data);
final short freq = data.getShort("freq");
if (!newType.isEmpty()) {
if (newType.getItem() instanceof IPartItem) {
final IPart testPart = ((IPartItem<?>) newType.getItem()).createPart(newType);
if (testPart instanceof PartP2PTunnel) {
this.getHost().removePart(this.getSide(), true);
final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand);
final IPart newBus = this.getHost().getPart(dir);
if (newBus instanceof PartP2PTunnel) {
final PartP2PTunnel<?> newTunnel = (PartP2PTunnel<?>) newBus;
newTunnel.setOutput(true);
try {
final P2PCache p2p = newTunnel.getProxy().getP2P();
p2p.updateFreq(newTunnel, freq);
} catch (final GridAccessException e) {
// :P
}
newTunnel.onTunnelNetworkChange();
}
mc.notifyUser(player, MemoryCardMessages.SETTINGS_LOADED);
return true;
}
}
}
mc.notifyUser(player, MemoryCardMessages.INVALID_MACHINE);
} else if (tt != null) // attunement
{
final ItemStack newType;
final IParts parts = AEApi.instance().definitions().parts();
switch (tt) {
case LIGHT:
newType = parts.p2PTunnelLight().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case FE_POWER:
newType = parts.p2PTunnelFE().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case FLUID:
newType = parts.p2PTunnelFluids().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case IC2_POWER:
newType = parts.p2PTunnelEU().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case ITEM:
newType = parts.p2PTunnelItems().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case ME:
newType = parts.p2PTunnelME().maybeStack(1).orElse(ItemStack.EMPTY);
break;
case REDSTONE:
newType = parts.p2PTunnelRedstone().maybeStack(1).orElse(ItemStack.EMPTY);
break;
/*
* case COMPUTER_MESSAGE: for( ItemStack stack :
* parts.p2PTunnelOpenComputers().maybeStack( 1 ).asSet() ) { newType = stack; }
* break;
*/
default:
newType = ItemStack.EMPTY;
break;
}
if (!newType.isEmpty() && !ItemStack.areItemsEqual(newType, this.getItemStack())) {
final boolean oldOutput = this.isOutput();
final short myFreq = this.getFrequency();
this.getHost().removePart(this.getSide(), false);
final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand);
final IPart newBus = this.getHost().getPart(dir);
if (newBus instanceof PartP2PTunnel) {
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
newTunnel.setOutput(oldOutput);
newTunnel.onTunnelNetworkChange();
try {
final P2PCache p2p = newTunnel.getProxy().getP2P();
p2p.updateFreq(newTunnel, myFreq);
} catch (final GridAccessException e) {
// :P
}
}
Platform.notifyBlocksOfNeighbors(this.getTile().getWorld(), this.getTile().getPos());
return true;
}
}
return false;
}
@Override
public boolean onPartShiftActivate(final PlayerEntity player, final Hand hand, final Vec3d pos) {
final ItemStack is = player.inventory.getCurrentItem();
if (!is.isEmpty() && is.getItem() instanceof IMemoryCard) {
if (Platform.isClient()) {
return true;
}
final IMemoryCard mc = (IMemoryCard) is.getItem();
final CompoundNBT data = mc.getData(is);
final short storedFrequency = data.getShort("freq");
short newFreq = this.getFrequency();
final boolean wasOutput = this.isOutput();
this.setOutput(false);
final boolean needsNewFrequency = wasOutput || this.getFrequency() == 0 || storedFrequency == newFreq;
try {
if (needsNewFrequency) {
newFreq = this.getProxy().getP2P().newFrequency();
}
this.getProxy().getP2P().updateFreq(this, newFreq);
} catch (final GridAccessException e) {
// :P
}
this.onTunnelConfigChange();
final ItemStack p2pItem = this.getItemStack(PartItemStack.WRENCH);
final String type = p2pItem.getTranslationKey();
p2pItem.write(data);
data.putShort("freq", this.getFrequency());
final AEColor[] colors = Platform.p2p().toColors(this.getFrequency());
final int[] colorCode = new int[] { colors[0].ordinal(), colors[0].ordinal(), colors[1].ordinal(),
colors[1].ordinal(), colors[2].ordinal(), colors[2].ordinal(), colors[3].ordinal(),
colors[3].ordinal(), };
data.putIntArray("colorCode", colorCode);
mc.setMemoryCardContents(is, type + ".name", data);
if (needsNewFrequency) {
mc.notifyUser(player, MemoryCardMessages.SETTINGS_RESET);
} else {
mc.notifyUser(player, MemoryCardMessages.SETTINGS_SAVED);
}
return true;
}
return false;
}
public void onTunnelConfigChange() {
}
public void onTunnelNetworkChange() {
}
protected void queueTunnelDrain(final PowerUnits unit, final double f) {
final double ae_to_tax = unit.convertTo(PowerUnits.AE, f * AEConfig.TUNNEL_POWER_LOSS);
try {
this.getProxy().getEnergy().extractAEPower(ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE);
} catch (final GridAccessException e) {
// :P
}
}
public short getFrequency() {
return this.freq;
}
public void setFrequency(final short freq) {
final short oldf = this.freq;
this.freq = freq;
if (oldf != this.freq) {
this.getHost().markForUpdate();
}
}
public boolean isOutput() {
return this.output;
}
void setOutput(final boolean output) {
this.output = output;
}
@Override
public IModelData getModelData() {
long ret = Short.toUnsignedLong(this.getFrequency());
if (this.isActive() && this.isPowered()) {
ret |= 0x10000L;
}
return new P2PTunnelFrequencyModelData(ret);
}
}
@@ -18,7 +18,6 @@
package appeng.parts.p2p;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.Iterator;
@@ -50,227 +49,174 @@ import appeng.me.cache.helpers.Connections;
import appeng.me.cache.helpers.TunnelConnection;
import appeng.me.helpers.AENetworkProxy;
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable {
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable
{
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_me");
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_me" );
@PartModels
public static List<IPartModel> getModels() {
return MODELS.getModels();
}
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
private final Connections connection = new Connections(this);
private final AENetworkProxy outerProxy = new AENetworkProxy(this, "outer", ItemStack.EMPTY, true);
private final Connections connection = new Connections( this );
private final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", ItemStack.EMPTY, true );
public PartP2PTunnelME(final ItemStack is) {
super(is);
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL, GridFlags.COMPRESSED_CHANNEL);
this.outerProxy.setFlags(GridFlags.DENSE_CAPACITY, GridFlags.CANNOT_CARRY_COMPRESSED);
}
public PartP2PTunnelME( final ItemStack is )
{
super( is );
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL, GridFlags.COMPRESSED_CHANNEL );
this.outerProxy.setFlags( GridFlags.DENSE_CAPACITY, GridFlags.CANNOT_CARRY_COMPRESSED );
}
@Override
public void readFromNBT(final CompoundNBT extra) {
super.readFromNBT(extra);
this.outerProxy.readFromNBT(extra);
}
@Override
public void readFromNBT( final CompoundNBT extra )
{
super.readFromNBT( extra );
this.outerProxy.readFromNBT( extra );
}
@Override
public void writeToNBT(final CompoundNBT extra) {
super.writeToNBT(extra);
this.outerProxy.writeToNBT(extra);
}
@Override
public void writeToNBT( final CompoundNBT extra )
{
super.writeToNBT( extra );
this.outerProxy.writeToNBT( extra );
}
@Override
public void onTunnelNetworkChange() {
super.onTunnelNetworkChange();
if (!this.isOutput()) {
try {
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
} catch (final GridAccessException e) {
// :P
}
}
}
@Override
public void onTunnelNetworkChange()
{
super.onTunnelNetworkChange();
if( !this.isOutput() )
{
try
{
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
}
catch( final GridAccessException e )
{
// :P
}
}
}
@Override
public AECableType getCableConnectionType(final AEPartLocation dir) {
return AECableType.DENSE_SMART;
}
@Override
public AECableType getCableConnectionType( final AEPartLocation dir )
{
return AECableType.DENSE_SMART;
}
@Override
public void removeFromWorld() {
super.removeFromWorld();
this.outerProxy.remove();
}
@Override
public void removeFromWorld()
{
super.removeFromWorld();
this.outerProxy.remove();
}
@Override
public void addToWorld() {
super.addToWorld();
this.outerProxy.onReady();
}
@Override
public void addToWorld()
{
super.addToWorld();
this.outerProxy.onReady();
}
@Override
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final TileEntity tile) {
super.setPartHostInfo(side, host, tile);
this.outerProxy.setValidSides(EnumSet.of(side.getFacing()));
}
@Override
public void setPartHostInfo( final AEPartLocation side, final IPartHost host, final TileEntity tile )
{
super.setPartHostInfo( side, host, tile );
this.outerProxy.setValidSides( EnumSet.of( side.getFacing() ) );
}
@Override
public IGridNode getExternalFacingNode() {
return this.outerProxy.getNode();
}
@Override
public IGridNode getExternalFacingNode()
{
return this.outerProxy.getNode();
}
@Override
public void onPlacement(final PlayerEntity player, final Hand hand, final ItemStack held,
final AEPartLocation side) {
super.onPlacement(player, hand, held, side);
this.outerProxy.setOwner(player);
}
@Override
public void onPlacement( final PlayerEntity player, final Hand hand, final ItemStack held, final AEPartLocation side )
{
super.onPlacement( player, hand, held, side );
this.outerProxy.setOwner( player );
}
@Override
public TickingRequest getTickingRequest(final IGridNode node) {
return new TickingRequest(TickRates.METunnel.getMin(), TickRates.METunnel.getMax(), true, false);
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
return new TickingRequest( TickRates.METunnel.getMin(), TickRates.METunnel.getMax(), true, false );
}
@Override
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
// just move on...
try {
if (!this.getProxy().getPath().isNetworkBooting()) {
if (!this.getProxy().getEnergy().isNetworkPowered()) {
this.connection.markDestroy();
TickHandler.INSTANCE.addCallable(this.getTile().getWorld(), this.connection);
} else {
if (this.getProxy().isActive()) {
this.connection.markCreate();
TickHandler.INSTANCE.addCallable(this.getTile().getWorld(), this.connection);
} else {
this.connection.markDestroy();
TickHandler.INSTANCE.addCallable(this.getTile().getWorld(), this.connection);
}
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
// just move on...
try
{
if( !this.getProxy().getPath().isNetworkBooting() )
{
if( !this.getProxy().getEnergy().isNetworkPowered() )
{
this.connection.markDestroy();
TickHandler.INSTANCE.addCallable( this.getTile().getWorld(), this.connection );
}
else
{
if( this.getProxy().isActive() )
{
this.connection.markCreate();
TickHandler.INSTANCE.addCallable( this.getTile().getWorld(), this.connection );
}
else
{
this.connection.markDestroy();
TickHandler.INSTANCE.addCallable( this.getTile().getWorld(), this.connection );
}
}
return TickRateModulation.SLEEP;
}
} catch (final GridAccessException e) {
// meh?
}
return TickRateModulation.SLEEP;
}
}
catch( final GridAccessException e )
{
// meh?
}
return TickRateModulation.IDLE;
}
return TickRateModulation.IDLE;
}
public void updateConnections(final Connections connections) {
if (connections.isDestroy()) {
for (final TunnelConnection cw : this.connection.getConnections().values()) {
cw.getConnection().destroy();
}
public void updateConnections( final Connections connections )
{
if( connections.isDestroy() )
{
for( final TunnelConnection cw : this.connection.getConnections().values() )
{
cw.getConnection().destroy();
}
this.connection.getConnections().clear();
} else if (connections.isCreate()) {
this.connection.getConnections().clear();
}
else if( connections.isCreate() )
{
final Iterator<TunnelConnection> i = this.connection.getConnections().values().iterator();
while (i.hasNext()) {
final TunnelConnection cw = i.next();
try {
if (cw.getTunnel().getProxy().getGrid() != this.getProxy().getGrid()) {
cw.getConnection().destroy();
i.remove();
} else if (!cw.getTunnel().getProxy().isActive()) {
cw.getConnection().destroy();
i.remove();
}
} catch (final GridAccessException e) {
// :P
}
}
final Iterator<TunnelConnection> i = this.connection.getConnections().values().iterator();
while( i.hasNext() )
{
final TunnelConnection cw = i.next();
try
{
if( cw.getTunnel().getProxy().getGrid() != this.getProxy().getGrid() )
{
cw.getConnection().destroy();
i.remove();
}
else if( !cw.getTunnel().getProxy().isActive() )
{
cw.getConnection().destroy();
i.remove();
}
}
catch( final GridAccessException e )
{
// :P
}
}
final List<PartP2PTunnelME> newSides = new ArrayList<>();
try {
for (final PartP2PTunnelME me : this.getOutputs()) {
if (me.getProxy().isActive() && connections.getConnections().get(me.getGridNode()) == null) {
newSides.add(me);
}
}
final List<PartP2PTunnelME> newSides = new ArrayList<>();
try
{
for( final PartP2PTunnelME me : this.getOutputs() )
{
if( me.getProxy().isActive() && connections.getConnections().get( me.getGridNode() ) == null )
{
newSides.add( me );
}
}
for (final PartP2PTunnelME me : newSides) {
try {
connections.getConnections().put(me.getGridNode(), new TunnelConnection(me, AEApi.instance()
.grid().createGridConnection(this.outerProxy.getNode(), me.outerProxy.getNode())));
} catch (final FailedConnectionException e) {
final TileEntity start = this.getTile();
final TileEntity end = me.getTile();
for( final PartP2PTunnelME me : newSides )
{
try
{
connections.getConnections()
.put( me.getGridNode(),
new TunnelConnection( me, AEApi.instance()
.grid()
.createGridConnection( this.outerProxy.getNode(),
me.outerProxy.getNode() ) ) );
}
catch( final FailedConnectionException e )
{
final TileEntity start = this.getTile();
final TileEntity end = me.getTile();
AELog.debug(e);
AELog.debug( e );
AELog.warn(
"Failed to establish a ME P2P Tunnel between the tunnels at [x=%d, y=%d, z=%d] and [x=%d, y=%d, z=%d]",
start.getPos().getX(), start.getPos().getY(), start.getPos().getZ(),
end.getPos().getX(), end.getPos().getY(), end.getPos().getZ());
// :(
}
}
} catch (final GridAccessException e) {
AELog.debug(e);
}
}
}
AELog.warn( "Failed to establish a ME P2P Tunnel between the tunnels at [x=%d, y=%d, z=%d] and [x=%d, y=%d, z=%d]",
start.getPos().getX(), start.getPos().getY(), start.getPos().getZ(), end.getPos().getX(), end.getPos().getY(),
end.getPos().getZ() );
// :(
}
}
}
catch( final GridAccessException e )
{
AELog.debug( e );
}
}
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( this.isPowered(), this.isActive() );
}
@Override
public IPartModel getStaticModels() {
return MODELS.getModel(this.isPowered(), this.isActive());
}
}