mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Significantly upped the performance on Item Laser Relays by making them remember the things around them
This commit is contained in:
parent
26d5d94f39
commit
91ca5aa4a1
5 changed files with 77 additions and 18 deletions
|
@ -12,11 +12,15 @@ package de.ellpeck.actuallyadditions.mod.blocks;
|
|||
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockItemViewer extends BlockContainerBase{
|
||||
|
@ -30,6 +34,17 @@ public class BlockItemViewer extends BlockContainerBase{
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block){
|
||||
if(!world.isRemote){
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityItemViewer){
|
||||
((TileEntityItemViewer)tile).saveConnectedRelay();
|
||||
System.out.println("------------Saving connected on change " + ((TileEntityItemViewer)tile).connectedRelay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World worldIn, int meta){
|
||||
return new TileEntityItemViewer();
|
||||
|
|
|
@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
|
|||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayEnergy;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemWhitelist;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
|
@ -115,6 +116,16 @@ public class BlockLaserRelay extends BlockContainerBase{
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block){
|
||||
if(!world.isRemote){
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if(tile instanceof TileEntityLaserRelayItem){
|
||||
((TileEntityLaserRelayItem)tile).saveAllHandlersAround();
|
||||
System.out.println("------------Saving around on change " + ((TileEntityLaserRelayItem)tile).handlersAround);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int i){
|
||||
|
|
|
@ -24,12 +24,27 @@ import java.util.List;
|
|||
|
||||
public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||
|
||||
public TileEntityLaserRelayItem connectedRelay;
|
||||
private boolean hasCheckedRelayOnLoad;
|
||||
|
||||
public TileEntityItemViewer(){
|
||||
super(0, "itemViewer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
|
||||
if(!this.worldObj.isRemote && !this.hasCheckedRelayOnLoad){
|
||||
this.saveConnectedRelay();
|
||||
this.hasCheckedRelayOnLoad = true;
|
||||
|
||||
System.out.println("------------Saving relay on load " + this.connectedRelay);
|
||||
}
|
||||
}
|
||||
|
||||
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
||||
TileEntityLaserRelayItem relay = this.getConnectedRelay();
|
||||
TileEntityLaserRelayItem relay = this.connectedRelay;
|
||||
if(relay != null){
|
||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(relay.getPos(), this.worldObj);
|
||||
if(network != null){
|
||||
|
@ -61,7 +76,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
|||
return null;
|
||||
}
|
||||
|
||||
private TileEntityLaserRelayItem getConnectedRelay(){
|
||||
public void saveConnectedRelay(){
|
||||
TileEntityLaserRelayItem tileFound = null;
|
||||
if(this.worldObj != null){ //Why is that even possible..?
|
||||
for(int i = 0; i <= 5; i++){
|
||||
|
@ -71,7 +86,8 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
|||
|
||||
if(tile instanceof TileEntityLaserRelayItem){
|
||||
if(tileFound != null){
|
||||
return null;
|
||||
this.connectedRelay = null;
|
||||
return;
|
||||
}
|
||||
else{
|
||||
tileFound = (TileEntityLaserRelayItem)tile;
|
||||
|
@ -79,7 +95,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
|||
}
|
||||
}
|
||||
}
|
||||
return tileFound;
|
||||
this.connectedRelay = tileFound;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,7 +119,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
|||
|
||||
private boolean isWhitelisted(SpecificItemHandlerInfo handler, ItemStack stack, boolean output){
|
||||
boolean whitelisted = handler.relayInQuestion.isWhitelisted(stack, output);
|
||||
TileEntityLaserRelayItem connected = this.getConnectedRelay();
|
||||
TileEntityLaserRelayItem connected = this.connectedRelay;
|
||||
if(connected != null && connected != handler.relayInQuestion){
|
||||
return whitelisted && connected.isWhitelisted(stack, !output);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
package de.ellpeck.actuallyadditions.mod.tile;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler.Network;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer.GenericItemHandlerInfo;
|
||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -24,6 +26,9 @@ import java.util.List;
|
|||
|
||||
public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||
|
||||
public List<IItemHandler> handlersAround = new ArrayList<IItemHandler>();
|
||||
private boolean hasCheckedHandlersOnLoad;
|
||||
|
||||
public TileEntityLaserRelayItem(String name){
|
||||
super(name, true);
|
||||
}
|
||||
|
@ -36,8 +41,21 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
|||
return true;
|
||||
}
|
||||
|
||||
public List<IItemHandler> getAllHandlersAround(){
|
||||
List<IItemHandler> handlers = new ArrayList<IItemHandler>();
|
||||
@Override
|
||||
public void updateEntity(){
|
||||
super.updateEntity();
|
||||
|
||||
if(!this.worldObj.isRemote && !this.hasCheckedHandlersOnLoad){
|
||||
this.saveAllHandlersAround();
|
||||
this.hasCheckedHandlersOnLoad = true;
|
||||
|
||||
System.out.println("------------Saving around on load " + this.handlersAround);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAllHandlersAround(){
|
||||
this.handlersAround.clear();
|
||||
|
||||
for(int i = 0; i <= 5; i++){
|
||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
||||
BlockPos pos = WorldUtil.getCoordsFromSide(side, this.getPos(), 0);
|
||||
|
@ -45,27 +63,26 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
|||
if(tile != null && !(tile instanceof TileEntityItemViewer)){
|
||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite());
|
||||
if(handler != null){
|
||||
handlers.add(handler);
|
||||
this.handlersAround.add(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public List<TileEntityItemViewer.GenericItemHandlerInfo> getItemHandlersInNetwork(LaserRelayConnectionHandler.Network network){
|
||||
List<TileEntityItemViewer.GenericItemHandlerInfo> handlers = new ArrayList<TileEntityItemViewer.GenericItemHandlerInfo>();
|
||||
public List<GenericItemHandlerInfo> getItemHandlersInNetwork(Network network){
|
||||
List<GenericItemHandlerInfo> handlers = new ArrayList<GenericItemHandlerInfo>();
|
||||
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
||||
for(BlockPos relay : pair.positions){
|
||||
if(relay != null){
|
||||
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
||||
if(aRelayTile instanceof de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem){
|
||||
de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem relayTile = (de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem)aRelayTile;
|
||||
if(!TileEntityItemViewer.GenericItemHandlerInfo.containsTile(handlers, relayTile)){
|
||||
TileEntityItemViewer.GenericItemHandlerInfo info = new TileEntityItemViewer.GenericItemHandlerInfo(relayTile);
|
||||
if(aRelayTile instanceof TileEntityLaserRelayItem){
|
||||
TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile;
|
||||
if(!GenericItemHandlerInfo.containsTile(handlers, relayTile)){
|
||||
GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile);
|
||||
|
||||
List<IItemHandler> handlersAroundTile = relayTile.getAllHandlersAround();
|
||||
List<IItemHandler> handlersAroundTile = relayTile.handlersAround;
|
||||
for(IItemHandler handler : handlersAroundTile){
|
||||
if(!TileEntityItemViewer.GenericItemHandlerInfo.containsHandler(handlers, handler)){
|
||||
if(!GenericItemHandlerInfo.containsHandler(handlers, handler)){
|
||||
info.handlers.add(handler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
|
|||
int slotStart = output ? 12 : 0;
|
||||
int slotStop = slotStart+12;
|
||||
|
||||
List<IItemHandler> handlers = this.getAllHandlersAround();
|
||||
List<IItemHandler> handlers = this.handlersAround;
|
||||
for(IItemHandler handler : handlers){
|
||||
for(int i = 0; i < handler.getSlots(); i++){
|
||||
ItemStack stack = handler.getStackInSlot(i);
|
||||
|
|
Loading…
Reference in a new issue