small steps forward

This commit is contained in:
2020-08-21 22:19:13 +02:00
parent f4550898a2
commit 737c4bd31a
3 changed files with 27 additions and 5 deletions

View File

@ -1,5 +1,8 @@
package de.jottyfan.minecraft.quickiefabric.container; package de.jottyfan.minecraft.quickiefabric.container;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager; import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
@ -14,9 +17,15 @@ import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
/**
*
* @author jotty
*
*/
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class BackpackScreen extends HandledScreen<BackpackScreenHandler> public class BackpackScreen extends HandledScreen<BackpackScreenHandler>
implements ScreenHandlerProvider<BackpackScreenHandler> { implements ScreenHandlerProvider<BackpackScreenHandler> {
private final static Logger LOGGER = LogManager.getLogger(BackpackScreen.class);
private final static Identifier TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, private final static Identifier TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC,
"textures/gui/backpack.png"); "textures/gui/backpack.png");
private final static Identifier SLOT_TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, private final static Identifier SLOT_TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC,

View File

@ -1,8 +1,11 @@
package de.jottyfan.minecraft.quickiefabric.container; package de.jottyfan.minecraft.quickiefabric.container;
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager; import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
@ -44,6 +47,10 @@ public class BackpackScreenHandler extends ScreenHandler {
return this.player; return this.player;
} }
public Inventory getInventory() {
return backpackInventory;
}
@Override @Override
public boolean canUse(PlayerEntity playerEntity) { public boolean canUse(PlayerEntity playerEntity) {
return backpackInventory.canPlayerUse(playerEntity); return backpackInventory.canPlayerUse(playerEntity);
@ -57,13 +64,13 @@ public class BackpackScreenHandler extends ScreenHandler {
} }
@Override @Override
public ItemStack transferSlot(PlayerEntity player, int slotNum) { public ItemStack transferSlot(PlayerEntity player, int slotIndex) {
ItemStack copy = ItemStack.EMPTY; ItemStack copy = ItemStack.EMPTY;
Slot chosenSlot = this.slots.get(slotNum); Slot chosenSlot = this.slots.get(slotIndex);
if (chosenSlot != null && chosenSlot.hasStack()) { if (chosenSlot != null && chosenSlot.hasStack()) {
ItemStack chosenStack = chosenSlot.getStack(); ItemStack chosenStack = chosenSlot.getStack();
copy = chosenStack.copy(); copy = chosenStack.copy();
if (slotNum < backpackInventory.size()) { if (slotIndex < backpackInventory.size()) {
if (!this.insertItem(chosenStack, backpackInventory.size(), this.slots.size(), true)) { if (!this.insertItem(chosenStack, backpackInventory.size(), this.slots.size(), true)) {
return ItemStack.EMPTY; return ItemStack.EMPTY;
} }
@ -78,4 +85,10 @@ public class BackpackScreenHandler extends ScreenHandler {
} }
return copy; return copy;
} }
@Environment(EnvType.CLIENT)
public int getRows() {
return 6;
}
} }