Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.4] Checking an ItemEntity is in water.
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 3
AzizD

[1.16.4] Checking an ItemEntity is in water.

By AzizD, January 3 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

AzizD    0

AzizD

AzizD    0

  • Tree Puncher
  • AzizD
  • Members
  • 0
  • 9 posts
Posted January 3
    @SubscribeEvent
    public static void crimsonIngotCraft(EntityJoinWorldEvent event){
        Entity entity = event.getEntity();
        if(entity instanceof ItemEntity){
            ItemEntity itemEntity = (ItemEntity) event.getEntity();
            if(itemEntity.getItem().getItem() == itemInit.RED_PEARL.get()){
                System.out.println("Working!!");
                if(itemEntity.isInWater()){
                    System.out.println("Not working :(");
                    itemEntity.remove();
                  	//FIXME Continue.
                }
            }
        }
    }

Everything is working except the

if(itemEntity.isInWater()){
                    System.out.println("Not working :(");
                    itemEntity.remove();
                }

this part. I wanna create a recipe that you throw an item into water and water transforms into another block.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2403

Draco18s

Draco18s    2403

  • Reality Controller
  • Draco18s
  • Members
  • 2403
  • 15926 posts
Posted January 3 (edited)

Well of course. That would only be true if the entity spawned already in the water.

(Try throwing your item while under water).

 

If you want to check for it being in water some time later you need to replace the entity with a custom entity and override the relevant method (there should already be one for when an entity is in water, or enters water, but Update would also work).

Edited January 3 by Draco18s
  • Quote

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.

Share this post


Link to post
Share on other sites

AzizD    0

AzizD

AzizD    0

  • Tree Puncher
  • AzizD
  • Members
  • 0
  • 9 posts
Posted January 4
    @SubscribeEvent
    public static void crimsonIngotCraft(EntityJoinWorldEvent event){
        Entity entity = event.getEntity();
        World world = entity.world;
        double posX = entity.getPosX();
        double posY = entity.getPosY();
        double posZ = entity.getPosZ();
        if(entity instanceof ItemEntity && !(entity instanceof SpecialItemEntity)){
            ItemEntity itemEntity = (ItemEntity) event.getEntity();
            if(itemEntity.getItem().getItem() == itemInit.RED_PEARL.get()){
                SpecialItemEntity ie = new SpecialItemEntity(entity.world,entity.getPosX(),entity.getPosY(),entity.getPosZ(),((ItemEntity) entity).getItem());
                event.setCanceled(true);
                SpecialItemEntity specialItemEntity = new SpecialItemEntity(world,posX,posY,posZ,((ItemEntity) entity).getItem().getStack());
            }
        }
    }

I changed code into this and SpecialItemEntity clas is:

package com.azizd.thunderbird.entities;

import com.azizd.thunderbird.init.blockInit;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class SpecialItemEntity extends ItemEntity {
    public SpecialItemEntity(World worldIn, double x, double y, double z, ItemStack stack) {
        super(worldIn, x, y, z, stack);
    }

    @Override
    public void tick() {
        BlockPos pos= new BlockPos(getPosX(),getPosY(),getPosZ());
        if(inWater){
            this.setDead();
            this.world.setBlockState(pos,blockInit.BLOCK_OF_RED_PEARL.get().getDefaultState());
        }
    }
}

The item deletes when i press the q button.

  • Quote

Share this post


Link to post
Share on other sites

Beethoven92    69

Beethoven92

Beethoven92    69

  • Dragon Slayer
  • Beethoven92
  • Members
  • 69
  • 556 posts
Posted January 4

You are canceling the event but you are not spawning your custom entity in the world. Also if you just need to change your item into something else when that item touches water i think you could just override the onEntityItemUpdate method inside your item class

  • Quote

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

A little fun project: https://www.curseforge.com/minecraft/mc-mods/two-players-one-horse

Share this post


Link to post
Share on other sites

AzizD    0

AzizD

AzizD    0

  • Tree Puncher
  • AzizD
  • Members
  • 0
  • 9 posts
Posted January 4

It is kinda working right now.

This is EventHandler part

public static void crimsonIngotCraft(EntityJoinWorldEvent event){
        Entity entity = event.getEntity();
        World world = entity.world;
        double posX = entity.getPosX();
        double posY = entity.getPosY();
        double posZ = entity.getPosZ();
        if(entity instanceof ItemEntity && !(entity instanceof SpecialItemEntity)){
            ItemEntity itemEntity = (ItemEntity) event.getEntity();
            if(itemEntity.getItem().getItem() == itemInit.RED_PEARL.get()){
                event.setCanceled(true);
                SpecialItemEntity specialItemEntity = new SpecialItemEntity(world,posX,posY,posZ);
                specialItemEntity.setItem(itemEntity.getItem());
                world.addEntity(specialItemEntity);
            }
        }
    }

 

and this is the special item entity class
 

package com.azizd.thunderbird.entities;

import com.azizd.thunderbird.init.itemInit;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.extensions.IForgeEntity;

public class SpecialItemEntity extends ItemEntity implements IForgeEntity {
    public SpecialItemEntity(World worldIn, double x, double y, double z) {
        super(worldIn, x, y, z);
    }

    @Override
    public void tick() {
        ItemEntity entity = new ItemEntity(getEntityWorld(),this.getPosX(),this.getPosY(),this.getPosZ());
        if(this.inWater){
            this.setDead();
            entity.setItem(new ItemStack(itemInit.CRIMSON_INGOT.get()));
            this.world.addEntity(entity);
        }
        ItemStack stack = this.getItem();

        if (stack != null && stack.getItem() != null && stack.getItem().onEntityItemUpdate(this.getItem(),entity)) return;
        if(entity == null) this.setDead();
        else{
            super.tick();
            this.setDefaultPickupDelay();
            this.prevPosX = this.getPosX();
            this.prevPosY = this.getPosY();
            this.prevPosZ = this.getPosZ();
            this.setMotion(0,-0.098,0);
        }
    }
}

 

The item converting part is complete but i can't pickup the item i threw and motion part is bad. When i  throw a whole stack it gives 1 single item rather than giving a stack.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2403

Draco18s

Draco18s    2403

  • Reality Controller
  • Draco18s
  • Members
  • 2403
  • 15926 posts
Posted January 5 (edited)
3 hours ago, AzizD said:

ItemEntity entity = new ItemEntity(getEntityWorld(),this.getPosX(),this.getPosY(),this.getPosZ());

Why are you creating a new ItemEntity every tick?

  

3 hours ago, AzizD said:

if (stack != null && stack.getItem() != null

Neither of these will ever be true.

Edited January 5 by Draco18s
  • Quote

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.

Share this post


Link to post
Share on other sites

AzizD    0

AzizD

AzizD    0

  • Tree Puncher
  • AzizD
  • Members
  • 0
  • 9 posts
Posted January 6

I am settting the pickup delay to default every tick. This is why i cant pick up the item. The motion part is incomplete so item drop part is bad.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2403

Draco18s

Draco18s    2403

  • Reality Controller
  • Draco18s
  • Members
  • 2403
  • 15926 posts
Posted January 7

No, you're creating a new entity, diddling some of its values, and then throwing it in the garbage when the method returns.

On 1/4/2021 at 4:21 PM, AzizD said:

if(entity == null)

This is also never false because you set entity = new ItemEntity already.

  • Quote

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.

Share this post


Link to post
Share on other sites

AzizD    0

AzizD

AzizD    0

  • Tree Puncher
  • AzizD
  • Members
  • 0
  • 9 posts
Posted January 12

I solved the pickup bug. The only problem is SpecialItemEntity motion.

  • Quote

Share this post


Link to post
Share on other sites

AzizD    0

AzizD

AzizD    0

  • Tree Puncher
  • AzizD
  • Members
  • 0
  • 9 posts
Posted January 13

Finally i fixed all the problems. Now it works exactly what i want.

 

This is my EventHandler Method 

@SubscribeEvent
    public static void crimsonIngotCraft(EntityJoinWorldEvent event){
        Entity entity = event.getEntity();
        World world = entity.world;
        double posX = entity.getPosX();
        double posY = entity.getPosY();
        double posZ = entity.getPosZ();
        if(entity instanceof ItemEntity && !(entity instanceof SpecialItemEntity)){
            ItemEntity itemEntity = (ItemEntity) event.getEntity();
            if(itemEntity.getItem().getItem() == itemInit.RED_PEARL.get()){
                event.setCanceled(true);
                SpecialItemEntity specialItemEntity = new SpecialItemEntity(world,posX,posY,posZ);
                specialItemEntity.setItem(itemEntity.getItem().getStack());
                specialItemEntity.setPickupDelay(50);
                specialItemEntity.setMotion(itemEntity.getMotion());
                world.addEntity(specialItemEntity);
            }
        }
    }

 

And this is my SpecialItemEntity class

package com.azizd.thunderbird.entities;

import com.azizd.thunderbird.init.itemInit;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.extensions.IForgeEntity;

public class SpecialItemEntity extends ItemEntity implements IForgeEntity {
    public SpecialItemEntity(World worldIn, double x, double y, double z) {
        super(worldIn, x, y, z);
    }
    ItemEntity entity = new ItemEntity(getEntityWorld(),this.getPosX(),this.getPosY(),this.getPosZ());

    @Override
    public void tick() {
        if(this.inWater){
            this.setDead();
            int count = this.getItem().getCount();
            entity.setPosition(this.getPosX(),this.getPosY(),this.getPosZ());
            entity.setItem(new ItemStack(itemInit.CRIMSON_INGOT.get()));
            entity.getItem().setCount(count);
            this.world.addEntity(entity);
        }
        else{
            super.tick();
        }
    }
}


Thanks for the helps.

  • Quote

Share this post


Link to post
Share on other sites

AzizD    0

AzizD

AzizD    0

  • Tree Puncher
  • AzizD
  • Members
  • 0
  • 9 posts
Posted January 13

But i still have a bug. If specialItemEntity is in the world. I can't join that world.

  • Quote

Share this post


Link to post
Share on other sites

poopoodice    111

poopoodice

poopoodice    111

  • Dragon Slayer
  • poopoodice
  • Members
  • 111
  • 892 posts
Posted January 13 (edited)

Why do you keep adding the same entity to the world every tick?

Edit: my bad, misread the code.

 

 

Edited January 13 by poopoodice
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2403

Draco18s

Draco18s    2403

  • Reality Controller
  • Draco18s
  • Members
  • 2403
  • 15926 posts
Posted January 13
3 hours ago, AzizD said:

ItemEntity entity = new ItemEntity(getEntityWorld(),this.getPosX(),this.getPosY(),this.getPosZ());

Why is this a class property and not a local variable?

  • Quote

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.

Share this post


Link to post
Share on other sites

AzizD    0

AzizD

AzizD    0

  • Tree Puncher
  • AzizD
  • Members
  • 0
  • 9 posts
Posted January 13
53 minutes ago, Draco18s said:

Why is this a class property and not a local variable?

This is not the issue.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2403

Draco18s

Draco18s    2403

  • Reality Controller
  • Draco18s
  • Members
  • 2403
  • 15926 posts
Posted January 13
17 minutes ago, AzizD said:

This is not the issue.

I didn't say it was. I was asking why you did it because its stupid.

  • Quote

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.

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 3
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      [1.16.3] Server won't start

      By diesieben07 · Posted 1 minute ago

      1.16.4 and 1.16.5 have almost no changes compared to 1.16.3, so mods should just load fine.
    • Silivek
      Mod won't load when in dev environment

      By Silivek · Posted 1 minute ago

      I'm pretty sure my code is horrendous and there are most likely files in the wrong places, but I can't figure out what is wrong. Minecraft will load up fine but only have forge running. My GitHub page is here
    • thinkcraftpl
      [1.16.3] Server won't start

      By thinkcraftpl · Posted 6 minutes ago

      This forge version is newest for 1.16.3 and some of mods I want to use don't support higher versions
    • diesieben07
      [1.16.3] Server won't start

      By diesieben07 · Posted 8 minutes ago

      I would recommend you stick with either an LTS version of Java or use the latest, otherwise you will not receive updates. However, your Forge version is outdated anyways, you should update.
    • thinkcraftpl
      [1.16.3] Server won't start

      By thinkcraftpl · Posted 11 minutes ago

      So to use this forge version I need to downgrade java to 11?
  • Topics

    • thinkcraftpl
      5
      [1.16.3] Server won't start

      By thinkcraftpl
      Started 27 minutes ago

    • Silivek
      0
      Mod won't load when in dev environment

      By Silivek
      Started 1 minute ago

    • monkeysHK
      1
      Register a Custom Command

      By monkeysHK
      Started 15 minutes ago

    • Luis_ST
      1
      [1.16.5] get SeverWorld

      By Luis_ST
      Started 33 minutes ago

    • Klarks
      20
      [1.16.4] what difference between custom slots and EquipmentSlotType

      By Klarks
      Started 11 hours ago

  • Who's Online (See full list)

    • Silivek
    • diesieben07
    • thinkcraftpl
    • aznkv
    • magn919
    • ozi
    • Harleyletsplay
    • Nite_Shad0w
    • Luis_ST
    • Warsade
    • monkeysHK
    • Linky132
    • Jake_Titan
    • ProTankerAlfa
    • dollarflower1
    • MemeMan
    • Klarks
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.4] Checking an ItemEntity is in water.
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community