mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Add a bunch of loadedness checks and add network caching to Laser Relays
This commit is contained in:
parent
ccb88fd416
commit
996b997363
9 changed files with 125 additions and 78 deletions
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.blocks;
|
package de.ellpeck.actuallyadditions.mod.blocks;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
||||||
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.blocks.base.BlockContainerBase;
|
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
||||||
|
@ -167,7 +166,7 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{
|
||||||
if(!world.isRemote){
|
if(!world.isRemote){
|
||||||
relay.onCompassAction(player);
|
relay.onCompassAction(player);
|
||||||
|
|
||||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(relay.getPos(), relay.getWorld());
|
Network network = relay.getNetwork();
|
||||||
if(network != null){
|
if(network != null){
|
||||||
network.changeAmount++;
|
network.changeAmount++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,7 +293,10 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
|
|
||||||
public void saveDataOnChangeOrWorldStart(){
|
public void saveDataOnChangeOrWorldStart(){
|
||||||
for(EnumFacing side : EnumFacing.values()){
|
for(EnumFacing side : EnumFacing.values()){
|
||||||
this.tilesAround[side.ordinal()] = this.world.getTileEntity(this.pos.offset(side));
|
BlockPos pos = this.pos.offset(side);
|
||||||
|
if(this.world.isBlockLoaded(pos)){
|
||||||
|
this.tilesAround[side.ordinal()] = this.world.getTileEntity(pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
|
@ -139,15 +140,22 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void saveDataOnChangeOrWorldStart(){
|
public void saveDataOnChangeOrWorldStart(){
|
||||||
|
this.placeToPull = null;
|
||||||
|
this.placeToPut = null;
|
||||||
|
|
||||||
if(this.sideToPull != -1){
|
if(this.sideToPull != -1){
|
||||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPull);
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPull);
|
||||||
this.placeToPull = this.world.getTileEntity(this.pos.offset(side));
|
BlockPos offset = this.pos.offset(side);
|
||||||
|
|
||||||
if(this.slotToPullEnd <= 0 && this.placeToPull != null){
|
if(this.world.isBlockLoaded(offset)){
|
||||||
if(this.placeToPull.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
|
this.placeToPull = this.world.getTileEntity(offset);
|
||||||
IItemHandler cap = this.placeToPull.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
|
||||||
if(cap != null){
|
if(this.slotToPullEnd <= 0 && this.placeToPull != null){
|
||||||
this.slotToPullEnd = cap.getSlots();
|
if(this.placeToPull.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
|
||||||
|
IItemHandler cap = this.placeToPull.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||||
|
if(cap != null){
|
||||||
|
this.slotToPullEnd = cap.getSlots();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,13 +163,17 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
|
||||||
|
|
||||||
if(this.sideToPut != -1){
|
if(this.sideToPut != -1){
|
||||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut);
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(this.sideToPut);
|
||||||
this.placeToPut = this.world.getTileEntity(this.pos.offset(side));
|
BlockPos offset = this.pos.offset(side);
|
||||||
|
|
||||||
if(this.slotToPutEnd <= 0 && this.placeToPut != null){
|
if(this.world.isBlockLoaded(offset)){
|
||||||
if(this.placeToPut.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
|
this.placeToPut = this.world.getTileEntity(offset);
|
||||||
IItemHandler cap = this.placeToPut.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
|
||||||
if(cap != null){
|
if(this.slotToPutEnd <= 0 && this.placeToPut != null){
|
||||||
this.slotToPutEnd = cap.getSlots();
|
if(this.placeToPut.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)){
|
||||||
|
IItemHandler cap = this.placeToPut.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
|
||||||
|
if(cap != null){
|
||||||
|
this.slotToPutEnd = cap.getSlots();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
||||||
import de.ellpeck.actuallyadditions.api.laser.Network;
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
||||||
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
|
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
|
||||||
|
@ -32,7 +31,6 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
private final List<GenericItemHandlerInfo> genericInfos = new ArrayList<GenericItemHandlerInfo>();
|
private final List<GenericItemHandlerInfo> genericInfos = new ArrayList<GenericItemHandlerInfo>();
|
||||||
private final Map<Integer, SpecificItemHandlerInfo> specificInfos = new HashMap<Integer, SpecificItemHandlerInfo>();
|
private final Map<Integer, SpecificItemHandlerInfo> specificInfos = new HashMap<Integer, SpecificItemHandlerInfo>();
|
||||||
public TileEntityLaserRelayItem connectedRelay;
|
public TileEntityLaserRelayItem connectedRelay;
|
||||||
private Network oldNetwork;
|
|
||||||
private int lastNetworkChangeAmount = -1;
|
private int lastNetworkChangeAmount = -1;
|
||||||
|
|
||||||
public TileEntityItemViewer(String name){
|
public TileEntityItemViewer(String name){
|
||||||
|
@ -45,8 +43,10 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
List<GenericItemHandlerInfo> infos = TileEntityItemViewer.this.getItemHandlerInfos();
|
List<GenericItemHandlerInfo> infos = TileEntityItemViewer.this.getItemHandlerInfos();
|
||||||
if(infos != null){
|
if(infos != null){
|
||||||
for(GenericItemHandlerInfo info : infos){
|
for(GenericItemHandlerInfo info : infos){
|
||||||
for(IItemHandler handler : info.handlers){
|
if(info.isLoaded()){
|
||||||
size += handler.getSlots();
|
for(IItemHandler handler : info.handlers){
|
||||||
|
size += handler.getSlots();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlot(int slot){
|
public ItemStack getStackInSlot(int slot){
|
||||||
SpecificItemHandlerInfo handler = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
SpecificItemHandlerInfo handler = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
||||||
if(handler != null){
|
if(handler != null && handler.isLoaded()){
|
||||||
return handler.handler.getStackInSlot(handler.switchedIndex);
|
return handler.handler.getStackInSlot(handler.switchedIndex);
|
||||||
}
|
}
|
||||||
return StackUtil.getNull();
|
return StackUtil.getNull();
|
||||||
|
@ -65,7 +65,7 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
@Override
|
@Override
|
||||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate){
|
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate){
|
||||||
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
||||||
if(info != null && TileEntityItemViewer.this.isWhitelisted(info, stack, false)){
|
if(info != null && info.isLoaded() && TileEntityItemViewer.this.isWhitelisted(info, stack, false)){
|
||||||
ItemStack remain = info.handler.insertItem(info.switchedIndex, stack, simulate);
|
ItemStack remain = info.handler.insertItem(info.switchedIndex, stack, simulate);
|
||||||
if(!ItemStack.areItemStacksEqual(remain, stack) && !simulate){
|
if(!ItemStack.areItemStacksEqual(remain, stack) && !simulate){
|
||||||
TileEntityItemViewer.this.markDirty();
|
TileEntityItemViewer.this.markDirty();
|
||||||
|
@ -81,7 +81,7 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
ItemStack stackIn = this.getStackInSlot(slot);
|
ItemStack stackIn = this.getStackInSlot(slot);
|
||||||
if(StackUtil.isValid(stackIn)){
|
if(StackUtil.isValid(stackIn)){
|
||||||
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
||||||
if(info != null && TileEntityItemViewer.this.isWhitelisted(info, stackIn, true)){
|
if(info != null && info.isLoaded() && TileEntityItemViewer.this.isWhitelisted(info, stackIn, true)){
|
||||||
ItemStack extracted = info.handler.extractItem(info.switchedIndex, amount, simulate);
|
ItemStack extracted = info.handler.extractItem(info.switchedIndex, amount, simulate);
|
||||||
if(StackUtil.isValid(extracted) && !simulate){
|
if(StackUtil.isValid(extracted) && !simulate){
|
||||||
TileEntityItemViewer.this.markDirty();
|
TileEntityItemViewer.this.markDirty();
|
||||||
|
@ -96,7 +96,7 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
@Override
|
@Override
|
||||||
public int getSlotLimit(int slot){
|
public int getSlotLimit(int slot){
|
||||||
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
SpecificItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
||||||
if(info != null){
|
if(info != null && info.isLoaded()){
|
||||||
return info.handler.getSlotLimit(info.switchedIndex);
|
return info.handler.getSlotLimit(info.switchedIndex);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -139,9 +139,9 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
|
|
||||||
private void queryAndSaveData(){
|
private void queryAndSaveData(){
|
||||||
if(this.connectedRelay != null){
|
if(this.connectedRelay != null){
|
||||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.connectedRelay.getPos(), this.world);
|
Network network = this.connectedRelay.getNetwork();
|
||||||
if(network != null){
|
if(network != null){
|
||||||
if(this.oldNetwork != network || this.lastNetworkChangeAmount != network.changeAmount){
|
if(this.lastNetworkChangeAmount != network.changeAmount){
|
||||||
this.clearInfos();
|
this.clearInfos();
|
||||||
|
|
||||||
this.connectedRelay.getItemHandlersInNetwork(network, this.genericInfos);
|
this.connectedRelay.getItemHandlersInNetwork(network, this.genericInfos);
|
||||||
|
@ -158,7 +158,6 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.oldNetwork = network;
|
|
||||||
this.lastNetworkChangeAmount = network.changeAmount;
|
this.lastNetworkChangeAmount = network.changeAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +166,7 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clearInfos();
|
this.clearInfos();
|
||||||
|
this.lastNetworkChangeAmount = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearInfos(){
|
private void clearInfos(){
|
||||||
|
@ -196,15 +196,18 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
for(int i = 0; i <= 5; i++){
|
for(int i = 0; i <= 5; i++){
|
||||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
||||||
BlockPos pos = this.getPos().offset(side);
|
BlockPos pos = this.getPos().offset(side);
|
||||||
TileEntity tile = this.world.getTileEntity(pos);
|
|
||||||
|
|
||||||
if(tile instanceof TileEntityLaserRelayItem){
|
if(this.world.isBlockLoaded(pos)){
|
||||||
if(tileFound != null){
|
TileEntity tile = this.world.getTileEntity(pos);
|
||||||
this.connectedRelay = null;
|
|
||||||
return;
|
if(tile instanceof TileEntityLaserRelayItem){
|
||||||
}
|
if(tileFound != null){
|
||||||
else{
|
this.connectedRelay = null;
|
||||||
tileFound = (TileEntityLaserRelayItem)tile;
|
return;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
tileFound = (TileEntityLaserRelayItem)tile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,6 +237,10 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
this.switchedIndex = switchedIndex;
|
this.switchedIndex = switchedIndex;
|
||||||
this.relayInQuestion = relayInQuestion;
|
this.relayInQuestion = relayInQuestion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLoaded(){
|
||||||
|
return this.relayInQuestion.hasWorld() && this.relayInQuestion.getWorld().isBlockLoaded(this.relayInQuestion.getPos());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GenericItemHandlerInfo implements Comparable<GenericItemHandlerInfo>{
|
public static class GenericItemHandlerInfo implements Comparable<GenericItemHandlerInfo>{
|
||||||
|
@ -245,6 +252,10 @@ public class TileEntityItemViewer extends TileEntityBase{
|
||||||
this.relayInQuestion = relayInQuestion;
|
this.relayInQuestion = relayInQuestion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLoaded(){
|
||||||
|
return this.relayInQuestion.hasWorld() && this.relayInQuestion.getWorld().isBlockLoaded(this.relayInQuestion.getPos());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(GenericItemHandlerInfo other){
|
public int compareTo(GenericItemHandlerInfo other){
|
||||||
int thisPrio = this.relayInQuestion.getPriority();
|
int thisPrio = this.relayInQuestion.getPriority();
|
||||||
|
|
|
@ -19,6 +19,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
|
|
||||||
|
@ -90,23 +91,23 @@ public class TileEntityItemViewerHopping extends TileEntityItemViewer{
|
||||||
public void saveDataOnChangeOrWorldStart(){
|
public void saveDataOnChangeOrWorldStart(){
|
||||||
super.saveDataOnChangeOrWorldStart();
|
super.saveDataOnChangeOrWorldStart();
|
||||||
|
|
||||||
|
this.handlerToPullFrom = null;
|
||||||
|
this.handlerToPushTo = null;
|
||||||
|
|
||||||
TileEntity from = this.world.getTileEntity(this.pos.offset(EnumFacing.UP));
|
TileEntity from = this.world.getTileEntity(this.pos.offset(EnumFacing.UP));
|
||||||
if(from != null && !(from instanceof TileEntityItemViewer) && from.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN)){
|
if(from != null && !(from instanceof TileEntityItemViewer) && from.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN)){
|
||||||
this.handlerToPullFrom = from.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
|
this.handlerToPullFrom = from.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
this.handlerToPullFrom = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
IBlockState state = this.world.getBlockState(this.pos);
|
IBlockState state = this.world.getBlockState(this.pos);
|
||||||
EnumFacing facing = state.getValue(BlockHopper.FACING);
|
EnumFacing facing = state.getValue(BlockHopper.FACING);
|
||||||
|
|
||||||
TileEntity to = this.world.getTileEntity(this.pos.offset(facing));
|
BlockPos toPos = this.pos.offset(facing);
|
||||||
if(to != null && !(to instanceof TileEntityItemViewer) && to.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite())){
|
if(this.world.isBlockLoaded(toPos)){
|
||||||
this.handlerToPushTo = to.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
|
TileEntity to = this.world.getTileEntity(toPos);
|
||||||
}
|
if(to != null && !(to instanceof TileEntityItemViewer) && to.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite())){
|
||||||
else{
|
this.handlerToPushTo = to.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
|
||||||
this.handlerToPushTo = null;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,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.IConnectionPair;
|
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
||||||
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
||||||
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.ConnectionPair;
|
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.ConnectionPair;
|
||||||
import io.netty.util.internal.ConcurrentSet;
|
import io.netty.util.internal.ConcurrentSet;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -30,6 +31,9 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
|
|
||||||
public final LaserType type;
|
public final LaserType type;
|
||||||
|
|
||||||
|
private Network cachedNetwork;
|
||||||
|
private int changeAmountAtCaching = -1;
|
||||||
|
|
||||||
private Set<IConnectionPair> tempConnectionStorage;
|
private Set<IConnectionPair> tempConnectionStorage;
|
||||||
|
|
||||||
public TileEntityLaserRelay(String name, LaserType type){
|
public TileEntityLaserRelay(String name, LaserType type){
|
||||||
|
@ -107,6 +111,21 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
public Network getNetwork(){
|
||||||
|
if(this.cachedNetwork == null || this.cachedNetwork.changeAmount != this.changeAmountAtCaching){
|
||||||
|
this.cachedNetwork = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.world);
|
||||||
|
|
||||||
|
if(this.cachedNetwork != null){
|
||||||
|
this.changeAmountAtCaching = this.cachedNetwork.changeAmount;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.changeAmountAtCaching = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.cachedNetwork;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate(){
|
public void invalidate(){
|
||||||
super.invalidate();
|
super.invalidate();
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
||||||
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
||||||
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
||||||
import de.ellpeck.actuallyadditions.api.laser.Network;
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
|
@ -90,7 +89,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
|
||||||
private int transmitEnergy(EnumFacing from, int maxTransmit, boolean simulate){
|
private int transmitEnergy(EnumFacing from, int maxTransmit, boolean simulate){
|
||||||
int transmitted = 0;
|
int transmitted = 0;
|
||||||
if(maxTransmit > 0 && this.mode != Mode.OUTPUT_ONLY){
|
if(maxTransmit > 0 && this.mode != Mode.OUTPUT_ONLY){
|
||||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.world);
|
Network network = this.getNetwork();
|
||||||
if(network != null){
|
if(network != null){
|
||||||
transmitted = this.transferEnergyToReceiverInNeed(from, network, maxTransmit, simulate);
|
transmitted = this.transferEnergyToReceiverInNeed(from, network, maxTransmit, simulate);
|
||||||
}
|
}
|
||||||
|
@ -116,21 +115,23 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
|
||||||
this.receiversAround.clear();
|
this.receiversAround.clear();
|
||||||
for(EnumFacing side : EnumFacing.values()){
|
for(EnumFacing side : EnumFacing.values()){
|
||||||
BlockPos pos = this.getPos().offset(side);
|
BlockPos pos = this.getPos().offset(side);
|
||||||
TileEntity tile = this.world.getTileEntity(pos);
|
if(this.world.isBlockLoaded(pos)){
|
||||||
if(tile != null && !(tile instanceof TileEntityLaserRelay)){
|
TileEntity tile = this.world.getTileEntity(pos);
|
||||||
if((ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, side.getOpposite())) || tile.hasCapability(CapabilityEnergy.ENERGY, side.getOpposite())){
|
if(tile != null && !(tile instanceof TileEntityLaserRelay)){
|
||||||
this.receiversAround.put(side, tile);
|
if((ActuallyAdditions.teslaLoaded && tile.hasCapability(TeslaUtil.teslaConsumer, side.getOpposite())) || tile.hasCapability(CapabilityEnergy.ENERGY, side.getOpposite())){
|
||||||
|
this.receiversAround.put(side, tile);
|
||||||
|
|
||||||
TileEntity oldTile = old.get(side);
|
TileEntity oldTile = old.get(side);
|
||||||
if(oldTile == null || !tile.equals(oldTile)){
|
if(oldTile == null || !tile.equals(oldTile)){
|
||||||
change = true;
|
change = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(change || old.size() != this.receiversAround.size()){
|
if(change || old.size() != this.receiversAround.size()){
|
||||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
|
Network network = this.getNetwork();
|
||||||
if(network != null){
|
if(network != null){
|
||||||
network.changeAmount++;
|
network.changeAmount++;
|
||||||
}
|
}
|
||||||
|
@ -147,7 +148,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay{
|
||||||
|
|
||||||
for(IConnectionPair pair : network.connections){
|
for(IConnectionPair pair : network.connections){
|
||||||
for(BlockPos relay : pair.getPositions()){
|
for(BlockPos relay : pair.getPositions()){
|
||||||
if(relay != null && !alreadyChecked.contains(relay)){
|
if(relay != null && this.world.isBlockLoaded(relay) && !alreadyChecked.contains(relay)){
|
||||||
alreadyChecked.add(relay);
|
alreadyChecked.add(relay);
|
||||||
TileEntity relayTile = this.world.getTileEntity(relay);
|
TileEntity relayTile = this.world.getTileEntity(relay);
|
||||||
if(relayTile instanceof TileEntityLaserRelayEnergy){
|
if(relayTile instanceof TileEntityLaserRelayEnergy){
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
||||||
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
||||||
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
||||||
import de.ellpeck.actuallyadditions.api.laser.Network;
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
|
@ -96,21 +95,23 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
|
||||||
this.handlersAround.clear();
|
this.handlersAround.clear();
|
||||||
for(EnumFacing side : EnumFacing.values()){
|
for(EnumFacing side : EnumFacing.values()){
|
||||||
BlockPos pos = this.getPos().offset(side);
|
BlockPos pos = this.getPos().offset(side);
|
||||||
TileEntity tile = this.world.getTileEntity(pos);
|
if(this.world.isBlockLoaded(pos)){
|
||||||
if(tile != null && !(tile instanceof TileEntityLaserRelay)){
|
TileEntity tile = this.world.getTileEntity(pos);
|
||||||
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())){
|
if(tile != null && !(tile instanceof TileEntityLaserRelay)){
|
||||||
this.handlersAround.put(side, tile);
|
if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())){
|
||||||
|
this.handlersAround.put(side, tile);
|
||||||
|
|
||||||
TileEntity oldTile = old.get(side);
|
TileEntity oldTile = old.get(side);
|
||||||
if(oldTile == null || !tile.equals(oldTile)){
|
if(oldTile == null || !tile.equals(oldTile)){
|
||||||
change = true;
|
change = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(change || old.size() != this.handlersAround.size()){
|
if(change || old.size() != this.handlersAround.size()){
|
||||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
|
Network network = this.getNetwork();
|
||||||
if(network != null){
|
if(network != null){
|
||||||
network.changeAmount++;
|
network.changeAmount++;
|
||||||
}
|
}
|
||||||
|
@ -125,7 +126,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
|
||||||
private int transmitFluid(EnumFacing from, FluidStack stack, boolean doFill){
|
private int transmitFluid(EnumFacing from, FluidStack stack, boolean doFill){
|
||||||
int transmitted = 0;
|
int transmitted = 0;
|
||||||
if(stack != null && this.mode != Mode.OUTPUT_ONLY){
|
if(stack != null && this.mode != Mode.OUTPUT_ONLY){
|
||||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.pos, this.world);
|
Network network = this.getNetwork();
|
||||||
if(network != null){
|
if(network != null){
|
||||||
transmitted = this.transferFluidToReceiverInNeed(from, network, stack, doFill);
|
transmitted = this.transferFluidToReceiverInNeed(from, network, stack, doFill);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +144,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay{
|
||||||
|
|
||||||
for(IConnectionPair pair : network.connections){
|
for(IConnectionPair pair : network.connections){
|
||||||
for(BlockPos relay : pair.getPositions()){
|
for(BlockPos relay : pair.getPositions()){
|
||||||
if(relay != null && !alreadyChecked.contains(relay)){
|
if(relay != null && this.world.isBlockLoaded(relay) && !alreadyChecked.contains(relay)){
|
||||||
alreadyChecked.add(relay);
|
alreadyChecked.add(relay);
|
||||||
TileEntity relayTile = this.world.getTileEntity(relay);
|
TileEntity relayTile = this.world.getTileEntity(relay);
|
||||||
if(relayTile instanceof TileEntityLaserRelayFluids){
|
if(relayTile instanceof TileEntityLaserRelayFluids){
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
||||||
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
import de.ellpeck.actuallyadditions.api.laser.IConnectionPair;
|
||||||
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
import de.ellpeck.actuallyadditions.api.laser.LaserType;
|
||||||
import de.ellpeck.actuallyadditions.api.laser.Network;
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
||||||
|
@ -69,22 +68,24 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||||
for(int i = 0; i <= 5; i++){
|
for(int i = 0; i <= 5; i++){
|
||||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
||||||
BlockPos pos = this.getPos().offset(side);
|
BlockPos pos = this.getPos().offset(side);
|
||||||
TileEntity tile = this.world.getTileEntity(pos);
|
if(this.world.isBlockLoaded(pos)){
|
||||||
if(tile != null && !(tile instanceof TileEntityItemViewer) && !(tile instanceof TileEntityLaserRelay)){
|
TileEntity tile = this.world.getTileEntity(pos);
|
||||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite());
|
if(tile != null && !(tile instanceof TileEntityItemViewer) && !(tile instanceof TileEntityLaserRelay)){
|
||||||
if(handler != null){
|
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite());
|
||||||
this.handlersAround.put(pos, handler);
|
if(handler != null){
|
||||||
|
this.handlersAround.put(pos, handler);
|
||||||
|
|
||||||
IItemHandler oldHandler = old.get(pos);
|
IItemHandler oldHandler = old.get(pos);
|
||||||
if(oldHandler == null || !handler.equals(oldHandler)){
|
if(oldHandler == null || !handler.equals(oldHandler)){
|
||||||
change = true;
|
change = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(change || old.size() != this.handlersAround.size()){
|
if(change || old.size() != this.handlersAround.size()){
|
||||||
Network network = ActuallyAdditionsAPI.connectionHandler.getNetworkFor(this.getPos(), this.getWorld());
|
Network network = this.getNetwork();
|
||||||
if(network != null){
|
if(network != null){
|
||||||
network.changeAmount++;
|
network.changeAmount++;
|
||||||
}
|
}
|
||||||
|
@ -97,15 +98,14 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||||
|
|
||||||
for(IConnectionPair pair : network.connections){
|
for(IConnectionPair pair : network.connections){
|
||||||
for(BlockPos relay : pair.getPositions()){
|
for(BlockPos relay : pair.getPositions()){
|
||||||
if(relay != null && !alreadyChecked.contains(relay)){
|
if(relay != null && this.world.isBlockLoaded(relay) && !alreadyChecked.contains(relay)){
|
||||||
alreadyChecked.add(relay);
|
alreadyChecked.add(relay);
|
||||||
TileEntity aRelayTile = this.world.getTileEntity(relay);
|
TileEntity aRelayTile = this.world.getTileEntity(relay);
|
||||||
if(aRelayTile instanceof TileEntityLaserRelayItem){
|
if(aRelayTile instanceof TileEntityLaserRelayItem){
|
||||||
TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile;
|
TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile;
|
||||||
GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile);
|
GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile);
|
||||||
|
|
||||||
Map<BlockPos, IItemHandler> handlersAroundTile = relayTile.handlersAround;
|
for(Map.Entry<BlockPos, IItemHandler> handler : relayTile.handlersAround.entrySet()){
|
||||||
for(Map.Entry<BlockPos, IItemHandler> handler : handlersAroundTile.entrySet()){
|
|
||||||
if(!alreadyChecked.contains(handler.getKey())){
|
if(!alreadyChecked.contains(handler.getKey())){
|
||||||
alreadyChecked.add(handler.getKey());
|
alreadyChecked.add(handler.getKey());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue