Jump to content

[1.7.10] Prevent Item From Falling in Liquid


mrkirby153

Recommended Posts

Hey guys,

 

How can I prevent an item from falling in a liquid. This is the code I have now but the item just seems to jump around and stuff:

 

package me.mrkirby153.KCNerfer.playTime;

import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class IndestructibleItem extends EntityItem {

    private final EntityPlayer owner;

    public IndestructibleItem(EntityPlayer owner, World world, double x, double y, double z, ItemStack itemStack) {
        super(world, x, y, z, itemStack);
        this.isImmuneToFire = true;
        this.owner = owner;
    }

    public boolean canPickup(EntityPlayer player) {
        return player.getCommandSenderName().equalsIgnoreCase(this.owner.getCommandSenderName());
    }

    @Override
    public boolean isEntityInvulnerable() {
        return true;
    }

    @Override
    public boolean canRenderOnFire() {
        return false;
    }

    @Override
    public void onUpdate() {
        super.onUpdate();
        Block currentBlock = worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ));
        if (currentBlock == null)
            return;
        if (currentBlock instanceof BlockLiquid) {
            posY += 1;
//            System.out.println("in liquid");
        }
    }
}

 

Link to comment
Share on other sites

Hey guys,

 

How can I prevent an item from falling in a liquid. This is the code I have now but the item just seems to jump around and stuff:

 

package me.mrkirby153.KCNerfer.playTime;

import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class IndestructibleItem extends EntityItem {

    private final EntityPlayer owner;

    public IndestructibleItem(EntityPlayer owner, World world, double x, double y, double z, ItemStack itemStack) {
        super(world, x, y, z, itemStack);
        this.isImmuneToFire = true;
        this.owner = owner;
    }

    public boolean canPickup(EntityPlayer player) {
        return player.getCommandSenderName().equalsIgnoreCase(this.owner.getCommandSenderName());
    }

    @Override
    public boolean isEntityInvulnerable() {
        return true;
    }

    @Override
    public boolean canRenderOnFire() {
        return false;
    }

    @Override
    public void onUpdate() {
        super.onUpdate();
        Block currentBlock = worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ));
        if (currentBlock == null)
            return;
        if (currentBlock instanceof BlockLiquid) {
            posY += 1;
//            System.out.println("in liquid");
        }
    }
}

try setting the velocity to 0.

I'm back from being gone for... I think its been about a year. I'm pretty sure nobody remembers me, but hello anybody who does!

Link to comment
Share on other sites

Hey guys,

 

How can I prevent an item from falling in a liquid. This is the code I have now but the item just seems to jump around and stuff:

 

package me.mrkirby153.KCNerfer.playTime;

import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class IndestructibleItem extends EntityItem {

    private final EntityPlayer owner;

    public IndestructibleItem(EntityPlayer owner, World world, double x, double y, double z, ItemStack itemStack) {
        super(world, x, y, z, itemStack);
        this.isImmuneToFire = true;
        this.owner = owner;
    }

    public boolean canPickup(EntityPlayer player) {
        return player.getCommandSenderName().equalsIgnoreCase(this.owner.getCommandSenderName());
    }

    @Override
    public boolean isEntityInvulnerable() {
        return true;
    }

    @Override
    public boolean canRenderOnFire() {
        return false;
    }

    @Override
    public void onUpdate() {
        super.onUpdate();
        Block currentBlock = worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ));
        if (currentBlock == null)
            return;
        if (currentBlock instanceof BlockLiquid) {
            posY += 1;
//            System.out.println("in liquid");
        }
    }
}

try setting the velocity to 0.

That didn't work. It still glitches around.

Link to comment
Share on other sites

Well if you actually go and look at the onUpdate function of EntityItem, you'd see why.

 

this.motionY -= 0.03999999910593033D;
this.moveEntity(this.motionX, this.motionY, this.motionZ);

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Well if you actually go and look at the onUpdate function of EntityItem, you'd see why.

 

this.motionY -= 0.03999999910593033D;
this.moveEntity(this.motionX, this.motionY, this.motionZ);

 

I see that the entity is still having its y axis position lowered. However, this doesn't really explain how to arrest the movement of an item.

Link to comment
Share on other sites

You know what the code does.

You know that the code runs.

What do you have to do such that when the code does what it does when it runs will it have the effect of stopping the motion?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You know what the code does.

You know that the code runs.

What do you have to do such that when the code does what it does when it runs will it have the effect of stopping the motion?

 

Okay. I saw that the entity was being moved down by  0.03999999910593033D so I tried conteracting that by moving it up by  0.03999999910593033D (The same number), but the item still glitches around. Code now:

 

@Override
    public void onUpdate() {
        super.onUpdate();
        Block currentBlock = worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ));
        /*if (currentBlock == null)
            return;
        if (currentBlock instanceof BlockLiquid) {
            this.motionY += 0.03999999910593033D;
            this.moveEntity(motionX, motionY, motionZ);
        }
        Block blockBelow = worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY -1), (int) Math.floor(posZ));
        if(blockBelow instanceof BlockLiquid){
            this.motionY += 0.03999999910593033D;
            this.moveEntity(motionX, motionY, motionZ);
        }*/
        this.motionY += 0.03999999910593033D;
        this.moveEntity(motionX, motionY, motionZ);
    }

Link to comment
Share on other sites

I included two lines, but you really only need to do one thing.  (Note: I haven't done something like this myself)

 

Try

public void onUpdate() {
    Block blockBelow = worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY -1), (int) Math.floor(posZ));
        if(blockBelow instanceof BlockLiquid){
            this.motionY = 0.03999999910593033D;
        }
    super.onUpdate();
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I included two lines, but you really only need to do one thing.  (Note: I haven't done something like this myself)

 

Try

public void onUpdate() {
    Block blockBelow = worldObj.getBlock((int) Math.floor(posX), (int) Math.floor(posY -1), (int) Math.floor(posZ));
        if(blockBelow instanceof BlockLiquid){
            this.motionY = 0.03999999910593033D;
        }
    super.onUpdate();
}

 

Hilariously, that still made the item bounce around. Does this have to deal with client/server syncing?

Link to comment
Share on other sites

Possible.  As I said, I haven't really looked into it, but you might be best off completely overriding onUpdate (copy all of the code from super and then edit as needed).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You would have to give correct acceleration for that, depend on the height from the liquid block.

giving same acceleration when it is over BlockLiquid would just make it glitch around, since it would not be 'smooth'

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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.

Announcements



×
×
  • Create New...

Important Information

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