From 83f66723c9313c2589f7f4321cee97489ddedb0b Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 12 Jun 2025 13:50:50 +0200 Subject: [PATCH] remove xp usage --- .../java/client/gui/container/GuiEnchant.java | 18 +- .../java/client/gui/container/GuiRepair.java | 2 +- .../common/enchantment/EnchantmentHelper.java | 4 +- .../common/enchantment/RngEnchantment.java | 21 +- .../java/common/entity/npc/EntityNPC.java | 133 +++------- .../main/java/common/inventory/Container.java | 8 - .../inventory/ContainerEnchantment.java | 239 ++++++------------ .../common/inventory/ContainerRepair.java | 5 +- .../java/common/item/ItemEnchantedBook.java | 10 +- .../src/main/java/common/item/ItemStack.java | 3 + .../src/main/java/server/network/Player.java | 12 +- 11 files changed, 159 insertions(+), 296 deletions(-) diff --git a/client/src/main/java/client/gui/container/GuiEnchant.java b/client/src/main/java/client/gui/container/GuiEnchant.java index 837bb02..95a32b9 100755 --- a/client/src/main/java/client/gui/container/GuiEnchant.java +++ b/client/src/main/java/client/gui/container/GuiEnchant.java @@ -88,14 +88,14 @@ public class GuiEnchant extends GuiContainer */ public void drawGuiContainerBackgroundLayer() { - this.nameRand.setSeed((long)this.container.xpSeed); + this.nameRand.setSeed((long)this.container.seed); for (int l = 0; l < 3; ++l) { int i1 = 60; int j1 = i1 + 20; String s = this.getRandomName(); - int l1 = this.container.enchantLevels[l]; + int l1 = this.container.mana[l]; if (l1 == 0) { @@ -106,7 +106,7 @@ public class GuiEnchant extends GuiContainer String s1 = "" + l1; int i2 = 6839882; - if (/* (k < l + 1 || */ this.gm.player.experienceLevel < l1) // && !this.gm.thePlayer.creative) + if (/* (k < l + 1 || */ this.gm.player.getManaPoints() < l1) // && !this.gm.thePlayer.creative) { this.rect(i1, 14 + 19 * l, 108, 19, 0x400000); this.rect(i1 + 1, 15 + 19 * l, 16, 16, 0x200000); @@ -149,8 +149,8 @@ public class GuiEnchant extends GuiContainer for (int j = 0; j < 3; ++j) { - int k = this.container.enchantLevels[j]; - int l = this.container.enchantmentIds[j]; + int k = this.container.mana[j]; + int l = this.container.ids[j]; int i1 = j + 1; if (this.isPointInRegion(60, 14 + 19 * j, 108, 17, mouseX, mouseY) && k > 0 && l >= 0) @@ -170,9 +170,9 @@ public class GuiEnchant extends GuiContainer // sb.append("\n"); // } - if (this.gm.player.experienceLevel < k) + if (this.gm.player.getManaPoints() < k) { - sb.append((sb.length() != 0 ? "\n" : "") + TextColor.RED + String.format("Erfahrungsstufe %d erforderlich", this.container.enchantLevels[j])); + sb.append((sb.length() != 0 ? "\n" : "") + TextColor.RED + String.format("%d Mana erforderlich", this.container.mana[j])); } else { @@ -198,11 +198,11 @@ public class GuiEnchant extends GuiContainer if (i1 == 1) { - s1 = "1 Erfahrungsstufe"; + s1 = "1 Manapunkt"; } else { - s1 = String.format("%d Erfahrungsstufen", i1); + s1 = String.format("%d Manapunkte", i1); } sb.append((sb.length() != 0 ? "\n" : "") + TextColor.LGRAY.toString() + "" + s1); diff --git a/client/src/main/java/client/gui/container/GuiRepair.java b/client/src/main/java/client/gui/container/GuiRepair.java index 2d7dfb7..b8257bc 100755 --- a/client/src/main/java/client/gui/container/GuiRepair.java +++ b/client/src/main/java/client/gui/container/GuiRepair.java @@ -68,7 +68,7 @@ public class GuiRepair extends GuiContainer implements ICrafting { int i = 8453920; boolean flag = true; - String s = String.format("Erfahrungskosten: %d", this.anvil.maximumCost); + String s = String.format("Manakosten: %d", this.anvil.maximumCost); if (this.anvil.maximumCost >= 40) // && !this.gm.thePlayer.creative) { diff --git a/common/src/main/java/common/enchantment/EnchantmentHelper.java b/common/src/main/java/common/enchantment/EnchantmentHelper.java index 6eea03a..4f99682 100755 --- a/common/src/main/java/common/enchantment/EnchantmentHelper.java +++ b/common/src/main/java/common/enchantment/EnchantmentHelper.java @@ -398,7 +398,7 @@ public class EnchantmentHelper } else { - p_77504_1_.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel); + p_77504_1_.addEnchantment(enchantmentdata.enchantment, enchantmentdata.level); } } } @@ -451,7 +451,7 @@ public class EnchantmentHelper for (RngEnchantment enchantmentdata1 : list) { - if (!enchantmentdata1.enchantmentobj.canApplyTogether(Enchantment.getEnchantmentById(integer.intValue()))) + if (!enchantmentdata1.enchantment.canApplyTogether(Enchantment.getEnchantmentById(integer.intValue()))) { flag = false; break; diff --git a/common/src/main/java/common/enchantment/RngEnchantment.java b/common/src/main/java/common/enchantment/RngEnchantment.java index d517860..d2ba1ad 100755 --- a/common/src/main/java/common/enchantment/RngEnchantment.java +++ b/common/src/main/java/common/enchantment/RngEnchantment.java @@ -2,18 +2,13 @@ package common.enchantment; import common.rng.RngItem; -public class RngEnchantment extends RngItem -{ - /** Enchantment object associated with this EnchantmentData */ - public final Enchantment enchantmentobj; +public class RngEnchantment extends RngItem { + public final Enchantment enchantment; + public final int level; - /** Enchantment level associated with this EnchantmentData */ - public final int enchantmentLevel; - - public RngEnchantment(Enchantment enchantmentObj, int enchLevel) - { - super(enchantmentObj.getWeight()); - this.enchantmentobj = enchantmentObj; - this.enchantmentLevel = enchLevel; - } + public RngEnchantment(Enchantment enchantment, int level) { + super(enchantment.getWeight()); + this.enchantment = enchantment; + this.level = level; + } } diff --git a/common/src/main/java/common/entity/npc/EntityNPC.java b/common/src/main/java/common/entity/npc/EntityNPC.java index 30de48f..dae3ff5 100755 --- a/common/src/main/java/common/entity/npc/EntityNPC.java +++ b/common/src/main/java/common/entity/npc/EntityNPC.java @@ -33,7 +33,6 @@ import common.entity.EntityType; import common.entity.animal.EntityDragonPart; import common.entity.animal.EntityHorse; import common.entity.animal.EntityPig; -import common.entity.item.EntityBoat; import common.entity.item.EntityCart; import common.entity.item.EntityItem; import common.entity.projectile.EntityArrow; @@ -209,11 +208,10 @@ public abstract class EntityNPC extends EntityLiving public double chasingPosZ; private WorldPos originPos = new WorldPos(0, 64, 0, Space.INSTANCE.getDimensionId()); private WorldPos spawnPos; -// private BlockPos startMinecartRidingCoordinate; public int experienceLevel; public int experienceTotal; public float experience; - protected int xpSeed; + protected int enchSeed; private ItemStack itemInUse; private int itemInUseCount; protected float speedInAir = 0.02F; @@ -246,8 +244,7 @@ public abstract class EntityNPC extends EntityLiving public float prevRenderArmPitch; private int horseJumpPowerCounter; private float horseJumpPower; -// public float nausea; -// public float prevNausea; + private long movedDistance; public EntityNPC(World worldIn) { @@ -2843,20 +2840,8 @@ public abstract class EntityNPC extends EntityLiving this.connection.resetLastExperience(); } - public void removeExperienceLevel(int levels) { - this.experienceLevel -= levels; - - if (this.experienceLevel < 0) - { - this.experienceLevel = 0; - this.experience = 0.0F; - this.experienceTotal = 0; - } - - this.xpSeed = this.rand.intv(); -// super.removeExperienceLevel(levels); - if(this.connection != null) - this.connection.resetLastExperience(); + public void updateEnchSeed() { + this.enchSeed = this.rand.intv(); } public void onDeath(DamageSource cause) { @@ -2920,15 +2905,13 @@ public abstract class EntityNPC extends EntityLiving super.updateFallState(y, onGroundIn, blockIn, pos); } - public void addStat(int amount) { -// if(this.connection != null) -// this.connection.addStat(amount); + public void addMoved(int amount) { + this.movedDistance += (long)amount; + } + + public long getMovedDistance() { + return this.movedDistance; } - -// public void removeStat(StatBase stat) { -// if(this.connection != null) -// this.connection.removeStat(stat); -// } protected void onItemUseFinish() { if(this.connection != null) @@ -3158,7 +3141,7 @@ public abstract class EntityNPC extends EntityLiving super.updateRidden(); this.prevCameraYaw = this.cameraYaw; this.cameraYaw = 0.0F; - this.addMountedMovementStat(this.posX - d0, this.posY - d1, this.posZ - d2); + this.addMountedMovement(this.posX - d0, this.posY - d1, this.posZ - d2); if (this.vehicle instanceof EntityPig) { @@ -3435,11 +3418,11 @@ public abstract class EntityNPC extends EntityLiving this.experience = tagCompund.getFloat("XpP"); this.experienceLevel = tagCompund.getInt("XpLevel"); this.experienceTotal = tagCompund.getInt("XpTotal"); - this.xpSeed = tagCompund.getInt("XpSeed"); + this.enchSeed = tagCompund.getInt("EnchSeed"); - if (this.xpSeed == 0) + if (this.enchSeed == 0) { - this.xpSeed = this.rand.intv(); + this.enchSeed = this.rand.intv(); } // this.setScore(tagCompund.getInteger("Score")); @@ -3480,6 +3463,8 @@ public abstract class EntityNPC extends EntityLiving this.warpChest.readTags(nbttaglist1); } + this.movedDistance = tagCompund.getLong("MovedDist"); + // ModelType // model; // try { // model = ModelType.getByName(tagCompund.getString("Model")); @@ -3573,7 +3558,7 @@ public abstract class EntityNPC extends EntityLiving tagCompound.setFloat("XpP", this.experience); tagCompound.setInt("XpLevel", this.experienceLevel); tagCompound.setInt("XpTotal", this.experienceTotal); - tagCompound.setInt("XpSeed", this.xpSeed); + tagCompound.setInt("EnchSeed", this.enchSeed); // tagCompound.setInteger("Score", this.getScore()); // tagCompound.setInteger("Mana", this.getManaPoints()); @@ -3611,6 +3596,8 @@ public abstract class EntityNPC extends EntityLiving tagCompound.setObject("SelectedItem", itemstack.writeTags(new TagObject())); } + tagCompound.setLong("MovedDist", this.movedDistance); + // tagCompound.setString("Model", this.getModel().name); // tagCompound.setInteger("PartFlags", this.getModelParts()); // tagCompound.setFloat("PlayerScale", this.getPlayerHeight()); @@ -3949,7 +3936,8 @@ public abstract class EntityNPC extends EntityLiving super.moveEntityWithHeading(strafe, forward); } - this.addMovementStat(this.posX - d0, this.posY - d1, this.posZ - d2); + if(!this.worldObj.client) + this.addMovement(this.posX - d0, this.posY - d1, this.posZ - d2); } /** @@ -3960,103 +3948,65 @@ public abstract class EntityNPC extends EntityLiving return this.isPlayer() ? (float)this.getEntityAttribute(Attribute.MOVEMENT_SPEED).getAttributeValue() : super.getAIMoveSpeed(); } - /** - * Adds a value to a movement statistic field - like run, walk, swin or climb. - */ - public void addMovementStat(double p_71000_1_, double p_71000_3_, double p_71000_5_) + public void addMovement(double x, double y, double z) { if (this.vehicle == null) { if (this.isInsideOfLiquid()) { - int i = Math.round(ExtMath.sqrtd(p_71000_1_ * p_71000_1_ + p_71000_3_ * p_71000_3_ + p_71000_5_ * p_71000_5_) * 100.0F); + int i = Math.round(ExtMath.sqrtd(x * x + y * y + z * z) * 100.0F); if (i > 0) { - this.addStat(i); + this.addMoved(i); } } else if (this.isInLiquid()) { - int j = Math.round(ExtMath.sqrtd(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F); + int j = Math.round(ExtMath.sqrtd(x * x + z * z) * 100.0F); if (j > 0) { - this.addStat(j); + this.addMoved(j); } } else if (this.isOnLadder()) { - if (p_71000_3_ > 0.0D) + if (y > 0.0D) { - this.addStat((int)Math.round(p_71000_3_ * 100.0D)); + this.addMoved((int)Math.round(y * 100.0D)); } } else if (this.onGround) { - int k = Math.round(ExtMath.sqrtd(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F); + int k = Math.round(ExtMath.sqrtd(x * x + z * z) * 100.0F); if (k > 0) { - this.addStat(k); - -// if (this.isSprinting()) -// { -// this.addStat(StatRegistry.distanceSprintedStat, k); -// } -// else -// { -// if (this.isSneaking()) -// { -// this.addStat(StatRegistry.distanceCrouchedStat, k); -// } -// } + this.addMoved(k); } } else { - int l = Math.round(ExtMath.sqrtd(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F); + int l = Math.round(ExtMath.sqrtd(x * x + z * z) * 100.0F); if (l > 25) { - this.addStat(l); + this.addMoved(l); } } } } - /** - * Adds a value to a mounted movement statistic field - by minecart, boat, or pig. - */ - private void addMountedMovementStat(double p_71015_1_, double p_71015_3_, double p_71015_5_) + private void addMountedMovement(double x, double y, double z) { if (this.vehicle != null) { - int i = Math.round(ExtMath.sqrtd(p_71015_1_ * p_71015_1_ + p_71015_3_ * p_71015_3_ + p_71015_5_ * p_71015_5_) * 100.0F); + int i = Math.round(ExtMath.sqrtd(x * x + y * y + z * z) * 100.0F); if (i > 0) { - if (this.vehicle instanceof EntityCart) - { - this.addStat(i); - -// if (this.startMinecartRidingCoordinate == null) -// { -// this.startMinecartRidingCoordinate = new BlockPos(this); -// } - } - else if (this.vehicle instanceof EntityBoat) - { - this.addStat(i); - } - else if (this.vehicle instanceof EntityPig) - { - this.addStat(i); - } - else if (this.vehicle instanceof EntityHorse) - { - this.addStat(i); - } + this.addMoved(i); } } } @@ -4071,7 +4021,7 @@ public abstract class EntityNPC extends EntityLiving { if (distance >= 2.0F) { - this.addStat((int)Math.round((double)distance * 100.0D)); + this.addMoved((int)Math.round((double)distance * 100.0D)); } if(!this.hasEffect(Potion.FLYING)) @@ -4126,9 +4076,6 @@ public abstract class EntityNPC extends EntityLiving return this.isPlayer() ? this.inventory.armorItemInSlot(slot) : this.equipment[slot + 1]; } - /** - * Add experience points to player. - */ public void addExperience(int amount) { int i = Integer.MAX_VALUE - this.experienceTotal; @@ -4147,14 +4094,14 @@ public abstract class EntityNPC extends EntityLiving } } - public int getXPSeed() + public int getEnchSeed() { - return this.xpSeed; + return this.enchSeed; } - public void setXPSeed(int xpSeed) + public void setEnchSeed(int seed) { - this.xpSeed = xpSeed; + this.enchSeed = seed; } /** diff --git a/common/src/main/java/common/inventory/Container.java b/common/src/main/java/common/inventory/Container.java index d7bcfbf..59197f1 100755 --- a/common/src/main/java/common/inventory/Container.java +++ b/common/src/main/java/common/inventory/Container.java @@ -97,14 +97,6 @@ public abstract class Container } } - /** - * Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy. - */ - public boolean enchantItem(EntityNPC playerIn, int id) - { - return false; - } - public Slot getSlotFromInventory(IInventory inv, int slotIn) { for (int i = 0; i < this.inventorySlots.size(); ++i) diff --git a/common/src/main/java/common/inventory/ContainerEnchantment.java b/common/src/main/java/common/inventory/ContainerEnchantment.java index ae9b48e..be3d991 100755 --- a/common/src/main/java/common/inventory/ContainerEnchantment.java +++ b/common/src/main/java/common/inventory/ContainerEnchantment.java @@ -14,18 +14,13 @@ import common.world.World; public class ContainerEnchantment extends Container { - /** SlotEnchantmentTable object with ItemStack to be enchanted */ - public IInventory tableInventory; - - /** current world (for bookshelf counting) */ - private World worldPointer; + public IInventory table; + private World world; private BlockPos position; private Random rand; - public int xpSeed; - - /** 3-member array storing the enchantment levels of each slot */ - public int[] enchantLevels; - public int[] enchantmentIds; + public int seed; + public int[] mana; + public int[] ids; public ContainerEnchantment(InventoryPlayer playerInv, World worldIn) { @@ -34,7 +29,7 @@ public class ContainerEnchantment extends Container public ContainerEnchantment(InventoryPlayer playerInv, World worldIn, BlockPos pos) { - this.tableInventory = new InventoryBasic("Enchant", true, 1) + this.table = new InventoryBasic("Enchant", true, 1) { public int getInventoryStackLimit() { @@ -47,12 +42,12 @@ public class ContainerEnchantment extends Container } }; this.rand = new Random(); - this.enchantLevels = new int[3]; - this.enchantmentIds = new int[] { -1, -1, -1}; - this.worldPointer = worldIn; + this.mana = new int[3]; + this.ids = new int[] { -1, -1, -1}; + this.world = worldIn; this.position = pos; - this.xpSeed = playerInv.player.getXPSeed(); - this.addSlotToContainer(new Slot(this.tableInventory, 0, 25, 47) + this.seed = playerInv.player.getEnchSeed(); + this.addSlotToContainer(new Slot(this.table, 0, 25, 47) { public boolean isItemValid(ItemStack stack) { @@ -63,13 +58,6 @@ public class ContainerEnchantment extends Container return 1; } }); -// this.addSlotToContainer(new Slot(this.tableInventory, 1, 35, 47) -// { -// public boolean isItemValid(ItemStack stack) -// { -// return stack.getItem() == Items.dye && EnumDyeColor.byDyeDamage(stack.getMetadata()) == EnumDyeColor.BLUE; -// } -// }); for (int i = 0; i < 3; ++i) { @@ -88,18 +76,15 @@ public class ContainerEnchantment extends Container public void onCraftGuiOpened(ICrafting listener) { super.onCraftGuiOpened(listener); - listener.sendProgressBarUpdate(this, 0, this.enchantLevels[0]); - listener.sendProgressBarUpdate(this, 1, this.enchantLevels[1]); - listener.sendProgressBarUpdate(this, 2, this.enchantLevels[2]); - listener.sendProgressBarUpdate(this, 3, this.xpSeed & -16); - listener.sendProgressBarUpdate(this, 4, this.enchantmentIds[0]); - listener.sendProgressBarUpdate(this, 5, this.enchantmentIds[1]); - listener.sendProgressBarUpdate(this, 6, this.enchantmentIds[2]); + listener.sendProgressBarUpdate(this, 0, this.mana[0]); + listener.sendProgressBarUpdate(this, 1, this.mana[1]); + listener.sendProgressBarUpdate(this, 2, this.mana[2]); + listener.sendProgressBarUpdate(this, 3, this.seed & -16); + listener.sendProgressBarUpdate(this, 4, this.ids[0]); + listener.sendProgressBarUpdate(this, 5, this.ids[1]); + listener.sendProgressBarUpdate(this, 6, this.ids[2]); } - /** - * Looks for changes made in the container, sends them to every listener. - */ public void detectAndSendChanges() { super.detectAndSendChanges(); @@ -107,13 +92,13 @@ public class ContainerEnchantment extends Container for (int i = 0; i < this.crafters.size(); ++i) { ICrafting icrafting = (ICrafting)this.crafters.get(i); - icrafting.sendProgressBarUpdate(this, 0, this.enchantLevels[0]); - icrafting.sendProgressBarUpdate(this, 1, this.enchantLevels[1]); - icrafting.sendProgressBarUpdate(this, 2, this.enchantLevels[2]); - icrafting.sendProgressBarUpdate(this, 3, this.xpSeed & -16); - icrafting.sendProgressBarUpdate(this, 4, this.enchantmentIds[0]); - icrafting.sendProgressBarUpdate(this, 5, this.enchantmentIds[1]); - icrafting.sendProgressBarUpdate(this, 6, this.enchantmentIds[2]); + icrafting.sendProgressBarUpdate(this, 0, this.mana[0]); + icrafting.sendProgressBarUpdate(this, 1, this.mana[1]); + icrafting.sendProgressBarUpdate(this, 2, this.mana[2]); + icrafting.sendProgressBarUpdate(this, 3, this.seed & -16); + icrafting.sendProgressBarUpdate(this, 4, this.ids[0]); + icrafting.sendProgressBarUpdate(this, 5, this.ids[1]); + icrafting.sendProgressBarUpdate(this, 6, this.ids[2]); } } @@ -121,15 +106,15 @@ public class ContainerEnchantment extends Container { if (id >= 0 && id <= 2) { - this.enchantLevels[id] = data; + this.mana[id] = data; } else if (id == 3) { - this.xpSeed = data; + this.seed = data; } else if (id >= 4 && id <= 6) { - this.enchantmentIds[id - 4] = data; + this.ids[id - 4] = data; } else { @@ -137,18 +122,15 @@ public class ContainerEnchantment extends Container } } - /** - * Callback for when the crafting matrix is changed. - */ public void onCraftMatrixChanged(IInventory inventoryIn) { - if (inventoryIn == this.tableInventory) + if (inventoryIn == this.table) { ItemStack itemstack = inventoryIn.getStackInSlot(0); if (itemstack != null && itemstack.isItemEnchantable()) { - if (!this.worldPointer.client) + if (!this.world.client) { int l = 0; @@ -156,36 +138,36 @@ public class ContainerEnchantment extends Container { for (int k = -1; k <= 1; ++k) { - if ((j != 0 || k != 0) && this.worldPointer.isAirBlock(this.position.add(k, 0, j)) && this.worldPointer.isAirBlock(this.position.add(k, 1, j))) + if ((j != 0 || k != 0) && this.world.isAirBlock(this.position.add(k, 0, j)) && this.world.isAirBlock(this.position.add(k, 1, j))) { - if (this.worldPointer.getState(this.position.add(k * 2, 0, j * 2)).getBlock() == Blocks.bookshelf) + if (this.world.getState(this.position.add(k * 2, 0, j * 2)).getBlock() == Blocks.bookshelf) { ++l; } - if (this.worldPointer.getState(this.position.add(k * 2, 1, j * 2)).getBlock() == Blocks.bookshelf) + if (this.world.getState(this.position.add(k * 2, 1, j * 2)).getBlock() == Blocks.bookshelf) { ++l; } if (k != 0 && j != 0) { - if (this.worldPointer.getState(this.position.add(k * 2, 0, j)).getBlock() == Blocks.bookshelf) + if (this.world.getState(this.position.add(k * 2, 0, j)).getBlock() == Blocks.bookshelf) { ++l; } - if (this.worldPointer.getState(this.position.add(k * 2, 1, j)).getBlock() == Blocks.bookshelf) + if (this.world.getState(this.position.add(k * 2, 1, j)).getBlock() == Blocks.bookshelf) { ++l; } - if (this.worldPointer.getState(this.position.add(k, 0, j * 2)).getBlock() == Blocks.bookshelf) + if (this.world.getState(this.position.add(k, 0, j * 2)).getBlock() == Blocks.bookshelf) { ++l; } - if (this.worldPointer.getState(this.position.add(k, 1, j * 2)).getBlock() == Blocks.bookshelf) + if (this.world.getState(this.position.add(k, 1, j * 2)).getBlock() == Blocks.bookshelf) { ++l; } @@ -194,29 +176,29 @@ public class ContainerEnchantment extends Container } } - this.rand.setSeed((long)this.xpSeed); + this.rand.setSeed((long)this.seed); for (int i1 = 0; i1 < 3; ++i1) { - this.enchantLevels[i1] = EnchantmentHelper.calcItemStackEnchantability(this.rand, i1, l, itemstack); - this.enchantmentIds[i1] = -1; + this.mana[i1] = EnchantmentHelper.calcItemStackEnchantability(this.rand, i1, l, itemstack); + this.ids[i1] = -1; - if (this.enchantLevels[i1] < i1 + 1) + if (this.mana[i1] < i1 + 1) { - this.enchantLevels[i1] = 0; + this.mana[i1] = 0; } } for (int j1 = 0; j1 < 3; ++j1) { - if (this.enchantLevels[j1] > 0) + if (this.mana[j1] > 0) { - List list = this.getRandomEnchantments(itemstack, j1, this.enchantLevels[j1]); + List list = this.getRandomEnchantments(itemstack, j1, this.mana[j1]); if (list != null && !list.isEmpty()) { RngEnchantment enchantmentdata = (RngEnchantment)list.get(this.rand.zrange(list.size())); - this.enchantmentIds[j1] = enchantmentdata.enchantmentobj.effectId | enchantmentdata.enchantmentLevel << 8; + this.ids[j1] = enchantmentdata.enchantment.effectId | enchantmentdata.level << 8; } } } @@ -228,85 +210,54 @@ public class ContainerEnchantment extends Container { for (int i = 0; i < 3; ++i) { - this.enchantLevels[i] = 0; - this.enchantmentIds[i] = -1; + this.mana[i] = 0; + this.ids[i] = -1; } } } } - /** - * Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy. - */ - public boolean enchantItem(EntityNPC playerIn, int id) - { - ItemStack itemstack = this.tableInventory.getStackInSlot(0); -// ItemStack itemstack1 = this.tableInventory.getStackInSlot(1); - int i = id + 1; + public boolean enchantItem(EntityNPC player, int id) { + ItemStack stack = this.table.getStackInSlot(0); + int cost = id + 1; -// if ((itemstack1 == null || itemstack1.stackSize < i) && !playerIn.capabilities.isCreativeMode) -// { -// return false; -// } -// else - if (this.enchantLevels[id] > 0 && itemstack != null && /* ( */ playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id]) // || playerIn.creative)) - { - if (!this.worldPointer.client) - { - List list = this.getRandomEnchantments(itemstack, id, this.enchantLevels[id]); - boolean flag = itemstack.getItem() == Items.book; + if(this.mana[id] > 0 && stack != null && player.getManaPoints() >= cost && player.getManaPoints() >= this.mana[id]) { + if(!this.world.client) { + List ench = this.getRandomEnchantments(stack, id, this.mana[id]); + boolean book = stack.getItem() == Items.book; - if (list != null) - { - playerIn.removeExperienceLevel(i); + if(ench != null) { + player.useMana(cost); + player.updateEnchSeed(); - if (flag) - { - itemstack.setItem(Items.enchanted_book); - } + if(book) + stack.setItem(Items.enchanted_book); - for (int j = 0; j < list.size(); ++j) - { - RngEnchantment enchantmentdata = (RngEnchantment)list.get(j); + for(int z = 0; z < ench.size(); z++) { + RngEnchantment itm = ench.get(z); - if (flag) - { - Items.enchanted_book.addEnchantment(itemstack, enchantmentdata); - } - else - { - itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel); - } - } + if(book) + Items.enchanted_book.addEnchantment(stack, itm); + else + stack.addEnchantment(itm.enchantment, itm.level); + } -// if (!playerIn.capabilities.isCreativeMode) -// { -// itemstack1.stackSize -= i; -// -// if (itemstack1.stackSize <= 0) -// { -// this.tableInventory.setInventorySlotContents(1, (ItemStack)null); -// } -// } + this.table.markDirty(); + this.seed = player.getEnchSeed(); + this.onCraftMatrixChanged(this.table); + } + } -// playerIn.triggerAchievement(StatRegistry.enchantedStat); - this.tableInventory.markDirty(); - this.xpSeed = playerIn.getXPSeed(); - this.onCraftMatrixChanged(this.tableInventory); - } - } - - return true; - } - else - { - return false; - } - } + return true; + } + else { + return false; + } + } private List getRandomEnchantments(ItemStack stack, int id, int level) { - this.rand.setSeed((long)(this.xpSeed + id)); + this.rand.setSeed((long)(this.seed + id)); List list = EnchantmentHelper.buildEnchantmentList(this.rand, stack, level); if (stack.getItem() == Items.book && list != null && list.size() > 1) @@ -317,24 +268,15 @@ public class ContainerEnchantment extends Container return list; } -// public int getLapisAmount() -// { -// ItemStack itemstack = this.tableInventory.getStackInSlot(1); -// return itemstack == null ? 0 : itemstack.stackSize; -// } - - /** - * Called when the container is closed. - */ public void onContainerClosed(EntityNPC playerIn) { super.onContainerClosed(playerIn); - if (!this.worldPointer.client) + if (!this.world.client) { - for (int i = 0; i < this.tableInventory.getSizeInventory(); ++i) + for (int i = 0; i < this.table.getSizeInventory(); ++i) { - ItemStack itemstack = this.tableInventory.removeStackFromSlot(i); + ItemStack itemstack = this.table.removeStackFromSlot(i); if (itemstack != null) { @@ -346,12 +288,9 @@ public class ContainerEnchantment extends Container public boolean canInteractWith(EntityNPC playerIn) { - return this.worldPointer.getState(this.position).getBlock() != Blocks.enchanting_table ? false : playerIn.getDistanceSq((double)this.position.getX() + 0.5D, (double)this.position.getY() + 0.5D, (double)this.position.getZ() + 0.5D) <= 64.0D; + return this.world.getState(this.position).getBlock() != Blocks.enchanting_table ? false : playerIn.getDistanceSq((double)this.position.getX() + 0.5D, (double)this.position.getY() + 0.5D, (double)this.position.getZ() + 0.5D) <= 64.0D; } - /** - * Take a stack from the specified inventory slot. - */ public ItemStack transferStackInSlot(EntityNPC playerIn, int index) { ItemStack itemstack = null; @@ -369,20 +308,6 @@ public class ContainerEnchantment extends Container return null; } } -// else if (index == 1) -// { -// if (!this.mergeItemStack(itemstack1, 2, 38, true)) -// { -// return null; -// } -// } -// else if (itemstack1.getItem() == Items.dye && EnumDyeColor.byDyeDamage(itemstack1.getMetadata()) == EnumDyeColor.BLUE) -// { -// if (!this.mergeItemStack(itemstack1, 1, 2, true)) -// { -// return null; -// } -// } else { if (((Slot)this.inventorySlots.get(0)).getHasStack() || !((Slot)this.inventorySlots.get(0)).isItemValid(itemstack1)) diff --git a/common/src/main/java/common/inventory/ContainerRepair.java b/common/src/main/java/common/inventory/ContainerRepair.java index 9ff6631..f22db4a 100755 --- a/common/src/main/java/common/inventory/ContainerRepair.java +++ b/common/src/main/java/common/inventory/ContainerRepair.java @@ -66,13 +66,14 @@ public class ContainerRepair extends Container } public boolean canTakeStack(EntityNPC playerIn) { - return /* (playerIn.creative || */ playerIn.experienceLevel >= ContainerRepair.this.maximumCost /* ) */ && ContainerRepair.this.maximumCost > 0 && this.getHasStack(); + return /* (playerIn.creative || */ playerIn.getManaPoints() >= ContainerRepair.this.maximumCost /* ) */ && ContainerRepair.this.maximumCost > 0 && this.getHasStack(); } public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack) { // if (!playerIn.creative) // { - playerIn.addExperienceLevel(-ContainerRepair.this.maximumCost); + if(!playerIn.worldObj.client) + playerIn.useMana(ContainerRepair.this.maximumCost); // } ContainerRepair.this.inputSlots.setInventorySlotContents(0, (ItemStack)null); diff --git a/common/src/main/java/common/item/ItemEnchantedBook.java b/common/src/main/java/common/item/ItemEnchantedBook.java index ee4cf76..a09e39a 100755 --- a/common/src/main/java/common/item/ItemEnchantedBook.java +++ b/common/src/main/java/common/item/ItemEnchantedBook.java @@ -89,11 +89,11 @@ public class ItemEnchantedBook extends Item { TagObject nbttagcompound = nbttaglist.get(i); - if (nbttagcompound.getShort("id") == enchantment.enchantmentobj.effectId) + if (nbttagcompound.getShort("id") == enchantment.enchantment.effectId) { - if (nbttagcompound.getShort("lvl") < enchantment.enchantmentLevel) + if (nbttagcompound.getShort("lvl") < enchantment.level) { - nbttagcompound.setShort("lvl", (short)enchantment.enchantmentLevel); + nbttagcompound.setShort("lvl", (short)enchantment.level); } flag = false; @@ -104,8 +104,8 @@ public class ItemEnchantedBook extends Item if (flag) { TagObject nbttagcompound1 = new TagObject(); - nbttagcompound1.setShort("id", (short)enchantment.enchantmentobj.effectId); - nbttagcompound1.setShort("lvl", (short)enchantment.enchantmentLevel); + nbttagcompound1.setShort("id", (short)enchantment.enchantment.effectId); + nbttagcompound1.setShort("lvl", (short)enchantment.level); nbttaglist.add(nbttagcompound1); } diff --git a/common/src/main/java/common/item/ItemStack.java b/common/src/main/java/common/item/ItemStack.java index 9485119..8285119 100755 --- a/common/src/main/java/common/item/ItemStack.java +++ b/common/src/main/java/common/item/ItemStack.java @@ -972,6 +972,9 @@ public final class ItemStack list.add(String.format("Haltbarkeit: %d" + (this.isItemDamaged() ? " / %d" : ""), this.isItemDamaged() ? (this.getMaxDamage() - this.getItemDamage()) : this.getMaxDamage(), this.getMaxDamage())); } + + if(this.getRepairCost() > 0) + list.add("Reparaturkosten: " + this.getRepairCost() + " Mana"); list.add(TextColor.GRAY + ItemRegistry.getNameFromItem(this.item)); diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index 3ed5122..c7ee6d3 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -33,6 +33,7 @@ import common.init.SoundEvent; import common.init.UniverseRegistry; import common.inventory.Container; import common.inventory.ContainerChest; +import common.inventory.ContainerEnchantment; import common.inventory.ContainerEntityInventory; import common.inventory.ContainerMerchant; import common.inventory.ICrafting; @@ -462,7 +463,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer this.entity.experienceLevel = oldPlayer.experienceLevel; this.entity.experienceTotal = oldPlayer.experienceTotal; this.entity.experience = oldPlayer.experience; - this.entity.setXPSeed(oldPlayer.getXPSeed()); + this.entity.setEnchSeed(oldPlayer.getEnchSeed()); this.entity.setWarpChest(oldPlayer.getWarpChest()); // this.entity.getDataWatcher().updateObject(10, Integer.valueOf(oldPlayer.getDataWatcher().getWatchableObjectInt(10))); this.lastExperience = -1; @@ -2167,7 +2168,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer } this.entity.setPositionAndRotation(d8, d9, d10, f1, f2); - this.entity.addMovementStat(this.entity.posX - d0, this.entity.posY - d1, this.entity.posZ - d2); + this.entity.addMovement(this.entity.posX - d0, this.entity.posY - d1, this.entity.posZ - d2); if (!this.entity.noClip) { @@ -2631,10 +2632,9 @@ public class Player extends User implements ICrafting, Executor, IPlayer break; case ENCHANT_ITEM: - if(this.entity.openContainer.windowId == (packetIn.getAuxData() & 255) && this.entity.openContainer.getCanCraft(this.entity)) // && !this.playerEntity.isSpectator()) - { - this.entity.openContainer.enchantItem(this.entity, (packetIn.getAuxData() >> 8) % 3); - this.entity.openContainer.detectAndSendChanges(); + if(this.entity.openContainer instanceof ContainerEnchantment ench && ench.windowId == (packetIn.getAuxData() & 255) && ench.getCanCraft(this.entity)) { + ench.enchantItem(this.entity, (packetIn.getAuxData() >> 8) % 3); + ench.detectAndSendChanges(); } break;