-
Posts
46 -
Joined
-
Last visited
Everything posted by Alekseyev
-
LivingJumpEvent issues: Firing twice, not finding capability/NBT
Alekseyev replied to Alekseyev's topic in Modder Support
There you go, these are the two log files I got: "Latest" "Debug" -
LivingJumpEvent issues: Firing twice, not finding capability/NBT
Alekseyev replied to Alekseyev's topic in Modder Support
Hey, sorry for replying so late - haven't really had the time to continue on it before due to unforseen developments. I currently have this method: @SubscribeEvent public void playerLogin(PlayerEvent.PlayerLoggedInEvent event) { System.out.println("Event active: playerLogin"); getHandler(event.player).setElement(BioElements.AIR); } If I add the line getHandler(Minecraft.getMinecraft().player).setElement(BioElements.AIR); to the it, the game crashes in the function public static IElementHandler getHandler(Entity entity) { if (entity.hasCapability(CAPABILITY_ELEMENT, EnumFacing.DOWN)) return entity.getCapability(CAPABILITY_ELEMENT, EnumFacing.DOWN); return null; } reporting a NullPointerException. If I add the same line in the LivingJumpEvent subscriber, it works completely fine and gives the desired result. I'm assuming this is because at the time the player joins the world, the entity Minecraft.getMinecraft().player doesn't exist yet? How do I get this to work? Or also, how do I have a method be called at a later point but be triggered within PlayerLoggedInEvent? Edit: If it helps anything, here's a github repository: https://github.com/JohnTheLate/NTutMod/tree/january2019/src/main/java/john/mod -
LivingJumpEvent issues: Firing twice, not finding capability/NBT
Alekseyev replied to Alekseyev's topic in Modder Support
How exactly do I do this? I followed this tutorial on capabilities: https://tutorials.darkhax.net/tutorials/custom_entity_data/ and I know the Forge documentation, but how to make it work on the client side specifically? -
LivingJumpEvent issues: Firing twice, not finding capability/NBT
Alekseyev replied to Alekseyev's topic in Modder Support
Right, but how do I store or retrieve the player's data that has been sent this way? In the event I could retrieve the object that performed the jump and then get its data, but how do I make sure the client has this data for this object? -
LivingJumpEvent issues: Firing twice, not finding capability/NBT
Alekseyev replied to Alekseyev's topic in Modder Support
Hey there, for a variety of reasons I didn't work on it since making the last post. Now, however, I decided to continue. How would I go about making sure the capability is synchronised between the server and the client? I found this tutorial on packets: Link, but it only fires once a certain action is performed. When jumping, sending the packets back and forth only upon requiring the capability info might be too slow? -
LivingJumpEvent issues: Firing twice, not finding capability/NBT
Alekseyev replied to Alekseyev's topic in Modder Support
I could have sword that it worked when testing your suggestion earlier, but now it doesn't. What I did was add // <check for EntityPlayer> if (evPlayer.world.isRemote) { // <code> } -
Hey again, I have a strange issue: I am subscribed to the LivingJumpEvent @SubscribeEvent public void jumpEffect(LivingEvent.LivingJumpEvent event) { if (event.getEntity() instanceof EntityPlayer) { System.out.println("jumpEvent: Entity is EntityPlayer"); EntityPlayer evPlayer = (EntityPlayer)event.getEntity(); Boolean abc = getHandler(evPlayer).getElement() == BioElements.AIR; Boolean def = 1+1 == 2; if (true) { System.out.println("Element is AIR, adjusting Jump 1"); evPlayer.motionY += 1.0D; } if (abc) // check for BioElements.AIR { System.out.println("Element is AIR, adjusting Jump 2"); evPlayer.motionX += 1.0D; } if (def) { System.out.println("Element is AIR, adjusting Jump 3"); evPlayer.motionZ += 1.0D; } } } The strange conditions like "def" and (true) are for testing. What I found out: When I jump in "single player", the event is first called for EntityPlayerSP. It does not find the capability or NBT data required for the boolean abc, so there is no movement on the X axis. Then, immediately after, it is called again for EntityPlayerMP. This time, all 3 conditions are met, however the movement change is not actually applied. However, If I jump and then receive damage mid-air (such as jumping against a cactus or getting hit by a mob), then the effects are all applied, including the previously missing X motion. Any advice on how to solve it?
-
BlockEvent.BreakEvent problem: Block not replaceable
Alekseyev replied to Alekseyev's topic in Modder Support
That was quick. Works great. Vielen Dank. :D -
I have the following code, to check if the player destroyed a stone block while wearing a certain tool (a fire sword), and if that is the case, replace the block in question by lava. @SubscribeEvent public void breakBlock(BlockEvent.BreakEvent event) { System.out.println("Event active: breakBlock"); if (event.getPlayer().inventory.getCurrentItem().getItem() == ItemInit.SWORD_FIRE) { System.out.println("Fire Sword found"); if (event.getState().getBlock() == Blocks.STONE) { System.out.println("Stone Block found"); event.getWorld().setBlockState((new BlockPos(event.getPos().getX() + 1, event.getPos().getY(), event.getPos().getZ())), Blocks.LAVA.getDefaultState()); } } } However, there is a problem: The code will replace any block, anywhere, just fine, except for the position of the destroyed block. So in the code above, I made it adjust the X position by +1, and it works. If I however do not do that, and use the actual broken block's positon, the lava will simply not be placed. (I know that the position can be accessed/set much better, but for testing reasons I split up all the coordinates.)
-
Changing the exhaustion level gained from doing actions
Alekseyev replied to Alekseyev's topic in Modder Support
What I did for now is to check if the foodstats of the player are an instance of CustomFoodStats. If that's the case, print a short notification, otherwise proceed as normal and replace it. Of course it's not perfect, as @Draco18s pointed out, but during debugging it did indeed seem like the stats are reverted to vanilla each time the world is joined, as the replacement always takes place. Thanks a lot for the help! :) -
Changing the exhaustion level gained from doing actions
Alekseyev replied to Alekseyev's topic in Modder Support
I'm a little embarrassed, now. Should have thought of debugging myself, but for some reason I often forget about that feature when doing stuff for Minecraft. Anyway, it seems like I somehow built up an insane stack of negative exhaustion (talking 6 figure negative number here), after resetting that to be positive, it works as intended. One thing I am wondering about, though: Will the player's FoodStats be reset to the vanilla class on every new joining of the world? Otherwise, the reflection triggered by each EntityJoinWorldEvent would loop and you'd get a deeply nested FoodStat under all those CustomFoodStats, right? -
Changing the exhaustion level gained from doing actions
Alekseyev replied to Alekseyev's topic in Modder Support
Alright, I'll look into the names. About the second thing: If you give the player 1 exhaustion per tick, the food bar will deplete in mere seconds. Using the same thing rerouted over CustomFoodStats does not have the same effect, regardless of calling it with or without the multiplier. I.e. I have this: @SubscribeEvent public void playerTick(TickEvent.PlayerTickEvent event) { event.player.getFoodStats().addExhaustion(1.0F); } for debug reasons. With the original, non-replaced FoodStats, it gives the desired effect of emptying your hunger bar in the blink of an eye. However, after I replaced the FoodStats with CustomFoodStats as decribed above, it ceases to work. -
Changing the exhaustion level gained from doing actions
Alekseyev replied to Alekseyev's topic in Modder Support
Thanks to you both for your answers. I think I'm making progress: I used reflection to replace the variable: @SubscribeEvent public void entityJoinWorld(EntityJoinWorldEvent event) { if (event.getEntity() instanceof EntityPlayer) { System.out.println("entityJoinWorld: Entity is EntityPlayer"); EntityPlayer evPlayer = (EntityPlayer)event.getEntity(); FoodStats oldFoodStats = evPlayer.getFoodStats(); CustomFoodStats newFoodStats = new CustomFoodStats(oldFoodStats, getHandler(evPlayer).getElement() == BioElements.ICE); System.out.println("Starting Reflection"); ReflectionHelper.setPrivateValue(EntityPlayer.class, evPlayer, newFoodStats, 15); } } and changed the CustomFoodClass as follows: I see the addExhaustion method being called a lot, which indicates to me that the replacement worked. However, while eating does correctly increase my food meter, I cannot seem to decrease it by any means - do you have any ideas on what could cause that? -
Changing the exhaustion level gained from doing actions
Alekseyev replied to Alekseyev's topic in Modder Support
Sorry for being so obtuse. Currently I have this code: @SubscribeEvent public void entityJoinWorld(EntityJoinWorldEvent event) { if (event.getEntity() instanceof EntityPlayer) { CustomFoodStats newFoodStats = new CustomFoodStats((EntityPlayer)event.getEntity()); } } And then the CustomFoodStats class: public class CustomFoodStats extends FoodStats { boolean isIce; FoodStats oldStats; public CustomFoodStats(EntityPlayer player) { super(); if (getHandler(player).getElement() == BioElements.ICE) { isIce = true; } oldStats = player.getFoodStats(); } @Override public void addExhaustion(float exhaustion) { if (isIce) { super.addExhaustion(exhaustion*20); // For testing purposes, will be /2 later } else { super.addExhaustion(exhaustion); } } } But... how to actually replace the old FoodStats with the custom, new one? -
Changing the exhaustion level gained from doing actions
Alekseyev replied to Alekseyev's topic in Modder Support
Thanks for the answer. However... how exactly would I go about doing that? (Taking in the original instance/overwriting it) -
Hey all, I have a question once again: How would I go about doing the following: I want to have players with a certain variable set only use up food half as quickly. Now the setting, storing, retrieving of said variable via the capability system is not an issue, my problem lies with the food mechanics. (As found in FoodStats.java) There is no method to get the exhaustion level from outside, and also no check preventing the addExhaustion method from reducing the exhaustion value to negative values. What I'm looking for is either: a) a way to intercept the calling of "addExhaustion" from outside, halving its value if other conditions are met, or b) some enlightenment on how you'd implement a system of reduced food consumption (while also keeping the original consumption system in place for when the conditions aren't met) Regards!
-
Hi all, I have a question. Let's say I want to have some crafting recipes that either give a different result are simply unavailable depending on a variable. (The question is not how to store/read this variable, but how to hijack the vanilla crafting process.) Two simple completely arbitrary examples: 1. Standard crafting recipe is 4 sand becomes 1 sandstone. Now I want to check some data stored on the player and if variable A = 3, putting 4 sand into the crafting box gives 4 sandstone instead of 1. 2. Usually, putting one piece of sand into the crafting box does nothing. If variable A = 4, it should be able to be crafted into glass. The idea is that this variable can be different for each player, so some should get these crafting options and others not. Is it even possible with vanilla crafting? I know that Thaumcraft has crafting recipes that you have to unlock first and per player, but those use a special custom crafting table. Regards
-
How do decompile and deobfuscate Minecraft code?
Alekseyev replied to s1320dazkj02's topic in Modder Support
Thanks! For some reason, I must have completely missed the net folder... and used MCP due to that. Now after having asked, I find it... classic. -
How do decompile and deobfuscate Minecraft code?
Alekseyev replied to s1320dazkj02's topic in Modder Support
I used the guide to setup the gradle workspace (and I can successfully run a custom mod from Eclipse), but where do I actually find the mentioned decompiled source code of the game? I can only find my own src files...