PrettyPipes/src/main/java/de/ellpeck/prettypipes/network/NetworkLocation.java

56 lines
1.5 KiB
Java
Raw Normal View History

2020-04-17 20:03:54 +02:00
package de.ellpeck.prettypipes.network;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
2020-04-17 20:03:54 +02:00
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.HashMap;
2020-04-17 20:03:54 +02:00
import java.util.List;
import java.util.Map;
public class NetworkLocation {
public final BlockPos pipePos;
public final Direction direction;
public final BlockPos pos;
public final IItemHandler handler;
private Map<Integer, ItemStack> items;
2020-04-17 20:03:54 +02:00
public NetworkLocation(BlockPos pipePos, Direction direction, IItemHandler handler) {
2020-04-17 20:03:54 +02:00
this.pipePos = pipePos;
this.direction = direction;
this.pos = pipePos.offset(direction);
this.handler = handler;
2020-04-17 22:29:02 +02:00
}
public void addItem(int slot, ItemStack stack) {
2020-04-17 22:29:02 +02:00
if (this.items == null)
this.items = new HashMap<>();
this.items.put(slot, stack);
2020-04-17 20:03:54 +02:00
}
public int getStackSlot(ItemStack stack) {
2020-04-17 22:29:02 +02:00
if (this.isEmpty())
return -1;
for (Map.Entry<Integer, ItemStack> entry : this.items.entrySet()) {
if (entry.getValue().isItemEqual(stack))
return entry.getKey();
2020-04-17 20:03:54 +02:00
}
return -1;
2020-04-17 20:03:54 +02:00
}
2020-04-17 22:29:02 +02:00
public boolean isEmpty() {
return this.items == null || this.items.isEmpty();
}
@Override
public String toString() {
return this.items.values().toString();
}
2020-04-17 20:03:54 +02:00
}