minecraft_25w45a_unobfuscated/net/minecraft/world/inventory/TransientCraftingContainer.java
2025-11-24 22:52:51 +03:00

112 lines
2.8 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package net.minecraft.world.inventory;
import java.util.List;
import net.minecraft.core.NonNullList;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.StackedItemContents;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.ItemStack;
public class TransientCraftingContainer
implements CraftingContainer {
private final NonNullList<ItemStack> items;
private final int width;
private final int height;
private final AbstractContainerMenu menu;
public TransientCraftingContainer(AbstractContainerMenu menu, int width, int height) {
this(menu, width, height, NonNullList.withSize(width * height, ItemStack.EMPTY));
}
private TransientCraftingContainer(AbstractContainerMenu menu, int width, int height, NonNullList<ItemStack> items) {
this.items = items;
this.menu = menu;
this.width = width;
this.height = height;
}
@Override
public int getContainerSize() {
return this.items.size();
}
@Override
public boolean isEmpty() {
for (ItemStack itemStack : this.items) {
if (itemStack.isEmpty()) continue;
return false;
}
return true;
}
@Override
public ItemStack getItem(int slot) {
if (slot >= this.getContainerSize()) {
return ItemStack.EMPTY;
}
return this.items.get(slot);
}
@Override
public ItemStack removeItemNoUpdate(int slot) {
return ContainerHelper.takeItem(this.items, slot);
}
@Override
public ItemStack removeItem(int slot, int count) {
ItemStack result = ContainerHelper.removeItem(this.items, slot, count);
if (!result.isEmpty()) {
this.menu.slotsChanged(this);
}
return result;
}
@Override
public void setItem(int slot, ItemStack itemStack) {
this.items.set(slot, itemStack);
this.menu.slotsChanged(this);
}
@Override
public void setChanged() {
}
@Override
public boolean stillValid(Player player) {
return true;
}
@Override
public void clearContent() {
this.items.clear();
}
@Override
public int getHeight() {
return this.height;
}
@Override
public int getWidth() {
return this.width;
}
@Override
public List<ItemStack> getItems() {
return List.copyOf(this.items);
}
@Override
public void fillStackedContents(StackedItemContents contents) {
for (ItemStack itemStack : this.items) {
contents.accountSimpleStack(itemStack);
}
}
}