Implemented new system of determining the type of laser relay connection

This commit is contained in:
Ellpeck 2016-09-01 18:02:03 +02:00
parent a89ff4bc29
commit 0e4967ea70
11 changed files with 94 additions and 26 deletions

View file

@ -31,7 +31,7 @@ public final class ActuallyAdditionsAPI{
public static final String MOD_ID = "actuallyadditions"; public static final String MOD_ID = "actuallyadditions";
public static final String API_ID = MOD_ID+"api"; public static final String API_ID = MOD_ID+"api";
public static final String API_VERSION = "21"; public static final String API_VERSION = "22";
public static final List<CrusherRecipe> CRUSHER_RECIPES = new ArrayList<CrusherRecipe>(); public static final List<CrusherRecipe> CRUSHER_RECIPES = new ArrayList<CrusherRecipe>();
public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<BallOfFurReturn>(); public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<BallOfFurReturn>();

View file

@ -13,15 +13,23 @@ package de.ellpeck.actuallyadditions.api.laser;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import java.util.ArrayList;
import java.util.List;
public class ConnectionPair{ public class ConnectionPair{
//TODO Remove eventually, just for making the implementation of LaserType work
public static final List<ConnectionPair> PAIRS_FOR_FIXING = new ArrayList<ConnectionPair>();
public final BlockPos[] positions = new BlockPos[2]; public final BlockPos[] positions = new BlockPos[2];
public final boolean suppressConnectionRender; public final boolean suppressConnectionRender;
public LaserType type;
public ConnectionPair(BlockPos firstRelay, BlockPos secondRelay, boolean suppressConnectionRender){ public ConnectionPair(BlockPos firstRelay, BlockPos secondRelay, LaserType type, boolean suppressConnectionRender){
this.positions[0] = firstRelay; this.positions[0] = firstRelay;
this.positions[1] = secondRelay; this.positions[1] = secondRelay;
this.suppressConnectionRender = suppressConnectionRender; this.suppressConnectionRender = suppressConnectionRender;
this.type = type;
} }
public static ConnectionPair readFromNBT(NBTTagCompound compound){ public static ConnectionPair readFromNBT(NBTTagCompound compound){
@ -33,7 +41,17 @@ public class ConnectionPair{
int aZ = compound.getInteger("z"+i); int aZ = compound.getInteger("z"+i);
pos[i] = new BlockPos(anX, aY, aZ); pos[i] = new BlockPos(anX, aY, aZ);
} }
return new ConnectionPair(pos[0], pos[1], compound.getBoolean("SuppressRender"));
LaserType type = null;
String typeStrg = compound.getString("Type");
if(typeStrg != null && !typeStrg.isEmpty()){
type = LaserType.valueOf(typeStrg);
}
ConnectionPair pair = new ConnectionPair(pos[0], pos[1], type, compound.getBoolean("SuppressRender"));
if(type == null){
PAIRS_FOR_FIXING.add(pair);
}
return pair;
} }
return null; return null;
} }
@ -60,6 +78,7 @@ public class ConnectionPair{
compound.setInteger("y"+i, relay.getY()); compound.setInteger("y"+i, relay.getY());
compound.setInteger("z"+i, relay.getZ()); compound.setInteger("z"+i, relay.getZ());
} }
compound.setString("Type", this.type.name());
compound.setBoolean("SuppressRender", this.suppressConnectionRender); compound.setBoolean("SuppressRender", this.suppressConnectionRender);
return compound; return compound;
} }

View file

@ -30,7 +30,7 @@ public interface ILaserRelayConnectionHandler{
Network getNetworkFor(BlockPos relay, World world); Network getNetworkFor(BlockPos relay, World world);
boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, World world); boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, LaserType type, World world);
boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, World world, boolean suppressConnectionRender); boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, LaserType type, World world, boolean suppressConnectionRender);
} }

View file

@ -0,0 +1,15 @@
/*
* This file ("LaserType.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
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.api.laser;
public enum LaserType{
ENERGY, ITEM, FLUID
}

View file

@ -10,15 +10,17 @@
package de.ellpeck.actuallyadditions.mod.event; package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.ConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements; import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements;
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements; import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.data.PlayerData;
import de.ellpeck.actuallyadditions.mod.data.WorldData; import de.ellpeck.actuallyadditions.mod.data.WorldData;
import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.Util; import de.ellpeck.actuallyadditions.mod.util.Util;
@ -30,6 +32,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent; import net.minecraftforge.event.entity.living.LivingDropsEvent;
@ -142,6 +145,33 @@ public class CommonEvents{
@SubscribeEvent @SubscribeEvent
public void onLoad(WorldEvent.Load event){ public void onLoad(WorldEvent.Load event){
WorldData.load(event.getWorld()); WorldData.load(event.getWorld());
//TODO Remove this eventually (part of the ConnectionPair system change)
if(!ConnectionPair.PAIRS_FOR_FIXING.isEmpty()){
for(ConnectionPair pair : ConnectionPair.PAIRS_FOR_FIXING){
TileEntity first = event.getWorld().getTileEntity(pair.positions[0]);
TileEntity second = event.getWorld().getTileEntity(pair.positions[1]);
boolean fixed = false;
if(first instanceof TileEntityLaserRelay && second instanceof TileEntityLaserRelay){
LaserType firstType = ((TileEntityLaserRelay)first).type;
LaserType secondType = ((TileEntityLaserRelay)second).type;
if(firstType == secondType){
pair.type = firstType;
fixed = true;
}
}
if(!fixed){
for(int i = 0; i < pair.positions.length; i++){
ActuallyAdditionsAPI.connectionHandler.removeRelayFromNetwork(pair.positions[i], event.getWorld());
}
ModUtil.LOGGER.error("Had to remove a Laser Relay connection between "+pair.positions[0]+" and "+pair.positions[1]+" because it couldn't be adapted to the new system!");
}
}
ModUtil.LOGGER.info("Adapted "+ConnectionPair.PAIRS_FOR_FIXING.size()+" Laser Relay Connections to the new system!");
ConnectionPair.PAIRS_FOR_FIXING.clear();
}
} }
@SubscribeEvent @SubscribeEvent

View file

@ -61,11 +61,12 @@ public class ItemLaserWrench extends ItemBase{
if(savedPos != null){ if(savedPos != null){
TileEntity savedTile = world.getTileEntity(savedPos); TileEntity savedTile = world.getTileEntity(savedPos);
int distanceSq = (int)savedPos.distanceSq(pos); int distanceSq = (int)savedPos.distanceSq(pos);
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).isItem == ((TileEntityLaserRelay)tile).isItem && distanceSq <= TileEntityLaserRelay.MAX_DISTANCE*TileEntityLaserRelay.MAX_DISTANCE && ActuallyAdditionsAPI.connectionHandler.addConnection(savedPos, pos, world)){ TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).type == relay.type && distanceSq <= TileEntityLaserRelay.MAX_DISTANCE*TileEntityLaserRelay.MAX_DISTANCE && ActuallyAdditionsAPI.connectionHandler.addConnection(savedPos, pos, relay.type, world)){
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored"); ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
((TileEntityLaserRelay)savedTile).sendUpdate(); ((TileEntityLaserRelay)savedTile).sendUpdate();
((TileEntityLaserRelay)tile).sendUpdate(); relay.sendUpdate();
player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc")); player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
} }

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.misc;
import de.ellpeck.actuallyadditions.api.laser.ConnectionPair; import de.ellpeck.actuallyadditions.api.laser.ConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.ILaserRelayConnectionHandler; import de.ellpeck.actuallyadditions.api.laser.ILaserRelayConnectionHandler;
import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.data.WorldData; import de.ellpeck.actuallyadditions.mod.data.WorldData;
import io.netty.util.internal.ConcurrentSet; import io.netty.util.internal.ConcurrentSet;
@ -68,7 +69,7 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH
WorldData.getDataForWorld(world).laserRelayNetworks.remove(network); WorldData.getDataForWorld(world).laserRelayNetworks.remove(network);
for(ConnectionPair pair : network.connections){ for(ConnectionPair pair : network.connections){
if(!pair.contains(relay)){ if(!pair.contains(relay)){
this.addConnection(pair.positions[0], pair.positions[1], world, pair.suppressConnectionRender); this.addConnection(pair.positions[0], pair.positions[1], pair.type, world, pair.suppressConnectionRender);
} }
} }
//System.out.println("Removing a Relay from the Network!"); //System.out.println("Removing a Relay from the Network!");
@ -91,8 +92,8 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH
} }
@Override @Override
public boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, World world){ public boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, LaserType type, World world){
return this.addConnection(firstRelay, secondRelay, world, false); return this.addConnection(firstRelay, secondRelay, type, world, false);
} }
/** /**
@ -100,7 +101,7 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH
* (Puts it into the correct network!) * (Puts it into the correct network!)
*/ */
@Override @Override
public boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, World world, boolean suppressConnectionRender){ public boolean addConnection(BlockPos firstRelay, BlockPos secondRelay, LaserType type, World world, boolean suppressConnectionRender){
if(firstRelay == null || secondRelay == null || firstRelay == secondRelay || firstRelay.equals(secondRelay)){ if(firstRelay == null || secondRelay == null || firstRelay == secondRelay || firstRelay.equals(secondRelay)){
return false; return false;
} }
@ -112,7 +113,7 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH
if(firstNetwork == null && secondNetwork == null){ if(firstNetwork == null && secondNetwork == null){
firstNetwork = new Network(); firstNetwork = new Network();
WorldData.getDataForWorld(world).laserRelayNetworks.add(firstNetwork); WorldData.getDataForWorld(world).laserRelayNetworks.add(firstNetwork);
firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay, suppressConnectionRender)); firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay, type, suppressConnectionRender));
} }
//The same Network //The same Network
else if(firstNetwork == secondNetwork){ else if(firstNetwork == secondNetwork){
@ -121,15 +122,15 @@ public final class LaserRelayConnectionHandler implements ILaserRelayConnectionH
//Both relays have laserRelayNetworks //Both relays have laserRelayNetworks
else if(firstNetwork != null && secondNetwork != null){ else if(firstNetwork != null && secondNetwork != null){
mergeNetworks(firstNetwork, secondNetwork, world); mergeNetworks(firstNetwork, secondNetwork, world);
firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay, suppressConnectionRender)); firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay, type, suppressConnectionRender));
} }
//Only first network exists //Only first network exists
else if(firstNetwork != null){ else if(firstNetwork != null){
firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay, suppressConnectionRender)); firstNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay, type, suppressConnectionRender));
} }
//Only second network exists //Only second network exists
else{ else{
secondNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay, suppressConnectionRender)); secondNetwork.connections.add(new ConnectionPair(firstRelay, secondRelay, type, suppressConnectionRender));
} }
//System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString()); //System.out.println("Connected "+firstRelay.toString()+" to "+secondRelay.toString());
//System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString()); //System.out.println(firstNetwork == null ? secondNetwork.toString() : firstNetwork.toString());

View file

@ -23,7 +23,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fluids.BlockFluidBase;
import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.fluids.IFluidBlock;
import java.util.List; import java.util.List;

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.ConnectionPair; import de.ellpeck.actuallyadditions.api.laser.ConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.data.PlayerData;
@ -36,15 +37,15 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
private static final float[] COLOR = new float[]{1F, 0F, 0F}; private static final float[] COLOR = new float[]{1F, 0F, 0F};
private static final float[] COLOR_ITEM = new float[]{139F/255F, 94F/255F, 1F}; private static final float[] COLOR_ITEM = new float[]{139F/255F, 94F/255F, 1F};
public final boolean isItem; public final LaserType type;
private Set<ConnectionPair> tempConnectionStorage; private Set<ConnectionPair> tempConnectionStorage;
private boolean hasCheckedHandlersAround; private boolean hasCheckedHandlersAround;
public TileEntityLaserRelay(String name, boolean isItem){ public TileEntityLaserRelay(String name, LaserType type){
super(name); super(name);
this.isItem = isItem; this.type = type;
} }
@Override @Override
@ -58,7 +59,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
if(!list.hasNoTags()){ if(!list.hasNoTags()){
for(int i = 0; i < list.tagCount(); i++){ for(int i = 0; i < list.tagCount(); i++){
ConnectionPair pair = ConnectionPair.readFromNBT(list.getCompoundTagAt(i)); ConnectionPair pair = ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
ActuallyAdditionsAPI.connectionHandler.addConnection(pair.positions[0], pair.positions[1], this.worldObj, pair.suppressConnectionRender); ActuallyAdditionsAPI.connectionHandler.addConnection(pair.positions[0], pair.positions[1], this.type, this.worldObj, pair.suppressConnectionRender);
} }
} }
} }
@ -112,7 +113,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
if(network != null){ if(network != null){
for(ConnectionPair aPair : network.connections){ for(ConnectionPair aPair : network.connections){
if(!aPair.suppressConnectionRender && aPair.contains(this.pos) && this.pos.equals(aPair.positions[0])){ if(!aPair.suppressConnectionRender && aPair.contains(this.pos) && this.pos.equals(aPair.positions[0])){
AssetUtil.renderParticlesFromAToB(aPair.positions[0].getX(), aPair.positions[0].getY(), aPair.positions[0].getZ(), aPair.positions[1].getX(), aPair.positions[1].getY(), aPair.positions[1].getZ(), ConfigBoolValues.LESS_PARTICLES.isEnabled() ? 1 : Util.RANDOM.nextInt(3)+1, 0.8F, this.isItem ? COLOR_ITEM : COLOR, 1F); AssetUtil.renderParticlesFromAToB(aPair.positions[0].getX(), aPair.positions[0].getY(), aPair.positions[0].getZ(), aPair.positions[1].getX(), aPair.positions[1].getY(), aPair.positions[1].getZ(), ConfigBoolValues.LESS_PARTICLES.isEnabled() ? 1 : Util.RANDOM.nextInt(3)+1, 0.8F, this.type == LaserType.ITEM ? COLOR_ITEM : COLOR, 1F);
} }
} }
} }
@ -136,7 +137,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
public void validate(){ public void validate(){
if(this.tempConnectionStorage != null){ if(this.tempConnectionStorage != null){
for(ConnectionPair pair : this.tempConnectionStorage){ for(ConnectionPair pair : this.tempConnectionStorage){
ActuallyAdditionsAPI.connectionHandler.addConnection(pair.positions[0], pair.positions[1], this.worldObj, pair.suppressConnectionRender); ActuallyAdditionsAPI.connectionHandler.addConnection(pair.positions[0], pair.positions[1], pair.type, this.worldObj, pair.suppressConnectionRender);
} }
this.tempConnectionStorage = null; this.tempConnectionStorage = null;
} }

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.IEnergyReceiver; import cofh.api.energy.IEnergyReceiver;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.laser.ConnectionPair; import de.ellpeck.actuallyadditions.api.laser.ConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
@ -35,7 +36,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
public static final int CAP = 1000; public static final int CAP = 1000;
public TileEntityLaserRelayEnergy(String name){ public TileEntityLaserRelayEnergy(String name){
super(name, false); super(name, LaserType.ENERGY);
} }
public TileEntityLaserRelayEnergy(){ public TileEntityLaserRelayEnergy(){

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.laser.ConnectionPair; import de.ellpeck.actuallyadditions.api.laser.ConnectionPair;
import de.ellpeck.actuallyadditions.api.laser.LaserType;
import de.ellpeck.actuallyadditions.api.laser.Network; import de.ellpeck.actuallyadditions.api.laser.Network;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo; import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
@ -31,7 +32,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
public final Map<BlockPos, IItemHandler> handlersAround = new ConcurrentHashMap<BlockPos, IItemHandler>(); public final Map<BlockPos, IItemHandler> handlersAround = new ConcurrentHashMap<BlockPos, IItemHandler>();
public TileEntityLaserRelayItem(String name){ public TileEntityLaserRelayItem(String name){
super(name, true); super(name, LaserType.ITEM);
} }
public TileEntityLaserRelayItem(){ public TileEntityLaserRelayItem(){