2016-05-16 22:52:27 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityItemViewer.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
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2016-05-16 22:52:27 +02:00
|
|
|
*/
|
|
|
|
|
2016-05-08 21:09:58 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
|
|
|
|
2016-07-30 17:07:32 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.laser.Network;
|
2017-02-04 14:12:17 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-12-27 17:40:27 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
|
2016-11-16 16:59:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-05-08 21:09:58 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2017-02-04 14:12:17 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.compat.CommonCapsUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.compat.SlotlessableItemHandlerWrapper;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
2016-05-08 21:09:58 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2016-05-08 21:09:58 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2017-02-04 14:12:17 +01:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
2016-05-08 21:09:58 +02:00
|
|
|
import net.minecraftforge.items.IItemHandler;
|
2021-02-26 22:15:48 +01:00
|
|
|
import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler;
|
|
|
|
import org.cyclops.commoncapabilities.capability.itemhandler.SlotlessItemHandlerConfig;
|
|
|
|
|
|
|
|
import java.util.*;
|
2016-05-08 21:09:58 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class TileEntityItemViewer extends TileEntityBase {
|
2016-05-08 21:09:58 +02:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
public final List<GenericItemHandlerInfo> genericInfos = new ArrayList<>();
|
|
|
|
public final Map<Integer, IItemHandlerInfo> itemHandlerInfos = new HashMap<>();
|
|
|
|
public final List<SlotlessItemHandlerInfo> slotlessInfos = new ArrayList<>();
|
2017-02-04 16:48:22 +01:00
|
|
|
protected final SlotlessableItemHandlerWrapper itemHandler;
|
2016-10-31 19:05:29 +01:00
|
|
|
public TileEntityLaserRelayItem connectedRelay;
|
2016-10-29 12:00:00 +02:00
|
|
|
private int lastNetworkChangeAmount = -1;
|
2019-11-08 22:22:08 +01:00
|
|
|
private int slotCount;
|
2016-10-29 12:00:00 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TileEntityItemViewer(String name) {
|
2016-12-18 13:27:14 +01:00
|
|
|
super(name);
|
2016-12-04 00:10:52 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
IItemHandler normalHandler = new IItemHandler() {
|
2016-12-04 00:10:52 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getSlots() {
|
2019-11-08 22:22:08 +01:00
|
|
|
return TileEntityItemViewer.this.getSlotCount();
|
2016-12-04 00:10:52 +01:00
|
|
|
}
|
2016-10-01 23:35:39 +02:00
|
|
|
|
2016-12-04 00:10:52 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public ItemStack getStackInSlot(int slot) {
|
2017-02-04 14:12:17 +01:00
|
|
|
IItemHandlerInfo handler = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
2021-02-26 22:15:48 +01:00
|
|
|
if (handler != null && handler.isLoaded()) {
|
|
|
|
return handler.handler.getStackInSlot(handler.switchedIndex);
|
|
|
|
}
|
2017-11-02 22:49:53 +01:00
|
|
|
return StackUtil.getEmpty();
|
2016-12-04 00:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
2017-02-04 14:12:17 +01:00
|
|
|
IItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (info != null && info.isLoaded() && TileEntityItemViewer.this.isWhitelisted(info, stack, false)) {
|
2016-12-27 17:40:27 +01:00
|
|
|
ItemStack remain = info.handler.insertItem(info.switchedIndex, stack, simulate);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!ItemStack.areItemStacksEqual(remain, stack) && !simulate) {
|
2016-12-04 00:10:52 +01:00
|
|
|
TileEntityItemViewer.this.markDirty();
|
2016-12-27 17:40:27 +01:00
|
|
|
TileEntityItemViewer.this.doItemParticle(stack, info.relayInQuestion.getPos(), TileEntityItemViewer.this.connectedRelay.getPos());
|
2016-12-04 00:10:52 +01:00
|
|
|
}
|
2016-12-27 17:40:27 +01:00
|
|
|
return remain;
|
2016-12-04 00:10:52 +01:00
|
|
|
}
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
2016-12-04 00:10:52 +01:00
|
|
|
ItemStack stackIn = this.getStackInSlot(slot);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stackIn)) {
|
2017-02-04 14:12:17 +01:00
|
|
|
IItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (info != null && info.isLoaded() && TileEntityItemViewer.this.isWhitelisted(info, stackIn, true)) {
|
2016-12-04 00:10:52 +01:00
|
|
|
ItemStack extracted = info.handler.extractItem(info.switchedIndex, amount, simulate);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(extracted) && !simulate) {
|
2016-12-04 00:10:52 +01:00
|
|
|
TileEntityItemViewer.this.markDirty();
|
2016-12-27 17:40:27 +01:00
|
|
|
TileEntityItemViewer.this.doItemParticle(extracted, TileEntityItemViewer.this.connectedRelay.getPos(), info.relayInQuestion.getPos());
|
2016-10-11 14:24:18 +02:00
|
|
|
}
|
2016-12-04 00:10:52 +01:00
|
|
|
return extracted;
|
2016-10-01 23:35:39 +02:00
|
|
|
}
|
|
|
|
}
|
2017-11-02 22:49:53 +01:00
|
|
|
return StackUtil.getEmpty();
|
2016-12-04 00:10:52 +01:00
|
|
|
}
|
2016-12-05 17:10:23 +01:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getSlotLimit(int slot) {
|
2017-02-04 14:12:17 +01:00
|
|
|
IItemHandlerInfo info = TileEntityItemViewer.this.getSwitchedIndexHandler(slot);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (info != null && info.isLoaded()) {
|
2016-12-05 17:10:23 +01:00
|
|
|
return info.handler.getSlotLimit(info.switchedIndex);
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-12-05 17:10:23 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2016-12-04 00:10:52 +01:00
|
|
|
};
|
2017-02-04 14:12:17 +01:00
|
|
|
|
|
|
|
Object slotlessHandler = null;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (ActuallyAdditions.commonCapsLoaded) {
|
2017-02-04 14:12:17 +01:00
|
|
|
slotlessHandler = CommonCapsUtil.createSlotlessItemViewerHandler(this, normalHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.itemHandler = new SlotlessableItemHandlerWrapper(normalHandler, slotlessHandler);
|
2016-12-04 00:10:52 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TileEntityItemViewer() {
|
2016-12-18 13:27:14 +01:00
|
|
|
this("itemViewer");
|
|
|
|
}
|
|
|
|
|
2016-12-04 00:10:52 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public IItemHandler getItemHandler(EnumFacing facing) {
|
2017-02-04 14:12:17 +01:00
|
|
|
return this.itemHandler.getNormalHandler();
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:01:41 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2019-02-27 19:53:05 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
|
|
|
if (ActuallyAdditions.commonCapsLoaded) {
|
|
|
|
if (capability == SlotlessItemHandlerConfig.CAPABILITY) {
|
2017-02-04 14:12:17 +01:00
|
|
|
Object handler = this.itemHandler.getSlotlessHandler();
|
2021-02-26 22:15:48 +01:00
|
|
|
if (handler != null) {
|
|
|
|
return (T) handler;
|
|
|
|
}
|
2017-02-04 14:12:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.getCapability(capability, facing);
|
2016-10-01 23:35:39 +02:00
|
|
|
}
|
|
|
|
|
2019-11-08 22:22:08 +01:00
|
|
|
private int getSlotCount() {
|
2016-10-29 12:00:00 +02:00
|
|
|
this.queryAndSaveData();
|
2019-11-08 22:22:08 +01:00
|
|
|
return this.slotCount;
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public void doItemParticle(ItemStack stack, BlockPos input, BlockPos output) {
|
|
|
|
if (!this.world.isRemote) {
|
2021-02-26 22:15:48 +01:00
|
|
|
CompoundNBT compound = new CompoundNBT();
|
2016-12-27 17:40:27 +01:00
|
|
|
stack.writeToNBT(compound);
|
|
|
|
|
|
|
|
compound.setDouble("InX", input.getX());
|
|
|
|
compound.setDouble("InY", input.getY());
|
|
|
|
compound.setDouble("InZ", input.getZ());
|
|
|
|
|
|
|
|
compound.setDouble("OutX", output.getX());
|
|
|
|
compound.setDouble("OutY", output.getY());
|
|
|
|
compound.setDouble("OutZ", output.getZ());
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
int rangeSq = 16 * 16;
|
2021-02-26 22:15:48 +01:00
|
|
|
for (PlayerEntity player : this.world.playerEntities) {
|
|
|
|
if (player instanceof ServerPlayerEntity) {
|
2019-05-02 09:10:29 +02:00
|
|
|
if (player.getDistanceSq(input) <= rangeSq || player.getDistanceSq(output) <= rangeSq) {
|
2021-02-26 22:15:48 +01:00
|
|
|
PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.LASER_PARTICLE_HANDLER), (ServerPlayerEntity) player);
|
2017-05-20 19:27:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-27 17:40:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private void queryAndSaveData() {
|
|
|
|
if (this.connectedRelay != null) {
|
2017-01-18 14:26:56 +01:00
|
|
|
Network network = this.connectedRelay.getNetwork();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (network != null) {
|
|
|
|
if (this.lastNetworkChangeAmount != network.changeAmount) {
|
2016-11-25 15:33:47 +01:00
|
|
|
this.clearInfos();
|
|
|
|
|
|
|
|
this.connectedRelay.getItemHandlersInNetwork(network, this.genericInfos);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!this.genericInfos.isEmpty()) {
|
2016-11-25 15:33:47 +01:00
|
|
|
Collections.sort(this.genericInfos);
|
|
|
|
|
|
|
|
int slotsQueried = 0;
|
2019-05-02 09:10:29 +02:00
|
|
|
for (GenericItemHandlerInfo info : this.genericInfos) {
|
|
|
|
for (SlotlessableItemHandlerWrapper handler : info.handlers) {
|
2017-02-04 14:12:17 +01:00
|
|
|
IItemHandler normalHandler = handler.getNormalHandler();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (normalHandler != null) {
|
|
|
|
for (int i = 0; i < normalHandler.getSlots(); i++) {
|
2017-02-04 14:12:17 +01:00
|
|
|
this.itemHandlerInfos.put(slotsQueried, new IItemHandlerInfo(normalHandler, i, info.relayInQuestion));
|
|
|
|
slotsQueried++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (ActuallyAdditions.commonCapsLoaded) {
|
2017-02-04 14:12:17 +01:00
|
|
|
Object slotlessHandler = handler.getSlotlessHandler();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (slotlessHandler instanceof ISlotlessItemHandler) {
|
2017-02-04 14:12:17 +01:00
|
|
|
this.slotlessInfos.add(new SlotlessItemHandlerInfo(slotlessHandler, info.relayInQuestion));
|
|
|
|
}
|
2016-11-25 15:33:47 +01:00
|
|
|
}
|
2016-10-29 12:00:00 +02:00
|
|
|
}
|
2016-05-16 22:52:27 +02:00
|
|
|
}
|
2019-11-08 22:22:08 +01:00
|
|
|
this.slotCount = slotsQueried;
|
2016-05-09 19:05:20 +02:00
|
|
|
}
|
2016-11-25 15:33:47 +01:00
|
|
|
this.lastNetworkChangeAmount = network.changeAmount;
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|
2016-10-29 12:00:00 +02:00
|
|
|
|
2016-11-25 15:33:47 +01:00
|
|
|
return;
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|
|
|
|
}
|
2016-11-25 15:33:47 +01:00
|
|
|
|
|
|
|
this.clearInfos();
|
2017-01-18 14:26:56 +01:00
|
|
|
this.lastNetworkChangeAmount = -1;
|
2016-11-25 15:33:47 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private void clearInfos() {
|
|
|
|
if (!this.genericInfos.isEmpty()) {
|
2016-11-25 15:33:47 +01:00
|
|
|
this.genericInfos.clear();
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!this.itemHandlerInfos.isEmpty()) {
|
2017-02-04 14:12:17 +01:00
|
|
|
this.itemHandlerInfos.clear();
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!this.slotlessInfos.isEmpty()) {
|
2017-02-04 14:12:17 +01:00
|
|
|
this.slotlessInfos.clear();
|
2016-11-25 15:33:47 +01:00
|
|
|
}
|
2016-10-29 12:00:00 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private IItemHandlerInfo getSwitchedIndexHandler(int i) {
|
2016-10-29 12:00:00 +02:00
|
|
|
this.queryAndSaveData();
|
2017-02-04 14:12:17 +01:00
|
|
|
return this.itemHandlerInfos.get(i);
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 18:40:09 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean shouldSaveDataOnChangeOrWorldStart() {
|
2016-09-09 18:40:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void saveDataOnChangeOrWorldStart() {
|
2016-05-09 19:05:20 +02:00
|
|
|
TileEntityLaserRelayItem tileFound = null;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.world != null) { //Why is that even possible..?
|
|
|
|
for (int i = 0; i <= 5; i++) {
|
2016-05-08 21:09:58 +02:00
|
|
|
EnumFacing side = WorldUtil.getDirectionBySidesInOrder(i);
|
2016-07-04 20:15:41 +02:00
|
|
|
BlockPos pos = this.getPos().offset(side);
|
2016-05-08 21:09:58 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.world.isBlockLoaded(pos)) {
|
2017-01-18 14:26:56 +01:00
|
|
|
TileEntity tile = this.world.getTileEntity(pos);
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (tile instanceof TileEntityLaserRelayItem) {
|
|
|
|
if (tileFound != null) {
|
2017-01-18 14:26:56 +01:00
|
|
|
this.connectedRelay = null;
|
|
|
|
return;
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
|
|
|
tileFound = (TileEntityLaserRelayItem) tile;
|
2017-01-18 14:26:56 +01:00
|
|
|
}
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-11 15:33:44 +02:00
|
|
|
this.connectedRelay = tileFound;
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean isWhitelisted(SpecificItemHandlerInfo handler, ItemStack stack, boolean output) {
|
2016-06-06 17:59:01 +02:00
|
|
|
boolean whitelisted = handler.relayInQuestion.isWhitelisted(stack, output);
|
2016-06-11 15:33:44 +02:00
|
|
|
TileEntityLaserRelayItem connected = this.connectedRelay;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (connected != null && connected != handler.relayInQuestion) {
|
2016-10-11 14:41:26 +02:00
|
|
|
return whitelisted && connected.isWhitelisted(stack, output);
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-05-11 20:59:38 +02:00
|
|
|
return whitelisted;
|
|
|
|
}
|
2016-05-11 20:55:29 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static class SlotlessItemHandlerInfo extends SpecificItemHandlerInfo {
|
2017-02-04 14:12:17 +01:00
|
|
|
|
|
|
|
public final Object handler;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public SlotlessItemHandlerInfo(Object handler, TileEntityLaserRelayItem relayInQuestion) {
|
2017-02-04 14:12:17 +01:00
|
|
|
super(relayInQuestion);
|
|
|
|
this.handler = handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private static class IItemHandlerInfo extends SpecificItemHandlerInfo {
|
2016-05-09 19:05:20 +02:00
|
|
|
|
2016-05-19 20:05:12 +02:00
|
|
|
public final IItemHandler handler;
|
|
|
|
public final int switchedIndex;
|
2016-05-09 19:05:20 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public IItemHandlerInfo(IItemHandler handler, int switchedIndex, TileEntityLaserRelayItem relayInQuestion) {
|
2017-02-04 14:12:17 +01:00
|
|
|
super(relayInQuestion);
|
2016-05-09 19:05:20 +02:00
|
|
|
this.handler = handler;
|
|
|
|
this.switchedIndex = switchedIndex;
|
2017-02-04 14:12:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private static class SpecificItemHandlerInfo {
|
2017-02-04 14:12:17 +01:00
|
|
|
|
|
|
|
public final TileEntityLaserRelayItem relayInQuestion;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public SpecificItemHandlerInfo(TileEntityLaserRelayItem relayInQuestion) {
|
2016-05-09 19:05:20 +02:00
|
|
|
this.relayInQuestion = relayInQuestion;
|
|
|
|
}
|
2017-01-18 14:26:56 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean isLoaded() {
|
2017-01-18 14:26:56 +01:00
|
|
|
return this.relayInQuestion.hasWorld() && this.relayInQuestion.getWorld().isBlockLoaded(this.relayInQuestion.getPos());
|
|
|
|
}
|
2016-05-09 19:05:20 +02:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public static class GenericItemHandlerInfo implements Comparable<GenericItemHandlerInfo> {
|
2016-05-09 19:05:20 +02:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
public final List<SlotlessableItemHandlerWrapper> handlers = new ArrayList<>();
|
2016-05-19 20:05:12 +02:00
|
|
|
public final TileEntityLaserRelayItem relayInQuestion;
|
2016-05-09 19:05:20 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public GenericItemHandlerInfo(TileEntityLaserRelayItem relayInQuestion) {
|
2016-05-09 19:05:20 +02:00
|
|
|
this.relayInQuestion = relayInQuestion;
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean isLoaded() {
|
2017-01-18 14:26:56 +01:00
|
|
|
return this.relayInQuestion.hasWorld() && this.relayInQuestion.getWorld().isBlockLoaded(this.relayInQuestion.getPos());
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:00:42 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int compareTo(GenericItemHandlerInfo other) {
|
2016-11-16 18:51:23 +01:00
|
|
|
int thisPrio = this.relayInQuestion.getPriority();
|
|
|
|
int otherPrio = other.relayInQuestion.getPriority();
|
2016-05-12 19:00:42 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (thisPrio == otherPrio) {
|
2016-11-16 18:51:23 +01:00
|
|
|
return 0;
|
2019-05-02 09:10:29 +02:00
|
|
|
} else if (thisPrio > otherPrio) {
|
2016-05-16 22:52:27 +02:00
|
|
|
return -1;
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-11-16 18:51:23 +01:00
|
|
|
return 1;
|
2016-05-12 19:00:42 +02:00
|
|
|
}
|
|
|
|
}
|
2016-05-09 19:05:20 +02:00
|
|
|
}
|
2016-05-08 21:09:58 +02:00
|
|
|
}
|