added bag (chest functionality only)
This commit is contained in:
parent
130d258ada
commit
033823d036
@ -9,7 +9,7 @@
|
||||
loader_version=0.12.12
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.18.1.3
|
||||
mod_version = 1.18.1.4
|
||||
maven_group = de.jottyfan.minecraft
|
||||
archives_base_name = quickiefabric
|
||||
|
||||
|
@ -156,4 +156,21 @@ public class BackpackInventory extends SimpleInventory {
|
||||
tag.put(NBT_ITEMS, listTag);
|
||||
itemStack.getOrCreateNbt().put(NBT_BACKPACK, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* replace every slot of the backpack with the content of backpackInventory
|
||||
*
|
||||
* @param itemStack the backpack's itemStack
|
||||
* @param backpackInventory the replacement inventory
|
||||
*/
|
||||
public static void setItemsToBackpack(ItemStack itemStack, BackpackInventory backpackInventory) {
|
||||
Collection<List<ItemStack>> itemStacks = new ArrayList<>();
|
||||
List<ItemStack> firstList = new ArrayList<>();
|
||||
for (int i = 0; i < backpackInventory.size(); i++) {
|
||||
ItemStack stack = backpackInventory.getStack(i);
|
||||
firstList.add(stack);
|
||||
}
|
||||
itemStacks.add(firstList);
|
||||
setItemsToBackpack(itemStack, itemStacks);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -14,12 +11,13 @@ import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.screen.slot.SlotActionType;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class BackpackScreenHandler extends ScreenHandler {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(BackpackScreenHandler.class);
|
||||
|
||||
private final BackpackInventory backpackInventory;
|
||||
private final PlayerEntity player;
|
||||
private final ItemStack thisStack;
|
||||
@ -68,41 +66,41 @@ public class BackpackScreenHandler extends ScreenHandler {
|
||||
super.close(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferSlot(PlayerEntity player, int index) {
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
Slot slot = (Slot) this.slots.get(index);
|
||||
if (slot != null && slot.hasStack()) {
|
||||
ItemStack itemStack2 = slot.getStack();
|
||||
itemStack = itemStack2.copy();
|
||||
if (index < 54 ? !this.insertItem(itemStack2, 54, this.slots.size(), true) : !this.insertItem(itemStack2, 0, 54, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (itemStack2.isEmpty()) {
|
||||
slot.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.markDirty();
|
||||
}
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotClick(int slotId, int quickCraftData, SlotActionType actionType, PlayerEntity playerEntity) {
|
||||
if (SlotActionType.QUICK_CRAFT.equals(actionType)) {
|
||||
return;
|
||||
}
|
||||
Slot slot = slotId >= 0 && slotId < this.slots.size() ? this.slots.get(slotId) : null;
|
||||
ItemStack stack = slot == null ? ItemStack.EMPTY : slot.getStack();
|
||||
if (actionType.equals(SlotActionType.PICKUP) || actionType.equals(SlotActionType.PICKUP_ALL)
|
||||
|| actionType.equals(SlotActionType.SWAP)) {
|
||||
super.onSlotClick(slotId, quickCraftData, actionType, playerEntity);
|
||||
} else if (actionType.equals(SlotActionType.THROW)) { // pickup from the active items line
|
||||
if (stack.getName().equals(thisStack.getName())) {
|
||||
return; // omit to put the backpack into itself; as a side effect, omits adding same
|
||||
// colored backpacks into this one
|
||||
} else {
|
||||
// do not throw but pickup
|
||||
if (!stack.getName().equals(thisStack.getName())) {
|
||||
if (SlotActionType.THROW.equals(actionType)) {
|
||||
super.onSlotClick(slotId, quickCraftData, SlotActionType.PICKUP, playerEntity);
|
||||
}
|
||||
} else if (actionType.equals(SlotActionType.QUICK_CRAFT)) { // drag - but does not drag the right slot content, stack is empty
|
||||
if (slotId < 0) {
|
||||
return; // do not execute anything if slotId is < 0 as sometimes -999
|
||||
}
|
||||
if (playerEntity.world.isClient) {
|
||||
LOGGER.debug("ignoring action type {} on slotId {} for {} x {}", actionType.toString(), slotId,
|
||||
stack.getCount(), stack.getItem().toString());
|
||||
}
|
||||
} else if (actionType.equals(SlotActionType.QUICK_MOVE)) { // shift click
|
||||
if (stack.getName().equals(thisStack.getName())) {
|
||||
return; // omit to put the backpack into itself; as a side effect, omits adding same
|
||||
// colored backpacks into this one
|
||||
} else {
|
||||
// do not move but pickup all
|
||||
super.onSlotClick(slotId, quickCraftData, SlotActionType.PICKUP_ALL, playerEntity);
|
||||
super.onSlotClick(slotId, quickCraftData, actionType, playerEntity);
|
||||
}
|
||||
} else {
|
||||
if (playerEntity.world.isClient) {
|
||||
LOGGER.debug("ignoring action type {} on slotId {} for {} x {}", actionType.toString(), slotId,
|
||||
stack.getCount(), stack.getItem().toString());
|
||||
playerEntity.world.playSound(null, new BlockPos(playerEntity.getPos()), SoundEvents.ENTITY_VILLAGER_NO, SoundCategory.PLAYERS, 1f, 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +125,7 @@ public class RegistryManager {
|
||||
stacks.add(new ItemStack(QuickieItems.BACKPACK_ORANGE));
|
||||
stacks.add(new ItemStack(QuickieItems.BACKPACK_PURPLE));
|
||||
stacks.add(new ItemStack(QuickieItems.BACKPACK_LIGHTBLUE));
|
||||
stacks.add(new ItemStack(QuickieItems.BAG));
|
||||
stacks.add(new ItemStack(QuickieItems.STUB));
|
||||
stacks.add(new ItemStack(QuickieTools.SPEEDPOWDERAXE));
|
||||
stacks.add(new ItemStack(QuickieTools.SPEEDPOWDERPICKAXE));
|
||||
@ -241,6 +242,7 @@ public class RegistryManager {
|
||||
registerItem(QuickieItems.BACKPACK_ORANGE, "backpack_orange");
|
||||
registerItem(QuickieItems.BACKPACK_PURPLE, "backpack_purple");
|
||||
registerItem(QuickieItems.BACKPACK_LIGHTBLUE, "backpack_lightblue");
|
||||
registerItem(QuickieItems.BAG, "bag");
|
||||
registerItem(QuickieItems.STUB, "stub");
|
||||
|
||||
ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE.put(QuickieItems.COTTONSEED, 0.5f);
|
||||
|
@ -0,0 +1,21 @@
|
||||
package de.jottyfan.minecraft.quickiefabric.item;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ModdedItemUsageContext extends ItemUsageContext {
|
||||
|
||||
public ModdedItemUsageContext(World world, PlayerEntity player, Hand hand, ItemStack stack, BlockHitResult hit) {
|
||||
super(world, player, hand, stack, hit);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package de.jottyfan.minecraft.quickiefabric.items;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import de.jottyfan.minecraft.quickiefabric.container.BackpackInventory;
|
||||
import de.jottyfan.minecraft.quickiefabric.item.ModdedItemUsageContext;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ItemBag extends ItemBackpack {
|
||||
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
BlockPos pos = context.getBlockPos();
|
||||
World world = context.getWorld();
|
||||
PlayerEntity player = context.getPlayer();
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (Blocks.FARMLAND.equals(block)) {
|
||||
if (!world.isClient) {
|
||||
player.sendMessage(new TranslatableText("msg.notyetimplemented"), false);
|
||||
}
|
||||
// BackpackInventory bi = new BackpackInventory(context.getStack());
|
||||
// for (int slot = 0; slot < ItemBackpack.SLOTSIZE; slot++) {
|
||||
// ItemStack stack = bi.getStack(slot);
|
||||
// if (stack.getCount() > 0) {
|
||||
// Item item = stack.getItem();
|
||||
// BlockPos newPos = pos; // TODO: replace by iteration
|
||||
// Vec3d newHitPos = context.getHitPos(); // TODO: replace by iteration
|
||||
// BlockHitResult hit = new BlockHitResult(newHitPos, context.getSide(), newPos, context.hitsInsideBlock());
|
||||
// ModdedItemUsageContext iuc = new ModdedItemUsageContext(world, player, Hand.MAIN_HAND, stack, hit);
|
||||
// if (item.useOnBlock(iuc).equals(ActionResult.PASS)) {
|
||||
// bi.setStack(slot, stack);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// ItemStack thisBackpack = player.getActiveItem();
|
||||
// BackpackInventory.setItemsToBackpack(thisBackpack, bi);
|
||||
return ActionResult.SUCCESS;
|
||||
} else {
|
||||
return super.useOnBlock(context);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ public class QuickieItems {
|
||||
public static final ItemBackpack BACKPACK_ORANGE = new ItemBackpack();
|
||||
public static final ItemBackpack BACKPACK_PURPLE = new ItemBackpack();
|
||||
public static final ItemBackpack BACKPACK_LIGHTBLUE = new ItemBackpack();
|
||||
public static final ItemBag BAG = new ItemBag();
|
||||
public static final ItemRottenFleshStripes ROTTEN_FLESH_STRIPES = new ItemRottenFleshStripes();
|
||||
public static final ItemCarrotstack CARROTSTACK = new ItemCarrotstack();
|
||||
public static final ItemCotton COTTON = new ItemCotton();
|
||||
|
@ -86,7 +86,9 @@ public class ToolSpeedpowderHoe extends HoeItem implements ToolRangeable {
|
||||
@Override
|
||||
public boolean canBreakNeighbors(BlockState blockState) {
|
||||
return ToolManager.handleIsEffectiveOn(blockState, new ItemStack(this), null)
|
||||
|| Blocks.GRASS.equals(blockState.getBlock());
|
||||
|| Blocks.GRASS.equals(blockState.getBlock())
|
||||
|| Blocks.FERN.equals(blockState.getBlock())
|
||||
|| Blocks.LARGE_FERN.equals(blockState.getBlock());
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
"item.quickiefabric.backpack_orange": "orangener Rucksack",
|
||||
"item.quickiefabric.backpack_purple": "lilaner Rucksack",
|
||||
"item.quickiefabric.backpack_lightblue": "hellblauer Rucksack",
|
||||
"item.quickiefabric.bag": "Beutel",
|
||||
"item.quickiefabric.rotten_flesh_stripes": "geschnittenes Gammelfleisch",
|
||||
"item.quickiefabric.carrotstack": "Karottenbündel",
|
||||
"item.quickiefabric.cotton": "Baumwolle",
|
||||
|
@ -29,6 +29,7 @@
|
||||
"item.quickiefabric.backpack_orange": "orange backpack",
|
||||
"item.quickiefabric.backpack_purple": "purple backpack",
|
||||
"item.quickiefabric.backpack_lightblue": "light blue backpack",
|
||||
"item.quickiefabric.bag": "bag",
|
||||
"item.quickiefabric.rotten_flesh_stripes": "rotten flesh stripes",
|
||||
"item.quickiefabric.carrotstack": "a bundle of carrots",
|
||||
"item.quickiefabric.cotton": "cotton",
|
||||
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiefabric:item/bag_empty",
|
||||
"layer1": "quickiefabric:item/bag_full"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 744 B |
Binary file not shown.
After Width: | Height: | Size: 781 B |
16
src/main/resources/data/quickiefabric/recipes/bag.json
Normal file
16
src/main/resources/data/quickiefabric/recipes/bag.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"type": "crafting_shaped",
|
||||
"pattern": [
|
||||
" ",
|
||||
"c c",
|
||||
" c "
|
||||
],
|
||||
"key": {
|
||||
"c": {
|
||||
"item": "minecraft:wheat"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"item": "quickiefabric:bag"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user