forbid backpack to place itself into it
This commit is contained in:
parent
515f3a6d28
commit
2ec6179053
@ -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
|
||||
|
||||
|
@ -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(":");
|
||||
|
@ -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<ItemStack> 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<ItemStack> 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<ItemStack> 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<ItemStack> 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);
|
||||
|
@ -22,10 +22,8 @@ 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 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;
|
||||
|
||||
@ -41,14 +39,10 @@ public class BackpackScreen extends HandledScreen<BackpackScreenHandler>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +66,6 @@ public class BackpackScreen extends HandledScreen<BackpackScreenHandler>
|
||||
|
||||
@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
|
||||
}
|
||||
}
|
||||
|
@ -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,11 +35,11 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,10 +87,14 @@ public class BackpackScreenHandler extends ScreenHandler {
|
||||
}
|
||||
|
||||
@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)
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
|
||||
// CommonToolCode.onItemRightClick(worldIn, playerIn, handIn);
|
||||
|
@ -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
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 35 KiB |
Loading…
x
Reference in New Issue
Block a user