Jump to content

Recommended Posts

Posted

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.

Posted

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
Posted

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
}

Posted

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
Posted

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.

Posted

"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.

Posted

"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.

Posted

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.

Posted

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.

Posted

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

Posted

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/

Posted

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.

Posted

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/

Posted
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.

Posted

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

Posted
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.

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.

Announcements



×
×
  • Create New...

Important Information

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