Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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");
        }
    }
}

 

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!

  • Author

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.

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.

  • Author

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.

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.

  • Author

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);
    }

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.

  • Author

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?

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.

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.