added backpack
This commit is contained in:
parent
63f131ecc5
commit
38458dd71d
@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
loader_version=0.8.8+build.202
|
loader_version=0.8.8+build.202
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.16.1.3
|
mod_version = 1.16.1.4
|
||||||
maven_group = de.jottyfan.minecraft
|
maven_group = de.jottyfan.minecraft
|
||||||
archives_base_name = quickiefabric
|
archives_base_name = quickiefabric
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ public class QuickieFabric implements ModInitializer {
|
|||||||
RegistryManager.registerEvents();
|
RegistryManager.registerEvents();
|
||||||
RegistryManager.registerBlocks();
|
RegistryManager.registerBlocks();
|
||||||
RegistryManager.registerBlockEntities();
|
RegistryManager.registerBlockEntities();
|
||||||
|
RegistryManager.registerContainer();
|
||||||
Registry.BIOME.forEach(RegistryManager::handleBiome);
|
Registry.BIOME.forEach(RegistryManager::handleBiome);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.container.BackpackScreen;
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class QuickieFabricClient implements ClientModInitializer {
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
ScreenRegistry.register(RegistryManager.BACKPACK_SCREEN_HANDLER, BackpackScreen::new);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric.container;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.items.ItemBackpack;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.inventory.Inventories;
|
||||||
|
import net.minecraft.inventory.Inventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
|
|
||||||
|
public class BackpackInventory implements Inventory {
|
||||||
|
public static final int SECTION_SIZE = 9;
|
||||||
|
private final DefaultedList<ItemStack> stacks;
|
||||||
|
public final PlayerEntity accessor;
|
||||||
|
private BackpackScreenHandler container;
|
||||||
|
|
||||||
|
public BackpackInventory(BackpackScreenHandler container, PlayerEntity player) {
|
||||||
|
this.accessor = player;
|
||||||
|
this.stacks = DefaultedList.ofSize(SECTION_SIZE * ItemBackpack.SLOTSIZE, ItemStack.EMPTY);
|
||||||
|
this.container = container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultedList<ItemStack> getList(DefaultedList<ItemStack> dl) {
|
||||||
|
dl = stacks;
|
||||||
|
return dl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clear() {
|
||||||
|
stacks.clear();
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canPlayerUse(PlayerEntity player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getStack(int slot) {
|
||||||
|
return slot >= stacks.size() ? ItemStack.EMPTY : stacks.get(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
for (ItemStack stack : stacks) {
|
||||||
|
if (!stack.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack removeStack(int slot) {
|
||||||
|
return Inventories.removeStack(this.stacks, slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack removeStack(int slot, int amount) {
|
||||||
|
ItemStack stack = this.stacks.get(slot);
|
||||||
|
stack.decrement(amount);
|
||||||
|
this.stacks.set(slot, stack);
|
||||||
|
markDirty();
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStack(int slot, ItemStack stack) {
|
||||||
|
this.stacks.set(slot, stack);
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size() {
|
||||||
|
return stacks.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markDirty() {
|
||||||
|
this.container.onContentChanged(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric.container;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.items.ItemBackpack;
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||||
|
import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.text.TranslatableText;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
|
public class BackpackScreen extends HandledScreen<BackpackScreenHandler> implements ScreenHandlerProvider<BackpackScreenHandler> {
|
||||||
|
private final static Identifier TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/backpack.png");
|
||||||
|
private final static Identifier SLOT_TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/slot.png");
|
||||||
|
private int slots;
|
||||||
|
private Integer containerHeight;
|
||||||
|
private Integer containerWidth;
|
||||||
|
|
||||||
|
public BackpackScreen(BackpackScreenHandler handler, PlayerInventory inventory, Text text) {
|
||||||
|
super(handler, inventory, new TranslatableText("container.quickiefabric.backpack"));
|
||||||
|
slots = ItemBackpack.SLOTSIZE;
|
||||||
|
if ((slots / 9) == 4) {
|
||||||
|
this.containerHeight = 184;
|
||||||
|
} else if ((slots / 9) > 4) {
|
||||||
|
this.containerHeight = 222;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
super.init();
|
||||||
|
this.x = (this.width - this.containerWidth) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawSlots(MatrixStack matrices, int guiX, int guiY) {
|
||||||
|
this.client.getTextureManager().bindTexture(SLOT_TEXTURE);
|
||||||
|
for (int y = 0; y < (slots / 9); y++)
|
||||||
|
for (int x = 0; x < 9; x++) {
|
||||||
|
this.drawTexture(matrices, guiX + 7 + (x * 18), guiY + 17 + (y * 18), 0, 0, 18, 18);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((slots % 9) != 0)
|
||||||
|
for (int x = 0; x < (slots % 9); x++) {
|
||||||
|
this.drawTexture(matrices, guiX + 7 + (x * 18), guiY + 17 + (slots / 9 * 18), 0, 0, 18, 18);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) {
|
||||||
|
this.renderBackground(matrices);
|
||||||
|
super.render(matrices, mouseX, mouseY, partialTicks);
|
||||||
|
this.drawMouseoverTooltip(matrices, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
|
||||||
|
GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
this.client.getTextureManager().bindTexture(TEXTURE);
|
||||||
|
int guiX = this.x;
|
||||||
|
int guiY = (this.height - this.containerHeight) / 2;
|
||||||
|
this.drawTexture(matrices, guiX, guiY, 0, 0, this.containerWidth, this.containerHeight);
|
||||||
|
|
||||||
|
drawSlots(matrices, guiX, guiY);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric.container;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.items.ItemBackpack;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
|
import net.minecraft.inventory.Inventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.screen.ScreenHandler;
|
||||||
|
import net.minecraft.screen.slot.Slot;
|
||||||
|
import net.minecraft.screen.slot.SlotActionType;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
|
|
||||||
|
public class BackpackScreenHandler extends ScreenHandler {
|
||||||
|
|
||||||
|
private final BackpackInventory inv;
|
||||||
|
private final PlayerEntity player;
|
||||||
|
private int backpackSlots;
|
||||||
|
private Hand hand;
|
||||||
|
|
||||||
|
public BackpackScreenHandler(int syncId, PlayerInventory playerInv) {
|
||||||
|
super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId);
|
||||||
|
this.inv = new BackpackInventory(this, playerInv.player);
|
||||||
|
this.player = playerInv.player;
|
||||||
|
this.hand = player.getActiveHand();
|
||||||
|
backpackSlots = ItemBackpack.SLOTSIZE;
|
||||||
|
|
||||||
|
int spacing;
|
||||||
|
if(backpackSlots % 9 == 0)
|
||||||
|
spacing = 30 + (backpackSlots /9) * 18 + ((backpackSlots /9) < 5 ? 0 : 2);
|
||||||
|
else
|
||||||
|
spacing = 30 + (backpackSlots /9 + 1) * 18 + ((backpackSlots /9) < 5 ? 0 : 2);
|
||||||
|
|
||||||
|
for(int y = 0; y < (backpackSlots /9); y++) {
|
||||||
|
for(int x = 0; x < 9; ++x) {
|
||||||
|
this.addSlot(new Slot(inv, x + y * 9, 8 + x * 18, 18 + y * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if((backpackSlots % 9) != 0)
|
||||||
|
for(int x = 0; x < (backpackSlots % 9); x++) {
|
||||||
|
this.addSlot(new Slot(inv, x + (backpackSlots /9) * 9, 8 + x * 18, 18 + (backpackSlots /9) * 18));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(int y = 0; y < 3; ++y) {
|
||||||
|
for(int x = 0; x < 9; ++x) {
|
||||||
|
this.addSlot(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, spacing + y * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int x = 0; x < 9; ++x) {
|
||||||
|
this.addSlot(new Slot(playerInv, x, 8 + x * 18, 58 + spacing));
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultedList<ItemStack> ad = DefaultedList.ofSize(backpackSlots, ItemStack.EMPTY);
|
||||||
|
ItemBackpack.getInventory(player.getStackInHand(this.hand), ad);
|
||||||
|
if(ad.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(int x = 0; x < 9; x++)
|
||||||
|
for(int y = 0; y < backpackSlots /9; y++) {
|
||||||
|
this.getSlot(x + y * 9).setStack(ad.get(x+y*9));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int x = 0; x < (backpackSlots % 9); x++) {
|
||||||
|
this.getSlot(x + (backpackSlots /9)*9).setStack(ad.get(x+(backpackSlots /9)*9));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUse(PlayerEntity player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onContentChanged(Inventory inv) {
|
||||||
|
super.onContentChanged(inv);
|
||||||
|
if (inv == this.inv) {
|
||||||
|
this.updateInv();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close(PlayerEntity player) {
|
||||||
|
super.close(player);
|
||||||
|
this.inv.onClose(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateInv() {
|
||||||
|
this.sendContentUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack transferSlot(PlayerEntity player, int slotNum) {
|
||||||
|
ItemStack copy = ItemStack.EMPTY;
|
||||||
|
Slot clickedSlot = this.slots.get(slotNum);
|
||||||
|
if (clickedSlot != null && clickedSlot.hasStack()) {
|
||||||
|
ItemStack clickedStack = clickedSlot.getStack();
|
||||||
|
copy = clickedStack.copy();
|
||||||
|
if (slotNum < backpackSlots) {
|
||||||
|
if (!this.insertItem(clickedStack, backpackSlots, this.slots.size(), true)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else if (!this.insertItem(clickedStack, 0, backpackSlots, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clickedStack.isEmpty()) {
|
||||||
|
clickedSlot.setStack(ItemStack.EMPTY);
|
||||||
|
} else {
|
||||||
|
clickedSlot.markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack onSlotClick(int int_1, int int_2, SlotActionType slotActionType_1, PlayerEntity playerEntity_1) {
|
||||||
|
if(int_1 > 0) {
|
||||||
|
if (this.getSlot(int_1).getStack().equals(playerEntity_1.getStackInHand(hand)))
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
return super.onSlotClick(int_1, int_2, slotActionType_1, playerEntity_1);
|
||||||
|
}
|
||||||
|
}
|
@ -10,11 +10,13 @@ import de.jottyfan.minecraft.quickiefabric.blockentity.ItemHoarderBlockEntity;
|
|||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.MonsterHoarderBlockEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.MonsterHoarderBlockEntity;
|
||||||
import de.jottyfan.minecraft.quickiefabric.blockentity.QuickieFabricBlockEntity;
|
import de.jottyfan.minecraft.quickiefabric.blockentity.QuickieFabricBlockEntity;
|
||||||
import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks;
|
import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks;
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.container.BackpackScreenHandler;
|
||||||
import de.jottyfan.minecraft.quickiefabric.event.BreakBlockCallback;
|
import de.jottyfan.minecraft.quickiefabric.event.BreakBlockCallback;
|
||||||
import de.jottyfan.minecraft.quickiefabric.event.EventBlockBreak;
|
import de.jottyfan.minecraft.quickiefabric.event.EventBlockBreak;
|
||||||
import de.jottyfan.minecraft.quickiefabric.items.QuickieItems;
|
import de.jottyfan.minecraft.quickiefabric.items.QuickieItems;
|
||||||
import de.jottyfan.minecraft.quickiefabric.tools.QuickieTools;
|
import de.jottyfan.minecraft.quickiefabric.tools.QuickieTools;
|
||||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||||
|
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
@ -23,6 +25,7 @@ import net.minecraft.item.BlockItem;
|
|||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemGroup;
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.screen.ScreenHandlerType;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
@ -43,7 +46,10 @@ import net.minecraft.world.gen.feature.SimpleBlockFeatureConfig;
|
|||||||
public class RegistryManager {
|
public class RegistryManager {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(RegistryManager.class);
|
private static final Logger LOGGER = LogManager.getLogger(RegistryManager.class);
|
||||||
|
|
||||||
private static final String QUICKIEFABRIC = "quickiefabric";
|
public static final String QUICKIEFABRIC = "quickiefabric";
|
||||||
|
|
||||||
|
public static final Identifier BACKPACK_CONTAINTER = new Identifier(QUICKIEFABRIC, "backpack");
|
||||||
|
public static final ScreenHandlerType<BackpackScreenHandler> BACKPACK_SCREEN_HANDLER = ScreenHandlerRegistry.registerSimple(RegistryManager.BACKPACK_CONTAINTER, BackpackScreenHandler::new);
|
||||||
|
|
||||||
public static final ItemGroup QUICKIEFABRIC_GROUP = FabricItemGroupBuilder.create(new Identifier(QUICKIEFABRIC, "all")).icon(() -> new ItemStack(QuickieItems.SPEEDPOWDER))
|
public static final ItemGroup QUICKIEFABRIC_GROUP = FabricItemGroupBuilder.create(new Identifier(QUICKIEFABRIC, "all")).icon(() -> new ItemStack(QuickieItems.SPEEDPOWDER))
|
||||||
.appendItems(stacks -> {
|
.appendItems(stacks -> {
|
||||||
@ -52,6 +58,7 @@ public class RegistryManager {
|
|||||||
stacks.add(new ItemStack(QuickieItems.SPEEDPOWDER));
|
stacks.add(new ItemStack(QuickieItems.SPEEDPOWDER));
|
||||||
stacks.add(new ItemStack(QuickieItems.LEVELUP));
|
stacks.add(new ItemStack(QuickieItems.LEVELUP));
|
||||||
stacks.add(new ItemStack(QuickieItems.PENCIL));
|
stacks.add(new ItemStack(QuickieItems.PENCIL));
|
||||||
|
stacks.add(new ItemStack(QuickieItems.BACKPACK));
|
||||||
stacks.add(new ItemStack(QuickieTools.SPEEDPOWDERAXE));
|
stacks.add(new ItemStack(QuickieTools.SPEEDPOWDERAXE));
|
||||||
stacks.add(new ItemStack(QuickieTools.SPEEDPOWDERPICKAXE));
|
stacks.add(new ItemStack(QuickieTools.SPEEDPOWDERPICKAXE));
|
||||||
stacks.add(new ItemStack(QuickieTools.SPEEDPOWDERSHOVEL));
|
stacks.add(new ItemStack(QuickieTools.SPEEDPOWDERSHOVEL));
|
||||||
@ -102,6 +109,7 @@ public class RegistryManager {
|
|||||||
registerItem(QuickieItems.PENCIL, "pencil");
|
registerItem(QuickieItems.PENCIL, "pencil");
|
||||||
registerItem(QuickieItems.SALPETER, "salpeter");
|
registerItem(QuickieItems.SALPETER, "salpeter");
|
||||||
registerItem(QuickieItems.SULPHOR, "sulphor");
|
registerItem(QuickieItems.SULPHOR, "sulphor");
|
||||||
|
registerItem(QuickieItems.BACKPACK, "backpack");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void registerTools() {
|
public static final void registerTools() {
|
||||||
@ -110,6 +118,10 @@ public class RegistryManager {
|
|||||||
registerItem(QuickieTools.SPEEDPOWDERPICKAXE, "speedpowderpickaxe");
|
registerItem(QuickieTools.SPEEDPOWDERPICKAXE, "speedpowderpickaxe");
|
||||||
registerItem(QuickieTools.SPEEDPOWDERSHOVEL, "speedpowdershovel");
|
registerItem(QuickieTools.SPEEDPOWDERSHOVEL, "speedpowdershovel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final void registerContainer() {
|
||||||
|
// ScreenHandlerRegistry.registerSimple(BACKPACK_CONTAINTER, (syncId, inventory) -> new BackpackScreenHandler(syncId, inventory));
|
||||||
|
}
|
||||||
|
|
||||||
public static final void registerEvents() {
|
public static final void registerEvents() {
|
||||||
LOGGER.debug("registering quickiefabric events");
|
LOGGER.debug("registering quickiefabric events");
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
package de.jottyfan.minecraft.quickiefabric.items;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.container.BackpackScreenHandler;
|
||||||
|
import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.inventory.Inventories;
|
||||||
|
import net.minecraft.item.DyeableItem;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.TypedActionResult;
|
||||||
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ItemBackpack extends Item implements DyeableItem {
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(ItemBackpack.class);
|
||||||
|
public final static Integer SLOTSIZE = 54;
|
||||||
|
|
||||||
|
public ItemBackpack() {
|
||||||
|
super(new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP).maxCount(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||||
|
if (!world.isClient) {
|
||||||
|
for (Identifier id : Registry.SCREEN_HANDLER.getIds()) {
|
||||||
|
LOGGER.info("found registered screen {}", id.toString());
|
||||||
|
}
|
||||||
|
SimpleNamedScreenHandlerFactory factory = new SimpleNamedScreenHandlerFactory(
|
||||||
|
(id, inventory, buf) -> new BackpackScreenHandler(id, player.inventory),
|
||||||
|
Text.method_30163(RegistryManager.BACKPACK_CONTAINTER.toString()));
|
||||||
|
player.openHandledScreen(factory);
|
||||||
|
}
|
||||||
|
return new TypedActionResult<ItemStack>(ActionResult.PASS, player.getStackInHand(hand));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setInventory(ItemStack backpack, DefaultedList<ItemStack> list) {
|
||||||
|
CompoundTag nbt = backpack.getOrCreateTag();
|
||||||
|
Inventories.toTag(nbt, list);
|
||||||
|
backpack.setTag(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void getInventory(ItemStack backpack, DefaultedList<ItemStack> defaultedList) {
|
||||||
|
CompoundTag nbt;
|
||||||
|
if (backpack.hasTag()) {
|
||||||
|
nbt = backpack.getTag();
|
||||||
|
} else {
|
||||||
|
nbt = new CompoundTag();
|
||||||
|
}
|
||||||
|
Inventories.fromTag(nbt, defaultedList);
|
||||||
|
backpack.setTag(nbt);
|
||||||
|
}
|
||||||
|
}
|
@ -11,4 +11,5 @@ public class QuickieItems {
|
|||||||
public static final ItemPencil PENCIL = new ItemPencil();
|
public static final ItemPencil PENCIL = new ItemPencil();
|
||||||
public static final ItemSalpeter SALPETER = new ItemSalpeter();
|
public static final ItemSalpeter SALPETER = new ItemSalpeter();
|
||||||
public static final ItemSulphor SULPHOR = new ItemSulphor();
|
public static final ItemSulphor SULPHOR = new ItemSulphor();
|
||||||
|
public static final ItemBackpack BACKPACK = new ItemBackpack();
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"item.quickiefabric.construction2": "fertiger Bauplan",
|
"item.quickiefabric.construction2": "fertiger Bauplan",
|
||||||
"item.quickiefabric.pencil": "Bleistift",
|
"item.quickiefabric.pencil": "Bleistift",
|
||||||
"item.quickiefabric.levelup": "Aufwerter",
|
"item.quickiefabric.levelup": "Aufwerter",
|
||||||
|
"item.quickiefabric.backpack": "Rucksack",
|
||||||
"block.quickiefabric.orenethersulphor": "Nether-Schwefel",
|
"block.quickiefabric.orenethersulphor": "Nether-Schwefel",
|
||||||
"block.quickiefabric.oresalpeter": "Salpetererz",
|
"block.quickiefabric.oresalpeter": "Salpetererz",
|
||||||
"block.quickiefabric.oresandsalpeter": "Salpetergestein",
|
"block.quickiefabric.oresandsalpeter": "Salpetergestein",
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"item.quickiefabric.construction2": "finished building plan",
|
"item.quickiefabric.construction2": "finished building plan",
|
||||||
"item.quickiefabric.pencil": "pencil",
|
"item.quickiefabric.pencil": "pencil",
|
||||||
"item.quickiefabric.levelup": "level up",
|
"item.quickiefabric.levelup": "level up",
|
||||||
|
"item.quickiefabric.backpack": "backpack",
|
||||||
"block.quickiefabric.orenethersulphor": "nether sulfur",
|
"block.quickiefabric.orenethersulphor": "nether sulfur",
|
||||||
"block.quickiefabric.oresalpeter": "salpeter ore",
|
"block.quickiefabric.oresalpeter": "salpeter ore",
|
||||||
"block.quickiefabric.oresandsalpeter": "salpeter stone",
|
"block.quickiefabric.oresandsalpeter": "salpeter stone",
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"parent": "item/generated",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "quickiefabric:item/backpack"
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
src/main/resources/assets/quickiefabric/textures/gui/slot.png
Normal file
BIN
src/main/resources/assets/quickiefabric/textures/gui/slot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 436 B |
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
22
src/main/resources/data/quickiefabric/recipes/backpack.json
Normal file
22
src/main/resources/data/quickiefabric/recipes/backpack.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"type": "crafting_shaped",
|
||||||
|
"pattern": [
|
||||||
|
"wlw",
|
||||||
|
"lsl",
|
||||||
|
"wlw"
|
||||||
|
],
|
||||||
|
"key": {
|
||||||
|
"s": {
|
||||||
|
"item": "minecraft:string"
|
||||||
|
},
|
||||||
|
"l": {
|
||||||
|
"item": "minecraft:leather"
|
||||||
|
},
|
||||||
|
"w": {
|
||||||
|
"item": "minecraft:white_wool"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"item": "quickiefabric:backpack"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user