2015-10-18 19:21:32 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityLaserRelay.java") is part of the Actually Additions mod for Minecraft.
|
2015-10-18 19:21:32 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-10-18 19:21:32 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-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
|
|
|
|
2016-07-30 17:07:32 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
2016-09-12 16:13:39 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
2016-09-01 18:02:03 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
2016-09-12 20:45:29 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.misc.ConnectionPair;
|
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-11-08 08:53:30 +01:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2016-05-08 21:09:58 +02:00
|
|
|
|
2016-06-05 16:01:10 +02:00
|
|
|
import java.util.Set;
|
|
|
|
|
2016-05-08 21:09:58 +02:00
|
|
|
public abstract class TileEntityLaserRelay extends TileEntityBase{
|
2015-10-18 19:21:32 +02:00
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
public static final int MAX_DISTANCE = 15;
|
2016-05-08 21:09:58 +02:00
|
|
|
|
2016-09-01 18:02:03 +02:00
|
|
|
public final LaserType type;
|
2015-11-28 19:02:01 +01:00
|
|
|
|
2016-09-12 16:13:39 +02:00
|
|
|
private Set<IConnectionPair> tempConnectionStorage;
|
2016-06-05 16:01:10 +02:00
|
|
|
|
2016-09-01 18:02:03 +02:00
|
|
|
public TileEntityLaserRelay(String name, LaserType type){
|
2016-05-08 21:09:58 +02:00
|
|
|
super(name);
|
2016-09-01 18:02:03 +02:00
|
|
|
this.type = type;
|
2016-05-06 23:23:29 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:54:33 +02:00
|
|
|
@Override
|
2016-09-01 17:08:34 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.readSyncableNBT(compound, type);
|
|
|
|
|
|
|
|
if(type == NBTType.SYNC){
|
|
|
|
ActuallyAdditionsAPI.connectionHandler.removeRelayFromNetwork(this.pos, this.worldObj);
|
|
|
|
|
|
|
|
NBTTagList list = compound.getTagList("Connections", 10);
|
|
|
|
if(!list.hasNoTags()){
|
|
|
|
for(int i = 0; i < list.tagCount(); i++){
|
2016-09-12 16:13:39 +02:00
|
|
|
ConnectionPair pair = new ConnectionPair();
|
|
|
|
pair.readFromNBT(list.getCompoundTagAt(i));
|
|
|
|
ActuallyAdditionsAPI.connectionHandler.addConnection(pair.getPositions()[0], pair.getPositions()[1], this.type, this.worldObj, pair.doesSuppressRender());
|
2016-09-01 17:08:34 +02:00
|
|
|
}
|
2015-10-26 22:28:49 +01:00
|
|
|
}
|
|
|
|
}
|
2015-10-23 16:54:33 +02:00
|
|
|
}
|
|
|
|
|
2015-10-18 19:21:32 +02:00
|
|
|
@Override
|
2016-09-01 17:08:34 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.writeSyncableNBT(compound, type);
|
|
|
|
|
|
|
|
if(type == NBTType.SYNC){
|
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
|
2016-09-12 16:13:39 +02:00
|
|
|
ConcurrentSet<IConnectionPair> connections = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(this.pos, this.worldObj);
|
2016-09-01 17:08:34 +02:00
|
|
|
if(connections != null && !connections.isEmpty()){
|
2016-09-12 16:13:39 +02:00
|
|
|
for(IConnectionPair pair : connections){
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
pair.writeToNBT(tag);
|
|
|
|
list.appendTag(tag);
|
2016-09-01 17:08:34 +02:00
|
|
|
}
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
2016-06-04 00:26:33 +02:00
|
|
|
|
2016-09-01 17:08:34 +02:00
|
|
|
compound.setTag("Connections", list);
|
|
|
|
}
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|
|
|
|
|
2016-11-08 08:53:30 +01: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(){
|
2016-11-07 19:58:34 +01:00
|
|
|
if(this.worldObj.rand.nextInt(8) == 0){
|
2016-06-08 21:09:41 +02:00
|
|
|
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
|
|
|
if(player != null){
|
2016-06-15 17:42:55 +02:00
|
|
|
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
|
|
|
|
WrenchMode mode = WrenchMode.values()[data.theCompound.getInteger("LaserWrenchMode")];
|
|
|
|
if(mode != WrenchMode.NO_PARTICLES){
|
|
|
|
ItemStack stack = player.getHeldItemMainhand();
|
2016-11-16 20:31:16 +01:00
|
|
|
if(mode == WrenchMode.ALWAYS_PARTICLES || (StackUtil.isValid(stack) && stack.getItem() instanceof ItemLaserWrench)){
|
2016-07-30 17:07:32 +02:00
|
|
|
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.worldObj);
|
2016-06-15 17:42:55 +02:00
|
|
|
if(network != null){
|
2016-09-12 16:13:39 +02:00
|
|
|
for(IConnectionPair aPair : network.connections){
|
|
|
|
if(!aPair.doesSuppressRender() && aPair.contains(this.pos) && this.pos.equals(aPair.getPositions()[0])){
|
2016-11-07 19:58:34 +01:00
|
|
|
AssetUtil.renderParticlesFromAToB(aPair.getPositions()[0].getX(), aPair.getPositions()[0].getY(), aPair.getPositions()[0].getZ(), aPair.getPositions()[1].getX(), aPair.getPositions()[1].getY(), aPair.getPositions()[1].getZ(), this.worldObj.rand.nextInt(3)+1, 0.8F, this.type == LaserType.ITEM ? COLOR_ITEM : (this.type == LaserType.FLUID ? COLOR_FLUIDS : COLOR), 1F);
|
2016-06-15 17:42:55 +02:00
|
|
|
}
|
2016-06-08 21:09:41 +02:00
|
|
|
}
|
|
|
|
}
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
}
|
2015-10-31 14:42:51 +01:00
|
|
|
}
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
2016-11-08 08:53:30 +01:00
|
|
|
}*/
|
2015-10-18 19:21:32 +02:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@Override
|
|
|
|
public void invalidate(){
|
|
|
|
super.invalidate();
|
2016-06-05 16:01:10 +02:00
|
|
|
//This is because Minecraft randomly invalidates tiles on world join and then validates them again
|
|
|
|
//We need to compensate for this so that connections don't get broken randomly
|
2016-07-30 17:07:32 +02:00
|
|
|
this.tempConnectionStorage = ActuallyAdditionsAPI.connectionHandler.getConnectionsFor(this.pos, this.worldObj);
|
2016-06-05 16:01:10 +02:00
|
|
|
|
2016-07-30 17:07:32 +02:00
|
|
|
ActuallyAdditionsAPI.connectionHandler.removeRelayFromNetwork(this.pos, this.worldObj);
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2016-06-05 16:01:10 +02:00
|
|
|
@Override
|
|
|
|
public void validate(){
|
|
|
|
if(this.tempConnectionStorage != null){
|
2016-09-12 16:13:39 +02:00
|
|
|
for(IConnectionPair pair : this.tempConnectionStorage){
|
|
|
|
ActuallyAdditionsAPI.connectionHandler.addConnection(pair.getPositions()[0], pair.getPositions()[1], pair.getType(), this.worldObj, pair.doesSuppressRender());
|
2016-06-05 16:01:10 +02:00
|
|
|
}
|
|
|
|
this.tempConnectionStorage = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
super.validate();
|
|
|
|
}
|
2016-11-08 08:53:30 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getRenderBoundingBox(){
|
|
|
|
return INFINITE_EXTENT_AABB;
|
|
|
|
}
|
2015-10-18 19:21:32 +02:00
|
|
|
}
|