diff --git a/gradle.properties b/gradle.properties index 6c431e6..1f6d91a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.9.3+build.207 # Mod Properties - mod_version = 1.16.3.0 + mod_version = 1.16.3.1 maven_group = de.jottyfan.minecraft archives_base_name = quickiefabric diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java index c5436bc..a244c0a 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blocks/BlockLavahoarder.java @@ -29,7 +29,7 @@ import net.minecraft.world.World; public class BlockLavahoarder extends Block { public BlockLavahoarder() { - super(FabricBlockSettings.of(Material.STONE).hardness(2.5f)); + super(FabricBlockSettings.of(Material.STONE).hardness(2.5f).lightLevel(16)); } @Override @@ -39,7 +39,6 @@ public class BlockLavahoarder extends Block { return list; } - private static final String stringOf(BlockPos pos) { StringBuilder buf = new StringBuilder(); buf.append(pos.getX()).append(":"); diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackInventory.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackInventory.java index ec93cd5..7cfa5db 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackInventory.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackInventory.java @@ -2,30 +2,25 @@ 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.inventory.SimpleInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.util.Hand; -import net.minecraft.util.collection.DefaultedList; /** * * @author jotty * */ -public class BackpackInventory implements Inventory { - private final DefaultedList stacks; - private final BackpackScreenHandler handler; +public class BackpackInventory extends SimpleInventory { private Hand hand; private BackpackInventory(CompoundTag tag, BackpackScreenHandler handler) { - this.handler = handler; - this.stacks = DefaultedList.ofSize(ItemBackpack.SLOTSIZE, ItemStack.EMPTY); - readItemsFromTag(this.stacks, tag); + super(ItemBackpack.SLOTSIZE); + readItemsFromTag(super.size(), tag); } public static final BackpackInventory getInventory(BackpackScreenHandler handler, PlayerEntity player, @@ -41,64 +36,15 @@ public class BackpackInventory implements Inventory { return new BackpackInventory(stack.getTag().getCompound("backpack"), handler); } - public DefaultedList getList() { - return stacks; - } - - @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() { - return this.stacks.stream().allMatch(ItemStack::isEmpty); - } - - @Override - public ItemStack removeStack(int slot) { - return Inventories.removeStack(this.stacks, slot); - } - - @Override - public ItemStack removeStack(int slot, int amount) { - return Inventories.splitStack(stacks, slot, amount); - } - - @Override - public void setStack(int slot, ItemStack stack) { - this.stacks.set(slot, stack); - } - - @Override - public int size() { - return stacks.size(); - } - - @Override - public void markDirty() { - } - @Override public void onOpen(PlayerEntity player) { - Inventory.super.onOpen(player); + super.onOpen(player); player.playSound(SoundEvents.BLOCK_WOOL_PLACE, SoundCategory.PLAYERS, 1f, 1f); } @Override public void onClose(PlayerEntity player) { - Inventory.super.onClose(player); + super.onClose(player); ItemStack stack = player.getStackInHand(hand); if (stack != null) { if (!stack.hasTag()) { @@ -110,24 +56,23 @@ public class BackpackInventory implements Inventory { player.playSound(SoundEvents.BLOCK_WOOL_PLACE, SoundCategory.PLAYERS, 1f, 1f); } - private void readItemsFromTag(DefaultedList inventory, CompoundTag tag) { + private void readItemsFromTag(Integer size, CompoundTag tag) { ListTag listTag = tag.getList("items", 10); for (int i = 0; i < listTag.size(); ++i) { CompoundTag compoundTag = listTag.getCompound(i); - int j = compoundTag.getInt("slot"); + int slot = compoundTag.getInt("slot"); - if (j >= 0 && j < inventory.size()) { - inventory.set(j, ItemStack.fromTag(compoundTag)); + if (slot >= 0 && slot < size) { + super.setStack(slot, ItemStack.fromTag(compoundTag)); } } } private CompoundTag writeItemsToTag() { - DefaultedList inventory = stacks; ListTag listTag = new ListTag(); - for (int i = 0; i < inventory.size(); ++i) { - ItemStack itemStack = (ItemStack) inventory.get(i); - if (!itemStack.isEmpty()) { + for (int i = 0; i < super.size(); ++i) { + ItemStack itemStack = (ItemStack) super.getStack(i); + if (!(itemStack == null) && !itemStack.isEmpty()) { CompoundTag compoundTag = new CompoundTag(); compoundTag.putInt("slot", i); compoundTag = itemStack.toTag(compoundTag); diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreen.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreen.java index 74a3653..4614c8d 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreen.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreen.java @@ -22,10 +22,8 @@ import net.minecraft.util.Identifier; @Environment(EnvType.CLIENT) public class BackpackScreen extends HandledScreen implements ScreenHandlerProvider { - 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 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 final Integer containerHeight = 222; private final Integer containerWidth = 176; @@ -38,18 +36,14 @@ public class BackpackScreen extends HandledScreen 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 < (ItemBackpack.SLOTSIZE / 9); y++) + for (int y = 0; y < (ItemBackpack.SLOTSIZE / 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 ((ItemBackpack.SLOTSIZE % 9) != 0) - for (int x = 0; x < (ItemBackpack.SLOTSIZE % 9); x++) { - this.drawTexture(matrices, guiX + 7 + (x * 18), guiY + 17 + (ItemBackpack.SLOTSIZE / 9 * 18), 0, 0, 18, 18); - } + } } @Override @@ -72,7 +66,6 @@ public class BackpackScreen extends HandledScreen @Override protected void drawForeground(MatrixStack matrixStack, int i, int j) { - this.textRenderer.draw(matrixStack, this.title, 8.0F, -20.0F, 4210752); - this.textRenderer.draw(matrixStack, this.playerInventory.getDisplayName(), 8.0F, 101f, 4210752); + this.textRenderer.draw(matrixStack, this.title, 8.0F, -20.0F, 0xffcccccc); // αrgb } } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreenHandler.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreenHandler.java index 815c6ad..fb632f2 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreenHandler.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreenHandler.java @@ -1,8 +1,5 @@ package de.jottyfan.minecraft.quickiefabric.container; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import de.jottyfan.minecraft.quickiefabric.init.RegistryManager; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -17,22 +14,18 @@ import net.minecraft.screen.slot.SlotActionType; import net.minecraft.util.Hand; public class BackpackScreenHandler extends ScreenHandler { - private final Logger LOGGER = LogManager.getLogger(BackpackScreenHandler.class); - + private final BackpackInventory backpackInventory; private final PlayerEntity player; - private final PlayerInventory playerInventory; + private final ItemStack thisStack; private final Hand hand; public BackpackScreenHandler(int syncId, PlayerInventory playerInventory, PacketByteBuf buf) { super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId); - this.playerInventory = playerInventory; this.player = playerInventory.player; - ItemStack stack = buf.readItemStack(); + thisStack = buf.readItemStack(); this.hand = buf.readByte() > 0 ? Hand.MAIN_HAND : Hand.OFF_HAND; - this.backpackInventory = BackpackInventory.getInventory(this, player, stack); - - int spacing = 112; + this.backpackInventory = BackpackInventory.getInventory(this, player, thisStack); backpackInventory.onOpen(player); for (int y = 0; y < 6; y++) { @@ -42,18 +35,18 @@ public class BackpackScreenHandler extends ScreenHandler { } for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { - this.addSlot(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, spacing + y * 18)); + this.addSlot(new Slot(playerInventory, x + (y * 9) + 9, 8 + x * 18, 112 + y * 18)); } } for (int x = 0; x < 9; ++x) { - this.addSlot(new Slot(playerInventory, x, 8 + x * 18, 58 + spacing)); + this.addSlot(new Slot(playerInventory, x, 8 + x * 18, 170)); } } public PlayerEntity getPlayer() { return this.player; } - + public Inventory getInventory() { return backpackInventory; } @@ -92,16 +85,20 @@ public class BackpackScreenHandler extends ScreenHandler { } return copy; } - + @Override - public ItemStack onSlotClick(int i, int j, SlotActionType actionType, PlayerEntity playerEntity) { - LOGGER.info("click on slot at {},{} with actionType {} by {}", i, j, actionType, playerEntity); - // TODO: prevent the one slot that contains the active backpack item - return super.onSlotClick(i, j, actionType, playerEntity); + public ItemStack onSlotClick(int slotId, int quickCraftData, SlotActionType actionType, PlayerEntity playerEntity) { + if (slotId >= 0) { + ItemStack stack = getSlot(slotId).getStack(); + if (stack.getName().equals(thisStack.getName())) { + return stack; + } + } + return super.onSlotClick(slotId, quickCraftData, actionType, playerEntity); + } + + @Environment(EnvType.CLIENT) + public int getRows() { + return 6; } - - @Environment(EnvType.CLIENT) - public int getRows() { - return 6; - } } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java index 9cbed09..ee40b60 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/init/RegistryManager.java @@ -40,9 +40,9 @@ import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.decorator.ChanceDecoratorConfig; import net.minecraft.world.gen.decorator.Decorator; import net.minecraft.world.gen.decorator.RangeDecoratorConfig; +import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.OreFeatureConfig; -import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraft.world.gen.feature.SimpleBlockFeatureConfig; /** @@ -146,7 +146,7 @@ public class RegistryManager { registerItem(QuickieTools.SPEEDPOWDERPICKAXE, "speedpowderpickaxe"); registerItem(QuickieTools.SPEEDPOWDERSHOVEL, "speedpowdershovel"); } - + public static final void registerContainer() { // ScreenHandlerRegistry.registerSimple(BACKPACK_CONTAINTER, (syncId, inventory) -> new BackpackScreenHandler(syncId, inventory)); } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/tools/ToolSpeedpowderPickaxe.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/tools/ToolSpeedpowderPickaxe.java index d9d4a2e..f816fc5 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/tools/ToolSpeedpowderPickaxe.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/tools/ToolSpeedpowderPickaxe.java @@ -18,11 +18,12 @@ import net.minecraft.item.ToolMaterials; */ public class ToolSpeedpowderPickaxe extends PickaxeItem implements ToolRangeable { + public static final Integer DEFAULT_HARVEST_RANGE = 3; private HarvestRange range; public ToolSpeedpowderPickaxe() { super(ToolMaterials.DIAMOND, 4, 2.0f, new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP)); - this.range = new HarvestRange(3); + this.range = new HarvestRange(DEFAULT_HARVEST_RANGE); } @Override @@ -40,6 +41,10 @@ public class ToolSpeedpowderPickaxe extends PickaxeItem implements ToolRangeable return Lists.newArrayList(block); } + public void setPlusRange(Integer plusRange) { + range.addXYZ(plusRange); + } + // @Override // public ActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { // CommonToolCode.onItemRightClick(worldIn, playerIn, handIn); diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/tools/ToolSpeedpowderShovel.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/tools/ToolSpeedpowderShovel.java index 2162ea7..5f398fe 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/tools/ToolSpeedpowderShovel.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/tools/ToolSpeedpowderShovel.java @@ -23,11 +23,12 @@ import net.minecraft.util.registry.Registry; */ public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable { private static final Logger LOGGER = LogManager.getLogger(ToolSpeedpowderShovel.class); + public static final Integer DEFAULT_HARVEST_RANGE = 3; public HarvestRange range; public ToolSpeedpowderShovel() { super(ToolMaterials.DIAMOND, 4, 2.0f, new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP)); - this.range = new HarvestRange(3); + this.range = new HarvestRange(DEFAULT_HARVEST_RANGE); } @Override diff --git a/src/main/resources/assets/quickiefabric/textures/gui/backpack.png b/src/main/resources/assets/quickiefabric/textures/gui/backpack.png index 345f09a..f24c05b 100644 Binary files a/src/main/resources/assets/quickiefabric/textures/gui/backpack.png and b/src/main/resources/assets/quickiefabric/textures/gui/backpack.png differ