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
  • 18 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    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15993 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
  • 18 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    72

Beethoven92

Beethoven92    72

  • Dragon Slayer
  • Beethoven92
  • Members
  • 72
  • 570 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
  • 18 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    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15993 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
  • 18 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    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15993 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
  • 18 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
  • 18 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
  • 18 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    117

poopoodice

poopoodice    117

  • Dragon Slayer
  • poopoodice
  • Members
  • 117
  • 921 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    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15993 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
  • 18 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    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15993 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

AzizD    0

AzizD

AzizD    0

  • Tree Puncher
  • AzizD
  • Members
  • 0
  • 18 posts
Posted January 24

Finally i fixed the all problems. I added this condition and thats all.

world.chunkExists(specialItemEntity.chunkCoordX,specialItemEntity.chunkCoordZ)

 

Final code is :

 

EventHandler class

package com.azizd.thunderbird.events;

import com.azizd.thunderbird.Thunderbird;
import com.azizd.thunderbird.entities.SpecialItemEntity;
import com.azizd.thunderbird.init.itemInit;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = Thunderbird.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class EventHandler {
    public static void register(){}

    @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();
        SpecialItemEntity specialItemEntity = new SpecialItemEntity(world, posX, posY, posZ);

        if(entity instanceof ItemEntity && !(entity instanceof SpecialItemEntity)){
            ItemEntity itemEntity = (ItemEntity) event.getEntity();
            ItemStack item = itemEntity.getItem();
            if(item.getItem() == itemInit.RED_PEARL.get()){
                if(world.chunkExists(specialItemEntity.chunkCoordX,specialItemEntity.chunkCoordZ)) {
                    event.setCanceled(true);
                    specialItemEntity.setItem(itemEntity.getItem().getStack());
                    specialItemEntity.setPickupDelay(30);
                    specialItemEntity.setMotion(itemEntity.getMotion());
                    world.addEntity(specialItemEntity);
                }
            }
        }
    }
}

 

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;

public class SpecialItemEntity extends ItemEntity {
    private ItemEntity entity = new ItemEntity(this.world,this.getPosX(),this.getPosY(),this.getPosZ());

    public SpecialItemEntity(World worldIn, double x, double y, double z) {
        super(worldIn, x, y, z);
    }

    @Override
    public void tick() {
        if(this.inWater && !this.world.isRemote){
            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();
        }
    }
}

 

  • Quote

Share this post


Link to post
Share on other sites

loordgek    176

loordgek

loordgek    176

  • World Shaper
  • loordgek
  • Members
  • 176
  • 1823 posts
Posted January 24

https://github.com/MinecraftForge/MinecraftForge/blob/1.16.x/src/main/java/net/minecraftforge/common/extensions/IForgeItem.java#L290-L305

  • Quote

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

    • CyberNation
      Forge 1.7.10 Server Failed to write Transciever Channels

      By CyberNation · Posted 10 minutes ago

      i made a custom 1.7.10 modpack for my friends and I to play on decided to move it over to my own server host and now im getting an error when starting ive spent several hours trying to look for a solution and cant seem to find one im not sure if im in the right place for this but i hope someone can help me     17:44:27 Can't revert to frozen GameData state without freezing first. Server thread/INFO 17:44:27 Applying holder lookups Holder lookups applied Server thread/WARN 17:44:27 Failed to write Transciever Channels on exit: java.util.concurrent.ExecutionException: java.lang.NullPointerException Server thread/INFO 17:44:27 The state engine was in incorrect state ERRORED and forced into state SERVER_STOPPED. Errors may have been discarded. The state engine was in incorrect state ERRORED and forced into state AVAILABLE. Errors may have been discarded.     full Crash Log Report: Paste Bin https://pastebin.com/cxgY3t6q
    • DrCowiber
      Failed To Start Minecraft Server

      By DrCowiber · Posted 31 minutes ago

      Im wondering if changing the launch options for the main server jar will fix that? I saw some threads where some peoples launch files had "-o" as a launch option, is there a way I can change the launch options for when the vanilla server is launched?
    • DrCowiber
      Failed To Start Minecraft Server

      By DrCowiber · Posted 41 minutes ago

      When I run my forge Server it goes fine, but when I try to host off my Raspberry Pi 4 Model B 8GB RAM, using the 32-bit raspbian and 64-bit raspbian, I get this error at the end of log.   jpotsimple.UnrecognizedOptionException: o is not a recognized option     The full log file: https://pastebin.com/n4GpC53Q
    • KBomb
      Forge 1.12.2 Server Crashing On Start-up

      By KBomb · Posted 45 minutes ago

      I have been able to run the server in vanilla, but after adding the mods the server is crashing during the start-up. I will attach the crash report. I also have screenshots of what the server console was displaying if that may be necessary. crash-2021-02-24_18.58.56-server.txt
    • milkman69
      My game keeps crashing and I haven't even added any mods on yet

      By milkman69 · Posted 2 hours ago

      here's the crash report or whatever:  Failed to download file. Name: 1.16.4-forge-35.1.37.jar URL: https://s3.amazonaws.com/Minecraft.Download/versions/1.16.4-forge-35.1.37/1.16.4-forge-35.1.37.jar Filename on disk: 1.16.4-forge-35.1.37.jar Path: C:\Users\donov\AppData\Roaming\.minecraft\versions\1.16.4-forge-35.1.37\1.16.4-forge-35.1.37.jar Exists: File
  • Topics

    • CyberNation
      0
      Forge 1.7.10 Server Failed to write Transciever Channels

      By CyberNation
      Started 10 minutes ago

    • DrCowiber
      1
      Failed To Start Minecraft Server

      By DrCowiber
      Started 41 minutes ago

    • KBomb
      0
      Forge 1.12.2 Server Crashing On Start-up

      By KBomb
      Started 45 minutes ago

    • milkman69
      0
      My game keeps crashing and I haven't even added any mods on yet

      By milkman69
      Started 2 hours ago

    • Skyriis
      0
      [1.16.5] Adding a Button to KeyBindings

      By Skyriis
      Started 3 hours ago

  • Who's Online (See full list)

    • William59
    • Taknax
    • DrCowiber
    • mcnuggies
    • Draco18s
    • Jeldrik
    • PyRoTheLifeLess
    • CyberNation
    • Babelincoln1809
  • 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