2015-10-18 19:21:32 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityLaserRelay.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-10-18 19:21:32 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-10-18 19:21:32 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-10-18 19:21:32 +02:00
|
|
|
|
|
|
|
import cofh.api.energy.IEnergyReceiver;
|
2016-01-23 11:02:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketParticle;
|
2016-01-08 13:31:58 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2015-10-29 17:36:30 +01:00
|
|
|
import io.netty.util.internal.ConcurrentSet;
|
2015-10-18 19:21:32 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-10-29 17:36:30 +01:00
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2016-01-07 23:42:42 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-10-18 19:21:32 +02:00
|
|
|
|
|
|
|
public class TileEntityLaserRelay extends TileEntityBase implements IEnergyReceiver{
|
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
public static final int MAX_DISTANCE = 15;
|
2015-12-16 20:40:52 +01:00
|
|
|
private static final float[] COLOR = new float[]{1F, 0F, 0F};
|
2015-11-28 19:02:01 +01:00
|
|
|
|
2015-10-23 16:54:33 +02:00
|
|
|
@Override
|
2016-02-01 17:49:55 +01:00
|
|
|
public void receiveSyncCompound(NBTTagCompound compound){
|
|
|
|
BlockPos thisPos = this.pos;
|
|
|
|
if(compound != null){
|
|
|
|
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(thisPos);
|
2015-10-27 23:09:23 +01:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
NBTTagList list = compound.getTagList("Connections", 10);
|
|
|
|
for(int i = 0; i < list.tagCount(); i++){
|
|
|
|
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
|
|
|
|
LaserRelayConnectionHandler.getInstance().addConnection(pair.firstRelay, pair.secondRelay);
|
2015-10-26 22:28:49 +01:00
|
|
|
}
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
else{
|
|
|
|
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(thisPos);
|
|
|
|
}
|
2015-10-23 16:54:33 +02:00
|
|
|
}
|
|
|
|
|
2015-10-18 19:21:32 +02:00
|
|
|
@Override
|
2016-01-17 20:46:51 +01:00
|
|
|
public NBTTagCompound getSyncCompound(){
|
2015-10-21 00:22:50 +02:00
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
2015-10-18 19:21:32 +02:00
|
|
|
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos thisPos = this.pos;
|
2015-10-29 17:36:30 +01:00
|
|
|
ConcurrentSet<LaserRelayConnectionHandler.ConnectionPair> connections = LaserRelayConnectionHandler.getInstance().getConnectionsFor(thisPos);
|
2015-10-21 00:22:50 +02:00
|
|
|
|
|
|
|
if(connections != null){
|
2015-10-29 17:36:30 +01:00
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
for(LaserRelayConnectionHandler.ConnectionPair pair : connections){
|
|
|
|
list.appendTag(pair.writeToNBT());
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
2015-10-29 17:36:30 +01:00
|
|
|
compound.setTag("Connections", list);
|
2016-01-17 20:46:51 +01:00
|
|
|
return compound;
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
|
|
|
return null;
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-02-01 17:49:55 +01:00
|
|
|
public void updateEntity(){
|
|
|
|
super.updateEntity();
|
|
|
|
if(this.worldObj.isRemote){
|
|
|
|
this.renderParticles();
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 00:22:50 +02:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void renderParticles(){
|
|
|
|
if(Util.RANDOM.nextInt(ConfigValues.lessParticles ? 15 : 8) == 0){
|
|
|
|
BlockPos thisPos = this.pos;
|
|
|
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(thisPos);
|
|
|
|
if(network != null){
|
|
|
|
for(LaserRelayConnectionHandler.ConnectionPair aPair : network.connections){
|
|
|
|
if(aPair.contains(thisPos) && PosUtil.areSamePos(thisPos, aPair.firstRelay)){
|
|
|
|
PacketParticle.renderParticlesFromAToB(aPair.firstRelay.getX(), aPair.firstRelay.getY(), aPair.firstRelay.getZ(), aPair.secondRelay.getX(), aPair.secondRelay.getY(), aPair.secondRelay.getZ(), ConfigValues.lessParticles ? 1 : Util.RANDOM.nextInt(3)+1, 0.8F, COLOR, 1F);
|
|
|
|
}
|
|
|
|
}
|
2015-10-31 14:42:51 +01:00
|
|
|
}
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@Override
|
|
|
|
public void invalidate(){
|
|
|
|
super.invalidate();
|
2016-01-08 13:31:58 +01:00
|
|
|
LaserRelayConnectionHandler.getInstance().removeRelayFromNetwork(this.pos);
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2015-10-18 19:21:32 +02:00
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate){
|
2016-01-08 13:31:58 +01:00
|
|
|
return this.transmitEnergy(WorldUtil.getCoordsFromSide(from, this.pos, 0), maxReceive, simulate);
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public int getEnergyStored(EnumFacing from){
|
2015-10-20 00:22:36 +02:00
|
|
|
return 0;
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public int getMaxEnergyStored(EnumFacing from){
|
2015-10-20 00:22:36 +02:00
|
|
|
return 0;
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
|
|
|
|
2016-01-08 13:31:58 +01:00
|
|
|
public int transmitEnergy(BlockPos blockFrom, int maxTransmit, boolean simulate){
|
2015-10-20 00:22:36 +02:00
|
|
|
int transmitted = 0;
|
|
|
|
if(maxTransmit > 0){
|
2016-01-08 13:31:58 +01:00
|
|
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getInstance().getNetworkFor(this.pos);
|
2015-10-20 00:22:36 +02:00
|
|
|
if(network != null){
|
2015-12-23 01:43:49 +01:00
|
|
|
transmitted = LaserRelayConnectionHandler.getInstance().transferEnergyToReceiverInNeed(worldObj, blockFrom, network, Math.min(ConfigIntValues.LASER_RELAY_MAX_TRANSFER.getValue(), maxTransmit), simulate);
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return transmitted;
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
2015-10-23 16:54:33 +02:00
|
|
|
|
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public boolean canConnectEnergy(EnumFacing from){
|
2015-10-23 16:54:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|