Posted August 14, 201411 yr So a youtuber named Syndicate said that he really wanted an enchantment that would let you walk on water. How would I go about doing that? Would I have the effect use the property of a boat floating in order to float on water? Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr I'd make the player's motionY 0.0 when the block below him is water. -Mitchellbrine Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible. It may be freaking fucking hard though, but still possible If you create a topic on Modder Support, live by this motto: I don't want your charity, I want your information
August 14, 201411 yr Author Would I put that in my tick handler class Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr Why not put it in whatever Item class that has the enchantment? Or would the enchantment be on many different kinds of items? In the latter case, I'd put it in the PlayerTickEvent. I've done something similar in the past, and I found that subtracting the previous motionY before equalizing it gave the best results, something like: flag = is block directly under player a water block? if (flag && player.motionY < 0.0D) { player.posY += -player.motionY; // player is falling, so motionY is negative, but we want to reverse that player.motionY = 0.0D; // no longer falling player.fallDistance = 0.0F; // otherwise I believe it adds up, which may surprise you when you come down } http://i.imgur.com/NdrFdld.png[/img]
August 14, 201411 yr Author Not sure what to do with the flag Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr World.getBlock much? -Mitchellbrine Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible. It may be freaking fucking hard though, but still possible If you create a topic on Modder Support, live by this motto: I don't want your charity, I want your information
August 14, 201411 yr Author Nope doesn't work Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr Nope doesn't work <sigh> Your last few comments sorely contest the bold statement in your signature... int i = MathHelper.floor_double(player.posX); int j = MathHelper.floor_double(player.boundingBox.minY); int k = MathHelper.floor_double(player.posZ); Material m = world.getBlock(i, j, k).getMaterial(); boolean flag = (m == Material.water); // or m.isLiquid() or whatever you want. http://i.imgur.com/NdrFdld.png[/img]
August 14, 201411 yr Author "Cannot make a static reference to the non-static method getBlock(int, int, int) from the type World" Sorry this may be noob questions The signature was just so that people started helping me rather than saying "Learn Basic Java" in situations that had nothing to do with basic java Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr Author BTW, the first thing is the error I get on World.getBlock(i, j, k).getMaterial(); Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr couldnt you check to see if the block below is an instance of BlockLiquid and then make your y movement 0?
August 14, 201411 yr "Cannot make a static reference to the non-static method getBlock(int, int, int) from the type World" Sorry this may be noob questions The signature was just so that people started helping me rather than saying "Learn Basic Java" in situations that had nothing to do with basic java Sure, but that is exactly the kind of thing people mean when they say 'Learn Basic Java' - that error message is basic Java, as in you cannot do "World.method()" because the method is not a static method, so you need an instance of World to access it. A little time on Google or Oracle's Java tutorials page goes a long way. http://i.imgur.com/NdrFdld.png[/img]
August 14, 201411 yr Author So that would be like "public static getBlock(int i, int j, int k)" Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr So that would be like "public static getBlock(int i, int j, int k)" Just Google 'cannot make a static reference' and you'll learn all about it. And no, you are NOT going to be re-writing the class methods of World. You need an instance of World - Google 'instance of class' or 'class object' or go through any basic Java tutorial and you'll learn what that is. Please. http://i.imgur.com/NdrFdld.png[/img]
August 14, 201411 yr Author So I did some research and I tried "World world = new World();" but I get "Cannot instantiate the type World" and I can't find an answer for this Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr So I did some research and I tried "World world = new World();" but I get "Cannot instantiate the type World" and I can't find an answer for this Even if you could instantiate it, it would be wrong to do so - how did you plan on initializing that object to contain all the correct information? Anyway, at least you did some research. Whenever you are in need of something, chances are you can find it in the parameters passed to whatever method you are in (you are writing this code inside of some class method somewhere, right? like onItemUpdate or something, right???). http://i.imgur.com/NdrFdld.png[/img]
August 14, 201411 yr Author Yes, it's under onPlayerTick Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr Yes, it's under onPlayerTick So what's the problem? Every entity has a world object, and the player is an entity. http://i.imgur.com/NdrFdld.png[/img]
August 14, 201411 yr For finding the block under an entity, you need to be bit careful with the y value as entities have a yOffset. if you follow the code in the build-in method onEntityWalking() I think you need code like this: public Block findBlockUnderEntity() { return worldObj.getBlock(MathHelper.floor_double(posX), MathHelper.floor_double(posY - 0.20000000298023224D - (double)yOffset), MathHelper.floor_double(posZ)); } Check out my tutorials here: http://jabelarminecraft.blogspot.com/
August 14, 201411 yr For finding the block under an entity, you need to be bit careful with the y value as entities have a yOffset. if you follow the code in the build-in method onEntityWalking() I think you need code like this: public Block findBlockUnderEntity() { return worldObj.getBlock(MathHelper.floor_double(posX), MathHelper.floor_double(posY - 0.20000000298023224D - (double)yOffset), MathHelper.floor_double(posZ)); } Or you could use what I mentioned earlier, though I forgot to mention you need to subtract 1 to get the block underneath: int j = MathHelper.floor_double(player.boundingBox.minY); That way you don't have to worry about any offset, as it's already at your feet regardless of the entity's size. http://i.imgur.com/NdrFdld.png[/img]
August 14, 201411 yr Yeah, boundingbox is good idea, but I was worried about your lack of -1 ... I know I've been immensely frustrated before trying to debug why code wasn't returning the block until I realized the -1 was missing... so I got in the habit of just copying the vanilla onEntityWalking(). But now that you mention it, for custom entities the yOffset is likely not very trustworthy while boundingbox is. Good idea. (Note this thread is becoming one of those where we all have fun showing off our expertise, but I'm not sure the person who started the thread is really making progress...) Check out my tutorials here: http://jabelarminecraft.blogspot.com/
August 14, 201411 yr Author So what's the problem? Every entity has a world object, and the player is an entity. I don't know why I'm getting that error, here is the entire code public static void onPlayerTick(EntityPlayer player){ if(player.getCurrentArmor(0)!= null){ ItemStack boots = player.getCurrentArmor(0); if(boots.getItem() == Items.diamond_boots || boots.getItem() == Items.golden_boots || boots.getItem() == Items.iron_boots || boots.getItem() == Items.leather_boots || boots.getItem() == Items.chainmail_boots || boots.getItem() == PupletItems.bootsPuplet){ World world = new World(); int i = MathHelper.floor_double(player.posX); int j = MathHelper.floor_double(player.boundingBox.minY - 1); int k = MathHelper.floor_double(player.posZ); Material m = world.getBlock(i, j, k).getMaterial(); boolean flag = (m == Material.water); int l = EnchantmentHelper.getEnchantmentLevel(MainClass.waterWalking.effectId, boots); if(l > 0 && flag && player.motionY < 0.0D){ player.posY += -player.motionY; player.motionY = 0.0D; player.fallDistance = 0.0F; } } } } Don't tell me to learn the basics of java, I already know.
August 14, 201411 yr <sigh> replace World world = new World(); with World world = player.worldObj; Every entity instance has a field with reference to world it belongs to. And yes, go learn some basic Java. Learn to analyze Forge sources you already have at your hand.
August 14, 201411 yr public static void onPlayerTick(EntityPlayer player) That's not how events work. Here is a tutorial on how to use events. http://i.imgur.com/NdrFdld.png[/img]
August 14, 201411 yr Author That's not how events work. Yeah, just reliazed. However, now whenever I walk on water with the boots minecraft gives me an error that says "Illegal stance." Don't tell me to learn the basics of java, I already know.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.