mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-11-22 19:58:35 +01:00
var
This commit is contained in:
parent
0df6401c4e
commit
1d9c22cb0a
36 changed files with 129 additions and 134 deletions
|
@ -20,10 +20,10 @@ public class PlayerPrefs {
|
||||||
public boolean syncJei = true;
|
public boolean syncJei = true;
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
File file = getFile();
|
var file = getFile();
|
||||||
if (file.exists())
|
if (file.exists())
|
||||||
file.delete();
|
file.delete();
|
||||||
try (FileWriter writer = new FileWriter(file)) {
|
try (var writer = new FileWriter(file)) {
|
||||||
GSON.toJson(this, writer);
|
GSON.toJson(this, writer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -32,9 +32,9 @@ public class PlayerPrefs {
|
||||||
|
|
||||||
public static PlayerPrefs get() {
|
public static PlayerPrefs get() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
File file = getFile();
|
var file = getFile();
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try (FileReader reader = new FileReader(file)) {
|
try (var reader = new FileReader(file)) {
|
||||||
instance = GSON.fromJson(reader, PlayerPrefs.class);
|
instance = GSON.fromJson(reader, PlayerPrefs.class);
|
||||||
return instance;
|
return instance;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -47,7 +47,7 @@ public class PlayerPrefs {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File getFile() {
|
private static File getFile() {
|
||||||
File location = Minecraft.getInstance().gameDirectory;
|
var location = Minecraft.getInstance().gameDirectory;
|
||||||
return new File(location, PrettyPipes.ID + "prefs");
|
return new File(location, PrettyPipes.ID + "prefs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag serializeNBT() {
|
public CompoundTag serializeNBT() {
|
||||||
CompoundTag nbt = new CompoundTag();
|
var nbt = new CompoundTag();
|
||||||
ListTag list = new ListTag();
|
var list = new ListTag();
|
||||||
for (BlockPos pos : this.pipes)
|
for (var pos : this.pipes)
|
||||||
list.add(NbtUtils.writeBlockPos(pos));
|
list.add(NbtUtils.writeBlockPos(pos));
|
||||||
nbt.put("pipes", list);
|
nbt.put("pipes", list);
|
||||||
return nbt;
|
return nbt;
|
||||||
|
@ -43,8 +43,8 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
|
||||||
@Override
|
@Override
|
||||||
public void deserializeNBT(CompoundTag nbt) {
|
public void deserializeNBT(CompoundTag nbt) {
|
||||||
this.pipes.clear();
|
this.pipes.clear();
|
||||||
ListTag list = nbt.getList("pipes", Tag.TAG_COMPOUND);
|
var list = nbt.getList("pipes", Tag.TAG_COMPOUND);
|
||||||
for (int i = 0; i < list.size(); i++)
|
for (var i = 0; i < list.size(); i++)
|
||||||
this.pipes.add(NbtUtils.readBlockPos(list.getCompound(i)));
|
this.pipes.add(NbtUtils.readBlockPos(list.getCompound(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class NetworkItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack asStack() {
|
public ItemStack asStack() {
|
||||||
ItemStack stack = this.item.stack().copy();
|
var stack = this.item.stack().copy();
|
||||||
stack.setCount(this.amount);
|
stack.setCount(this.amount);
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,10 +51,10 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
|
||||||
|
|
||||||
public Map<Integer, ItemStack> getItems(Level world) {
|
public Map<Integer, ItemStack> getItems(Level world) {
|
||||||
if (this.itemCache == null) {
|
if (this.itemCache == null) {
|
||||||
IItemHandler handler = this.getItemHandler(world);
|
var handler = this.getItemHandler(world);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
for (int i = 0; i < handler.getSlots(); i++) {
|
for (var i = 0; i < handler.getSlots(); i++) {
|
||||||
ItemStack stack = handler.getStackInSlot(i);
|
var stack = handler.getStackInSlot(i);
|
||||||
// check if the slot is accessible to us
|
// check if the slot is accessible to us
|
||||||
if (stack.isEmpty())
|
if (stack.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
|
@ -69,21 +69,21 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canExtract(Level world, int slot) {
|
public boolean canExtract(Level world, int slot) {
|
||||||
IItemHandler handler = this.getItemHandler(world);
|
var handler = this.getItemHandler(world);
|
||||||
return handler != null && !handler.extractItem(slot, 1, true).isEmpty();
|
return handler != null && !handler.extractItem(slot, 1, true).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IItemHandler getItemHandler(Level world) {
|
public IItemHandler getItemHandler(Level world) {
|
||||||
if (this.handlerCache == null) {
|
if (this.handlerCache == null) {
|
||||||
PipeNetwork network = PipeNetwork.get(world);
|
var network = PipeNetwork.get(world);
|
||||||
PipeBlockEntity pipe = network.getPipe(this.pipePos);
|
var pipe = network.getPipe(this.pipePos);
|
||||||
this.handlerCache = pipe.getItemHandler(this.direction);
|
this.handlerCache = pipe.getItemHandler(this.direction);
|
||||||
}
|
}
|
||||||
return this.handlerCache;
|
return this.handlerCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty(Level world) {
|
public boolean isEmpty(Level world) {
|
||||||
Map<Integer, ItemStack> items = this.getItems(world);
|
var items = this.getItems(world);
|
||||||
return items == null || items.isEmpty();
|
return items == null || items.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag serializeNBT() {
|
public CompoundTag serializeNBT() {
|
||||||
CompoundTag nbt = new CompoundTag();
|
var nbt = new CompoundTag();
|
||||||
nbt.put("pipe_pos", NbtUtils.writeBlockPos(this.pipePos));
|
nbt.put("pipe_pos", NbtUtils.writeBlockPos(this.pipePos));
|
||||||
nbt.putInt("direction", this.direction.ordinal());
|
nbt.putInt("direction", this.direction.ordinal());
|
||||||
return nbt;
|
return nbt;
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class NetworkLock implements INBTSerializable<CompoundTag> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag serializeNBT() {
|
public CompoundTag serializeNBT() {
|
||||||
CompoundTag nbt = new CompoundTag();
|
var nbt = new CompoundTag();
|
||||||
nbt.putUUID("id", this.lockId);
|
nbt.putUUID("id", this.lockId);
|
||||||
nbt.put("location", this.location.serializeNBT());
|
nbt.put("location", this.location.serializeNBT());
|
||||||
nbt.put("stack", this.stack.save(new CompoundTag()));
|
nbt.put("stack", this.stack.save(new CompoundTag()));
|
||||||
|
|
|
@ -27,22 +27,22 @@ public class PacketCraftingModuleTransfer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketCraftingModuleTransfer fromBytes(FriendlyByteBuf buf) {
|
public static PacketCraftingModuleTransfer fromBytes(FriendlyByteBuf buf) {
|
||||||
PacketCraftingModuleTransfer packet = new PacketCraftingModuleTransfer();
|
var packet = new PacketCraftingModuleTransfer();
|
||||||
packet.inputs = new ArrayList<>();
|
packet.inputs = new ArrayList<>();
|
||||||
for (int i = buf.readInt(); i > 0; i--)
|
for (var i = buf.readInt(); i > 0; i--)
|
||||||
packet.inputs.add(buf.readItem());
|
packet.inputs.add(buf.readItem());
|
||||||
packet.outputs = new ArrayList<>();
|
packet.outputs = new ArrayList<>();
|
||||||
for (int i = buf.readInt(); i > 0; i--)
|
for (var i = buf.readInt(); i > 0; i--)
|
||||||
packet.outputs.add(buf.readItem());
|
packet.outputs.add(buf.readItem());
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void toBytes(PacketCraftingModuleTransfer packet, FriendlyByteBuf buf) {
|
public static void toBytes(PacketCraftingModuleTransfer packet, FriendlyByteBuf buf) {
|
||||||
buf.writeInt(packet.inputs.size());
|
buf.writeInt(packet.inputs.size());
|
||||||
for (ItemStack stack : packet.inputs)
|
for (var stack : packet.inputs)
|
||||||
buf.writeItem(stack);
|
buf.writeItem(stack);
|
||||||
buf.writeInt(packet.outputs.size());
|
buf.writeInt(packet.outputs.size());
|
||||||
for (ItemStack stack : packet.outputs)
|
for (var stack : packet.outputs)
|
||||||
buf.writeItem(stack);
|
buf.writeItem(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ public class PacketCraftingModuleTransfer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copy(ItemStackHandler container, List<ItemStack> contents) {
|
private static void copy(ItemStackHandler container, List<ItemStack> contents) {
|
||||||
for (int i = 0; i < container.getSlots(); i++)
|
for (var i = 0; i < container.getSlots(); i++)
|
||||||
container.setStackInSlot(i, ItemStack.EMPTY);
|
container.setStackInSlot(i, ItemStack.EMPTY);
|
||||||
for (ItemStack stack : contents)
|
for (var stack : contents)
|
||||||
ItemHandlerHelper.insertItem(container, stack, false);
|
ItemHandlerHelper.insertItem(container, stack, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,10 @@ public class PacketGhostSlot {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketGhostSlot fromBytes(FriendlyByteBuf buf) {
|
public static PacketGhostSlot fromBytes(FriendlyByteBuf buf) {
|
||||||
PacketGhostSlot packet = new PacketGhostSlot();
|
var packet = new PacketGhostSlot();
|
||||||
packet.pos = buf.readBlockPos();
|
packet.pos = buf.readBlockPos();
|
||||||
packet.stacks = ArrayListMultimap.create();
|
packet.stacks = ArrayListMultimap.create();
|
||||||
for (int i = buf.readInt(); i > 0; i--)
|
for (var i = buf.readInt(); i > 0; i--)
|
||||||
packet.stacks.put(buf.readInt(), buf.readItem());
|
packet.stacks.put(buf.readInt(), buf.readItem());
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class PacketGhostSlot {
|
||||||
public static void toBytes(PacketGhostSlot packet, FriendlyByteBuf buf) {
|
public static void toBytes(PacketGhostSlot packet, FriendlyByteBuf buf) {
|
||||||
buf.writeBlockPos(packet.pos);
|
buf.writeBlockPos(packet.pos);
|
||||||
buf.writeInt(packet.stacks.size());
|
buf.writeInt(packet.stacks.size());
|
||||||
for (Map.Entry<Integer, ItemStack> entry : packet.stacks.entries()) {
|
for (var entry : packet.stacks.entries()) {
|
||||||
buf.writeInt(entry.getKey());
|
buf.writeInt(entry.getKey());
|
||||||
buf.writeItem(entry.getValue());
|
buf.writeItem(entry.getValue());
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ public class PacketGhostSlot {
|
||||||
|
|
||||||
@SuppressWarnings("Convert2Lambda")
|
@SuppressWarnings("Convert2Lambda")
|
||||||
public static void onMessage(PacketGhostSlot message, Supplier<NetworkEvent.Context> ctx) {
|
public static void onMessage(PacketGhostSlot message, Supplier<NetworkEvent.Context> ctx) {
|
||||||
Consumer<Player> doIt = p -> {
|
var doIt = (Consumer<Player>) p -> {
|
||||||
CraftingTerminalBlockEntity tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, p.level, message.pos);
|
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, p.level, message.pos);
|
||||||
if (tile != null)
|
if (tile != null)
|
||||||
tile.setGhostItems(message.stacks);
|
tile.setGhostItems(message.stacks);
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class PacketItemEnterPipe {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketItemEnterPipe fromBytes(FriendlyByteBuf buf) {
|
public static PacketItemEnterPipe fromBytes(FriendlyByteBuf buf) {
|
||||||
PacketItemEnterPipe client = new PacketItemEnterPipe();
|
var client = new PacketItemEnterPipe();
|
||||||
client.tilePos = buf.readBlockPos();
|
client.tilePos = buf.readBlockPos();
|
||||||
client.item = buf.readNbt();
|
client.item = buf.readNbt();
|
||||||
return client;
|
return client;
|
||||||
|
@ -42,11 +42,11 @@ public class PacketItemEnterPipe {
|
||||||
ctx.get().enqueueWork(new Runnable() {
|
ctx.get().enqueueWork(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Minecraft mc = Minecraft.getInstance();
|
var mc = Minecraft.getInstance();
|
||||||
if (mc.level == null)
|
if (mc.level == null)
|
||||||
return;
|
return;
|
||||||
IPipeItem item = IPipeItem.load(message.item);
|
var item = IPipeItem.load(message.item);
|
||||||
PipeBlockEntity pipe = Utility.getBlockEntity(PipeBlockEntity.class, mc.level, message.tilePos);
|
var pipe = Utility.getBlockEntity(PipeBlockEntity.class, mc.level, message.tilePos);
|
||||||
if (pipe != null)
|
if (pipe != null)
|
||||||
pipe.getItems().add(item);
|
pipe.getItems().add(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,35 +27,35 @@ public class PacketNetworkItems {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketNetworkItems fromBytes(FriendlyByteBuf buf) {
|
public static PacketNetworkItems fromBytes(FriendlyByteBuf buf) {
|
||||||
PacketNetworkItems client = new PacketNetworkItems();
|
var client = new PacketNetworkItems();
|
||||||
client.items = new ArrayList<>();
|
client.items = new ArrayList<>();
|
||||||
for (int i = buf.readVarInt(); i > 0; i--) {
|
for (var i = buf.readVarInt(); i > 0; i--) {
|
||||||
ItemStack stack = buf.readItem();
|
var stack = buf.readItem();
|
||||||
stack.setCount(buf.readVarInt());
|
stack.setCount(buf.readVarInt());
|
||||||
client.items.add(stack);
|
client.items.add(stack);
|
||||||
}
|
}
|
||||||
client.craftables = new ArrayList<>();
|
client.craftables = new ArrayList<>();
|
||||||
for (int i = buf.readVarInt(); i > 0; i--)
|
for (var i = buf.readVarInt(); i > 0; i--)
|
||||||
client.craftables.add(buf.readItem());
|
client.craftables.add(buf.readItem());
|
||||||
client.currentlyCrafting = new ArrayList<>();
|
client.currentlyCrafting = new ArrayList<>();
|
||||||
for (int i = buf.readVarInt(); i > 0; i--)
|
for (var i = buf.readVarInt(); i > 0; i--)
|
||||||
client.currentlyCrafting.add(buf.readItem());
|
client.currentlyCrafting.add(buf.readItem());
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void toBytes(PacketNetworkItems packet, FriendlyByteBuf buf) {
|
public static void toBytes(PacketNetworkItems packet, FriendlyByteBuf buf) {
|
||||||
buf.writeVarInt(packet.items.size());
|
buf.writeVarInt(packet.items.size());
|
||||||
for (ItemStack stack : packet.items) {
|
for (var stack : packet.items) {
|
||||||
ItemStack copy = stack.copy();
|
var copy = stack.copy();
|
||||||
copy.setCount(1);
|
copy.setCount(1);
|
||||||
buf.writeItem(copy);
|
buf.writeItem(copy);
|
||||||
buf.writeVarInt(stack.getCount());
|
buf.writeVarInt(stack.getCount());
|
||||||
}
|
}
|
||||||
buf.writeVarInt(packet.craftables.size());
|
buf.writeVarInt(packet.craftables.size());
|
||||||
for (ItemStack stack : packet.craftables)
|
for (var stack : packet.craftables)
|
||||||
buf.writeItem(stack);
|
buf.writeItem(stack);
|
||||||
buf.writeVarInt(packet.currentlyCrafting.size());
|
buf.writeVarInt(packet.currentlyCrafting.size());
|
||||||
for (ItemStack stack : packet.currentlyCrafting)
|
for (var stack : packet.currentlyCrafting)
|
||||||
buf.writeItem(stack);
|
buf.writeItem(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public class PacketNetworkItems {
|
||||||
ctx.get().enqueueWork(new Runnable() {
|
ctx.get().enqueueWork(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Minecraft mc = Minecraft.getInstance();
|
var mc = Minecraft.getInstance();
|
||||||
if (mc.screen instanceof ItemTerminalGui terminal)
|
if (mc.screen instanceof ItemTerminalGui terminal)
|
||||||
terminal.updateItemList(message.items, message.craftables, message.currentlyCrafting);
|
terminal.updateItemList(message.items, message.craftables, message.currentlyCrafting);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class PacketRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PacketRequest fromBytes(FriendlyByteBuf buf) {
|
public static PacketRequest fromBytes(FriendlyByteBuf buf) {
|
||||||
PacketRequest packet = new PacketRequest();
|
var packet = new PacketRequest();
|
||||||
packet.pos = buf.readBlockPos();
|
packet.pos = buf.readBlockPos();
|
||||||
packet.stack = buf.readItem();
|
packet.stack = buf.readItem();
|
||||||
packet.amount = buf.readVarInt();
|
packet.amount = buf.readVarInt();
|
||||||
|
@ -46,7 +46,7 @@ public class PacketRequest {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Player player = ctx.get().getSender();
|
Player player = ctx.get().getSender();
|
||||||
ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, message.pos);
|
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, player.level, message.pos);
|
||||||
message.stack.setCount(message.amount);
|
message.stack.setCount(message.amount);
|
||||||
tile.requestItem(player, message.stack);
|
tile.requestItem(player, message.stack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag getUpdateTag() {
|
public CompoundTag getUpdateTag() {
|
||||||
// sync pipe items on load
|
// sync pipe items on load
|
||||||
CompoundTag nbt = this.save(new CompoundTag());
|
var nbt = this.save(new CompoundTag());
|
||||||
nbt.put("items", Utility.serializeAll(this.getItems()));
|
nbt.put("items", Utility.serializeAll(this.getItems()));
|
||||||
return nbt;
|
return nbt;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
||||||
var maxAmount = this.streamModules().mapToInt(m -> m.getRight().getMaxInsertionAmount(m.getLeft(), this, stack, handler)).min().orElse(Integer.MAX_VALUE);
|
var maxAmount = this.streamModules().mapToInt(m -> m.getRight().getMaxInsertionAmount(m.getLeft(), this, stack, handler)).min().orElse(Integer.MAX_VALUE);
|
||||||
if (maxAmount < toInsert.getCount())
|
if (maxAmount < toInsert.getCount())
|
||||||
toInsert.setCount(maxAmount);
|
toInsert.setCount(maxAmount);
|
||||||
BlockPos offset = this.worldPosition.relative(dir);
|
var offset = this.worldPosition.relative(dir);
|
||||||
if (preventOversending || maxAmount < Integer.MAX_VALUE) {
|
if (preventOversending || maxAmount < Integer.MAX_VALUE) {
|
||||||
var network = PipeNetwork.get(this.level);
|
var network = PipeNetwork.get(this.level);
|
||||||
// these are the items that are currently in the pipes, going to this inventory
|
// these are the items that are currently in the pipes, going to this inventory
|
||||||
|
@ -448,7 +448,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
|
public ConnectionType getConnectionType(BlockPos pipePos, Direction direction) {
|
||||||
BlockState state = this.level.getBlockState(pipePos.relative(direction));
|
var state = this.level.getBlockState(pipePos.relative(direction));
|
||||||
if (state.getValue(PipeBlock.DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED)
|
if (state.getValue(PipeBlock.DIRECTIONS.get(direction.getOpposite())) == ConnectionType.BLOCKED)
|
||||||
return ConnectionType.BLOCKED;
|
return ConnectionType.BLOCKED;
|
||||||
return ConnectionType.CONNECTED;
|
return ConnectionType.CONNECTED;
|
||||||
|
|
|
@ -21,9 +21,9 @@ public class PipeRenderer implements BlockEntityRenderer<PipeBlockEntity> {
|
||||||
public void render(PipeBlockEntity tile, float partialTicks, PoseStack matrixStack, MultiBufferSource source, int light, int overlay) {
|
public void render(PipeBlockEntity tile, float partialTicks, PoseStack matrixStack, MultiBufferSource source, int light, int overlay) {
|
||||||
if (!tile.getItems().isEmpty()) {
|
if (!tile.getItems().isEmpty()) {
|
||||||
matrixStack.pushPose();
|
matrixStack.pushPose();
|
||||||
BlockPos tilePos = tile.getBlockPos();
|
var tilePos = tile.getBlockPos();
|
||||||
matrixStack.translate(-tilePos.getX(), -tilePos.getY(), -tilePos.getZ());
|
matrixStack.translate(-tilePos.getX(), -tilePos.getY(), -tilePos.getZ());
|
||||||
for (IPipeItem item : tile.getItems()) {
|
for (var item : tile.getItems()) {
|
||||||
matrixStack.pushPose();
|
matrixStack.pushPose();
|
||||||
item.render(tile, matrixStack, this.random, partialTicks, light, overlay, source);
|
item.render(tile, matrixStack, this.random, partialTicks, light, overlay, source);
|
||||||
matrixStack.popPose();
|
matrixStack.popPose();
|
||||||
|
|
|
@ -7,14 +7,12 @@ import de.ellpeck.prettypipes.items.IModule;
|
||||||
import de.ellpeck.prettypipes.packets.PacketButton;
|
import de.ellpeck.prettypipes.packets.PacketButton;
|
||||||
import de.ellpeck.prettypipes.packets.PacketHandler;
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
||||||
import net.minecraft.client.gui.components.AbstractWidget;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.components.Widget;
|
|
||||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.inventory.Slot;
|
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.items.SlotItemHandler;
|
import net.minecraftforge.items.SlotItemHandler;
|
||||||
|
|
||||||
|
@ -43,9 +41,9 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
||||||
public void containerTick() {
|
public void containerTick() {
|
||||||
super.containerTick();
|
super.containerTick();
|
||||||
|
|
||||||
boolean changed = false;
|
var changed = false;
|
||||||
for (int i = 0; i < this.menu.tile.modules.getSlots(); i++) {
|
for (var i = 0; i < this.menu.tile.modules.getSlots(); i++) {
|
||||||
ItemStack stack = this.menu.tile.modules.getStackInSlot(i);
|
var stack = this.menu.tile.modules.getStackInSlot(i);
|
||||||
if (stack != this.lastItems[i]) {
|
if (stack != this.lastItems[i]) {
|
||||||
this.lastItems[i] = stack;
|
this.lastItems[i] = stack;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
@ -59,7 +57,7 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
||||||
public void render(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
|
public void render(PoseStack matrix, int mouseX, int mouseY, float partialTicks) {
|
||||||
this.renderBackground(matrix);
|
this.renderBackground(matrix);
|
||||||
super.render(matrix, mouseX, mouseY, partialTicks);
|
super.render(matrix, mouseX, mouseY, partialTicks);
|
||||||
for (Widget widget : this.renderables) {
|
for (var widget : this.renderables) {
|
||||||
if (widget instanceof AbstractWidget abstractWidget) {
|
if (widget instanceof AbstractWidget abstractWidget) {
|
||||||
if (abstractWidget.isHoveredOrFocused())
|
if (abstractWidget.isHoveredOrFocused())
|
||||||
abstractWidget.renderToolTip(matrix, mouseX, mouseY);
|
abstractWidget.renderToolTip(matrix, mouseX, mouseY);
|
||||||
|
@ -72,7 +70,7 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
||||||
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
protected void renderLabels(PoseStack matrix, int mouseX, int mouseY) {
|
||||||
this.font.draw(matrix, this.playerInventoryTitle.getString(), 8, this.imageHeight - 96 + 2, 4210752);
|
this.font.draw(matrix, this.playerInventoryTitle.getString(), 8, this.imageHeight - 96 + 2, 4210752);
|
||||||
this.font.draw(matrix, this.title.getString(), 8, 6 + 32, 4210752);
|
this.font.draw(matrix, this.title.getString(), 8, 6 + 32, 4210752);
|
||||||
for (Tab tab : this.tabs)
|
for (var tab : this.tabs)
|
||||||
tab.drawForeground(matrix, mouseX, mouseY);
|
tab.drawForeground(matrix, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,11 +79,11 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
||||||
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||||
this.blit(matrix, this.leftPos, this.topPos + 32, 0, 0, 176, 171);
|
this.blit(matrix, this.leftPos, this.topPos + 32, 0, 0, 176, 171);
|
||||||
|
|
||||||
for (Tab tab : this.tabs)
|
for (var tab : this.tabs)
|
||||||
tab.draw(matrix);
|
tab.draw(matrix);
|
||||||
|
|
||||||
// draw the slots since we're using a blank ui
|
// draw the slots since we're using a blank ui
|
||||||
for (Slot slot : this.menu.slots) {
|
for (var slot : this.menu.slots) {
|
||||||
if (slot instanceof SlotItemHandler)
|
if (slot instanceof SlotItemHandler)
|
||||||
this.blit(matrix, this.leftPos + slot.x - 1, this.topPos + slot.y - 1, 176, 62, 18, 18);
|
this.blit(matrix, this.leftPos + slot.x - 1, this.topPos + slot.y - 1, 176, 62, 18, 18);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +91,7 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(double x, double y, int button) {
|
public boolean mouseClicked(double x, double y, int button) {
|
||||||
for (Tab tab : this.tabs) {
|
for (var tab : this.tabs) {
|
||||||
if (tab.onClicked(x, y, button))
|
if (tab.onClicked(x, y, button))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -103,11 +101,11 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
||||||
private void initTabs() {
|
private void initTabs() {
|
||||||
this.tabs.clear();
|
this.tabs.clear();
|
||||||
this.tabs.add(new Tab(new ItemStack(Registry.pipeBlock), 0, -1));
|
this.tabs.add(new Tab(new ItemStack(Registry.pipeBlock), 0, -1));
|
||||||
for (int i = 0; i < this.menu.tile.modules.getSlots(); i++) {
|
for (var i = 0; i < this.menu.tile.modules.getSlots(); i++) {
|
||||||
ItemStack stack = this.menu.tile.modules.getStackInSlot(i);
|
var stack = this.menu.tile.modules.getStackInSlot(i);
|
||||||
if (stack.isEmpty())
|
if (stack.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
IModule module = (IModule) stack.getItem();
|
var module = (IModule) stack.getItem();
|
||||||
if (module.hasContainer(stack, this.menu.tile))
|
if (module.hasContainer(stack, this.menu.tile))
|
||||||
this.tabs.add(new Tab(stack, this.tabs.size(), i));
|
this.tabs.add(new Tab(stack, this.tabs.size(), i));
|
||||||
}
|
}
|
||||||
|
@ -128,10 +126,10 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
|
||||||
}
|
}
|
||||||
|
|
||||||
private void draw(PoseStack matrix) {
|
private void draw(PoseStack matrix) {
|
||||||
int y = 2;
|
var y = 2;
|
||||||
int v = 0;
|
var v = 0;
|
||||||
int height = 30;
|
var height = 30;
|
||||||
int itemOffset = 9;
|
var itemOffset = 9;
|
||||||
if (this.index == AbstractPipeGui.this.menu.moduleIndex) {
|
if (this.index == AbstractPipeGui.this.menu.moduleIndex) {
|
||||||
y = 0;
|
y = 0;
|
||||||
v = 30;
|
v = 30;
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class MainPipeContainer extends AbstractPipeContainer<IModule> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addSlots() {
|
protected void addSlots() {
|
||||||
for (int i = 0; i < 3; i++)
|
for (var i = 0; i < 3; i++)
|
||||||
this.addSlot(new SlotItemHandler(this.tile.modules, i, 62 + i * 18, 17 + 32));
|
this.addSlot(new SlotItemHandler(this.tile.modules, i, 62 + i * 18, 17 + 32));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class SortingModuleItem extends ModuleItem {
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case ROUND_ROBIN:
|
case ROUND_ROBIN:
|
||||||
// store an ever-increasing index and choose destinations based on that
|
// store an ever-increasing index and choose destinations based on that
|
||||||
int next = module.hasTag() ? module.getTag().getInt("last") + 1 : 0;
|
var next = module.hasTag() ? module.getTag().getInt("last") + 1 : 0;
|
||||||
module.getOrCreateTag().putInt("last", next);
|
module.getOrCreateTag().putInt("last", next);
|
||||||
return next % nodes.size();
|
return next % nodes.size();
|
||||||
case RANDOM:
|
case RANDOM:
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
||||||
@Override
|
@Override
|
||||||
protected void addSlots() {
|
protected void addSlots() {
|
||||||
this.input = this.module.getInput(this.moduleStack);
|
this.input = this.module.getInput(this.moduleStack);
|
||||||
for (int i = 0; i < this.input.getSlots(); i++) {
|
for (var i = 0; i < this.input.getSlots(); i++) {
|
||||||
this.addSlot(new FilterSlot(this.input, i, (176 - this.module.inputSlots * 18) / 2 + 1 + i % 9 * 18, 17 + 32 + i / 9 * 18, false) {
|
this.addSlot(new FilterSlot(this.input, i, (176 - this.module.inputSlots * 18) / 2 + 1 + i % 9 * 18, 17 + 32 + i / 9 * 18, false) {
|
||||||
@Override
|
@Override
|
||||||
public void setChanged() {
|
public void setChanged() {
|
||||||
|
@ -32,7 +32,7 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
|
||||||
}
|
}
|
||||||
|
|
||||||
this.output = this.module.getOutput(this.moduleStack);
|
this.output = this.module.getOutput(this.moduleStack);
|
||||||
for (int i = 0; i < this.output.getSlots(); i++) {
|
for (var i = 0; i < this.output.getSlots(); i++) {
|
||||||
this.addSlot(new FilterSlot(this.output, i, (176 - this.module.outputSlots * 18) / 2 + 1 + i % 9 * 18, 85 + i / 9 * 18, false) {
|
this.addSlot(new FilterSlot(this.output, i, (176 - this.module.outputSlots * 18) / 2 + 1 + i % 9 * 18, 85 + i / 9 * 18, false) {
|
||||||
@Override
|
@Override
|
||||||
public void setChanged() {
|
public void setChanged() {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.MenuType;
|
import net.minecraft.world.inventory.MenuType;
|
||||||
import net.minecraft.world.inventory.Slot;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -21,7 +20,7 @@ public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionM
|
||||||
@Override
|
@Override
|
||||||
protected void addSlots() {
|
protected void addSlots() {
|
||||||
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
||||||
for (Slot slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
|
for (var slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
|
||||||
this.addSlot(slot);
|
this.addSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class FilterIncreaseModuleContainer extends AbstractPipeContainer<FilterI
|
||||||
@Override
|
@Override
|
||||||
protected void addSlots() {
|
protected void addSlots() {
|
||||||
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
||||||
for (Slot slot : this.filter.getSlots(8, 49))
|
for (var slot : this.filter.getSlots(8, 49))
|
||||||
this.addSlot(slot);
|
this.addSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class FilterIncreaseModuleItem extends ModuleItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
||||||
ItemFilter filter = new ItemFilter(18, module, tile);
|
var filter = new ItemFilter(18, module, tile);
|
||||||
filter.canModifyWhitelist = false;
|
filter.canModifyWhitelist = false;
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleIte
|
||||||
@Override
|
@Override
|
||||||
protected void addSlots() {
|
protected void addSlots() {
|
||||||
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
||||||
for (Slot slot : this.filter.getSlots((176 - Math.min(this.module.filterSlots, 9) * 18) / 2 + 1, 17 + 32))
|
for (var slot : this.filter.getSlots((176 - Math.min(this.module.filterSlots, 9) * 18) / 2 + 1, 17 + 32))
|
||||||
this.addSlot(slot);
|
this.addSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class FilterModuleGui extends AbstractPipeGui<FilterModuleContainer> {
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
for (AbstractWidget widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 18 * Mth.ceil(this.menu.filter.getSlots() / 9F) + 2))
|
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 18 * Mth.ceil(this.menu.filter.getSlots() / 9F) + 2))
|
||||||
this.addRenderableWidget(widget);
|
this.addRenderableWidget(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class FilterModuleItem extends ModuleItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
|
public boolean canAcceptItem(ItemStack module, PipeBlockEntity tile, ItemStack stack) {
|
||||||
ItemFilter filter = this.getItemFilter(module, tile);
|
var filter = this.getItemFilter(module, tile);
|
||||||
return filter.isAllowed(stack);
|
return filter.isAllowed(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class FilterModuleItem extends ModuleItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
||||||
ItemFilter filter = new ItemFilter(this.filterSlots, module, tile);
|
var filter = new ItemFilter(this.filterSlots, module, tile);
|
||||||
filter.canPopulateFromInventories = this.canPopulateFromInventories;
|
filter.canPopulateFromInventories = this.canPopulateFromInventories;
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ public class FilterModifierModuleContainer extends AbstractPipeContainer<FilterM
|
||||||
|
|
||||||
public List<ResourceLocation> getTags() {
|
public List<ResourceLocation> getTags() {
|
||||||
Set<ResourceLocation> unsortedTags = new HashSet<>();
|
Set<ResourceLocation> unsortedTags = new HashSet<>();
|
||||||
for (ItemFilter filter : this.tile.getFilters()) {
|
for (var filter : this.tile.getFilters()) {
|
||||||
for (int i = 0; i < filter.getSlots(); i++) {
|
for (var i = 0; i < filter.getSlots(); i++) {
|
||||||
ItemStack stack = filter.getStackInSlot(i);
|
var stack = filter.getStackInSlot(i);
|
||||||
unsortedTags.addAll(stack.getItem().getTags());
|
unsortedTags.addAll(stack.getItem().getTags());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class FilterModifierModuleItem extends ModuleItem {
|
||||||
public static ResourceLocation getFilterTag(ItemStack stack) {
|
public static ResourceLocation getFilterTag(ItemStack stack) {
|
||||||
if (!stack.hasTag())
|
if (!stack.hasTag())
|
||||||
return null;
|
return null;
|
||||||
String tag = stack.getTag().getString("filter_tag");
|
var tag = stack.getTag().getString("filter_tag");
|
||||||
if (Strings.isNullOrEmpty(tag))
|
if (Strings.isNullOrEmpty(tag))
|
||||||
return null;
|
return null;
|
||||||
return new ResourceLocation(tag);
|
return new ResourceLocation(tag);
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalMod
|
||||||
@Override
|
@Override
|
||||||
protected void addSlots() {
|
protected void addSlots() {
|
||||||
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
this.filter = this.module.getItemFilter(this.moduleStack, this.tile);
|
||||||
for (Slot slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
|
for (var slot : this.filter.getSlots((176 - this.module.filterSlots * 18) / 2 + 1, 17 + 32))
|
||||||
this.addSlot(slot);
|
this.addSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class RetrievalModuleGui extends AbstractPipeGui<RetrievalModuleContainer
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
for (AbstractWidget widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
|
for (var widget : this.menu.filter.getButtons(this, this.leftPos + 7, this.topPos + 17 + 32 + 20))
|
||||||
this.addRenderableWidget(widget);
|
this.addRenderableWidget(widget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,21 +34,21 @@ public class RetrievalModuleItem extends ModuleItem {
|
||||||
public void tick(ItemStack module, PipeBlockEntity tile) {
|
public void tick(ItemStack module, PipeBlockEntity tile) {
|
||||||
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
|
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
|
||||||
return;
|
return;
|
||||||
PipeNetwork network = PipeNetwork.get(tile.getLevel());
|
var network = PipeNetwork.get(tile.getLevel());
|
||||||
|
|
||||||
ItemEquality[] equalityTypes = ItemFilter.getEqualityTypes(tile);
|
var equalityTypes = ItemFilter.getEqualityTypes(tile);
|
||||||
// loop through filters to see which items to pull
|
// loop through filters to see which items to pull
|
||||||
for (ItemFilter subFilter : tile.getFilters()) {
|
for (var subFilter : tile.getFilters()) {
|
||||||
for (int f = 0; f < subFilter.getSlots(); f++) {
|
for (var f = 0; f < subFilter.getSlots(); f++) {
|
||||||
ItemStack filtered = subFilter.getStackInSlot(f);
|
var filtered = subFilter.getStackInSlot(f);
|
||||||
if (filtered.isEmpty())
|
if (filtered.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
ItemStack copy = filtered.copy();
|
var copy = filtered.copy();
|
||||||
copy.setCount(this.maxExtraction);
|
copy.setCount(this.maxExtraction);
|
||||||
Pair<BlockPos, ItemStack> dest = tile.getAvailableDestination(copy, true, this.preventOversending);
|
var dest = tile.getAvailableDestination(copy, true, this.preventOversending);
|
||||||
if (dest == null)
|
if (dest == null)
|
||||||
continue;
|
continue;
|
||||||
ItemStack remain = dest.getRight().copy();
|
var remain = dest.getRight().copy();
|
||||||
// are we already waiting for crafting results? If so, don't request those again
|
// are we already waiting for crafting results? If so, don't request those again
|
||||||
remain.shrink(network.getCurrentlyCraftingAmount(tile.getBlockPos(), copy, equalityTypes));
|
remain.shrink(network.getCurrentlyCraftingAmount(tile.getBlockPos(), copy, equalityTypes));
|
||||||
if (network.requestItem(tile.getBlockPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
if (network.requestItem(tile.getBlockPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
|
||||||
|
@ -84,7 +84,7 @@ public class RetrievalModuleItem extends ModuleItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
|
||||||
ItemFilter filter = new ItemFilter(this.filterSlots, module, tile);
|
var filter = new ItemFilter(this.filterSlots, module, tile);
|
||||||
filter.canModifyWhitelist = false;
|
filter.canModifyWhitelist = false;
|
||||||
filter.isWhitelist = true;
|
filter.isWhitelist = true;
|
||||||
return filter;
|
return filter;
|
||||||
|
|
|
@ -23,11 +23,11 @@ public class StackSizeModuleGui extends AbstractPipeGui<StackSizeModuleContainer
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
EditBox textField = this.addRenderableWidget(new EditBox(this.font, this.leftPos + 7, this.topPos + 17 + 32 + 10, 40, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".max_stack_size")) {
|
var textField = this.addRenderableWidget(new EditBox(this.font, this.leftPos + 7, this.topPos + 17 + 32 + 10, 40, 20, new TranslatableComponent("info." + PrettyPipes.ID + ".max_stack_size")) {
|
||||||
@Override
|
@Override
|
||||||
public void insertText(String textToWrite) {
|
public void insertText(String textToWrite) {
|
||||||
StringBuilder ret = new StringBuilder();
|
var ret = new StringBuilder();
|
||||||
for (char c : textToWrite.toCharArray()) {
|
for (var c : textToWrite.toCharArray()) {
|
||||||
if (Character.isDigit(c))
|
if (Character.isDigit(c))
|
||||||
ret.append(c);
|
ret.append(c);
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,10 @@ public class StackSizeModuleGui extends AbstractPipeGui<StackSizeModuleContainer
|
||||||
textField.setResponder(s -> {
|
textField.setResponder(s -> {
|
||||||
if (s.isEmpty())
|
if (s.isEmpty())
|
||||||
return;
|
return;
|
||||||
int amount = Integer.parseInt(s);
|
var amount = Integer.parseInt(s);
|
||||||
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), ButtonResult.STACK_SIZE_AMOUNT, amount);
|
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), ButtonResult.STACK_SIZE_AMOUNT, amount);
|
||||||
});
|
});
|
||||||
Supplier<TranslatableComponent> buttonText = () -> new TranslatableComponent("info." + PrettyPipes.ID + ".limit_to_max_" + (StackSizeModuleItem.getLimitToMaxStackSize(this.menu.moduleStack) ? "on" : "off"));
|
var buttonText = (Supplier<TranslatableComponent>) () -> new TranslatableComponent("info." + PrettyPipes.ID + ".limit_to_max_" + (StackSizeModuleItem.getLimitToMaxStackSize(this.menu.moduleStack) ? "on" : "off"));
|
||||||
this.addRenderableWidget(new Button(this.leftPos + 7, this.topPos + 17 + 32 + 10 + 22, 120, 20, buttonText.get(), b -> {
|
this.addRenderableWidget(new Button(this.leftPos + 7, this.topPos + 17 + 32 + 10 + 22, 120, 20, buttonText.get(), b -> {
|
||||||
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), ButtonResult.STACK_SIZE_MODULE_BUTTON);
|
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), ButtonResult.STACK_SIZE_MODULE_BUTTON);
|
||||||
b.setMessage(buttonText.get());
|
b.setMessage(buttonText.get());
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class StackSizeModuleItem extends ModuleItem {
|
||||||
|
|
||||||
public static int getMaxStackSize(ItemStack module) {
|
public static int getMaxStackSize(ItemStack module) {
|
||||||
if (module.hasTag()) {
|
if (module.hasTag()) {
|
||||||
int amount = module.getTag().getInt("max_stack_size");
|
var amount = module.getTag().getInt("max_stack_size");
|
||||||
if (amount > 0)
|
if (amount > 0)
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,12 @@ public class StackSizeModuleItem extends ModuleItem {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination) {
|
public int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination) {
|
||||||
int max = getMaxStackSize(module);
|
var max = getMaxStackSize(module);
|
||||||
if (getLimitToMaxStackSize(module))
|
if (getLimitToMaxStackSize(module))
|
||||||
max = Math.min(max, stack.getMaxStackSize());
|
max = Math.min(max, stack.getMaxStackSize());
|
||||||
int amount = 0;
|
var amount = 0;
|
||||||
for (int i = 0; i < destination.getSlots(); i++) {
|
for (var i = 0; i < destination.getSlots(); i++) {
|
||||||
ItemStack stored = destination.getStackInSlot(i);
|
var stored = destination.getStackInSlot(i);
|
||||||
if (stored.isEmpty())
|
if (stored.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
if (!ItemEquality.compareItems(stored, stack))
|
if (!ItemEquality.compareItems(stored, stack))
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class PressurizerBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
|
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
|
||||||
PressurizerBlockEntity tile = Utility.getBlockEntity(PressurizerBlockEntity.class, worldIn, pos);
|
var tile = Utility.getBlockEntity(PressurizerBlockEntity.class, worldIn, pos);
|
||||||
if (tile == null)
|
if (tile == null)
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
if (!worldIn.isClientSide)
|
if (!worldIn.isClientSide)
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean pressurizeItem(ItemStack stack, boolean simulate) {
|
public boolean pressurizeItem(ItemStack stack, boolean simulate) {
|
||||||
int amount = 100 * stack.getCount();
|
var amount = 100 * stack.getCount();
|
||||||
return this.storage.extractInternal(amount, simulate) >= amount;
|
return this.storage.extractInternal(amount, simulate) >= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
private int extractInternal(int maxExtract, boolean simulate) {
|
private int extractInternal(int maxExtract, boolean simulate) {
|
||||||
int energyExtracted = Math.min(this.energy, maxExtract);
|
var energyExtracted = Math.min(this.energy, maxExtract);
|
||||||
if (!simulate)
|
if (!simulate)
|
||||||
this.energy -= energyExtracted;
|
this.energy -= energyExtracted;
|
||||||
return energyExtracted;
|
return energyExtracted;
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class PressurizerGui extends AbstractContainerScreen<PressurizerContainer
|
||||||
protected void renderBg(PoseStack matrixStack, float partialTicks, int x, int y) {
|
protected void renderBg(PoseStack matrixStack, float partialTicks, int x, int y) {
|
||||||
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
|
||||||
this.blit(matrixStack, this.leftPos, this.topPos, 0, 0, 176, 137);
|
this.blit(matrixStack, this.leftPos, this.topPos, 0, 0, 176, 137);
|
||||||
int energy = (int) (this.menu.tile.getEnergyPercentage() * 124);
|
var energy = (int) (this.menu.tile.getEnergyPercentage() * 124);
|
||||||
this.blit(matrixStack, this.leftPos + 26, this.topPos + 22, 0, 137, energy, 12);
|
this.blit(matrixStack, this.leftPos + 26, this.topPos + 22, 0, 137, energy, 12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,10 +34,10 @@ public class ItemTerminalBlock extends BaseEntityBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
|
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult result) {
|
||||||
ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
|
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
|
||||||
if (tile == null)
|
if (tile == null)
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
String reason = tile.getInvalidTerminalReason();
|
var reason = tile.getInvalidTerminalReason();
|
||||||
if (reason != null) {
|
if (reason != null) {
|
||||||
if (!worldIn.isClientSide)
|
if (!worldIn.isClientSide)
|
||||||
player.sendMessage(new TranslatableComponent(reason).withStyle(ChatFormatting.RED), UUID.randomUUID());
|
player.sendMessage(new TranslatableComponent(reason).withStyle(ChatFormatting.RED), UUID.randomUUID());
|
||||||
|
@ -53,7 +53,7 @@ public class ItemTerminalBlock extends BaseEntityBlock {
|
||||||
@Override
|
@Override
|
||||||
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
|
||||||
if (state.getBlock() != newState.getBlock()) {
|
if (state.getBlock() != newState.getBlock()) {
|
||||||
ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
|
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
|
||||||
if (tile != null)
|
if (tile != null)
|
||||||
Utility.dropInventory(tile, tile.items);
|
Utility.dropInventory(tile, tile.items);
|
||||||
super.onRemove(state, worldIn, pos, newState, isMoving);
|
super.onRemove(state, worldIn, pos, newState, isMoving);
|
||||||
|
|
|
@ -9,12 +9,10 @@ import net.minecraft.world.Container;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.*;
|
import net.minecraft.world.inventory.*;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
|
||||||
import net.minecraft.world.item.crafting.RecipeType;
|
import net.minecraft.world.item.crafting.RecipeType;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class CraftingTerminalContainer extends ItemTerminalContainer {
|
public class CraftingTerminalContainer extends ItemTerminalContainer {
|
||||||
|
|
||||||
|
@ -33,8 +31,8 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
|
||||||
this.craftInventory = new WrappedCraftingInventory(this.getTile().craftItems, this, 3, 3);
|
this.craftInventory = new WrappedCraftingInventory(this.getTile().craftItems, this, 3, 3);
|
||||||
this.craftResult = new ResultContainer();
|
this.craftResult = new ResultContainer();
|
||||||
this.addSlot(new ResultSlot(this.player, this.craftInventory, this.craftResult, 0, 25, 77));
|
this.addSlot(new ResultSlot(this.player, this.craftInventory, this.craftResult, 0, 25, 77));
|
||||||
for (int i = 0; i < 3; i++)
|
for (var i = 0; i < 3; i++)
|
||||||
for (int j = 0; j < 3; j++)
|
for (var j = 0; j < 3; j++)
|
||||||
this.addSlot(new Slot(this.craftInventory, j + i * 3, 7 + j * 18, 18 + i * 18));
|
this.addSlot(new Slot(this.craftInventory, j + i * 3, 7 + j * 18, 18 + i * 18));
|
||||||
super.addDataSlots(data);
|
super.addDataSlots(data);
|
||||||
}
|
}
|
||||||
|
@ -42,8 +40,8 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
|
||||||
@Override
|
@Override
|
||||||
public void slotsChanged(Container inventoryIn) {
|
public void slotsChanged(Container inventoryIn) {
|
||||||
if (!this.player.level.isClientSide) {
|
if (!this.player.level.isClientSide) {
|
||||||
ItemStack ret = ItemStack.EMPTY;
|
var ret = ItemStack.EMPTY;
|
||||||
Optional<CraftingRecipe> optional = this.player.level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftInventory, this.player.level);
|
var optional = this.player.level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftInventory, this.player.level);
|
||||||
if (optional.isPresent())
|
if (optional.isPresent())
|
||||||
ret = optional.get().assemble(this.craftInventory);
|
ret = optional.get().assemble(this.craftInventory);
|
||||||
this.craftResult.setItem(0, ret);
|
this.craftResult.setItem(0, ret);
|
||||||
|
@ -64,7 +62,7 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
|
||||||
@Override
|
@Override
|
||||||
public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) {
|
public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) {
|
||||||
if (slotId > 0 && clickTypeIn == ClickType.PICKUP) {
|
if (slotId > 0 && clickTypeIn == ClickType.PICKUP) {
|
||||||
Slot slot = this.slots.get(slotId);
|
var slot = this.slots.get(slotId);
|
||||||
if (slot.container == this.craftInventory && !slot.hasItem())
|
if (slot.container == this.craftInventory && !slot.hasItem())
|
||||||
this.getTile().ghostItems.setStackInSlot(slot.getSlotIndex(), ItemStack.EMPTY);
|
this.getTile().ghostItems.setStackInSlot(slot.getSlotIndex(), ItemStack.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,19 +23,19 @@ public class ItemTerminalContainer extends AbstractContainerMenu {
|
||||||
|
|
||||||
this.addOwnSlots(player);
|
this.addOwnSlots(player);
|
||||||
|
|
||||||
int off = this.getSlotXOffset();
|
var off = this.getSlotXOffset();
|
||||||
for (int l = 0; l < 3; ++l)
|
for (var l = 0; l < 3; ++l)
|
||||||
for (int j1 = 0; j1 < 9; ++j1)
|
for (var j1 = 0; j1 < 9; ++j1)
|
||||||
this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + off + j1 * 18, 154 + l * 18));
|
this.addSlot(new Slot(player.getInventory(), j1 + l * 9 + 9, 8 + off + j1 * 18, 154 + l * 18));
|
||||||
for (int i1 = 0; i1 < 9; ++i1)
|
for (var i1 = 0; i1 < 9; ++i1)
|
||||||
this.addSlot(new Slot(player.getInventory(), i1, 8 + off + i1 * 18, 212));
|
this.addSlot(new Slot(player.getInventory(), i1, 8 + off + i1 * 18, 212));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addOwnSlots(Player player) {
|
protected void addOwnSlots(Player player) {
|
||||||
int off = this.getSlotXOffset();
|
var off = this.getSlotXOffset();
|
||||||
for (int i = 0; i < 6; i++)
|
for (var i = 0; i < 6; i++)
|
||||||
this.addSlot(new SlotItemHandler(this.tile.items, i, 8 + off + i % 3 * 18, 102 + i / 3 * 18));
|
this.addSlot(new SlotItemHandler(this.tile.items, i, 8 + off + i % 3 * 18, 102 + i / 3 * 18));
|
||||||
for (int i = 0; i < 6; i++)
|
for (var i = 0; i < 6; i++)
|
||||||
this.addSlot(new SlotItemHandler(this.tile.items, i + 6, 116 + off + i % 3 * 18, 102 + i / 3 * 18));
|
this.addSlot(new SlotItemHandler(this.tile.items, i + 6, 116 + off + i % 3 * 18, 102 + i / 3 * 18));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class WrappedCraftingInventory extends CraftingContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
for (int i = 0; i < this.items.getSlots(); i++) {
|
for (var i = 0; i < this.items.getSlots(); i++) {
|
||||||
if (!this.items.getStackInSlot(i).isEmpty())
|
if (!this.items.getStackInSlot(i).isEmpty())
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -38,15 +38,15 @@ public class WrappedCraftingInventory extends CraftingContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack removeItemNoUpdate(int index) {
|
public ItemStack removeItemNoUpdate(int index) {
|
||||||
ItemStack before = this.items.getStackInSlot(index);
|
var before = this.items.getStackInSlot(index);
|
||||||
this.items.setStackInSlot(index, ItemStack.EMPTY);
|
this.items.setStackInSlot(index, ItemStack.EMPTY);
|
||||||
return before;
|
return before;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack removeItem(int index, int count) {
|
public ItemStack removeItem(int index, int count) {
|
||||||
ItemStack slotStack = this.items.getStackInSlot(index);
|
var slotStack = this.items.getStackInSlot(index);
|
||||||
ItemStack ret = !slotStack.isEmpty() && count > 0 ? slotStack.split(count) : ItemStack.EMPTY;
|
var ret = !slotStack.isEmpty() && count > 0 ? slotStack.split(count) : ItemStack.EMPTY;
|
||||||
if (!ret.isEmpty())
|
if (!ret.isEmpty())
|
||||||
this.eventHandler.slotsChanged(this);
|
this.eventHandler.slotsChanged(this);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -60,13 +60,13 @@ public class WrappedCraftingInventory extends CraftingContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearContent() {
|
public void clearContent() {
|
||||||
for (int i = 0; i < this.items.getSlots(); i++)
|
for (var i = 0; i < this.items.getSlots(); i++)
|
||||||
this.items.setStackInSlot(i, ItemStack.EMPTY);
|
this.items.setStackInSlot(i, ItemStack.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillStackedContents(StackedContents helper) {
|
public void fillStackedContents(StackedContents helper) {
|
||||||
for (int i = 0; i < this.items.getSlots(); i++)
|
for (var i = 0; i < this.items.getSlots(); i++)
|
||||||
helper.accountStack(this.items.getStackInSlot(i));
|
helper.accountStack(this.items.getStackInSlot(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue