1
0
Fork 0

change hotbar behaviour

This commit is contained in:
Sen 2025-09-04 13:58:29 +02:00
parent c10996bbda
commit 771a8bfa89
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
17 changed files with 169 additions and 114 deletions

View file

@ -1072,6 +1072,8 @@ public class Client implements IThreadListener {
this.displayTick(ExtMath.floord(this.player.posX), ExtMath.floord(this.player.posY), ExtMath.floord(this.player.posZ)); this.displayTick(ExtMath.floord(this.player.posX), ExtMath.floord(this.player.posY), ExtMath.floord(this.player.posZ));
} }
this.effectRenderer.update(); this.effectRenderer.update();
if(this.player != null && this.player.getHeldItem() == null)
this.select(1);
} }
else if (this.connection != null) else if (this.connection != null)
{ {
@ -1136,10 +1138,20 @@ public class Client implements IThreadListener {
final int selected = this.world != null && this.player != null && this.viewEntity == this.player ? this.player.getSelectedIndex() : -1; final int selected = this.world != null && this.player != null && this.viewEntity == this.player ? this.player.getSelectedIndex() : -1;
final int scale = this.scaleHotbar ? 2 : 1; final int scale = this.scaleHotbar ? 2 : 1;
final int size = this.world != null && this.player != null && this.viewEntity == this.player ? this.player.getHotbarSize() : 1; final int size = this.world != null && this.player != null && this.viewEntity == this.player ? this.player.getHotbarSize() : 1;
final int width = (this.fbX / scale - 20) / size; int total = 1;
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)
++total;
}
if(total == 0)
total = 1;
}
final int width = (this.fbX / scale - 20) / total;
// final int bx = this.fbX / 2 - size * (width >= 20 ? 10 : width / 2) * scale + 2 * scale; // final int bx = this.fbX / 2 - size * (width >= 20 ? 10 : width / 2) * scale + 2 * scale;
final int by = this.fbY - 20 * scale; final int by = this.fbY - 20 * scale;
final int xoff = (this.fbX / scale - (width < 20 ? ((size - 2) * width + 40 + width / 2) : (size * 20 - 2))) / 2 + (width < 20 && selected == 0 ? 20 - width : 0) - 2; final int xoff = (this.fbX / scale - (width < 20 ? ((total - 2) * width + 40 + width / 2) : (total * 20 - 2))) / 2 + (width < 20 && selected == 0 ? 20 - width : 0) - 2;
this.setupOverlay(); this.setupOverlay();
if(this.world != null && !(this.open instanceof GuiConsole) && this.player != null && this.viewEntity == this.player) { if(this.world != null && !(this.open instanceof GuiConsole) && this.player != null && this.viewEntity == this.player) {
if(this.open == null) { if(this.open == null) {
@ -1162,6 +1174,8 @@ public class Client implements IThreadListener {
int x = xoff * scale; int x = xoff * scale;
for(int n = 0; n < size; n++) { for(int n = 0; n < size; n++) {
if(this.player.getStackInSlot(n) == null)
continue;
if(selected == n) if(selected == n)
Drawing.drawRect(x - scale * 2, by - scale * 2, 20 * scale, 20 * scale, 0xffffffff); Drawing.drawRect(x - scale * 2, by - scale * 2, 20 * scale, 20 * scale, 0xffffffff);
InventoryButton.drawButton(this, x - scale, by - scale, 18 * scale, 18 * scale, this.scaleHotbar); InventoryButton.drawButton(this, x - scale, by - scale, 18 * scale, 18 * scale, this.scaleHotbar);
@ -1323,19 +1337,21 @@ public class Client implements IThreadListener {
GL15.glScalef(2.0f, 2.0f, 2.0f); GL15.glScalef(2.0f, 2.0f, 2.0f);
int xPos = xoff; int xPos = xoff;
int cnt = 0;
for(int index = 0; index < size; ++index) { for(int index = 0; index < size; ++index) {
ItemStack itemstack = this.player.getStackInSlot(index); ItemStack itemstack = this.player.getStackInSlot(index);
if(itemstack != null) { if(itemstack != null) {
if(width < 20 && selected != index && selected != index + 1 && index != size - 1) { 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); this.scissor(xPos * scale, this.fbY - (by + 16 * scale), (width - 1) * scale, 16 * scale);
GL15.glEnable(GL15.GL_SCISSOR_TEST); GL15.glEnable(GL15.GL_SCISSOR_TEST);
} }
GlState.enableDepth(); GlState.enableDepth();
this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0); this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, 0);
if(width < 20 && selected != index && selected != index + 1 && index != size - 1) if(width < 20 && selected != index && selected != index + 1 && cnt != total - 1)
GL15.glDisable(GL15.GL_SCISSOR_TEST); GL15.glDisable(GL15.GL_SCISSOR_TEST);
}
xPos += width >= 20 || selected == index || selected == index + 1 ? 20 : width; xPos += width >= 20 || selected == index || selected == index + 1 ? 20 : width;
++cnt;
}
} }
if(this.infoOverlay) { if(this.infoOverlay) {
@ -1372,6 +1388,7 @@ public class Client implements IThreadListener {
GuiContainer.renderItemOverlay(itemstack, GuiContainer.renderItemOverlay(itemstack,
xPos, by, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), scale); xPos, by, null, index == this.player.getSelectedIndex() ? this.controller.getUseCooldown() : 0, this.controller.getUseCooldownMax(), scale);
} }
if(itemstack != null)
xPos += (width >= 20 || selected == index || selected == index + 1 ? 20 : width) * scale; xPos += (width >= 20 || selected == index || selected == index + 1 ? 20 : width) * scale;
} }
} }
@ -1488,14 +1505,22 @@ public class Client implements IThreadListener {
public void scroll(int dir) { public void scroll(int dir) {
if(this.zooming) if(this.zooming)
this.zoomLevel = ExtMath.clampf(this.zoomLevel + (dir < 0 ? -0.25f : 0.25f), this.viewEntity != this.player ? 1.0f : 2.0f, 16.0f); this.zoomLevel = ExtMath.clampf(this.zoomLevel + (dir < 0 ? -0.25f : 0.25f), this.viewEntity != this.player ? 1.0f : 2.0f, 16.0f);
else if(this.player != null) { else if(this.player != null)
this.player.setSelectedIndex(this.player.getSelectedIndex() - dir); this.select(-dir);
}
private void select(int dir) {
int n = 0;
do {
this.player.setSelectedIndex(this.player.getSelectedIndex() + dir);
if(this.player.getSelectedIndex() < 0) if(this.player.getSelectedIndex() < 0)
this.player.setSelectedIndex(this.player.getHotbarSize() - 1); this.player.setSelectedIndex(this.player.getHotbarSize() - 1);
else if(this.player.getSelectedIndex() >= this.player.getHotbarSize()) else if(this.player.getSelectedIndex() >= this.player.getHotbarSize())
this.player.setSelectedIndex(0); this.player.setSelectedIndex(0);
this.controller.resetUseCooldown(); ++n;
} }
while(this.player.getHeldItem() == null && n < this.player.getHotbarSize());
this.controller.resetUseCooldown();
} }
public void moveCamera(float x, float y) { public void moveCamera(float x, float y) {

View file

@ -29,7 +29,7 @@ public class InventoryButton extends Element {
public static void drawButton(Client gm, int x, int y, int w, int h, boolean border) { public static void drawButton(Client gm, int x, int y, int w, int h, boolean border) {
if(border) if(border)
Drawing.drawDoubleRect(x, y, w, h, gm.style.fill_top, gm.style.fill_btm, gm.style.brdr_top, gm.style.brdr_btm); Drawing.drawGradientBorder(x, y, w, h, gm.style.fill_top, gm.style.fill_btm, 0xff000000, gm.style.brdr_top, gm.style.brdr_btm);
else else
Drawing.drawGradient(x, y, w, h, gm.style.fill_top, gm.style.fill_btm, gm.style.brdr_top, gm.style.brdr_btm); Drawing.drawGradient(x, y, w, h, gm.style.fill_top, gm.style.fill_btm, gm.style.brdr_top, gm.style.brdr_btm);
} }

View file

@ -33,7 +33,7 @@ import common.inventory.IInventory;
import common.item.CheatTab; import common.item.CheatTab;
import common.item.Item; import common.item.Item;
import common.item.ItemStack; import common.item.ItemStack;
import common.item.StackSize; import common.item.ItemWeight;
import common.model.Model; import common.model.Model;
import common.model.Model.ModelProvider; import common.model.Model.ModelProvider;
import common.model.GuiPosition; import common.model.GuiPosition;
@ -1019,7 +1019,7 @@ public class Block {
return true; return true;
} }
public StackSize getMaxAmount() { public ItemWeight getWeight() {
return null; return null;
} }

View file

@ -7,7 +7,7 @@ import common.entity.npc.EntityNPC;
import common.item.CheatTab; import common.item.CheatTab;
import common.item.Item; import common.item.Item;
import common.item.ItemStack; import common.item.ItemStack;
import common.item.StackSize; import common.item.ItemWeight;
import common.model.Model; import common.model.Model;
import common.model.Model.ModelProvider; import common.model.Model.ModelProvider;
import common.model.ModelRotation; import common.model.ModelRotation;
@ -199,8 +199,8 @@ public class BlockBed extends Block implements Rotatable {
return this.getState().withProperty(PART, EnumPartType.HEAD).withProperty(FACING, Facing.NORTH); return this.getState().withProperty(PART, EnumPartType.HEAD).withProperty(FACING, Facing.NORTH);
} }
public StackSize getMaxAmount() { public ItemWeight getWeight() {
return StackSize.S; return ItemWeight.L;
} }
public boolean place(ItemStack stack, EntityNPC playerIn, World worldIn, LocalPos pos, Facing side, float hitX, float hitY, float hitZ) public boolean place(ItemStack stack, EntityNPC playerIn, World worldIn, LocalPos pos, Facing side, float hitX, float hitY, float hitZ)

View file

@ -11,7 +11,7 @@ import common.init.Blocks;
import common.item.CheatTab; import common.item.CheatTab;
import common.item.Item; import common.item.Item;
import common.item.ItemStack; import common.item.ItemStack;
import common.item.StackSize; import common.item.ItemWeight;
import common.item.tool.ItemKey; import common.item.tool.ItemKey;
import common.model.Model; import common.model.Model;
import common.model.Model.ModelProvider; import common.model.Model.ModelProvider;
@ -299,8 +299,8 @@ public class BlockDoor extends Block implements Rotatable {
return this == Blocks.iron_door; return this == Blocks.iron_door;
} }
public StackSize getMaxAmount() { public ItemWeight getWeight() {
return StackSize.S; return ItemWeight.L;
} }
public boolean place(ItemStack stack, EntityNPC playerIn, World worldIn, LocalPos pos, Facing side, float hitX, float hitY, float hitZ) public boolean place(ItemStack stack, EntityNPC playerIn, World worldIn, LocalPos pos, Facing side, float hitX, float hitY, float hitZ)

View file

@ -9,7 +9,7 @@ import common.init.Blocks;
import common.init.Items; import common.init.Items;
import common.item.Item; import common.item.Item;
import common.item.ItemStack; import common.item.ItemStack;
import common.item.StackSize; import common.item.ItemWeight;
import common.item.tool.ItemTool; import common.item.tool.ItemTool;
import common.model.Model; import common.model.Model;
import common.model.Model.ModelProvider; import common.model.Model.ModelProvider;
@ -279,8 +279,8 @@ public class BlockDoublePlant extends BlockBush implements IGrowable
return this.getState().withProperty(HALF, EnumBlockHalf.UPPER); return this.getState().withProperty(HALF, EnumBlockHalf.UPPER);
} }
public StackSize getMaxAmount() { public ItemWeight getWeight() {
return StackSize.S; return ItemWeight.L;
} }
public static enum EnumBlockHalf implements Identifyable public static enum EnumBlockHalf implements Identifyable

View file

@ -3,7 +3,7 @@ package common.block.foliage;
import common.block.Block; import common.block.Block;
import common.block.Material; import common.block.Material;
import common.init.Blocks; import common.init.Blocks;
import common.item.StackSize; import common.item.ItemWeight;
import common.model.Model; import common.model.Model;
import common.model.Model.ModelProvider; import common.model.Model.ModelProvider;
import common.model.GuiPosition; import common.model.GuiPosition;
@ -151,8 +151,8 @@ public class BlockReed extends Block
return new Property[] {AGE}; return new Property[] {AGE};
} }
public StackSize getMaxAmount() { public ItemWeight getWeight() {
return StackSize.L; return ItemWeight.S;
} }
public GuiPosition getItemPosition() { public GuiPosition getItemPosition() {

View file

@ -5,7 +5,7 @@ import java.util.List;
import common.block.Block; import common.block.Block;
import common.block.Material; import common.block.Material;
import common.entity.Entity; import common.entity.Entity;
import common.item.StackSize; import common.item.ItemWeight;
import common.model.Model; import common.model.Model;
import common.model.Model.ModelProvider; import common.model.Model.ModelProvider;
import common.model.ModelRotation; import common.model.ModelRotation;
@ -298,8 +298,8 @@ public class BlockString extends Block
return new Property[] {TOUCHED}; return new Property[] {TOUCHED};
} }
public StackSize getMaxAmount() { public ItemWeight getWeight() {
return StackSize.XXXL; return ItemWeight.XXXS;
} }
protected Property[] getUnsavedProperties() { protected Property[] getUnsavedProperties() {

View file

@ -7,7 +7,7 @@ import java.util.Set;
import common.block.Block; import common.block.Block;
import common.block.Material; import common.block.Material;
import common.collect.Sets; import common.collect.Sets;
import common.item.StackSize; import common.item.ItemWeight;
import common.model.Model; import common.model.Model;
import common.model.Model.ModelProvider; import common.model.Model.ModelProvider;
import common.model.ModelRotation; import common.model.ModelRotation;
@ -525,8 +525,8 @@ public class BlockWire extends Block
.u("wire_line").uv(2, 2, 14, 14).noCull(); .u("wire_line").uv(2, 2, 14, 14).noCull();
} }
public StackSize getMaxAmount() { public ItemWeight getWeight() {
return StackSize.XL; return ItemWeight.XS;
} }
protected Property[] getUnsavedProperties() { protected Property[] getUnsavedProperties() {

View file

@ -22,7 +22,7 @@ import common.entity.npc.SpeciesInfo;
import common.item.CheatTab; import common.item.CheatTab;
import common.item.Item; import common.item.Item;
import common.item.ItemStack; import common.item.ItemStack;
import common.item.StackSize; import common.item.ItemWeight;
import common.item.consumable.ItemAppleGold; import common.item.consumable.ItemAppleGold;
import common.item.consumable.ItemMilkBottle; import common.item.consumable.ItemMilkBottle;
import common.item.consumable.ItemFishFood; import common.item.consumable.ItemFishFood;
@ -163,13 +163,13 @@ public abstract class ItemRegistry {
register("minecart", (new ItemMinecart()).setDisplay("Lore", "Füße zu träge? Keine Kraft mehr in den Beinen?", "Diese Lore wird dich garantiert mühelos an dein Ziel bringen!", "Hinweis: Keine Haftung bei Schäden oder spontanem Tod durch", "ungünstig platzierte Schienen oder darüber laufende Kreaturen")); register("minecart", (new ItemMinecart()).setDisplay("Lore", "Füße zu träge? Keine Kraft mehr in den Beinen?", "Diese Lore wird dich garantiert mühelos an dein Ziel bringen!", "Hinweis: Keine Haftung bei Schäden oder spontanem Tod durch", "ungünstig platzierte Schienen oder darüber laufende Kreaturen"));
for(EntityInfo egg : EntityRegistry.DNA.values()) { for(EntityInfo egg : EntityRegistry.DNA.values()) {
register("dna_sample_" + egg.id().toLowerCase(), (new ItemMobTemplate(egg.id())) register("dna_sample_" + egg.id().toLowerCase(), (new ItemMobTemplate(egg.id()))
.setMaxAmount(StackSize.L)); .setWeight(ItemWeight.S));
} }
for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) { for(SpeciesInfo species : SpeciesRegistry.SPECIMEN) {
for(CharacterInfo charinfo : species.chars) { for(CharacterInfo charinfo : species.chars) {
if(charinfo.dna) if(charinfo.dna)
register("dna_sample_" + charinfo.skin, (new ItemCharTemplate(charinfo)) register("dna_sample_" + charinfo.skin, (new ItemCharTemplate(charinfo))
.setMaxAmount(StackSize.L)); .setWeight(ItemWeight.S));
} }
} }
@ -178,16 +178,16 @@ public abstract class ItemRegistry {
register("trident", (new ItemTrident()).setDisplay("Geladenes Zepter")); register("trident", (new ItemTrident()).setDisplay("Geladenes Zepter"));
register("banhammer", (new ItemBanHammer()).setDisplay("Hammer der Verbannung")); register("banhammer", (new ItemBanHammer()).setDisplay("Hammer der Verbannung"));
ItemKey key; ItemKey key;
register("key", (key = new ItemKey()).setDisplay("Schlüssel").setTab(CheatTab.TOOLS).setMaxAmount(StackSize.L)); register("key", (key = new ItemKey()).setDisplay("Schlüssel").setTab(CheatTab.TOOLS).setWeight(ItemWeight.S));
register("black_key", (new ItemKey()).setDisplay("Schwarzer Schlüssel").setTab(CheatTab.TOOLS).setMaxAmount(StackSize.L)); register("black_key", (new ItemKey()).setDisplay("Schwarzer Schlüssel").setTab(CheatTab.TOOLS).setWeight(ItemWeight.S));
register("shiny_key", (new ItemKey()).setDisplay("Glänzender Schlüssel").setTab(CheatTab.TOOLS).setMaxAmount(StackSize.L)); register("shiny_key", (new ItemKey()).setDisplay("Glänzender Schlüssel").setTab(CheatTab.TOOLS).setWeight(ItemWeight.S));
register("rusty_key", (new ItemKey()).setDisplay("Rostiger Schlüssel").setTab(CheatTab.TOOLS).setMaxAmount(StackSize.L)); register("rusty_key", (new ItemKey()).setDisplay("Rostiger Schlüssel").setTab(CheatTab.TOOLS).setWeight(ItemWeight.S));
register("red_keycard", (new ItemKey()).setDisplay("Rote Schlüsselkarte").setTab(CheatTab.TOOLS).setMaxAmount(StackSize.L)); register("red_keycard", (new ItemKey()).setDisplay("Rote Schlüsselkarte").setTab(CheatTab.TOOLS).setWeight(ItemWeight.S));
register("green_keycard", (new ItemKey()).setDisplay("Grüne Schlüsselkarte").setTab(CheatTab.TOOLS).setMaxAmount(StackSize.L)); register("green_keycard", (new ItemKey()).setDisplay("Grüne Schlüsselkarte").setTab(CheatTab.TOOLS).setWeight(ItemWeight.S));
register("blue_keycard", (new ItemKey()).setDisplay("Blaue Schlüsselkarte").setTab(CheatTab.TOOLS).setMaxAmount(StackSize.L)); register("blue_keycard", (new ItemKey()).setDisplay("Blaue Schlüsselkarte").setTab(CheatTab.TOOLS).setWeight(ItemWeight.S));
register("black_keycard", (new ItemKey()).setDisplay("Schwarze Schlüsselkarte").setTab(CheatTab.TOOLS).setMaxAmount(StackSize.L)); register("black_keycard", (new ItemKey()).setDisplay("Schwarze Schlüsselkarte").setTab(CheatTab.TOOLS).setWeight(ItemWeight.S));
for(Pair<Integer, Color> sides : ItemDie.DIE_SIDES) { for(Pair<Integer, Color> sides : ItemDie.DIE_SIDES) {
register("die_" + sides.first(), (new ItemDie(sides.first(), sides.second())).setMaxAmount(StackSize.L)); register("die_" + sides.first(), (new ItemDie(sides.first(), sides.second())).setWeight(ItemWeight.S));
} }
register("chick_magnet", (new ItemMagnet(true)).setDisplay("Kükenmagnet")); register("chick_magnet", (new ItemMagnet(true)).setDisplay("Kükenmagnet"));
register("magnet", (new ItemMagnet(false)).setDisplay("Magnet")); register("magnet", (new ItemMagnet(false)).setDisplay("Magnet"));
@ -201,20 +201,20 @@ public abstract class ItemRegistry {
register("burning_soul", (new ItemFire(Blocks.soul_fire)).setDisplay("Brennende Seele")); register("burning_soul", (new ItemFire(Blocks.soul_fire)).setDisplay("Brennende Seele"));
register("dark_lighter", (new ItemFire(Blocks.black_fire)).setDisplay("Verdunkelndes Feuerzeug")); register("dark_lighter", (new ItemFire(Blocks.black_fire)).setDisplay("Verdunkelndes Feuerzeug"));
register("hoe", (new ItemHoe()).setDisplay("Hacke")); register("hoe", (new ItemHoe()).setDisplay("Hacke"));
register("apple", (new ItemFood(4, false)).setDisplay("Apfel").setMaxAmount(StackSize.L)); register("apple", (new ItemFood(4, false)).setDisplay("Apfel").setWeight(ItemWeight.S));
register("bow", (new ItemBow()).setDisplay("Bogen")); register("bow", (new ItemBow()).setDisplay("Bogen"));
register("boltgun", (new ItemBoltgun()).setDisplay("Bolter")); register("boltgun", (new ItemBoltgun()).setDisplay("Bolter"));
register("bolt", (new ItemAmmo(5, 1.0f, StackSize.L)).setDisplay("Bolter-Munition")); register("bolt", (new ItemAmmo(5, 1.0f, ItemWeight.S)).setDisplay("Bolter-Munition"));
register("rocket_launcher", (new ItemRocketLauncher()).setDisplay("Raketenwerfer")); register("rocket_launcher", (new ItemRocketLauncher()).setDisplay("Raketenwerfer"));
register("rocket", (new ItemAmmo(6, 6.0f, StackSize.L)).setDisplay("Rakete").setExplosive(4)); register("rocket", (new ItemAmmo(6, 6.0f, ItemWeight.S)).setDisplay("Rakete").setExplosive(4));
register("arrow", (new ItemArrow()).setDisplay("Pfeil").setTab(CheatTab.WEAPONS).setMaxAmount(StackSize.L)); register("arrow", (new ItemArrow()).setDisplay("Pfeil").setTab(CheatTab.WEAPONS).setWeight(ItemWeight.S));
register("charcoal", (new Item()).setDisplay("Holzkohle").setTab(CheatTab.METALS).setFuelAmount(1200)); register("charcoal", (new Item()).setDisplay("Holzkohle").setTab(CheatTab.METALS).setFuelAmount(1200));
register("stick", (new Item()).setDisplay("Stock").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XL).setFuelAmount(100)); register("stick", (new Item()).setDisplay("Stock").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XS).setFuelAmount(100));
register("feather", (new Item()).setDisplay("Feder").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XXL)); register("feather", (new Item()).setDisplay("Feder").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XXS));
register("gunpowder", (new Item()).setDisplay("Schwarzpulver").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XL).setExplosive(1)); register("gunpowder", (new Item()).setDisplay("Schwarzpulver").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XS).setExplosive(1));
register("wheat", (new Item()).setDisplay("Weizen").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.L)); register("wheat", (new Item()).setDisplay("Weizen").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("bread", (new ItemFood(5, false)).setDisplay("Brot")); register("bread", (new ItemFood(5, false)).setDisplay("Brot"));
register("flint", (new Item()).setDisplay("Feuerstein").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.L)); register("flint", (new Item()).setDisplay("Feuerstein").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("porkchop", (new ItemFood(3, true)).setDisplay("Rohes Schweinefleisch")); register("porkchop", (new ItemFood(3, true)).setDisplay("Rohes Schweinefleisch"));
register("cooked_porkchop", (new ItemFood(8, true)).setDisplay("Gebratenes Schweinefleisch")); register("cooked_porkchop", (new ItemFood(8, true)).setDisplay("Gebratenes Schweinefleisch"));
register("golden_apple", (new ItemAppleGold(4, false)).setPotionEffect(Effect.REGENERATION, 5, 1, 1.0F) register("golden_apple", (new ItemAppleGold(4, false)).setPotionEffect(Effect.REGENERATION, 5, 1, 1.0F)
@ -222,19 +222,19 @@ public abstract class ItemRegistry {
register("charged_apple", (new ItemAppleGold(4, true)).setPotionEffect(Effect.REGENERATION, 5, 1, 1.0F) register("charged_apple", (new ItemAppleGold(4, true)).setPotionEffect(Effect.REGENERATION, 5, 1, 1.0F)
.setDisplay("Geladener Apfel").setExplosive(3)); .setDisplay("Geladener Apfel").setExplosive(3));
register("saddle", (new ItemSaddle()).setDisplay("Sattel")); register("saddle", (new ItemSaddle()).setDisplay("Sattel"));
register("snowball", (new ItemSnowball()).setDisplay("Schneeball").setMaxAmount(StackSize.L)); register("snowball", (new ItemSnowball()).setDisplay("Schneeball").setWeight(ItemWeight.S));
register("leather", (new Item()).setDisplay("Leder").setTab(CheatTab.MATERIALS)); register("leather", (new Item()).setDisplay("Leder").setTab(CheatTab.MATERIALS));
register("brick", (new Item()).setDisplay("Ziegel").setTab(CheatTab.MATERIALS)); register("brick", (new Item()).setDisplay("Ziegel").setTab(CheatTab.MATERIALS));
register("clay_lump", (new Item()).setDisplay("Ton").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.L)); register("clay_lump", (new Item()).setDisplay("Ton").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("paper", (new Item()).setDisplay("Papier").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XL).setDefaultColor(0xffffff).setFuelAmount(40)); register("paper", (new Item()).setDisplay("Papier").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XS).setDefaultColor(0xffffff).setFuelAmount(40));
register("book", (new ItemBook()).setDisplay("Buch").setTab(CheatTab.MATERIALS).setFuelAmount(60)); register("book", (new ItemBook()).setDisplay("Buch").setTab(CheatTab.MATERIALS).setFuelAmount(60));
register("slime_blob", (new Item()).setDisplay("Schleim").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.L)); register("slime_blob", (new Item()).setDisplay("Schleim").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("egg", (new ItemEgg()).setDisplay("Ei").setMaxAmount(StackSize.L)); register("egg", (new ItemEgg()).setDisplay("Ei").setWeight(ItemWeight.S));
register("navigator", (new ItemSpaceNavigator()).setDisplay("Elektronischer Navigator").setTab(CheatTab.TOOLS)); register("navigator", (new ItemSpaceNavigator()).setDisplay("Elektronischer Navigator").setTab(CheatTab.TOOLS));
register("exterminator", (new ItemExterminator()).setDisplay("Weltenzerstörer")); register("exterminator", (new ItemExterminator()).setDisplay("Weltenzerstörer"));
register("fishing_rod", (new ItemFishingRod()).setDisplay("Angel")); register("fishing_rod", (new ItemFishingRod()).setDisplay("Angel"));
register("glowing_powder", (new Item()).setDisplay("Glühender Staub") register("glowing_powder", (new Item()).setDisplay("Glühender Staub")
.setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XL).setFuelAmount(600)); .setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XS).setFuelAmount(600));
for(ItemFishFood.FishType type : ItemFishFood.FishType.values()) { for(ItemFishFood.FishType type : ItemFishFood.FishType.values()) {
register(type.getName(), (new ItemFishFood(false, type))); register(type.getName(), (new ItemFishFood(false, type)));
register("cooked_" + type.getName(), (new ItemFishFood(true, type))); register("cooked_" + type.getName(), (new ItemFishFood(true, type)));
@ -242,9 +242,9 @@ public abstract class ItemRegistry {
for(Color color : Color.values()) { for(Color color : Color.values()) {
register(color.getName() + "_dye", new ItemDye(color)); register(color.getName() + "_dye", new ItemDye(color));
} }
register("bone", (new Item()).setDisplay("Knochen").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.L)); register("bone", (new Item()).setDisplay("Knochen").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.S));
register("sugar", (new Item()).setDisplay("Zucker").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XXL)); register("sugar", (new Item()).setDisplay("Zucker").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XXS));
register("cookie", (new ItemFood(2, false)).setDisplay("Keks").setMaxAmount(StackSize.L)); register("cookie", (new ItemFood(2, false)).setDisplay("Keks").setWeight(ItemWeight.S));
register("melon", (new ItemFood(2, false)).setDisplay("Melone")); register("melon", (new ItemFood(2, false)).setDisplay("Melone"));
register("beef", (new ItemFood(3, true)).setDisplay("Rohes Rindfleisch")); register("beef", (new ItemFood(3, true)).setDisplay("Rohes Rindfleisch"));
register("cooked_beef", (new ItemFood(8, true)).setDisplay("Steak")); register("cooked_beef", (new ItemFood(8, true)).setDisplay("Steak"));
@ -252,9 +252,9 @@ public abstract class ItemRegistry {
register("cooked_chicken", (new ItemFood(6, true)).setDisplay("Gebratenes Hühnchen")); register("cooked_chicken", (new ItemFood(6, true)).setDisplay("Gebratenes Hühnchen"));
register("rotten_flesh", (new ItemFood(4, true)).setDisplay("Verrottetes Fleisch")); register("rotten_flesh", (new ItemFood(4, true)).setDisplay("Verrottetes Fleisch"));
register("orb", (new Item()).setDisplay("Kugel").setTab(CheatTab.MAGIC).setFragile()); register("orb", (new Item()).setDisplay("Kugel").setTab(CheatTab.MAGIC).setFragile());
register("demon_rod", (new Item()).setDisplay("Dämonenrute").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XL).setFuelAmount(2400)); register("demon_rod", (new Item()).setDisplay("Dämonenrute").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XS).setFuelAmount(2400));
register("gold_coin", (new Item()).setDisplay("Goldmünze").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XL)); register("gold_coin", (new Item()).setDisplay("Goldmünze").setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XS));
register("gold_nugget", (new Item()).setDisplay("Goldnugget").setTab(CheatTab.METALS).setMaxAmount(StackSize.XL)); register("gold_nugget", (new Item()).setDisplay("Goldnugget").setTab(CheatTab.METALS).setWeight(ItemWeight.XS));
Item bottle; Item bottle;
register("bottle", (bottle = new ItemBottle()).setDisplay("Flasche")); register("bottle", (bottle = new ItemBottle()).setDisplay("Flasche"));
for(Pair<String, Effect> pot : ItemPotion.getBasePotions()) { for(Pair<String, Effect> pot : ItemPotion.getBasePotions()) {
@ -265,22 +265,22 @@ public abstract class ItemRegistry {
} }
register("milk_bottle", (new ItemMilkBottle()).setDisplay("Flasche mit Milch").setContainerItem(bottle)); register("milk_bottle", (new ItemMilkBottle()).setDisplay("Flasche mit Milch").setContainerItem(bottle));
register("eye", (new ItemFood(2, false)).setPotionEffect(Effect.POISON, 5, 0, 1.0F).setDisplay("Auge") register("eye", (new ItemFood(2, false)).setPotionEffect(Effect.POISON, 5, 0, 1.0F).setDisplay("Auge")
.setMaxAmount(StackSize.L)); .setWeight(ItemWeight.S));
register("blazing_powder", (new Item()).setDisplay("Schillernder Staub") register("blazing_powder", (new Item()).setDisplay("Schillernder Staub")
.setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XL).setFuelAmount(600)); .setTab(CheatTab.MATERIALS).setWeight(ItemWeight.XS).setFuelAmount(600));
register("charged_orb", (new ItemChargedOrb()).setDisplay("Geladene Kugel")); register("charged_orb", (new ItemChargedOrb()).setDisplay("Geladene Kugel"));
register("fireball", (new ItemFireball()).setDisplay("Feuerkugel").setFuelAmount(1000)); register("fireball", (new ItemFireball()).setDisplay("Feuerkugel").setFuelAmount(1000));
register("cocoa_powder", new Item().setTab(CheatTab.MATERIALS).setDisplay("Gemahlene Kakaobohnen").setMaxAmount(StackSize.L)); register("cocoa_powder", new Item().setTab(CheatTab.MATERIALS).setDisplay("Gemahlene Kakaobohnen").setWeight(ItemWeight.S));
register("grinded_bones", new ItemGrindedBones().setTab(CheatTab.MATERIALS).setDisplay("Gemahlene Knochen").setMaxAmount(StackSize.L)); register("grinded_bones", new ItemGrindedBones().setTab(CheatTab.MATERIALS).setDisplay("Gemahlene Knochen").setWeight(ItemWeight.S));
register("ink_sack", new Item().setTab(CheatTab.MATERIALS).setDisplay("Tintenbeutel").setMaxAmount(StackSize.L)); register("ink_sack", new Item().setTab(CheatTab.MATERIALS).setDisplay("Tintenbeutel").setWeight(ItemWeight.S));
register("carrot", new ItemSeedFood(3, Blocks.carrots, Blocks.farmland).setDisplay("Karotte").setMaxAmount(StackSize.L)); register("carrot", new ItemSeedFood(3, Blocks.carrots, Blocks.farmland).setDisplay("Karotte").setWeight(ItemWeight.S));
register("potato", new ItemSeedFood(1, Blocks.potatoes, Blocks.farmland).setDisplay("Kartoffel").setMaxAmount(StackSize.L)); register("potato", new ItemSeedFood(1, Blocks.potatoes, Blocks.farmland).setDisplay("Kartoffel").setWeight(ItemWeight.S));
register("wheat_seed", new ItemSeeds(Blocks.wheats, Blocks.farmland).setDisplay("Weizenkörner").setMaxAmount(StackSize.XL)); register("wheat_seed", new ItemSeeds(Blocks.wheats, Blocks.farmland).setDisplay("Weizenkörner").setWeight(ItemWeight.XS));
register("soul_seed", new ItemSeeds(Blocks.soul_grass, Blocks.soul_sand).setDisplay("Seelenwarze").setMaxAmount(StackSize.L)); register("soul_seed", new ItemSeeds(Blocks.soul_grass, Blocks.soul_sand).setDisplay("Seelenwarze").setWeight(ItemWeight.S));
register("pumpkin_seed", new ItemSeeds(Blocks.pumpkin_stem, Blocks.farmland).setDisplay("Kürbiskerne").setMaxAmount(StackSize.XL)); register("pumpkin_seed", new ItemSeeds(Blocks.pumpkin_stem, Blocks.farmland).setDisplay("Kürbiskerne").setWeight(ItemWeight.XS));
register("melon_seed", new ItemSeeds(Blocks.melon_stem, Blocks.farmland).setDisplay("Melonenkerne").setMaxAmount(StackSize.XL)); register("melon_seed", new ItemSeeds(Blocks.melon_stem, Blocks.farmland).setDisplay("Melonenkerne").setWeight(ItemWeight.XS));
register("whip", (new ItemWhip()).setDisplay("Peitsche")); register("whip", (new ItemWhip()).setDisplay("Peitsche"));
register("charge_crystal", (new Item()).setDisplay("Energiekristall").setTab(CheatTab.MATERIALS).setColor(Color.DARK_MAGENTA).setFuelAmount(120000)); register("charge_crystal", (new Item()).setDisplay("Energiekristall").setTab(CheatTab.MATERIALS).setColor(Color.DARK_MAGENTA).setFuelAmount(120000));
@ -294,7 +294,7 @@ public abstract class ItemRegistry {
} }
register("bloodbrick", (new Item()).setDisplay("Blutroter Ziegel").setTab(CheatTab.MATERIALS)); register("bloodbrick", (new Item()).setDisplay("Blutroter Ziegel").setTab(CheatTab.MATERIALS));
register("blackbrick", (new Item()).setDisplay("Schwarzer Ziegel").setTab(CheatTab.MATERIALS)); register("blackbrick", (new Item()).setDisplay("Schwarzer Ziegel").setTab(CheatTab.MATERIALS));
register("lead", (new ItemLead()).setDisplay("Leine").setMaxAmount(StackSize.L)); register("lead", (new ItemLead()).setDisplay("Leine").setWeight(ItemWeight.S));
register("name_tag", (new ItemNameTag()).setDisplay("Namensschild")); register("name_tag", (new ItemNameTag()).setDisplay("Namensschild"));
for(int z = 0; z < ItemDynamite.DYNAMITE.length; z++) { for(int z = 0; z < ItemDynamite.DYNAMITE.length; z++) {
register("dynamite" + (z == 0 ? "" : ("_" + z)), (new ItemDynamite(z)).setDisplay("Dynamit" + Util.getTierSuffix(z)).setColor(Color.RED)); register("dynamite" + (z == 0 ? "" : ("_" + z)), (new ItemDynamite(z)).setDisplay("Dynamit" + Util.getTierSuffix(z)).setColor(Color.RED));

View file

@ -25,7 +25,8 @@ import common.world.World;
public class Item { public class Item {
private final Block block; private final Block block;
private int maxAmount = StackSize.M.getAmount(); private boolean stackable = true;
private int weight = ItemWeight.M.getWeight();
private int maxDamage = 0; private int maxDamage = 0;
private Item containerItem; private Item containerItem;
private String display; private String display;
@ -48,8 +49,8 @@ public class Item {
this.setTab(this.block.getTab()); this.setTab(this.block.getTab());
if(this.block.isMagnetic()) if(this.block.isMagnetic())
this.setMagnetic(); this.setMagnetic();
if(this.block.getMaxAmount() != null) if(this.block.getWeight() != null)
this.setMaxAmount(this.block.getMaxAmount()); this.setWeight(this.block.getWeight());
if(this.block.getItemColor() != null) if(this.block.getItemColor() != null)
this.setColor(this.block.getItemColor()); this.setColor(this.block.getItemColor());
if(this.block.getExplosive() > 0) if(this.block.getExplosive() > 0)
@ -59,19 +60,22 @@ public class Item {
} }
public final Item setUnstackable() { public final Item setUnstackable() {
this.maxAmount = 1; this.stackable = false;
this.maxDamage = 0; this.maxDamage = 0;
return this; return this;
} }
public final Item setMaxAmount(StackSize size) { public final Item setWeight(int weight) {
this.maxAmount = size.getAmount(); this.weight = weight;
this.maxDamage = 0;
return this; return this;
} }
public final Item setWeight(ItemWeight size) {
return this.setWeight(size.getWeight());
}
public final Item setMaxDamage(int max) { public final Item setMaxDamage(int max) {
this.maxAmount = 1; this.stackable = false;
this.maxDamage = max; this.maxDamage = max;
return this; return this;
} }
@ -128,7 +132,7 @@ public class Item {
} }
public final int getMaxAmount() { public final int getMaxAmount() {
return this.maxAmount; return this.stackable ? 67108864 : 1;
} }
public final int getMaxDamage() { public final int getMaxDamage() {

View file

@ -21,6 +21,24 @@ import common.util.Color;
import common.util.Equipment; import common.util.Equipment;
public final class ItemStack { public final class ItemStack {
public class ItemKey {
public ItemStack getStack() {
return ItemStack.this;
}
public int hashCode() {
return ItemStack.this.item.hashCode();
}
public boolean equals(Object other) {
if(other == this)
return true;
if(other instanceof ItemKey key)
return ItemStack.this == key.getStack() || (ItemStack.this.isStackable() && key.getStack().isStackable() && ItemStack.this.itemEquals(key.getStack()) && ItemStack.this.dataEquals(key.getStack()));
return false;
}
}
private Item item; private Item item;
private int size; private int size;
private String name; private String name;
@ -28,6 +46,7 @@ public final class ItemStack {
private int damage; private int damage;
private int repairCost; private int repairCost;
private Map<Enchantment, Integer> enchantments; private Map<Enchantment, Integer> enchantments;
private ItemKey key;
public static ItemStack readFromTag(TagObject tag) { public static ItemStack readFromTag(TagObject tag) {
Item item = tag.hasString("id") ? ItemRegistry.byName(tag.getString("id")) : null; Item item = tag.hasString("id") ? ItemRegistry.byName(tag.getString("id")) : null;
@ -410,4 +429,10 @@ public final class ItemStack {
public void damage(int amount, EntityLiving entity) { public void damage(int amount, EntityLiving entity) {
this.damage(amount, entity, entity.getRNG()); this.damage(amount, entity, entity.getRNG());
} }
public ItemKey getKey() {
if(this.key == null)
this.key = new ItemKey();
return this.key;
}
} }

View file

@ -0,0 +1,23 @@
package common.item;
public enum ItemWeight {
XXXL(100),
XXL(70),
XL(35),
L(20),
M(10),
S(6),
XS(4),
XXS(2),
XXXS(1);
private final int amount;
private ItemWeight(int amount) {
this.amount = amount;
}
public int getWeight() {
return this.amount;
}
}

View file

@ -1,22 +0,0 @@
package common.item;
public enum StackSize {
XXS(8),
XS(16),
S(32),
M(64),
L(128),
XL(256),
XXL(512),
XXXL(1024);
private final int amount;
private StackSize(int amount) {
this.amount = amount;
}
public int getAmount() {
return this.amount;
}
}

View file

@ -15,7 +15,7 @@ import common.item.Item;
import common.item.ItemAction; import common.item.ItemAction;
import common.item.ItemControl; import common.item.ItemControl;
import common.item.ItemStack; import common.item.ItemStack;
import common.item.StackSize; import common.item.ItemWeight;
import common.tileentity.TileEntity; import common.tileentity.TileEntity;
import common.util.LocalPos; import common.util.LocalPos;
import common.util.Clientside; import common.util.Clientside;
@ -72,7 +72,7 @@ public class ItemPotion extends Item
{ {
this.type = type; this.type = type;
this.effect = effect; this.effect = effect;
this.setMaxAmount(StackSize.XS); this.setWeight(ItemWeight.XL);
this.setTab(CheatTab.POTIONS); this.setTab(CheatTab.POTIONS);
this.setColor(Color.ORK); this.setColor(Color.ORK);
this.setDisplay(getDisplay(this)); this.setDisplay(getDisplay(this));

View file

@ -10,7 +10,7 @@ import common.init.Blocks;
import common.item.CheatTab; import common.item.CheatTab;
import common.item.Item; import common.item.Item;
import common.item.ItemStack; import common.item.ItemStack;
import common.item.StackSize; import common.item.ItemWeight;
import common.util.LocalPos; import common.util.LocalPos;
import common.util.Facing; import common.util.Facing;
import common.util.Color; import common.util.Color;
@ -31,7 +31,7 @@ public class ItemDye extends Item {
this.color = color; this.color = color;
this.setTab(CheatTab.MATERIALS); this.setTab(CheatTab.MATERIALS);
this.setDisplay(color.getSubject(1) + " Farbstoff"); this.setDisplay(color.getSubject(1) + " Farbstoff");
this.setMaxAmount(StackSize.XXL); this.setWeight(ItemWeight.XXS);
DIES[this.color.ordinal()] = this; DIES[this.color.ordinal()] = this;
} }

View file

@ -3,14 +3,14 @@ package common.item.weapon;
import common.item.CheatTab; import common.item.CheatTab;
import common.item.Item; import common.item.Item;
import common.item.ItemStack; import common.item.ItemStack;
import common.item.StackSize; import common.item.ItemWeight;
public class ItemAmmo extends Item { public class ItemAmmo extends Item {
private final int damage; private final int damage;
private final float explosion; private final float explosion;
public ItemAmmo(int damage, float explosion, StackSize stack) { public ItemAmmo(int damage, float explosion, ItemWeight stack) {
this.setMaxAmount(stack); this.setWeight(stack);
this.setTab(CheatTab.WEAPONS); this.setTab(CheatTab.WEAPONS);
this.setMagnetic(); this.setMagnetic();
this.damage = damage; this.damage = damage;