diff --git a/gradle.properties b/gradle.properties index ddfeac6..552fb06 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ loader_version=0.12.12 # Mod Properties - mod_version = 1.18.1.6 + mod_version = 1.18.1.7 maven_group = de.jottyfan.minecraft archives_base_name = quickiefabric diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockEastEntity.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockEastEntity.java index 5224054..6d09d01 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockEastEntity.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockEastEntity.java @@ -26,6 +26,9 @@ public class DrillBlockEastEntity extends DrillBlockEntity { DrillBlockEastEntity dbe = (DrillBlockEastEntity) be; List list = new ArrayList<>(); list.add(pos.east()); + list.add(pos.east().up()); + list.add(pos.east().up().up()); + list.add(pos.east().up().up().up()); list.add(pos.east().down()); // must be last position DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list); } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockEntity.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockEntity.java index 587a707..a801ab0 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockEntity.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockEntity.java @@ -26,8 +26,8 @@ public abstract class DrillBlockEntity extends BlockEntity { if (be != null) { world.setBlockState(from, Blocks.AIR.getDefaultState()); world.setBlockState(to, bs); - world.removeBlockEntity(from); world.addBlockEntity(be); + world.removeBlockEntity(from); } } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockNorthEntity.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockNorthEntity.java index 7cda76c..99b2cce 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockNorthEntity.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockNorthEntity.java @@ -26,6 +26,9 @@ public class DrillBlockNorthEntity extends DrillBlockEntity { DrillBlockNorthEntity dbe = (DrillBlockNorthEntity) be; List list = new ArrayList<>(); list.add(pos.north()); + list.add(pos.north().up()); + list.add(pos.north().up().up()); + list.add(pos.north().up().up().up()); list.add(pos.north().down()); // must be last position DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list); } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockSouthEntity.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockSouthEntity.java index afebe7d..119a4d8 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockSouthEntity.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockSouthEntity.java @@ -25,6 +25,9 @@ public class DrillBlockSouthEntity extends DrillBlockEntity { DrillBlockSouthEntity dbe = (DrillBlockSouthEntity) be; List list = new ArrayList<>(); list.add(pos.south()); + list.add(pos.south().up()); + list.add(pos.south().up().up()); + list.add(pos.south().up().up().up()); list.add(pos.south().down()); // must be last position DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list); } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockWestEntity.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockWestEntity.java index 983ab24..bb317bc 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockWestEntity.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/blockentity/DrillBlockWestEntity.java @@ -26,6 +26,9 @@ public class DrillBlockWestEntity extends DrillBlockEntity { DrillBlockWestEntity dbe = (DrillBlockWestEntity) be; List list = new ArrayList<>(); list.add(pos.west()); + list.add(pos.west().up()); + list.add(pos.west().up().up()); + list.add(pos.west().up().up().up()); list.add(pos.west().down()); // must be last position DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list); } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemBackpack.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemBackpack.java index 94b0985..f61e3de 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemBackpack.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemBackpack.java @@ -10,12 +10,8 @@ import de.jottyfan.minecraft.quickiefabric.container.BackpackScreenHandler; import de.jottyfan.minecraft.quickiefabric.init.RegistryManager; import io.netty.buffer.Unpooled; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.block.entity.ChestBlockEntity; +import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.Item; @@ -77,7 +73,8 @@ public class ItemBackpack extends Item { } /** - * sort the content of the backpack; for spreaded items, combine them until the itemstack size is reached + * sort the content of the backpack; for spreaded items, combine them until the + * itemstack size is reached * * @param itemStack the itemStack of the backpack * @return the itemStack of the sorted backpack @@ -105,44 +102,65 @@ public class ItemBackpack extends Item { BlockPos pos = context.getBlockPos(); World world = context.getWorld(); PlayerEntity player = context.getPlayer(); - BlockState blockState = world.getBlockState(pos); - Block block = blockState.getBlock(); - if (Blocks.CHEST.equals(block)) { - BlockEntity entity = world.getBlockEntity(pos); - BlockEntityType type = entity.getType(); - if (BlockEntityType.CHEST.equals(type)) { - ChestBlockEntity cbe = (ChestBlockEntity) entity; - BackpackInventory bi = new BackpackInventory(context.getStack()); - bi.setHand(context.getHand()); - if (cbe.isEmpty()) { - for (int slot = 0; slot < ItemBackpack.SLOTSIZE; slot++) { - if (slot < cbe.size()) { - cbe.setStack(slot, bi.getStack(slot)); - bi.removeStack(slot); + BlockEntity entity = world.getBlockEntity(pos); + if (entity != null && entity instanceof LootableContainerBlockEntity) { + BackpackInventory bi = new BackpackInventory(context.getStack()); + bi.setHand(context.getHand()); + LootableContainerBlockEntity blockEntity = (LootableContainerBlockEntity) entity; + if (bi.isEmpty()) { // fill backpack + for (int slot = 0; slot < ItemBackpack.SLOTSIZE; slot++) { + if (slot < blockEntity.size()) { + bi.setStack(slot, blockEntity.getStack(slot)); + blockEntity.setStack(slot, ItemStack.EMPTY); + } + } + bi.onClose(player); + if (!world.isClient) { + player.sendMessage(new TranslatableText("msg.backpack.transfer.filled"), false); + } + } else { // empty backpack as long as possible + for (int slot = 0; slot < ItemBackpack.SLOTSIZE; slot++) { + List slots = findSlots(blockEntity, bi.getStack(slot)); + for (Integer barrelSlot : slots) { + ItemStack barrelStack = blockEntity.getStack(barrelSlot); + ItemStack backpackStack = bi.getStack(slot); + int foundCount = barrelStack.getCount(); + int transferCount = 64 - foundCount; + int newBackpackCount = backpackStack.getCount() - transferCount; + if (newBackpackCount < 0) { + transferCount = backpackStack.getCount(); + newBackpackCount = 0; } + // if it was air, replace it with something + blockEntity.setStack(barrelSlot, new ItemStack(backpackStack.getItem(), foundCount + transferCount)); + backpackStack.decrement(transferCount); } - bi.onClose(player); - if (!world.isClient) { - player.sendMessage(new TranslatableText("msg.backpack.transfer.cleared"), false); - } - } else if (bi.isEmpty()) { - for (int slot = 0; slot < ItemBackpack.SLOTSIZE; slot++) { - if (slot < cbe.size()) { - bi.setStack(slot, cbe.getStack(slot)); - cbe.setStack(slot, ItemStack.EMPTY); - } - } - bi.onClose(player); - if (!world.isClient) { - player.sendMessage(new TranslatableText("msg.backpack.transfer.filled"), false); - } - } else { - if (!world.isClient) { - player.sendMessage(new TranslatableText("msg.backpack.transfer.cancel"), false); - } + } + bi.onClose(player); + if (!world.isClient) { + player.sendMessage(new TranslatableText("msg.backpack.transfer.cleared"), false); } } } return super.useOnBlock(context); } + + /** + * find the numbers of the slots that contain items of stack or have Air + * + * @param blockEntity the block entity + * @param stack the item stack + * @return a list of found stack positions; an empty list at least + */ + private final List findSlots(LootableContainerBlockEntity blockEntity, ItemStack stack) { + List list = new ArrayList<>(); + if (!stack.isEmpty()) + for (int i = 0; i < blockEntity.size(); i++) { + ItemStack containerStack = blockEntity.getStack(i); + if (containerStack.isEmpty() || containerStack.getItem().equals(stack.getItem())) { + list.add(i); + } + } + return list; + } } diff --git a/src/main/resources/assets/quickiefabric/lang/de_de.json b/src/main/resources/assets/quickiefabric/lang/de_de.json index 3f55c7c..648b995 100644 --- a/src/main/resources/assets/quickiefabric/lang/de_de.json +++ b/src/main/resources/assets/quickiefabric/lang/de_de.json @@ -76,8 +76,8 @@ "msg.buildingplan.failonplayer": "Der Bau wurde abgelehnt, um Spieler %s nicht zu gefährden.", "msg.itemhoarder.summary": "Der Itemsauger enthält: %s", "msg.notyetimplemented": "leider noch nicht verfügbar", - "msg.backpack.transfer.filled": "Der Rucksack wurde aus der Kiste befüllt.", - "msg.backpack.transfer.cleared": "Der Rucksackinhalt wurde in die Kiste geschüttet.", + "msg.backpack.transfer.filled": "Der Rucksack wurde befüllt.", + "msg.backpack.transfer.cleared": "Der Rucksackinhalt wurde soweit möglich geleert.", "msg.backpack.transfer.cancel": "Entweder der Rucksack oder die Kiste sind nicht komplett leer.", "error.unleveling.inventory.full": "Es ist kein Platz mehr frei, um die Aufwertungen abzulegen." } diff --git a/src/main/resources/assets/quickiefabric/lang/en_us.json b/src/main/resources/assets/quickiefabric/lang/en_us.json index 5292adb..975ec1b 100644 --- a/src/main/resources/assets/quickiefabric/lang/en_us.json +++ b/src/main/resources/assets/quickiefabric/lang/en_us.json @@ -76,8 +76,8 @@ "msg.buildingplan.failonplayer": "The building execution was rejected because of %s who could be injured.", "msg.itemhoarder.summary": "The item hoarder contains: %s", "msg.notyetimplemented": "not yet implemented", - "msg.backpack.transfer.filled": "Filled the backpack from the chest.", - "msg.backpack.transfer.cleared": "Filled the chest from the backpack.", + "msg.backpack.transfer.filled": "Filled the backpack.", + "msg.backpack.transfer.cleared": "Cleared the backpack as much as possible.", "msg.backpack.transfer.cancel": "Eigther backpack or chest are not completely empty.", "error.unleveling.inventory.full": "There is no free stack in your inventory for the level ups." }