mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +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.blocks.base.BlockContainerBase;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityItemViewer;
|
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.SoundType;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.item.EnumRarity;
|
import net.minecraft.item.EnumRarity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class BlockItemViewer extends BlockContainerBase{
|
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
|
@Override
|
||||||
public TileEntity createNewTileEntity(World worldIn, int meta){
|
public TileEntity createNewTileEntity(World worldIn, int meta){
|
||||||
return new TileEntityItemViewer();
|
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.TileEntityLaserRelayEnergy;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem;
|
||||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemWhitelist;
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemWhitelist;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.SoundType;
|
import net.minecraft.block.SoundType;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.properties.PropertyInteger;
|
import net.minecraft.block.properties.PropertyInteger;
|
||||||
|
@ -115,6 +116,16 @@ public class BlockLaserRelay extends BlockContainerBase{
|
||||||
return false;
|
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
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int i){
|
public TileEntity createNewTileEntity(World world, int i){
|
||||||
|
|
|
@ -24,12 +24,27 @@ import java.util.List;
|
||||||
|
|
||||||
public class TileEntityItemViewer extends TileEntityInventoryBase{
|
public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||||
|
|
||||||
|
public TileEntityLaserRelayItem connectedRelay;
|
||||||
|
private boolean hasCheckedRelayOnLoad;
|
||||||
|
|
||||||
public TileEntityItemViewer(){
|
public TileEntityItemViewer(){
|
||||||
super(0, "itemViewer");
|
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(){
|
private List<GenericItemHandlerInfo> getItemHandlerInfos(){
|
||||||
TileEntityLaserRelayItem relay = this.getConnectedRelay();
|
TileEntityLaserRelayItem relay = this.connectedRelay;
|
||||||
if(relay != null){
|
if(relay != null){
|
||||||
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(relay.getPos(), this.worldObj);
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(relay.getPos(), this.worldObj);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
|
@ -61,7 +76,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TileEntityLaserRelayItem getConnectedRelay(){
|
public void saveConnectedRelay(){
|
||||||
TileEntityLaserRelayItem tileFound = null;
|
TileEntityLaserRelayItem tileFound = null;
|
||||||
if(this.worldObj != null){ //Why is that even possible..?
|
if(this.worldObj != null){ //Why is that even possible..?
|
||||||
for(int i = 0; i <= 5; i++){
|
for(int i = 0; i <= 5; i++){
|
||||||
|
@ -71,7 +86,8 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||||
|
|
||||||
if(tile instanceof TileEntityLaserRelayItem){
|
if(tile instanceof TileEntityLaserRelayItem){
|
||||||
if(tileFound != null){
|
if(tileFound != null){
|
||||||
return null;
|
this.connectedRelay = null;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
tileFound = (TileEntityLaserRelayItem)tile;
|
tileFound = (TileEntityLaserRelayItem)tile;
|
||||||
|
@ -79,7 +95,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tileFound;
|
this.connectedRelay = tileFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -103,7 +119,7 @@ public class TileEntityItemViewer extends TileEntityInventoryBase{
|
||||||
|
|
||||||
private boolean isWhitelisted(SpecificItemHandlerInfo handler, ItemStack stack, boolean output){
|
private boolean isWhitelisted(SpecificItemHandlerInfo handler, ItemStack stack, boolean output){
|
||||||
boolean whitelisted = handler.relayInQuestion.isWhitelisted(stack, output);
|
boolean whitelisted = handler.relayInQuestion.isWhitelisted(stack, output);
|
||||||
TileEntityLaserRelayItem connected = this.getConnectedRelay();
|
TileEntityLaserRelayItem connected = this.connectedRelay;
|
||||||
if(connected != null && connected != handler.relayInQuestion){
|
if(connected != null && connected != handler.relayInQuestion){
|
||||||
return whitelisted && connected.isWhitelisted(stack, !output);
|
return whitelisted && connected.isWhitelisted(stack, !output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.misc.LaserRelayConnectionHandler;
|
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 de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
@ -24,6 +26,9 @@ import java.util.List;
|
||||||
|
|
||||||
public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||||
|
|
||||||
|
public List<IItemHandler> handlersAround = new ArrayList<IItemHandler>();
|
||||||
|
private boolean hasCheckedHandlersOnLoad;
|
||||||
|
|
||||||
public TileEntityLaserRelayItem(String name){
|
public TileEntityLaserRelayItem(String name){
|
||||||
super(name, true);
|
super(name, true);
|
||||||
}
|
}
|
||||||
|
@ -36,8 +41,21 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IItemHandler> getAllHandlersAround(){
|
@Override
|
||||||
List<IItemHandler> handlers = new ArrayList<IItemHandler>();
|
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++){
|
for(int i = 0; i <= 5; i++){
|
||||||
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
||||||
BlockPos pos = WorldUtil.getCoordsFromSide(side, this.getPos(), 0);
|
BlockPos pos = WorldUtil.getCoordsFromSide(side, this.getPos(), 0);
|
||||||
|
@ -45,27 +63,26 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||||
if(tile != null && !(tile instanceof TileEntityItemViewer)){
|
if(tile != null && !(tile instanceof TileEntityItemViewer)){
|
||||||
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite());
|
IItemHandler handler = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side.getOpposite());
|
||||||
if(handler != null){
|
if(handler != null){
|
||||||
handlers.add(handler);
|
this.handlersAround.add(handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return handlers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TileEntityItemViewer.GenericItemHandlerInfo> getItemHandlersInNetwork(LaserRelayConnectionHandler.Network network){
|
public List<GenericItemHandlerInfo> getItemHandlersInNetwork(Network network){
|
||||||
List<TileEntityItemViewer.GenericItemHandlerInfo> handlers = new ArrayList<TileEntityItemViewer.GenericItemHandlerInfo>();
|
List<GenericItemHandlerInfo> handlers = new ArrayList<GenericItemHandlerInfo>();
|
||||||
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
||||||
for(BlockPos relay : pair.positions){
|
for(BlockPos relay : pair.positions){
|
||||||
if(relay != null){
|
if(relay != null){
|
||||||
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
||||||
if(aRelayTile instanceof de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem){
|
if(aRelayTile instanceof TileEntityLaserRelayItem){
|
||||||
de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem relayTile = (de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem)aRelayTile;
|
TileEntityLaserRelayItem relayTile = (TileEntityLaserRelayItem)aRelayTile;
|
||||||
if(!TileEntityItemViewer.GenericItemHandlerInfo.containsTile(handlers, relayTile)){
|
if(!GenericItemHandlerInfo.containsTile(handlers, relayTile)){
|
||||||
TileEntityItemViewer.GenericItemHandlerInfo info = new TileEntityItemViewer.GenericItemHandlerInfo(relayTile);
|
GenericItemHandlerInfo info = new GenericItemHandlerInfo(relayTile);
|
||||||
|
|
||||||
List<IItemHandler> handlersAroundTile = relayTile.getAllHandlersAround();
|
List<IItemHandler> handlersAroundTile = relayTile.handlersAround;
|
||||||
for(IItemHandler handler : handlersAroundTile){
|
for(IItemHandler handler : handlersAroundTile){
|
||||||
if(!TileEntityItemViewer.GenericItemHandlerInfo.containsHandler(handlers, handler)){
|
if(!GenericItemHandlerInfo.containsHandler(handlers, handler)){
|
||||||
info.handlers.add(handler);
|
info.handlers.add(handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
|
||||||
int slotStart = output ? 12 : 0;
|
int slotStart = output ? 12 : 0;
|
||||||
int slotStop = slotStart+12;
|
int slotStop = slotStart+12;
|
||||||
|
|
||||||
List<IItemHandler> handlers = this.getAllHandlersAround();
|
List<IItemHandler> handlers = this.handlersAround;
|
||||||
for(IItemHandler handler : handlers){
|
for(IItemHandler handler : handlers){
|
||||||
for(int i = 0; i < handler.getSlots(); i++){
|
for(int i = 0; i < handler.getSlots(); i++){
|
||||||
ItemStack stack = handler.getStackInSlot(i);
|
ItemStack stack = handler.getStackInSlot(i);
|
||||||
|
|
Loading…
Reference in a new issue