1
0
Fork 0

add basic inventory mode switch (tab)

This commit is contained in:
Sen 2025-09-05 18:50:20 +02:00
parent 9f452b410e
commit 83dca68f11
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
46 changed files with 198 additions and 22 deletions

View file

@ -468,6 +468,7 @@ public class Client implements IThreadListener {
private boolean saving;
private boolean drawFps;
private boolean drawDebug;
private boolean placeMode;
public boolean jump;
public boolean sneak;
public boolean debugCamEnable;
@ -961,6 +962,11 @@ public class Client implements IThreadListener {
this.renderer.setDisplayListEntitiesDirty();
}
if (Bind.ITEMMODE.isPressed() && this.viewEntity == this.player)
{
this.placeMode ^= true;
}
boolean hadZoom = this.zooming;
this.zooming = Bind.ZOOM.isDown() || this.viewEntity != this.player;
@ -1096,7 +1102,7 @@ public class Client implements IThreadListener {
this.displayTick(ExtMath.floord(this.player.posX), ExtMath.floord(this.player.posY), ExtMath.floord(this.player.posZ));
}
this.effectRenderer.update();
if(this.player != null && this.player.getHeldItem() == null)
if(this.player != null && (this.player.getHeldItem() == null || !this.player.getHeldItem().getItem().canBeHeld() || (this.player.getHeldItem().getItem().getBlock() != null) != this.placeMode))
this.select(1);
}
else if (this.connection != null)
@ -1166,7 +1172,7 @@ public class Client implements IThreadListener {
if(this.world != null && this.player != null && this.viewEntity == this.player) {
total = 0;
for(int z = 0; z < this.player.getHotbarSize(); z++) {
if(this.player.getStackInSlot(z) != null)
if(this.player.getStackInSlot(z) != null && this.player.getStackInSlot(z).getItem().canBeHeld() && (this.player.getStackInSlot(z).getItem().getBlock() != null) == this.placeMode)
++total;
}
if(total == 0)
@ -1198,7 +1204,7 @@ public class Client implements IThreadListener {
int x = xoff * scale;
for(int n = 0; n < size; n++) {
if(this.player.getStackInSlot(n) == null)
if(this.player.getStackInSlot(n) == null || !this.player.getStackInSlot(n).getItem().canBeHeld() || (this.player.getStackInSlot(n).getItem().getBlock() != null) != this.placeMode)
continue;
if(selected == n)
Drawing.drawRect(x - scale * 2, by - scale * 2, 20 * scale, 20 * scale, 0xffffffff);
@ -1364,7 +1370,7 @@ public class Client implements IThreadListener {
int cnt = 0;
for(int index = 0; index < size; ++index) {
ItemStack itemstack = this.player.getStackInSlot(index);
if(itemstack != null) {
if(itemstack != null && itemstack.getItem().canBeHeld() && (itemstack.getItem().getBlock() != null) == this.placeMode) {
if(width < 20 && selected != index && selected != index + 1 && cnt != total - 1) {
this.scissor(xPos * scale, this.fbY - (by + 16 * scale), (width - 1) * scale, 16 * scale);
GL15.glEnable(GL15.GL_SCISSOR_TEST);
@ -1408,12 +1414,13 @@ public class Client implements IThreadListener {
int xPos = xoff * scale;
for(int index = 0; index < size; ++index) {
ItemStack itemstack = this.player.getStackInSlot(index);
if(itemstack != null && (width >= 17 || index == selected)) {
GuiContainer.renderItemOverlay(itemstack,
xPos, by, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), scale);
}
if(itemstack != null)
if(itemstack != null && itemstack.getItem().canBeHeld() && (itemstack.getItem().getBlock() != null) == this.placeMode) {
if(width >= 17 || index == selected) {
GuiContainer.renderItemOverlay(itemstack,
xPos, by, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), scale);
}
xPos += (width >= 20 || selected == index || selected == index + 1 ? 20 : width) * scale;
}
}
}
if(this.open != null)
@ -1543,7 +1550,7 @@ public class Client implements IThreadListener {
this.player.setSelectedIndex(0);
++n;
}
while(this.player.getHeldItem() == null && n < this.player.getHotbarSize());
while((this.player.getHeldItem() == null || !this.player.getHeldItem().getItem().canBeHeld() || (this.player.getHeldItem().getItem().getBlock() != null) != this.placeMode) && n < this.player.getHotbarSize());
this.controller.resetUseCooldown();
}

View file

@ -179,10 +179,12 @@ public abstract class GuiContainer extends Gui
if(stack.getRepairCost() > 0)
list.add("Reparaturkosten: " + stack.getRepairCost() + " Mana");
if(stack.getItem().getMaxAmount() == 1)
list.add("Nicht stapelbar");
else
list.add("Stapelbar bis " + stack.getItem().getMaxAmount());
list.add(stack.getItem().getMaxAmount() == 1 ? "Nicht stapelbar" : "Stapelbar");
list.add("Gewicht: " + (stack.getSize() != 1 ? stack.getSize() * stack.getItem().getWeight() + "(" + stack.getSize() + "x " + stack.getItem().getWeight() + ")" : stack.getItem().getWeight()));
if(stack.getItem().canBeHeld())
list.add("Kann gehalten werden");
list.add(Color.GRAY + ItemRegistry.getName(stack.getItem()));

View file

@ -17,6 +17,7 @@ public enum Bind implements Identifyable, CVar {
DOWN(BindCategory.MOVEMENT, "down", "Abwärts, Langsam", Keysym.LEFT_CONTROL),
FAST(BindCategory.MOVEMENT, "fast", "Schneller", Keysym.LEFT_SHIFT),
INVENTORY(BindCategory.INTERACTION, "inventory", "Inventar", Keysym.E),
ITEMMODE(BindCategory.INTERACTION, "itemmode", "Platziermodus", Keysym.TAB),
PRIMARY(BindCategory.INTERACTION, "primary", "Primäre Aktion", Button.MOUSE_LEFT),
SECONDARY(BindCategory.INTERACTION, "secondary", "Sekundäre Aktion", Button.MOUSE_RIGHT),
TERTIARY(BindCategory.INTERACTION, "tertiary", "Tertiäre Aktion", Button.MOUSE_MIDDLE),
@ -42,7 +43,7 @@ public enum Bind implements Identifyable, CVar {
RENAME(BindCategory.INTERACTION, "rename", "Umbenennen", Keysym.N),
CONSOLE(BindCategory.GENERAL, "console", "Konsole", Keysym.F1),
COMMAND(BindCategory.GENERAL, "command", "Befehl / Chat", Keysym.C),
INFO(BindCategory.GENERAL, "info", "Infos einblenden", Keysym.TAB),
INFO(BindCategory.GENERAL, "info", "Infos einblenden", Keysym.CIRCUMFLEX),
PERSPECTIVE(BindCategory.GENERAL, "perspective", "Perspektive", Keysym.F4),
ZOOM(BindCategory.GENERAL, "zoom", "Kamera zoomen", Keysym.Y),
MENU(BindCategory.GENERAL, "menu", "Menü", Keysym.ESCAPE),

View file

@ -47,7 +47,7 @@ public class BlockNuke extends Block
public boolean onUse(World worldIn, LocalPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) {
if(playerIn.getHeldItem() != null) {
Item item = playerIn.getHeldItem().getItem();
if(item == Items.charged_powder) {
if(item == Items.fireball) {
this.explode(worldIn, pos, playerIn);
worldIn.setBlockToAir(pos);
playerIn.getHeldItem().decrSize();

View file

@ -28,7 +28,7 @@ public class EntityMouse extends EntityAnimal {
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIPanic(this, 1.4D));
this.tasks.addTask(2, new EntityAIMate(this, 1.0D));
this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.sugar, false));
this.tasks.addTask(3, new EntityAITempt(this, 1.0D, Items.cheese, false));
this.tasks.addTask(4, new EntityAIFollowParent(this, 1.1D));
this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
this.tasks.addTask(6, new EntityAIWatchClosest(this, null, 6.0F));
@ -85,7 +85,7 @@ public class EntityMouse extends EntityAnimal {
}
public boolean isBreedingItem(ItemStack stack) {
return stack != null && stack.getItem() == Items.sugar;
return stack != null && stack.getItem() == Items.cheese;
}
protected int getExperiencePoints(EntityNPC player) {

View file

@ -36,6 +36,7 @@ import common.item.material.ItemBucket;
import common.item.material.ItemDye;
import common.item.material.ItemEnchantedBook;
import common.item.material.ItemGrindedBones;
import common.item.material.ItemLure;
import common.item.material.ItemAnimalArmor;
import common.item.material.ItemMetal;
import common.item.material.ItemRecord;
@ -212,7 +213,7 @@ public abstract class ItemRegistry {
register("stick", (new Item()).setDisplay("Stock").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XS).setFuelAmount(100));
register("feather", (new Item()).setDisplay("Feder").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XXS));
register("gunpowder", (new Item()).setDisplay("Schwarzpulver").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XS).setExplosive(1));
register("wheat", (new Item()).setDisplay("Weizen").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("wheat", (new ItemLure()).setDisplay("Weizen").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("bread", (new ItemFood(5, false)).setDisplay("Brot"));
register("flint", (new Item()).setDisplay("Feuerstein").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("porkchop", (new ItemFood(3, true)).setDisplay("Rohes Schweinefleisch"));
@ -242,7 +243,7 @@ public abstract class ItemRegistry {
for(Color color : Color.values()) {
register(color.getName() + "_dye", new ItemDye(color));
}
register("bone", (new Item()).setDisplay("Knochen").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("bone", (new ItemLure()).setDisplay("Knochen").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("sugar", (new Item()).setDisplay("Zucker").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XXS));
register("cookie", (new ItemFood(2, false)).setDisplay("Keks").setWeight(ItemWeight.S));
register("melon", (new ItemFood(2, false)).setDisplay("Melone"));

View file

@ -24,6 +24,7 @@ import common.item.material.ItemBucket;
import common.item.material.ItemDye;
import common.item.material.ItemEnchantedBook;
import common.item.material.ItemGrindedBones;
import common.item.material.ItemLure;
import common.item.material.ItemAnimalArmor;
import common.item.material.ItemMetal;
import common.item.material.ItemRecord;
@ -183,7 +184,7 @@ public abstract class Items {
public static final ItemBoat boat = get("boat");
public static final ItemAmmo bolt = get("bolt");
public static final ItemBoltgun boltgun = get("boltgun");
public static final Item bone = get("bone");
public static final ItemLure bone = get("bone");
public static final ItemBook book = get("book");
public static final Item bookshelf = get("bookshelf");
public static final ItemBow bow = get("bow");
@ -770,7 +771,7 @@ public abstract class Items {
public static final ItemWeatherToken weather_token_thunder = get("weather_token_thunder");
public static final Item web = get("web");
public static final ItemSeeds wheat_seed = get("wheat_seed");
public static final Item wheat = get("wheat");
public static final ItemLure wheat = get("wheat");
public static final Item white_bed = get("white_bed");
public static final Item white_carpet = get("white_carpet");
public static final Item white_clay = get("white_clay");

View file

@ -131,6 +131,10 @@ public class Item {
return this.block;
}
public final int getWeight() {
return this.weight;
}
public final int getMaxAmount() {
return this.stackable ? 67108864 : 1;
}
@ -281,6 +285,10 @@ public class Item {
return this.block != null ? this.block.getRadiation() * (float)stack.getSize() : 0.0f;
}
public boolean canBeHeld() {
return this.block != null;
}
public WieldType getWieldType() {
return null;
}

View file

@ -28,6 +28,10 @@ public class ItemFood extends Item
this.setTab(CheatTab.FOOD);
}
public boolean canBeHeld() {
return true;
}
/**
* Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
* the Item before the action is complete.

View file

@ -18,6 +18,10 @@ public class ItemMilkBottle extends Item {
this.setMagnetic();
}
public boolean canBeHeld() {
return true;
}
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityNPC playerIn) {
stack.decrSize();
if(!worldIn.client)

View file

@ -80,6 +80,10 @@ public class ItemPotion extends Item
POTIONS.add(this);
}
public boolean canBeHeld() {
return true;
}
public StatusEffect getEffect()
{
return this.effect;

View file

@ -71,6 +71,7 @@ public class ItemArmor extends Item {
return this.material.isRepairItem(repair.getItem()) ? true : super.getIsRepairable(toRepair, repair);
}
/*
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn) {
for(Equipment slot : this.type.getPossibleSlots(playerIn)) {
if(playerIn.getArmor(slot) == null) {
@ -82,6 +83,7 @@ public class ItemArmor extends Item {
return itemStackIn;
}
*/
public void getArmorModifiers(Map<Attribute, Float> map) {
if(this.material.getRadiationReduction(this.type) > 0.0f)

View file

@ -15,8 +15,13 @@ public class ItemBottle extends Item
public ItemBottle()
{
this.setTab(CheatTab.TOOLS);
this.setFragile();
}
public boolean canBeHeld() {
return true;
}
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/

View file

@ -132,6 +132,10 @@ public class ItemBucket extends Item
MAPPING.put(liquid.getStaticBlock(), this);
}
}
public boolean canBeHeld() {
return true;
}
public BlockDynamicLiquid getLiquid() {
return this.liquid;

View file

@ -34,6 +34,10 @@ public class ItemDye extends Item {
this.setWeight(ItemWeight.XXS);
DIES[this.color.ordinal()] = this;
}
public boolean canBeHeld() {
return true;
}
public Color getColor() {
return this.color;

View file

@ -40,6 +40,10 @@ public class ItemGrindedBones extends Item {
}
}
public boolean canBeHeld() {
return true;
}
public static boolean applyBonemeal(ItemStack stack, World worldIn, LocalPos target)
{
State iblockstate = worldIn.getState(target);

View file

@ -0,0 +1,9 @@
package common.item.material;
import common.item.Item;
public class ItemLure extends Item {
public boolean canBeHeld() {
return true;
}
}

View file

@ -22,6 +22,10 @@ public class ItemSeeds extends Item
this.setTab(CheatTab.MATERIALS);
}
public boolean canBeHeld() {
return true;
}
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, LocalPos pos, Facing side, float hitX, float hitY, float hitZ)
{
if (side != Facing.UP)

View file

@ -25,6 +25,10 @@ public class ItemChargedOrb extends Item
this.setColor(Color.DARK_MAGENTA);
this.setFragile();
}
public boolean canBeHeld() {
return true;
}
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
{

View file

@ -52,6 +52,10 @@ public class ItemDie extends Item
this.setDisplay("Würfel W" + this.sides);
DICE.put(sides, this);
}
public boolean canBeHeld() {
return true;
}
public int getSides() {
return this.sides;

View file

@ -31,6 +31,10 @@ public class ItemDynamite extends Item {
DYNAMITE[power] = this;
}
public boolean canBeHeld() {
return true;
}
public int getExplosionPower() {
return this.power;
}

View file

@ -21,6 +21,10 @@ public class ItemEgg extends Item
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/

View file

@ -22,6 +22,10 @@ public class ItemFireball extends Item
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
/**
* Called when a Block is right-clicked with this Item
*/

View file

@ -21,6 +21,10 @@ public class ItemSnowball extends Item
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/

View file

@ -29,6 +29,10 @@ public class ItemBoat extends Item
this.setTab(CheatTab.VEHICLES);
}
public boolean canBeHeld() {
return true;
}
/**
* Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
*/

View file

@ -40,6 +40,10 @@ public class ItemCharTemplate extends Item
this.setDisplay("delegate");
TEMPLATES.add(this);
}
public boolean canBeHeld() {
return true;
}
public void delegateSetDisplay() {
this.setDisplay("DNA-Probe von " + this.getCharName());

View file

@ -26,6 +26,10 @@ public class ItemMinecart extends Item
this.setMagnetic();
}
public boolean canBeHeld() {
return true;
}
/**
* Called when a Block is right-clicked with this Item
*/

View file

@ -38,6 +38,10 @@ public class ItemMobTemplate extends Item
this.setDisplay("delegate");
TEMPLATES.add(this);
}
public boolean canBeHeld() {
return true;
}
public void delegateSetDisplay() {
this.setDisplay("DNA-Probe von " + EntityRegistry.getEntityName(this.entityId));

View file

@ -13,6 +13,10 @@ public class ItemCamera extends Item {
this.setUnstackable();
this.setMagnetic();
}
public boolean canBeHeld() {
return true;
}
public boolean onAction(ItemStack stack, EntityNPC player, World world, ItemControl control, LocalPos block) {
if(control == ItemControl.SECONDARY) {

View file

@ -13,6 +13,10 @@ public class ItemEditor extends Item {
this.setUnstackable();
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
public boolean onAction(ItemStack stack, EntityNPC player, World world, ItemControl control, LocalPos block) {
if(!world.client && control == ItemControl.TERTIARY && player.connection.isAdmin())

View file

@ -30,6 +30,10 @@ public class ItemFire extends Item
this.setMagnetic();
}
public boolean canBeHeld() {
return true;
}
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip) {
this.fireBlock.getTooltips(stack, playerIn, tooltip);
}

View file

@ -18,6 +18,10 @@ public class ItemFishingRod extends Item
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
// /**
// * Returns True is the item is renderer in full 3D when hold.
// */

View file

@ -20,6 +20,10 @@ public class ItemHoe extends Item
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
public boolean onItemUse(ItemStack stack, EntityNPC playerIn, World worldIn, LocalPos pos, Facing side, float hitX, float hitY, float hitZ)
{
if (!playerIn.canPlayerEdit(pos.offset(side), side, stack))

View file

@ -6,4 +6,8 @@ public class ItemKey extends Item {
public ItemKey() {
this.setMagnetic();
}
public boolean canBeHeld() {
return true;
}
}

View file

@ -20,6 +20,10 @@ public class ItemLead extends Item
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
/**
* Called when a Block is right-clicked with this Item
*/

View file

@ -24,6 +24,10 @@ public class ItemMagnet extends Item {
this.chicken = chicken;
}
public boolean canBeHeld() {
return true;
}
// public boolean isFull3D() {
// return true;
// }

View file

@ -13,6 +13,10 @@ public class ItemNameTag extends Item
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
/**
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
*/

View file

@ -15,6 +15,10 @@ public class ItemSaddle extends Item
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
/**
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
*/

View file

@ -22,6 +22,10 @@ public class ItemSpaceNavigator extends Item {
this.setColor(Color.DARK_GREEN);
this.setMagnetic();
}
public boolean canBeHeld() {
return true;
}
public void setLocalTime(String local) {
this.localTime = local;

View file

@ -34,6 +34,10 @@ public class ItemTool extends Item {
this.setFuelAmount(200);
}
public boolean canBeHeld() {
return true;
}
@Clientside
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip)
{

View file

@ -23,6 +23,10 @@ public abstract class ItemWand extends Item {
this.setTab(CheatTab.TOOLS);
}
public boolean canBeHeld() {
return true;
}
public final boolean onAction(ItemStack stack, EntityNPC player, World world, ItemControl control, LocalPos block) {
if(control == ItemControl.SECONDARY && !world.client && block == null) {
LocalPos vec = world.getBlockTrace(player, this.getRange(stack, player));

View file

@ -19,6 +19,10 @@ public class ItemWeatherToken extends Item {
this.setDisplay("Wetterkristall (" + this.weather.getDisplay() + ")");
this.setMagnetic();
}
public boolean canBeHeld() {
return true;
}
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
{

View file

@ -16,6 +16,10 @@ public class ItemWhip extends Item
this.setMaxDamage(35);
}
public boolean canBeHeld() {
return true;
}
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityNPC playerIn)
{
if (playerIn.isRiding() && playerIn.vehicle instanceof EntityPig)

View file

@ -22,6 +22,10 @@ public class ItemBow extends Item
this.setTab(CheatTab.WEAPONS);
}
public boolean canBeHeld() {
return true;
}
/**
* Called when the player stops using an Item (stops holding the right mouse button).
*/

View file

@ -18,6 +18,10 @@ public class ItemExterminator extends Item {
this.setMagnetic();
}
public boolean canBeHeld() {
return true;
}
public ItemStack onItemRightClick(ItemStack stack, World world, EntityNPC player) {
if(!world.client && player.connection.isAdmin()) {
world.playSoundAtEntity(player, SoundEvent.CLICK, 1.0F);

View file

@ -26,6 +26,10 @@ public abstract class ItemGunBase extends Item
this.setTab(CheatTab.WEAPONS);
}
public boolean canBeHeld() {
return true;
}
@Clientside
public ItemAction getItemPosition()
{