
Thornack
Members-
Posts
629 -
Joined
-
Last visited
Everything posted by Thornack
-
I found the following. in vanilla FoodStats onUpdate if (this.foodTimer >= 80) { p_75118_1_.heal(1.0F); this.addExhaustion(3.0F); this.foodTimer = 0; } inEntityPlayer #onLivingUpdate if (this.worldObj.difficultySetting == EnumDifficulty.PEACEFUL && this.getHealth() < this.getMaxHealth() && this.worldObj.getGameRules().getGameRuleBooleanValue("naturalRegeneration") && this.ticksExisted % 20 * 12 == 0) { this.heal(1.0F); } and there is the issue that Failender Pointed out with the food stats not being replaced in all cases if I use Login event... ugh... This altering of healing behaviour is a pain...
-
Funny Thing is if I move the refletion code to @SubscribeEvent public void playerLogIn(PlayerLoggedInEvent event) { ObfuscationReflectionHelper.setPrivateValue(EntityPlayer.class, (EntityPlayer) event.player, new CustomFoodStats(), "foodStats", "field_71100_bB"); } Then I do get Overridden printed to the consol but again the player still regens hp... And he shouldnt
-
@SubscribeEvent public void onEntityConstructing(EntityConstructing event) { if (event.entity instanceof EntityPlayer) { System.out.println("CAAAAAAAAAALLLLLLLLLLLLLLLEEEEEEEEEEEEEDDDDDDDDDDDDDDDDDD"); ObfuscationReflectionHelper.setPrivateValue(EntityPlayer.class, (EntityPlayer) event.entity, new CustomFoodStats(), "foodStats", "field_71100_bB"); } } I see the print line so yes it is being called but I dont see the "OVERRIDDEN" being printed public class CustomFoodStats extends FoodStats { @Override public void onUpdate(EntityPlayer player) { System.out.println("OVERRIDDEN"); } } And I should. I deleted the //super.onUpdate(player); but my player still gains health over time.... AND he shouldnt
-
But if I do @SubscribeEvent public void playerLogIn(PlayerLoggedInEvent event) { ObfuscationReflectionHelper.setPrivateValue(EntityPlayer.class, (EntityPlayer) event.player, new CustomFoodStats(), "foodStats", "field_71100_bB"); } Then I get "OVERRIDDEN" outprinted to consol (from my custom class). But my player still gains HP like he would normally due to the regular food stats onUpdate method...
-
Im particularily interested in changing the onUpdate Method to be my own. This is my code The Event @SubscribeEvent public void onEntityConstructing(EntityConstructing event) { if (event.entity instanceof EntityPlayer) { ObfuscationReflectionHelper.setPrivateValue(EntityPlayer.class, (EntityPlayer)event.entity, new CustomFoodStats(), "foodStats", "field_71100_bB"); } } My Custom FoodStats Class (based on Vanilla public class CustomFoodStats extends FoodStats { /** The player's food level. */ private int foodLevel = 20; /** The player's food saturation. */ private float foodSaturationLevel = 5.0F; /** The player's food exhaustion. */ private float foodExhaustionLevel; /** The player's food timer value. */ private int foodTimer; private int prevFoodLevel = 20; /** * Args: int foodLevel, float foodSaturationModifier */ public void addStats(int min, float max) { this.foodLevel = Math.min(min + this.foodLevel, 20); this.foodSaturationLevel = Math.min(this.foodSaturationLevel + (float)min * max * 2.0F, (float)this.foodLevel); } public void func_151686_a(ItemFood food, ItemStack itemStack) { this.addStats(food.func_150905_g(itemStack), food.func_150906_h(itemStack)); } /** * Handles the food game logic. */ public void onUpdate(EntityPlayer player) { System.out.println("OVERRIDDEN"); } /** * Reads food stats from an NBT object. */ public void readNBT(NBTTagCompound nbt) { if (nbt.hasKey("foodLevel", 99)) { this.foodLevel = nbt.getInteger("foodLevel"); this.foodTimer = nbt.getInteger("foodTickTimer"); this.foodSaturationLevel = nbt.getFloat("foodSaturationLevel"); this.foodExhaustionLevel = nbt.getFloat("foodExhaustionLevel"); } } /** * Writes food stats to an NBT object. */ public void writeNBT(NBTTagCompound nbt) { nbt.setInteger("foodLevel", this.foodLevel); nbt.setInteger("foodTickTimer", this.foodTimer); nbt.setFloat("foodSaturationLevel", this.foodSaturationLevel); nbt.setFloat("foodExhaustionLevel", this.foodExhaustionLevel); } /** * Get the player's food level. */ public int getFoodLevel() { return this.foodLevel; } @SideOnly(Side.CLIENT) public int getPrevFoodLevel() { return this.prevFoodLevel; } /** * If foodLevel is not max. */ public boolean needFood() { return this.foodLevel < 20; } /** * adds input to foodExhaustionLevel to a max of 40 */ public void addExhaustion(float amount) { this.foodExhaustionLevel = Math.min(this.foodExhaustionLevel + amount, 40.0F); } /** * Get the player's food saturation level. */ public float getSaturationLevel() { return this.foodSaturationLevel; } @SideOnly(Side.CLIENT) public void setFoodLevel(int amount) { this.foodLevel = amount; } @SideOnly(Side.CLIENT) public void setFoodSaturationLevel(float amount) { this.foodSaturationLevel = amount; } }
-
Hi everyone, So EntityPlayer has protected FoodStats foodStats = new FoodStats(); I want to replace this instance with my own so that I can control the food behaviour completely. I also have created my own FoodStats Class and made it extend the vanilla FoodStats class. This is the class where I will implement custom food behaviour. Now I know that to get the protected field I have to use ObfuscationReflectionHelper.getPrivateValue(EntityPlayer.class, (EntityPlayer)event.entity, "foodStats", "field_71100_bB"); I also know that to set a protected field I can use ObfuscationReflectionHelper.setPrivateValue(EntityPlayer.class, (EntityPlayer)event.entity, customFieldValue, "foodStats", "field_71100_bB"); But I am unsure how to actually do the replacement so that when the player begins gameplay the vanilla FoodStats Instance is thrown away and mine is put in its place. I have my EntityConstructing event, my IEEP class, a PlayerLoggedInEvent and a EntityJoinWorldEvent working and created but I am unsure what to do next. Any help is appreciated.
-
What I would do is create a bounding box within which I would check which entities are tracking the player. Then check if these entities have died or not. Look at @SubscribeEvent(priority=EventPriority.NORMAL) public void onTracking(PlayerEvent.StartTracking event) {}
-
[1.7.10][Solved] How to conditionally disable player hp regeneration
Thornack replied to Thornack's topic in Modder Support
I tried the following to get the field and it doesnt seem to fail, it outprints the following on EntityConstructing: TRYING custommod.player.properties.CustomFoodStats@16c8fa04 try{ Field field = ReflectionHelper.findField(EntityPlayer.class,"field_71100_bB","foodStats"); field.setAccessible(true); field.set((EntityPlayer)event.entity, new CustomFoodStats()); System.out.println("TRYING " + field.get(event.entity)); }catch (Throwable e){ System.out.println("Reflection on foodStats variable for Player has FAILED!!"); e.printStackTrace(); } -
[1.7.10][Solved] How to conditionally disable player hp regeneration
Thornack replied to Thornack's topic in Modder Support
Im not really sure what I have to do here to replace the FoodStats object that the player is using with my own. I know that I have to get the object but when I do that using Entity Constructing event I get a value of null for it and I know that I have to replace the object after it has been initialized with my own (the class is above) But i am not sure what the steps are -
[1.7.10][Solved] How to conditionally disable player hp regeneration
Thornack replied to Thornack's topic in Modder Support
I believe the SRG-name is field_71100_bB for 1.7.10 but I still get null when I use it -
[1.7.10][Solved] How to conditionally disable player hp regeneration
Thornack replied to Thornack's topic in Modder Support
Ok, so in my EntityConstructing event I get the access player#foodStats. But this outprints as Null when I do this. Im not sure what else to do @SubscribeEvent public void onEntityConstructing(EntityConstructing event) { if (event.entity instanceof EntityPlayer) { if (BattlePlayerProperties.get((EntityPlayer) event.entity) == null) { BattlePlayerProperties.register((EntityPlayer) event.entity); } FoodStats foodStats = ObfuscationReflectionHelper.getPrivateValue(EntityPlayer.class, (EntityPlayer)event.entity, "foodStats", "findSrgInFiles"); System.out.println(foodStats); //PRINTS A VALUE OF NULL } } -
[1.7.10][Solved] How to conditionally disable player hp regeneration
Thornack replied to Thornack's topic in Modder Support
I understand that copying the class wont do anything, I am bad at reflection so I guess I wasnt being clear I wasnt sure how to actually override the actual object so that I can use my class instead. -
[1.7.10][Solved] How to conditionally disable player hp regeneration
Thornack replied to Thornack's topic in Modder Support
in my IEEP I do the following. public CustomFoodStats foodStats = new CustomFoodStats(); to initialize it, Then inside the onLivingUpdate Event I get the IEEP instance from the player and then do ieep.foodStats.onUpdate((EntityPlayer) event.entity); but this doesnt override anything it just calls my onUpdate method -
[1.7.10][Solved] How to conditionally disable player hp regeneration
Thornack replied to Thornack's topic in Modder Support
Ok, Im not sure exactly how to do this. So far I have the following in my custom class (its all based on vanilla except the onUpdate method which is different (I changed it completely to just outprint to consol (the outprint doesnt currently show up btw))) The CustomFoodStats class public class CustomFoodStats extends FoodStats { /** The player's food level. */ private int foodLevel = 20; /** The player's food saturation. */ private float foodSaturationLevel = 5.0F; /** The player's food exhaustion. */ private float foodExhaustionLevel; /** The player's food timer value. */ private int foodTimer; private int prevFoodLevel = 20; /** * Args: int foodLevel, float foodSaturationModifier */ @Override public void addStats(int min, float max) { super.addStats(min, max); this.foodLevel = Math.min(min + this.foodLevel, 20); this.foodSaturationLevel = Math.min(this.foodSaturationLevel + (float)min * max * 2.0F, (float)this.foodLevel); } @Override public void func_151686_a(ItemFood food, ItemStack itemStack) { super.func_151686_a(food, itemStack); this.addStats(food.func_150905_g(itemStack), food.func_150906_h(itemStack)); } /** * Handles the food game logic. */ @Override public void onUpdate(EntityPlayer player) { super.onUpdate(player); System.out.println("OVERRIDDEN"); } /** * Reads food stats from an NBT object. */ @Override public void readNBT(NBTTagCompound nbt) { super.readNBT(nbt); if (nbt.hasKey("foodLevel", 99)) { this.foodLevel = nbt.getInteger("foodLevel"); this.foodTimer = nbt.getInteger("foodTickTimer"); this.foodSaturationLevel = nbt.getFloat("foodSaturationLevel"); this.foodExhaustionLevel = nbt.getFloat("foodExhaustionLevel"); } } /** * Writes food stats to an NBT object. */ @Override public void writeNBT(NBTTagCompound nbt) { super.writeNBT(nbt); nbt.setInteger("foodLevel", this.foodLevel); nbt.setInteger("foodTickTimer", this.foodTimer); nbt.setFloat("foodSaturationLevel", this.foodSaturationLevel); nbt.setFloat("foodExhaustionLevel", this.foodExhaustionLevel); } /** * Get the player's food level. */ @Override public int getFoodLevel() { super.getFoodLevel(); return this.foodLevel; } @Override @SideOnly(Side.CLIENT) public int getPrevFoodLevel() { super.getPrevFoodLevel(); return this.prevFoodLevel; } /** * If foodLevel is not max. */ @Override public boolean needFood() { super.needFood(); return this.foodLevel < 20; } /** * adds input to foodExhaustionLevel to a max of 40 */ @Override public void addExhaustion(float amount) { super.addExhaustion(amount); this.foodExhaustionLevel = Math.min(this.foodExhaustionLevel + amount, 40.0F); } /** * Get the player's food saturation level. */ @Override public float getSaturationLevel() { super.getSaturationLevel(); return this.foodSaturationLevel; } @Override @SideOnly(Side.CLIENT) public void setFoodLevel(int amount) { super.setFoodLevel(amount); this.foodLevel = amount; } @Override @SideOnly(Side.CLIENT) public void setFoodSaturationLevel(float amount) { super.setFoodSaturationLevel(amount); this.foodSaturationLevel = amount; } } -
[1.7.10][Solved] How to conditionally disable player hp regeneration
Thornack replied to Thornack's topic in Modder Support
Also, Im not really sure how to Override the food stats object for the player. I know how to override methods but Ive never overridden an object before. In Entityplayer the food stats variable is protected. I made my custom Food Stats Class extend the vanilla Food Stats class and in the onUpdate method I call super.onUpdate() and I put a @Override annotation above it as per usual. Not sure what else I am missing -
[1.7.10][Solved] How to conditionally disable player hp regeneration
Thornack replied to Thornack's topic in Modder Support
Would it be preferable to create my own custom class that extends the foodstats class and override its onUpdate method to conditionally disable the hp regen or would just updating forge be a better solution so that I can use the LivingHealEvent?