Jump to content

Walking on water


yanksrock1019

Recommended Posts

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
Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

"Cannot make a static reference to the non-static method getBlock(int, int, int) from the type World"

 

Sorry this may be noob questions :P

 

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.

Link to comment
Share on other sites

"Cannot make a static reference to the non-static method getBlock(int, int, int) from the type World"

 

Sorry this may be noob questions :P

 

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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??????).

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were intended to be used on tutorial posts so that people could easily find tutorials based on their skill level, but instead the tags were abused for unrelated things that made the original intent useless... for example, people often posted crash reports with the "beginner" tag, so instead of finding tutorials for beginners, you got crash reports showing up in searches.
    • The crash says: Exception caught when registering wandering trader java.lang.NullPointerException: Cannot invoke "net.minecraft.world.entity.Entity.m_9236_()" because "entity" is null at com.telepathicgrunt.repurposedstructures.misc.maptrades.StructureSpecificMaps$TreasureMapForEmeralds.m_213663_(StructureSpecificMaps.java:53) ~[repurposed_structures-7.1.15+1.20.1-forge.jar%23708!/:?] at jeresources.collection.TradeList.addMerchantRecipe(TradeList.java:58) ~[JustEnoughResources-1.20.1-1.4.0.247.jar%23630!/:1.4.0.247] JustEnoughResources is mentioned, too Does it work without one of these mods?
    • I have been trying to place a jigsaw structure for about a week now and cant get it to work. I have the template pool etc set up and working it does randomly generate now I just want to place it in the world using a coded trigger. I cant seem to find any useful information on the internet and am completely stuck I think I need to use : JigsawPlacement.generateJigsaw() But I cant get the Holder<StructureTemplatePool>
    • There are more - maybe   watut, whatdurability, playeranimator and vanillafix
    • cen you be a bit more specific pls there are many mods in the log mentioned by name does any error mention it or something couse when i search on   repurposed_structures i dont find anything helpfull cen you tell me which line you say that it might couse the problem?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.