remove xp usage

This commit is contained in:
Sen 2025-06-12 13:50:50 +02:00
parent 47021f9e49
commit 83f66723c9
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
11 changed files with 159 additions and 296 deletions

View file

@ -88,14 +88,14 @@ public class GuiEnchant extends GuiContainer
*/ */
public void drawGuiContainerBackgroundLayer() public void drawGuiContainerBackgroundLayer()
{ {
this.nameRand.setSeed((long)this.container.xpSeed); this.nameRand.setSeed((long)this.container.seed);
for (int l = 0; l < 3; ++l) for (int l = 0; l < 3; ++l)
{ {
int i1 = 60; int i1 = 60;
int j1 = i1 + 20; int j1 = i1 + 20;
String s = this.getRandomName(); String s = this.getRandomName();
int l1 = this.container.enchantLevels[l]; int l1 = this.container.mana[l];
if (l1 == 0) if (l1 == 0)
{ {
@ -106,7 +106,7 @@ public class GuiEnchant extends GuiContainer
String s1 = "" + l1; String s1 = "" + l1;
int i2 = 6839882; 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, 14 + 19 * l, 108, 19, 0x400000);
this.rect(i1 + 1, 15 + 19 * l, 16, 16, 0x200000); 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) for (int j = 0; j < 3; ++j)
{ {
int k = this.container.enchantLevels[j]; int k = this.container.mana[j];
int l = this.container.enchantmentIds[j]; int l = this.container.ids[j];
int i1 = j + 1; int i1 = j + 1;
if (this.isPointInRegion(60, 14 + 19 * j, 108, 17, mouseX, mouseY) && k > 0 && l >= 0) 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"); // 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 else
{ {
@ -198,11 +198,11 @@ public class GuiEnchant extends GuiContainer
if (i1 == 1) if (i1 == 1)
{ {
s1 = "1 Erfahrungsstufe"; s1 = "1 Manapunkt";
} }
else else
{ {
s1 = String.format("%d Erfahrungsstufen", i1); s1 = String.format("%d Manapunkte", i1);
} }
sb.append((sb.length() != 0 ? "\n" : "") + TextColor.LGRAY.toString() + "" + s1); sb.append((sb.length() != 0 ? "\n" : "") + TextColor.LGRAY.toString() + "" + s1);

View file

@ -68,7 +68,7 @@ public class GuiRepair extends GuiContainer implements ICrafting
{ {
int i = 8453920; int i = 8453920;
boolean flag = true; 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) if (this.anvil.maximumCost >= 40) // && !this.gm.thePlayer.creative)
{ {

View file

@ -398,7 +398,7 @@ public class EnchantmentHelper
} }
else 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) for (RngEnchantment enchantmentdata1 : list)
{ {
if (!enchantmentdata1.enchantmentobj.canApplyTogether(Enchantment.getEnchantmentById(integer.intValue()))) if (!enchantmentdata1.enchantment.canApplyTogether(Enchantment.getEnchantmentById(integer.intValue())))
{ {
flag = false; flag = false;
break; break;

View file

@ -2,18 +2,13 @@ package common.enchantment;
import common.rng.RngItem; import common.rng.RngItem;
public class RngEnchantment extends RngItem public class RngEnchantment extends RngItem {
{ public final Enchantment enchantment;
/** Enchantment object associated with this EnchantmentData */ public final int level;
public final Enchantment enchantmentobj;
/** Enchantment level associated with this EnchantmentData */ public RngEnchantment(Enchantment enchantment, int level) {
public final int enchantmentLevel; super(enchantment.getWeight());
this.enchantment = enchantment;
public RngEnchantment(Enchantment enchantmentObj, int enchLevel) this.level = level;
{
super(enchantmentObj.getWeight());
this.enchantmentobj = enchantmentObj;
this.enchantmentLevel = enchLevel;
} }
} }

View file

@ -33,7 +33,6 @@ import common.entity.EntityType;
import common.entity.animal.EntityDragonPart; import common.entity.animal.EntityDragonPart;
import common.entity.animal.EntityHorse; import common.entity.animal.EntityHorse;
import common.entity.animal.EntityPig; import common.entity.animal.EntityPig;
import common.entity.item.EntityBoat;
import common.entity.item.EntityCart; import common.entity.item.EntityCart;
import common.entity.item.EntityItem; import common.entity.item.EntityItem;
import common.entity.projectile.EntityArrow; import common.entity.projectile.EntityArrow;
@ -209,11 +208,10 @@ public abstract class EntityNPC extends EntityLiving
public double chasingPosZ; public double chasingPosZ;
private WorldPos originPos = new WorldPos(0, 64, 0, Space.INSTANCE.getDimensionId()); private WorldPos originPos = new WorldPos(0, 64, 0, Space.INSTANCE.getDimensionId());
private WorldPos spawnPos; private WorldPos spawnPos;
// private BlockPos startMinecartRidingCoordinate;
public int experienceLevel; public int experienceLevel;
public int experienceTotal; public int experienceTotal;
public float experience; public float experience;
protected int xpSeed; protected int enchSeed;
private ItemStack itemInUse; private ItemStack itemInUse;
private int itemInUseCount; private int itemInUseCount;
protected float speedInAir = 0.02F; protected float speedInAir = 0.02F;
@ -246,8 +244,7 @@ public abstract class EntityNPC extends EntityLiving
public float prevRenderArmPitch; public float prevRenderArmPitch;
private int horseJumpPowerCounter; private int horseJumpPowerCounter;
private float horseJumpPower; private float horseJumpPower;
// public float nausea; private long movedDistance;
// public float prevNausea;
public EntityNPC(World worldIn) public EntityNPC(World worldIn)
{ {
@ -2843,20 +2840,8 @@ public abstract class EntityNPC extends EntityLiving
this.connection.resetLastExperience(); this.connection.resetLastExperience();
} }
public void removeExperienceLevel(int levels) { public void updateEnchSeed() {
this.experienceLevel -= levels; this.enchSeed = this.rand.intv();
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 onDeath(DamageSource cause) { public void onDeath(DamageSource cause) {
@ -2920,15 +2905,13 @@ public abstract class EntityNPC extends EntityLiving
super.updateFallState(y, onGroundIn, blockIn, pos); super.updateFallState(y, onGroundIn, blockIn, pos);
} }
public void addStat(int amount) { public void addMoved(int amount) {
// if(this.connection != null) this.movedDistance += (long)amount;
// this.connection.addStat(amount);
} }
// public void removeStat(StatBase stat) { public long getMovedDistance() {
// if(this.connection != null) return this.movedDistance;
// this.connection.removeStat(stat); }
// }
protected void onItemUseFinish() { protected void onItemUseFinish() {
if(this.connection != null) if(this.connection != null)
@ -3158,7 +3141,7 @@ public abstract class EntityNPC extends EntityLiving
super.updateRidden(); super.updateRidden();
this.prevCameraYaw = this.cameraYaw; this.prevCameraYaw = this.cameraYaw;
this.cameraYaw = 0.0F; 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) if (this.vehicle instanceof EntityPig)
{ {
@ -3435,11 +3418,11 @@ public abstract class EntityNPC extends EntityLiving
this.experience = tagCompund.getFloat("XpP"); this.experience = tagCompund.getFloat("XpP");
this.experienceLevel = tagCompund.getInt("XpLevel"); this.experienceLevel = tagCompund.getInt("XpLevel");
this.experienceTotal = tagCompund.getInt("XpTotal"); 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")); // this.setScore(tagCompund.getInteger("Score"));
@ -3480,6 +3463,8 @@ public abstract class EntityNPC extends EntityLiving
this.warpChest.readTags(nbttaglist1); this.warpChest.readTags(nbttaglist1);
} }
this.movedDistance = tagCompund.getLong("MovedDist");
// ModelType // model; // ModelType // model;
// try { // try {
// model = ModelType.getByName(tagCompund.getString("Model")); // model = ModelType.getByName(tagCompund.getString("Model"));
@ -3573,7 +3558,7 @@ public abstract class EntityNPC extends EntityLiving
tagCompound.setFloat("XpP", this.experience); tagCompound.setFloat("XpP", this.experience);
tagCompound.setInt("XpLevel", this.experienceLevel); tagCompound.setInt("XpLevel", this.experienceLevel);
tagCompound.setInt("XpTotal", this.experienceTotal); tagCompound.setInt("XpTotal", this.experienceTotal);
tagCompound.setInt("XpSeed", this.xpSeed); tagCompound.setInt("EnchSeed", this.enchSeed);
// tagCompound.setInteger("Score", this.getScore()); // tagCompound.setInteger("Score", this.getScore());
// tagCompound.setInteger("Mana", this.getManaPoints()); // tagCompound.setInteger("Mana", this.getManaPoints());
@ -3611,6 +3596,8 @@ public abstract class EntityNPC extends EntityLiving
tagCompound.setObject("SelectedItem", itemstack.writeTags(new TagObject())); tagCompound.setObject("SelectedItem", itemstack.writeTags(new TagObject()));
} }
tagCompound.setLong("MovedDist", this.movedDistance);
// tagCompound.setString("Model", this.getModel().name); // tagCompound.setString("Model", this.getModel().name);
// tagCompound.setInteger("PartFlags", this.getModelParts()); // tagCompound.setInteger("PartFlags", this.getModelParts());
// tagCompound.setFloat("PlayerScale", this.getPlayerHeight()); // tagCompound.setFloat("PlayerScale", this.getPlayerHeight());
@ -3949,7 +3936,8 @@ public abstract class EntityNPC extends EntityLiving
super.moveEntityWithHeading(strafe, forward); 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(); return this.isPlayer() ? (float)this.getEntityAttribute(Attribute.MOVEMENT_SPEED).getAttributeValue() : super.getAIMoveSpeed();
} }
/** public void addMovement(double x, double y, double z)
* 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_)
{ {
if (this.vehicle == null) if (this.vehicle == null)
{ {
if (this.isInsideOfLiquid()) 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) if (i > 0)
{ {
this.addStat(i); this.addMoved(i);
} }
} }
else if (this.isInLiquid()) 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) if (j > 0)
{ {
this.addStat(j); this.addMoved(j);
} }
} }
else if (this.isOnLadder()) 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) 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) if (k > 0)
{ {
this.addStat(k); this.addMoved(k);
// if (this.isSprinting())
// {
// this.addStat(StatRegistry.distanceSprintedStat, k);
// }
// else
// {
// if (this.isSneaking())
// {
// this.addStat(StatRegistry.distanceCrouchedStat, k);
// }
// }
} }
} }
else 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) if (l > 25)
{ {
this.addStat(l); this.addMoved(l);
} }
} }
} }
} }
/** private void addMountedMovement(double x, double y, double z)
* 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_)
{ {
if (this.vehicle != null) 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 (i > 0)
{ {
if (this.vehicle instanceof EntityCart) this.addMoved(i);
{
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);
}
} }
} }
} }
@ -4071,7 +4021,7 @@ public abstract class EntityNPC extends EntityLiving
{ {
if (distance >= 2.0F) 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)) 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]; return this.isPlayer() ? this.inventory.armorItemInSlot(slot) : this.equipment[slot + 1];
} }
/**
* Add experience points to player.
*/
public void addExperience(int amount) public void addExperience(int amount)
{ {
int i = Integer.MAX_VALUE - this.experienceTotal; 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;
} }
/** /**

View file

@ -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) public Slot getSlotFromInventory(IInventory inv, int slotIn)
{ {
for (int i = 0; i < this.inventorySlots.size(); ++i) for (int i = 0; i < this.inventorySlots.size(); ++i)

View file

@ -14,18 +14,13 @@ import common.world.World;
public class ContainerEnchantment extends Container public class ContainerEnchantment extends Container
{ {
/** SlotEnchantmentTable object with ItemStack to be enchanted */ public IInventory table;
public IInventory tableInventory; private World world;
/** current world (for bookshelf counting) */
private World worldPointer;
private BlockPos position; private BlockPos position;
private Random rand; private Random rand;
public int xpSeed; public int seed;
public int[] mana;
/** 3-member array storing the enchantment levels of each slot */ public int[] ids;
public int[] enchantLevels;
public int[] enchantmentIds;
public ContainerEnchantment(InventoryPlayer playerInv, World worldIn) public ContainerEnchantment(InventoryPlayer playerInv, World worldIn)
{ {
@ -34,7 +29,7 @@ public class ContainerEnchantment extends Container
public ContainerEnchantment(InventoryPlayer playerInv, World worldIn, BlockPos pos) 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() public int getInventoryStackLimit()
{ {
@ -47,12 +42,12 @@ public class ContainerEnchantment extends Container
} }
}; };
this.rand = new Random(); this.rand = new Random();
this.enchantLevels = new int[3]; this.mana = new int[3];
this.enchantmentIds = new int[] { -1, -1, -1}; this.ids = new int[] { -1, -1, -1};
this.worldPointer = worldIn; this.world = worldIn;
this.position = pos; this.position = pos;
this.xpSeed = playerInv.player.getXPSeed(); this.seed = playerInv.player.getEnchSeed();
this.addSlotToContainer(new Slot(this.tableInventory, 0, 25, 47) this.addSlotToContainer(new Slot(this.table, 0, 25, 47)
{ {
public boolean isItemValid(ItemStack stack) public boolean isItemValid(ItemStack stack)
{ {
@ -63,13 +58,6 @@ public class ContainerEnchantment extends Container
return 1; 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) for (int i = 0; i < 3; ++i)
{ {
@ -88,18 +76,15 @@ public class ContainerEnchantment extends Container
public void onCraftGuiOpened(ICrafting listener) public void onCraftGuiOpened(ICrafting listener)
{ {
super.onCraftGuiOpened(listener); super.onCraftGuiOpened(listener);
listener.sendProgressBarUpdate(this, 0, this.enchantLevels[0]); listener.sendProgressBarUpdate(this, 0, this.mana[0]);
listener.sendProgressBarUpdate(this, 1, this.enchantLevels[1]); listener.sendProgressBarUpdate(this, 1, this.mana[1]);
listener.sendProgressBarUpdate(this, 2, this.enchantLevels[2]); listener.sendProgressBarUpdate(this, 2, this.mana[2]);
listener.sendProgressBarUpdate(this, 3, this.xpSeed & -16); listener.sendProgressBarUpdate(this, 3, this.seed & -16);
listener.sendProgressBarUpdate(this, 4, this.enchantmentIds[0]); listener.sendProgressBarUpdate(this, 4, this.ids[0]);
listener.sendProgressBarUpdate(this, 5, this.enchantmentIds[1]); listener.sendProgressBarUpdate(this, 5, this.ids[1]);
listener.sendProgressBarUpdate(this, 6, this.enchantmentIds[2]); listener.sendProgressBarUpdate(this, 6, this.ids[2]);
} }
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges() public void detectAndSendChanges()
{ {
super.detectAndSendChanges(); super.detectAndSendChanges();
@ -107,13 +92,13 @@ public class ContainerEnchantment extends Container
for (int i = 0; i < this.crafters.size(); ++i) for (int i = 0; i < this.crafters.size(); ++i)
{ {
ICrafting icrafting = (ICrafting)this.crafters.get(i); ICrafting icrafting = (ICrafting)this.crafters.get(i);
icrafting.sendProgressBarUpdate(this, 0, this.enchantLevels[0]); icrafting.sendProgressBarUpdate(this, 0, this.mana[0]);
icrafting.sendProgressBarUpdate(this, 1, this.enchantLevels[1]); icrafting.sendProgressBarUpdate(this, 1, this.mana[1]);
icrafting.sendProgressBarUpdate(this, 2, this.enchantLevels[2]); icrafting.sendProgressBarUpdate(this, 2, this.mana[2]);
icrafting.sendProgressBarUpdate(this, 3, this.xpSeed & -16); icrafting.sendProgressBarUpdate(this, 3, this.seed & -16);
icrafting.sendProgressBarUpdate(this, 4, this.enchantmentIds[0]); icrafting.sendProgressBarUpdate(this, 4, this.ids[0]);
icrafting.sendProgressBarUpdate(this, 5, this.enchantmentIds[1]); icrafting.sendProgressBarUpdate(this, 5, this.ids[1]);
icrafting.sendProgressBarUpdate(this, 6, this.enchantmentIds[2]); icrafting.sendProgressBarUpdate(this, 6, this.ids[2]);
} }
} }
@ -121,15 +106,15 @@ public class ContainerEnchantment extends Container
{ {
if (id >= 0 && id <= 2) if (id >= 0 && id <= 2)
{ {
this.enchantLevels[id] = data; this.mana[id] = data;
} }
else if (id == 3) else if (id == 3)
{ {
this.xpSeed = data; this.seed = data;
} }
else if (id >= 4 && id <= 6) else if (id >= 4 && id <= 6)
{ {
this.enchantmentIds[id - 4] = data; this.ids[id - 4] = data;
} }
else else
{ {
@ -137,18 +122,15 @@ public class ContainerEnchantment extends Container
} }
} }
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory inventoryIn) public void onCraftMatrixChanged(IInventory inventoryIn)
{ {
if (inventoryIn == this.tableInventory) if (inventoryIn == this.table)
{ {
ItemStack itemstack = inventoryIn.getStackInSlot(0); ItemStack itemstack = inventoryIn.getStackInSlot(0);
if (itemstack != null && itemstack.isItemEnchantable()) if (itemstack != null && itemstack.isItemEnchantable())
{ {
if (!this.worldPointer.client) if (!this.world.client)
{ {
int l = 0; int l = 0;
@ -156,36 +138,36 @@ public class ContainerEnchantment extends Container
{ {
for (int k = -1; k <= 1; ++k) 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; ++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; ++l;
} }
if (k != 0 && j != 0) 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; ++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; ++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; ++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; ++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) for (int i1 = 0; i1 < 3; ++i1)
{ {
this.enchantLevels[i1] = EnchantmentHelper.calcItemStackEnchantability(this.rand, i1, l, itemstack); this.mana[i1] = EnchantmentHelper.calcItemStackEnchantability(this.rand, i1, l, itemstack);
this.enchantmentIds[i1] = -1; 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) for (int j1 = 0; j1 < 3; ++j1)
{ {
if (this.enchantLevels[j1] > 0) if (this.mana[j1] > 0)
{ {
List<RngEnchantment> list = this.getRandomEnchantments(itemstack, j1, this.enchantLevels[j1]); List<RngEnchantment> list = this.getRandomEnchantments(itemstack, j1, this.mana[j1]);
if (list != null && !list.isEmpty()) if (list != null && !list.isEmpty())
{ {
RngEnchantment enchantmentdata = (RngEnchantment)list.get(this.rand.zrange(list.size())); 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) for (int i = 0; i < 3; ++i)
{ {
this.enchantLevels[i] = 0; this.mana[i] = 0;
this.enchantmentIds[i] = -1; this.ids[i] = -1;
} }
} }
} }
} }
/** public boolean enchantItem(EntityNPC player, int id) {
* Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy. ItemStack stack = this.table.getStackInSlot(0);
*/ int cost = id + 1;
public boolean enchantItem(EntityNPC playerIn, int id)
{
ItemStack itemstack = this.tableInventory.getStackInSlot(0);
// ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
int i = id + 1;
// if ((itemstack1 == null || itemstack1.stackSize < i) && !playerIn.capabilities.isCreativeMode) if(this.mana[id] > 0 && stack != null && player.getManaPoints() >= cost && player.getManaPoints() >= this.mana[id]) {
// { if(!this.world.client) {
// return false; List<RngEnchantment> ench = this.getRandomEnchantments(stack, id, this.mana[id]);
// } boolean book = stack.getItem() == Items.book;
// else
if (this.enchantLevels[id] > 0 && itemstack != null && /* ( */ playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id]) // || playerIn.creative))
{
if (!this.worldPointer.client)
{
List<RngEnchantment> list = this.getRandomEnchantments(itemstack, id, this.enchantLevels[id]);
boolean flag = itemstack.getItem() == Items.book;
if (list != null) if(ench != null) {
{ player.useMana(cost);
playerIn.removeExperienceLevel(i); player.updateEnchSeed();
if (flag) if(book)
{ stack.setItem(Items.enchanted_book);
itemstack.setItem(Items.enchanted_book);
}
for (int j = 0; j < list.size(); ++j) for(int z = 0; z < ench.size(); z++) {
{ RngEnchantment itm = ench.get(z);
RngEnchantment enchantmentdata = (RngEnchantment)list.get(j);
if (flag) if(book)
{ Items.enchanted_book.addEnchantment(stack, itm);
Items.enchanted_book.addEnchantment(itemstack, enchantmentdata);
}
else else
{ stack.addEnchantment(itm.enchantment, itm.level);
itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
}
} }
// if (!playerIn.capabilities.isCreativeMode) this.table.markDirty();
// { this.seed = player.getEnchSeed();
// itemstack1.stackSize -= i; this.onCraftMatrixChanged(this.table);
//
// if (itemstack1.stackSize <= 0)
// {
// this.tableInventory.setInventorySlotContents(1, (ItemStack)null);
// }
// }
// playerIn.triggerAchievement(StatRegistry.enchantedStat);
this.tableInventory.markDirty();
this.xpSeed = playerIn.getXPSeed();
this.onCraftMatrixChanged(this.tableInventory);
} }
} }
return true; return true;
} }
else else {
{
return false; return false;
} }
} }
private List<RngEnchantment> getRandomEnchantments(ItemStack stack, int id, int level) private List<RngEnchantment> getRandomEnchantments(ItemStack stack, int id, int level)
{ {
this.rand.setSeed((long)(this.xpSeed + id)); this.rand.setSeed((long)(this.seed + id));
List<RngEnchantment> list = EnchantmentHelper.buildEnchantmentList(this.rand, stack, level); List<RngEnchantment> list = EnchantmentHelper.buildEnchantmentList(this.rand, stack, level);
if (stack.getItem() == Items.book && list != null && list.size() > 1) if (stack.getItem() == Items.book && list != null && list.size() > 1)
@ -317,24 +268,15 @@ public class ContainerEnchantment extends Container
return list; 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) public void onContainerClosed(EntityNPC playerIn)
{ {
super.onContainerClosed(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) if (itemstack != null)
{ {
@ -346,12 +288,9 @@ public class ContainerEnchantment extends Container
public boolean canInteractWith(EntityNPC playerIn) 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) public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
{ {
ItemStack itemstack = null; ItemStack itemstack = null;
@ -369,20 +308,6 @@ public class ContainerEnchantment extends Container
return null; 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 else
{ {
if (((Slot)this.inventorySlots.get(0)).getHasStack() || !((Slot)this.inventorySlots.get(0)).isItemValid(itemstack1)) if (((Slot)this.inventorySlots.get(0)).getHasStack() || !((Slot)this.inventorySlots.get(0)).isItemValid(itemstack1))

View file

@ -66,13 +66,14 @@ public class ContainerRepair extends Container
} }
public boolean canTakeStack(EntityNPC playerIn) 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) public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack)
{ {
// if (!playerIn.creative) // if (!playerIn.creative)
// { // {
playerIn.addExperienceLevel(-ContainerRepair.this.maximumCost); if(!playerIn.worldObj.client)
playerIn.useMana(ContainerRepair.this.maximumCost);
// } // }
ContainerRepair.this.inputSlots.setInventorySlotContents(0, (ItemStack)null); ContainerRepair.this.inputSlots.setInventorySlotContents(0, (ItemStack)null);

View file

@ -89,11 +89,11 @@ public class ItemEnchantedBook extends Item
{ {
TagObject nbttagcompound = nbttaglist.get(i); 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; flag = false;
@ -104,8 +104,8 @@ public class ItemEnchantedBook extends Item
if (flag) if (flag)
{ {
TagObject nbttagcompound1 = new TagObject(); TagObject nbttagcompound1 = new TagObject();
nbttagcompound1.setShort("id", (short)enchantment.enchantmentobj.effectId); nbttagcompound1.setShort("id", (short)enchantment.enchantment.effectId);
nbttagcompound1.setShort("lvl", (short)enchantment.enchantmentLevel); nbttagcompound1.setShort("lvl", (short)enchantment.level);
nbttaglist.add(nbttagcompound1); nbttaglist.add(nbttagcompound1);
} }

View file

@ -973,6 +973,9 @@ public final class ItemStack
this.isItemDamaged() ? (this.getMaxDamage() - this.getItemDamage()) : this.getMaxDamage(), this.getMaxDamage())); 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)); list.add(TextColor.GRAY + ItemRegistry.getNameFromItem(this.item));
if (this.hasTagCompound()) if (this.hasTagCompound())

View file

@ -33,6 +33,7 @@ import common.init.SoundEvent;
import common.init.UniverseRegistry; import common.init.UniverseRegistry;
import common.inventory.Container; import common.inventory.Container;
import common.inventory.ContainerChest; import common.inventory.ContainerChest;
import common.inventory.ContainerEnchantment;
import common.inventory.ContainerEntityInventory; import common.inventory.ContainerEntityInventory;
import common.inventory.ContainerMerchant; import common.inventory.ContainerMerchant;
import common.inventory.ICrafting; import common.inventory.ICrafting;
@ -462,7 +463,7 @@ public class Player extends User implements ICrafting, Executor, IPlayer
this.entity.experienceLevel = oldPlayer.experienceLevel; this.entity.experienceLevel = oldPlayer.experienceLevel;
this.entity.experienceTotal = oldPlayer.experienceTotal; this.entity.experienceTotal = oldPlayer.experienceTotal;
this.entity.experience = oldPlayer.experience; this.entity.experience = oldPlayer.experience;
this.entity.setXPSeed(oldPlayer.getXPSeed()); this.entity.setEnchSeed(oldPlayer.getEnchSeed());
this.entity.setWarpChest(oldPlayer.getWarpChest()); this.entity.setWarpChest(oldPlayer.getWarpChest());
// this.entity.getDataWatcher().updateObject(10, Integer.valueOf(oldPlayer.getDataWatcher().getWatchableObjectInt(10))); // this.entity.getDataWatcher().updateObject(10, Integer.valueOf(oldPlayer.getDataWatcher().getWatchableObjectInt(10)));
this.lastExperience = -1; 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.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) if (!this.entity.noClip)
{ {
@ -2631,10 +2632,9 @@ public class Player extends User implements ICrafting, Executor, IPlayer
break; break;
case ENCHANT_ITEM: case ENCHANT_ITEM:
if(this.entity.openContainer.windowId == (packetIn.getAuxData() & 255) && this.entity.openContainer.getCanCraft(this.entity)) // && !this.playerEntity.isSpectator()) if(this.entity.openContainer instanceof ContainerEnchantment ench && ench.windowId == (packetIn.getAuxData() & 255) && ench.getCanCraft(this.entity)) {
{ ench.enchantItem(this.entity, (packetIn.getAuxData() >> 8) % 3);
this.entity.openContainer.enchantItem(this.entity, (packetIn.getAuxData() >> 8) % 3); ench.detectAndSendChanges();
this.entity.openContainer.detectAndSendChanges();
} }
break; break;