This commit is contained in:
Ell 2021-12-02 17:46:56 +01:00
parent 0df6401c4e
commit 1d9c22cb0a
36 changed files with 129 additions and 134 deletions

View file

@ -20,10 +20,10 @@ public class PlayerPrefs {
public boolean syncJei = true;
public void save() {
File file = getFile();
var file = getFile();
if (file.exists())
file.delete();
try (FileWriter writer = new FileWriter(file)) {
try (var writer = new FileWriter(file)) {
GSON.toJson(this, writer);
} catch (IOException e) {
e.printStackTrace();
@ -32,9 +32,9 @@ public class PlayerPrefs {
public static PlayerPrefs get() {
if (instance == null) {
File file = getFile();
var file = getFile();
if (file.exists()) {
try (FileReader reader = new FileReader(file)) {
try (var reader = new FileReader(file)) {
instance = GSON.fromJson(reader, PlayerPrefs.class);
return instance;
} catch (IOException e) {
@ -47,7 +47,7 @@ public class PlayerPrefs {
}
private static File getFile() {
File location = Minecraft.getInstance().gameDirectory;
var location = Minecraft.getInstance().gameDirectory;
return new File(location, PrettyPipes.ID + "prefs");
}
}

View file

@ -32,9 +32,9 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
@Override
public CompoundTag serializeNBT() {
CompoundTag nbt = new CompoundTag();
ListTag list = new ListTag();
for (BlockPos pos : this.pipes)
var nbt = new CompoundTag();
var list = new ListTag();
for (var pos : this.pipes)
list.add(NbtUtils.writeBlockPos(pos));
nbt.put("pipes", list);
return nbt;
@ -43,8 +43,8 @@ public class NetworkEdge extends DefaultWeightedEdge implements INBTSerializable
@Override
public void deserializeNBT(CompoundTag nbt) {
this.pipes.clear();
ListTag list = nbt.getList("pipes", Tag.TAG_COMPOUND);
for (int i = 0; i < list.size(); i++)
var list = nbt.getList("pipes", Tag.TAG_COMPOUND);
for (var i = 0; i < list.size(); i++)
this.pipes.add(NbtUtils.readBlockPos(list.getCompound(i)));
}
}

View file

@ -26,7 +26,7 @@ public class NetworkItem {
}
public ItemStack asStack() {
ItemStack stack = this.item.stack().copy();
var stack = this.item.stack().copy();
stack.setCount(this.amount);
return stack;
}

View file

@ -51,10 +51,10 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
public Map<Integer, ItemStack> getItems(Level world) {
if (this.itemCache == null) {
IItemHandler handler = this.getItemHandler(world);
var handler = this.getItemHandler(world);
if (handler != null) {
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack stack = handler.getStackInSlot(i);
for (var i = 0; i < handler.getSlots(); i++) {
var stack = handler.getStackInSlot(i);
// check if the slot is accessible to us
if (stack.isEmpty())
continue;
@ -69,21 +69,21 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
}
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();
}
public IItemHandler getItemHandler(Level world) {
if (this.handlerCache == null) {
PipeNetwork network = PipeNetwork.get(world);
PipeBlockEntity pipe = network.getPipe(this.pipePos);
var network = PipeNetwork.get(world);
var pipe = network.getPipe(this.pipePos);
this.handlerCache = pipe.getItemHandler(this.direction);
}
return this.handlerCache;
}
public boolean isEmpty(Level world) {
Map<Integer, ItemStack> items = this.getItems(world);
var items = this.getItems(world);
return items == null || items.isEmpty();
}
@ -93,7 +93,7 @@ public class NetworkLocation implements INBTSerializable<CompoundTag> {
@Override
public CompoundTag serializeNBT() {
CompoundTag nbt = new CompoundTag();
var nbt = new CompoundTag();
nbt.put("pipe_pos", NbtUtils.writeBlockPos(this.pipePos));
nbt.putInt("direction", this.direction.ordinal());
return nbt;

View file

@ -26,7 +26,7 @@ public class NetworkLock implements INBTSerializable<CompoundTag> {
@Override
public CompoundTag serializeNBT() {
CompoundTag nbt = new CompoundTag();
var nbt = new CompoundTag();
nbt.putUUID("id", this.lockId);
nbt.put("location", this.location.serializeNBT());
nbt.put("stack", this.stack.save(new CompoundTag()));

View file

@ -27,22 +27,22 @@ public class PacketCraftingModuleTransfer {
}
public static PacketCraftingModuleTransfer fromBytes(FriendlyByteBuf buf) {
PacketCraftingModuleTransfer packet = new PacketCraftingModuleTransfer();
var packet = new PacketCraftingModuleTransfer();
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.outputs = new ArrayList<>();
for (int i = buf.readInt(); i > 0; i--)
for (var i = buf.readInt(); i > 0; i--)
packet.outputs.add(buf.readItem());
return packet;
}
public static void toBytes(PacketCraftingModuleTransfer packet, FriendlyByteBuf buf) {
buf.writeInt(packet.inputs.size());
for (ItemStack stack : packet.inputs)
for (var stack : packet.inputs)
buf.writeItem(stack);
buf.writeInt(packet.outputs.size());
for (ItemStack stack : packet.outputs)
for (var stack : packet.outputs)
buf.writeItem(stack);
}
@ -64,9 +64,9 @@ public class PacketCraftingModuleTransfer {
}
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);
for (ItemStack stack : contents)
for (var stack : contents)
ItemHandlerHelper.insertItem(container, stack, false);
}
}

View file

@ -30,10 +30,10 @@ public class PacketGhostSlot {
}
public static PacketGhostSlot fromBytes(FriendlyByteBuf buf) {
PacketGhostSlot packet = new PacketGhostSlot();
var packet = new PacketGhostSlot();
packet.pos = buf.readBlockPos();
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());
return packet;
}
@ -41,7 +41,7 @@ public class PacketGhostSlot {
public static void toBytes(PacketGhostSlot packet, FriendlyByteBuf buf) {
buf.writeBlockPos(packet.pos);
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.writeItem(entry.getValue());
}
@ -49,8 +49,8 @@ public class PacketGhostSlot {
@SuppressWarnings("Convert2Lambda")
public static void onMessage(PacketGhostSlot message, Supplier<NetworkEvent.Context> ctx) {
Consumer<Player> doIt = p -> {
CraftingTerminalBlockEntity tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, p.level, message.pos);
var doIt = (Consumer<Player>) p -> {
var tile = Utility.getBlockEntity(CraftingTerminalBlockEntity.class, p.level, message.pos);
if (tile != null)
tile.setGhostItems(message.stacks);
};

View file

@ -26,7 +26,7 @@ public class PacketItemEnterPipe {
}
public static PacketItemEnterPipe fromBytes(FriendlyByteBuf buf) {
PacketItemEnterPipe client = new PacketItemEnterPipe();
var client = new PacketItemEnterPipe();
client.tilePos = buf.readBlockPos();
client.item = buf.readNbt();
return client;
@ -42,11 +42,11 @@ public class PacketItemEnterPipe {
ctx.get().enqueueWork(new Runnable() {
@Override
public void run() {
Minecraft mc = Minecraft.getInstance();
var mc = Minecraft.getInstance();
if (mc.level == null)
return;
IPipeItem item = IPipeItem.load(message.item);
PipeBlockEntity pipe = Utility.getBlockEntity(PipeBlockEntity.class, mc.level, message.tilePos);
var item = IPipeItem.load(message.item);
var pipe = Utility.getBlockEntity(PipeBlockEntity.class, mc.level, message.tilePos);
if (pipe != null)
pipe.getItems().add(item);
}

View file

@ -27,35 +27,35 @@ public class PacketNetworkItems {
}
public static PacketNetworkItems fromBytes(FriendlyByteBuf buf) {
PacketNetworkItems client = new PacketNetworkItems();
var client = new PacketNetworkItems();
client.items = new ArrayList<>();
for (int i = buf.readVarInt(); i > 0; i--) {
ItemStack stack = buf.readItem();
for (var i = buf.readVarInt(); i > 0; i--) {
var stack = buf.readItem();
stack.setCount(buf.readVarInt());
client.items.add(stack);
}
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.currentlyCrafting = new ArrayList<>();
for (int i = buf.readVarInt(); i > 0; i--)
for (var i = buf.readVarInt(); i > 0; i--)
client.currentlyCrafting.add(buf.readItem());
return client;
}
public static void toBytes(PacketNetworkItems packet, FriendlyByteBuf buf) {
buf.writeVarInt(packet.items.size());
for (ItemStack stack : packet.items) {
ItemStack copy = stack.copy();
for (var stack : packet.items) {
var copy = stack.copy();
copy.setCount(1);
buf.writeItem(copy);
buf.writeVarInt(stack.getCount());
}
buf.writeVarInt(packet.craftables.size());
for (ItemStack stack : packet.craftables)
for (var stack : packet.craftables)
buf.writeItem(stack);
buf.writeVarInt(packet.currentlyCrafting.size());
for (ItemStack stack : packet.currentlyCrafting)
for (var stack : packet.currentlyCrafting)
buf.writeItem(stack);
}
@ -64,7 +64,7 @@ public class PacketNetworkItems {
ctx.get().enqueueWork(new Runnable() {
@Override
public void run() {
Minecraft mc = Minecraft.getInstance();
var mc = Minecraft.getInstance();
if (mc.screen instanceof ItemTerminalGui terminal)
terminal.updateItemList(message.items, message.craftables, message.currentlyCrafting);
}

View file

@ -27,7 +27,7 @@ public class PacketRequest {
}
public static PacketRequest fromBytes(FriendlyByteBuf buf) {
PacketRequest packet = new PacketRequest();
var packet = new PacketRequest();
packet.pos = buf.readBlockPos();
packet.stack = buf.readItem();
packet.amount = buf.readVarInt();
@ -46,7 +46,7 @@ public class PacketRequest {
@Override
public void run() {
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);
tile.requestItem(player, message.stack);
}

View file

@ -125,7 +125,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
@Override
public CompoundTag getUpdateTag() {
// sync pipe items on load
CompoundTag nbt = this.save(new CompoundTag());
var nbt = this.save(new CompoundTag());
nbt.put("items", Utility.serializeAll(this.getItems()));
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);
if (maxAmount < toInsert.getCount())
toInsert.setCount(maxAmount);
BlockPos offset = this.worldPosition.relative(dir);
var offset = this.worldPosition.relative(dir);
if (preventOversending || maxAmount < Integer.MAX_VALUE) {
var network = PipeNetwork.get(this.level);
// 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
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)
return ConnectionType.BLOCKED;
return ConnectionType.CONNECTED;

View file

@ -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) {
if (!tile.getItems().isEmpty()) {
matrixStack.pushPose();
BlockPos tilePos = tile.getBlockPos();
var tilePos = tile.getBlockPos();
matrixStack.translate(-tilePos.getX(), -tilePos.getY(), -tilePos.getZ());
for (IPipeItem item : tile.getItems()) {
for (var item : tile.getItems()) {
matrixStack.pushPose();
item.render(tile, matrixStack, this.random, partialTicks, light, overlay, source);
matrixStack.popPose();

View file

@ -7,14 +7,12 @@ import de.ellpeck.prettypipes.items.IModule;
import de.ellpeck.prettypipes.packets.PacketButton;
import de.ellpeck.prettypipes.packets.PacketHandler;
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.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.items.SlotItemHandler;
@ -43,9 +41,9 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
public void containerTick() {
super.containerTick();
boolean changed = false;
for (int i = 0; i < this.menu.tile.modules.getSlots(); i++) {
ItemStack stack = this.menu.tile.modules.getStackInSlot(i);
var changed = false;
for (var i = 0; i < this.menu.tile.modules.getSlots(); i++) {
var stack = this.menu.tile.modules.getStackInSlot(i);
if (stack != this.lastItems[i]) {
this.lastItems[i] = stack;
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) {
this.renderBackground(matrix);
super.render(matrix, mouseX, mouseY, partialTicks);
for (Widget widget : this.renderables) {
for (var widget : this.renderables) {
if (widget instanceof AbstractWidget abstractWidget) {
if (abstractWidget.isHoveredOrFocused())
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) {
this.font.draw(matrix, this.playerInventoryTitle.getString(), 8, this.imageHeight - 96 + 2, 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);
}
@ -81,11 +79,11 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
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);
// 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)
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
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))
return true;
}
@ -103,11 +101,11 @@ public abstract class AbstractPipeGui<T extends AbstractPipeContainer<?>> extend
private void initTabs() {
this.tabs.clear();
this.tabs.add(new Tab(new ItemStack(Registry.pipeBlock), 0, -1));
for (int i = 0; i < this.menu.tile.modules.getSlots(); i++) {
ItemStack stack = this.menu.tile.modules.getStackInSlot(i);
for (var i = 0; i < this.menu.tile.modules.getSlots(); i++) {
var stack = this.menu.tile.modules.getStackInSlot(i);
if (stack.isEmpty())
continue;
IModule module = (IModule) stack.getItem();
var module = (IModule) stack.getItem();
if (module.hasContainer(stack, this.menu.tile))
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) {
int y = 2;
int v = 0;
int height = 30;
int itemOffset = 9;
var y = 2;
var v = 0;
var height = 30;
var itemOffset = 9;
if (this.index == AbstractPipeGui.this.menu.moduleIndex) {
y = 0;
v = 30;

View file

@ -16,7 +16,7 @@ public class MainPipeContainer extends AbstractPipeContainer<IModule> {
@Override
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));
}
}

View file

@ -33,7 +33,7 @@ public class SortingModuleItem extends ModuleItem {
switch (this.type) {
case ROUND_ROBIN:
// 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);
return next % nodes.size();
case RANDOM:

View file

@ -20,7 +20,7 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
@Override
protected void addSlots() {
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) {
@Override
public void setChanged() {
@ -32,7 +32,7 @@ public class CraftingModuleContainer extends AbstractPipeContainer<CraftingModul
}
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) {
@Override
public void setChanged() {

View file

@ -6,7 +6,6 @@ import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import javax.annotation.Nullable;
@ -21,7 +20,7 @@ public class ExtractionModuleContainer extends AbstractPipeContainer<ExtractionM
@Override
protected void addSlots() {
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);
}

View file

@ -18,7 +18,7 @@ public class FilterIncreaseModuleContainer extends AbstractPipeContainer<FilterI
@Override
protected void addSlots() {
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);
}

View file

@ -34,7 +34,7 @@ public class FilterIncreaseModuleItem extends ModuleItem {
@Override
public ItemFilter getItemFilter(ItemStack module, PipeBlockEntity tile) {
ItemFilter filter = new ItemFilter(18, module, tile);
var filter = new ItemFilter(18, module, tile);
filter.canModifyWhitelist = false;
return filter;
}

View file

@ -21,7 +21,7 @@ public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleIte
@Override
protected void addSlots() {
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);
}

View file

@ -15,7 +15,7 @@ public class FilterModuleGui extends AbstractPipeGui<FilterModuleContainer> {
@Override
protected void 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);
}
}

View file

@ -24,7 +24,7 @@ public class FilterModuleItem extends ModuleItem {
@Override
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);
}
@ -45,7 +45,7 @@ public class FilterModuleItem extends ModuleItem {
@Override
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;
return filter;
}

View file

@ -22,9 +22,9 @@ public class FilterModifierModuleContainer extends AbstractPipeContainer<FilterM
public List<ResourceLocation> getTags() {
Set<ResourceLocation> unsortedTags = new HashSet<>();
for (ItemFilter filter : this.tile.getFilters()) {
for (int i = 0; i < filter.getSlots(); i++) {
ItemStack stack = filter.getStackInSlot(i);
for (var filter : this.tile.getFilters()) {
for (var i = 0; i < filter.getSlots(); i++) {
var stack = filter.getStackInSlot(i);
unsortedTags.addAll(stack.getItem().getTags());
}
}

View file

@ -48,7 +48,7 @@ public class FilterModifierModuleItem extends ModuleItem {
public static ResourceLocation getFilterTag(ItemStack stack) {
if (!stack.hasTag())
return null;
String tag = stack.getTag().getString("filter_tag");
var tag = stack.getTag().getString("filter_tag");
if (Strings.isNullOrEmpty(tag))
return null;
return new ResourceLocation(tag);

View file

@ -21,7 +21,7 @@ public class RetrievalModuleContainer extends AbstractPipeContainer<RetrievalMod
@Override
protected void addSlots() {
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);
}

View file

@ -14,7 +14,7 @@ public class RetrievalModuleGui extends AbstractPipeGui<RetrievalModuleContainer
@Override
protected void 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);
}
}

View file

@ -34,21 +34,21 @@ public class RetrievalModuleItem extends ModuleItem {
public void tick(ItemStack module, PipeBlockEntity tile) {
if (!tile.shouldWorkNow(this.speed) || !tile.canWork())
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
for (ItemFilter subFilter : tile.getFilters()) {
for (int f = 0; f < subFilter.getSlots(); f++) {
ItemStack filtered = subFilter.getStackInSlot(f);
for (var subFilter : tile.getFilters()) {
for (var f = 0; f < subFilter.getSlots(); f++) {
var filtered = subFilter.getStackInSlot(f);
if (filtered.isEmpty())
continue;
ItemStack copy = filtered.copy();
var copy = filtered.copy();
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)
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
remain.shrink(network.getCurrentlyCraftingAmount(tile.getBlockPos(), copy, equalityTypes));
if (network.requestItem(tile.getBlockPos(), dest.getLeft(), remain, equalityTypes).isEmpty())
@ -84,7 +84,7 @@ public class RetrievalModuleItem extends ModuleItem {
@Override
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.isWhitelist = true;
return filter;

View file

@ -23,11 +23,11 @@ public class StackSizeModuleGui extends AbstractPipeGui<StackSizeModuleContainer
@Override
protected void 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
public void insertText(String textToWrite) {
StringBuilder ret = new StringBuilder();
for (char c : textToWrite.toCharArray()) {
var ret = new StringBuilder();
for (var c : textToWrite.toCharArray()) {
if (Character.isDigit(c))
ret.append(c);
}
@ -40,10 +40,10 @@ public class StackSizeModuleGui extends AbstractPipeGui<StackSizeModuleContainer
textField.setResponder(s -> {
if (s.isEmpty())
return;
int amount = Integer.parseInt(s);
var amount = Integer.parseInt(s);
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 -> {
PacketButton.sendAndExecute(this.menu.tile.getBlockPos(), ButtonResult.STACK_SIZE_MODULE_BUTTON);
b.setMessage(buttonText.get());

View file

@ -20,7 +20,7 @@ public class StackSizeModuleItem extends ModuleItem {
public static int getMaxStackSize(ItemStack module) {
if (module.hasTag()) {
int amount = module.getTag().getInt("max_stack_size");
var amount = module.getTag().getInt("max_stack_size");
if (amount > 0)
return amount;
}
@ -43,12 +43,12 @@ public class StackSizeModuleItem extends ModuleItem {
@Override
public int getMaxInsertionAmount(ItemStack module, PipeBlockEntity tile, ItemStack stack, IItemHandler destination) {
int max = getMaxStackSize(module);
var max = getMaxStackSize(module);
if (getLimitToMaxStackSize(module))
max = Math.min(max, stack.getMaxStackSize());
int amount = 0;
for (int i = 0; i < destination.getSlots(); i++) {
ItemStack stored = destination.getStackInSlot(i);
var amount = 0;
for (var i = 0; i < destination.getSlots(); i++) {
var stored = destination.getStackInSlot(i);
if (stored.isEmpty())
continue;
if (!ItemEquality.compareItems(stored, stack))

View file

@ -32,7 +32,7 @@ public class PressurizerBlock extends BaseEntityBlock {
@Override
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)
return InteractionResult.PASS;
if (!worldIn.isClientSide)

View file

@ -38,7 +38,7 @@ public class PressurizerBlockEntity extends BlockEntity implements MenuProvider,
}
public boolean pressurizeItem(ItemStack stack, boolean simulate) {
int amount = 100 * stack.getCount();
var amount = 100 * stack.getCount();
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) {
int energyExtracted = Math.min(this.energy, maxExtract);
var energyExtracted = Math.min(this.energy, maxExtract);
if (!simulate)
this.energy -= energyExtracted;
return energyExtracted;

View file

@ -37,7 +37,7 @@ public class PressurizerGui extends AbstractContainerScreen<PressurizerContainer
protected void renderBg(PoseStack matrixStack, float partialTicks, int x, int y) {
this.getMinecraft().getTextureManager().bindForSetup(TEXTURE);
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);
}
}

View file

@ -34,10 +34,10 @@ public class ItemTerminalBlock extends BaseEntityBlock {
@Override
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)
return InteractionResult.PASS;
String reason = tile.getInvalidTerminalReason();
var reason = tile.getInvalidTerminalReason();
if (reason != null) {
if (!worldIn.isClientSide)
player.sendMessage(new TranslatableComponent(reason).withStyle(ChatFormatting.RED), UUID.randomUUID());
@ -53,7 +53,7 @@ public class ItemTerminalBlock extends BaseEntityBlock {
@Override
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
ItemTerminalBlockEntity tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
var tile = Utility.getBlockEntity(ItemTerminalBlockEntity.class, worldIn, pos);
if (tile != null)
Utility.dropInventory(tile, tile.items);
super.onRemove(state, worldIn, pos, newState, isMoving);

View file

@ -9,12 +9,10 @@ import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.*;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeType;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import java.util.Optional;
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.craftResult = new ResultContainer();
this.addSlot(new ResultSlot(this.player, this.craftInventory, this.craftResult, 0, 25, 77));
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
for (var i = 0; i < 3; i++)
for (var j = 0; j < 3; j++)
this.addSlot(new Slot(this.craftInventory, j + i * 3, 7 + j * 18, 18 + i * 18));
super.addDataSlots(data);
}
@ -42,8 +40,8 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
@Override
public void slotsChanged(Container inventoryIn) {
if (!this.player.level.isClientSide) {
ItemStack ret = ItemStack.EMPTY;
Optional<CraftingRecipe> optional = this.player.level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftInventory, this.player.level);
var ret = ItemStack.EMPTY;
var optional = this.player.level.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, this.craftInventory, this.player.level);
if (optional.isPresent())
ret = optional.get().assemble(this.craftInventory);
this.craftResult.setItem(0, ret);
@ -64,7 +62,7 @@ public class CraftingTerminalContainer extends ItemTerminalContainer {
@Override
public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) {
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())
this.getTile().ghostItems.setStackInSlot(slot.getSlotIndex(), ItemStack.EMPTY);
}

View file

@ -23,19 +23,19 @@ public class ItemTerminalContainer extends AbstractContainerMenu {
this.addOwnSlots(player);
int off = this.getSlotXOffset();
for (int l = 0; l < 3; ++l)
for (int j1 = 0; j1 < 9; ++j1)
var off = this.getSlotXOffset();
for (var l = 0; l < 3; ++l)
for (var j1 = 0; j1 < 9; ++j1)
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));
}
protected void addOwnSlots(Player player) {
int off = this.getSlotXOffset();
for (int i = 0; i < 6; i++)
var off = this.getSlotXOffset();
for (var i = 0; i < 6; i++)
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));
}

View file

@ -24,7 +24,7 @@ public class WrappedCraftingInventory extends CraftingContainer {
@Override
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())
return false;
}
@ -38,15 +38,15 @@ public class WrappedCraftingInventory extends CraftingContainer {
@Override
public ItemStack removeItemNoUpdate(int index) {
ItemStack before = this.items.getStackInSlot(index);
var before = this.items.getStackInSlot(index);
this.items.setStackInSlot(index, ItemStack.EMPTY);
return before;
}
@Override
public ItemStack removeItem(int index, int count) {
ItemStack slotStack = this.items.getStackInSlot(index);
ItemStack ret = !slotStack.isEmpty() && count > 0 ? slotStack.split(count) : ItemStack.EMPTY;
var slotStack = this.items.getStackInSlot(index);
var ret = !slotStack.isEmpty() && count > 0 ? slotStack.split(count) : ItemStack.EMPTY;
if (!ret.isEmpty())
this.eventHandler.slotsChanged(this);
return ret;
@ -60,13 +60,13 @@ public class WrappedCraftingInventory extends CraftingContainer {
@Override
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);
}
@Override
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));
}
}