Make an item go invisible.

Started by Ima-builder on

Topic category: Help with modding (Java Edition)

Last seen on 04:25, 19. Mar 2023
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Make an item go invisible.

Hi, I am trying to make a super invisibility potion (with a stack size of 16) , where even the potion disappears, I thought about swiping out the potion with a dummy invisible item but I'm not quite Shure how to do that (preferably with block coding).

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You need to import; import…
Wed, 06/17/2020 - 22:03

You need to import;

import net.minecraftforge.client.event.RenderPlayerEvent;

 

Last seen on 04:25, 19. Mar 2023
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
What about "@SubscribeEvent"
Wed, 06/17/2020 - 22:06

What about "@SubscribeEvent"

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You need to import that to,…
Wed, 06/17/2020 - 22:11

You need to import that to, I dont have access to my computer anymore. But I think you can just do imports using (CTRL  I)

Last seen on 04:25, 19. Mar 2023
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
so... um... what would I…
Wed, 06/17/2020 - 23:41

so... um... what would I import exactly? this:

@SubscribeEvent public void renderPlayerPre(RenderPlayerEvent.Pre event) { if (event.getPlayer().getPersistentData().getBoolean("cancelrendering") == true) { event.setCanceled(true); } }

Last seen on 04:25, 19. Mar 2023
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
also, sorry for being so…
Wed, 06/17/2020 - 23:44

also, sorry for being so noobish

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm on my way home, I'll…
Thu, 06/18/2020 - 00:08

I'm on my way home, I'll give you the import in a sec

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Alright, I just got home…
Thu, 06/18/2020 - 02:14

Alright, I just got home. This is what you are looking for;

import net.minecraftforge.eventbus.api.SubscribeEvent;

 

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can you post code? Something…
Thu, 06/18/2020 - 02:23

Can you post code? Something is very wrong lol

Last seen on 04:25, 19. Mar 2023
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
package net.mcreator…
Thu, 06/18/2020 - 02:24

package net.mcreator.smokebombs.procedures;

import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.World;
import net.minecraft.potion.Effects;
import net.minecraft.potion.EffectInstance;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.Entity;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import net.mcreator.smokebombs.SmokeBombsModElements;

@SmokeBombsModElements.ModElement.Tag
public class SB2Procedure extends SmokeBombsModElements.ModElement {
    public SB2Procedure(SmokeBombsModElements instance) {
        super(instance, 4);
    }

    public static void executeProcedure(java.util.HashMap<String, Object> dependencies){
        if(dependencies.get("entity")==null){
            System.err.println("Failed to load dependency entity for procedure SB2!");
            return;
        }
        if(dependencies.get("itemstack")==null){
            System.err.println("Failed to load dependency itemstack for procedure SB2!");
            return;
        }
        if(dependencies.get("world")==null){
            System.err.println("Failed to load dependency world for procedure SB2!");
            return;
        }
            Entity entity =(Entity)dependencies.get("entity" );
            ItemStack itemstack =(ItemStack)dependencies.get("itemstack" );
            World world =(World)dependencies.get("world" );
        double X = 0;double Y = 0;double Z = 0;double Tic = 0;double BombNum = 0;((itemstack)).shrink((int) 1);        Tic =(double)0;
        X =(double)(entity.getPosX());
        Y =(double)(entity.getPosY());
        Z =(double)(entity.getPosZ());
if(entity instanceof LivingEntity)
    ((LivingEntity)entity).addPotionEffect(new EffectInstance(Effects.SPEED,(int) 200,(int) 1, (false), (false)));event.getPlayer().getPersistentData().putBoolean("cancelrendering", true);if(entity instanceof PlayerEntity)
    ((PlayerEntity)entity).getCooldownTracker().setCooldown(((itemstack)).getItem(), (int) 200);while((        (Tic)
<200)) {if ((        (Tic)
<80)) {if(world instanceof ServerWorld) {
        ((ServerWorld)world).spawnParticle(ParticleTypes.CLOUD,         (X)
,         (Y)
,         (Z)
,
        (int)500, 1, 1, 1, 0.01);
}if(world instanceof ServerWorld) {
        ((ServerWorld)world).spawnParticle(ParticleTypes.CLOUD,         (X)
, (        (Y)
+1),         (Z)
,
        (int)500, 1, 1, 1, 0.01);
}}        Tic =(double)(        (Tic)
+1);
} event.getPlayer().getPersistentData().putBoolean("cancelrendering", false);
    }
    @SubscribeEvent
    public void renderPlayerPre(RenderPlayerEvent.Pre event)
    {
        if (event.getPlayer().getPersistentData().getBoolean("cancelrendering") == true)
        {
            event.setCanceled(true);
        }
    }
}

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
@SmokeBombsModElements…
Thu, 06/18/2020 - 02:39
@SmokeBombsModElements.ModElement.Tag
public class SB2Procedure extends SmokeBombsModElements.ModElement {
    public SB2Procedure(SmokeBombsModElements instance) {
        super(instance, 4);
    }

    public static void executeProcedure(java.util.HashMap<String, Object> dependencies){
        if(dependencies.get("entity")==null){
            System.err.println("Failed to load dependency entity for procedure SB2!");
            return;
        }
        if(dependencies.get("itemstack")==null){
            System.err.println("Failed to load dependency itemstack for procedure SB2!");
            return;
        }
        if(dependencies.get("world")==null){
            System.err.println("Failed to load dependency world for procedure SB2!");
            return;
        }
            Entity entity =(Entity)dependencies.get("entity" );
            ItemStack itemstack =(ItemStack)dependencies.get("itemstack" );
            World world =(World)dependencies.get("world" );
        double X = 0;double Y = 0;double Z = 0;double Tic = 0;double BombNum = 0;((itemstack)).shrink((int) 1);        Tic =(double)0;
        X =(double)(entity.getPosX());
        Y =(double)(entity.getPosY());
        Z =(double)(entity.getPosZ());
if(entity instanceof LivingEntity)
    ((LivingEntity)entity).addPotionEffect(new EffectInstance(Effects.SPEED,(int) 200,(int) 1, (false), (false)));
    if(entity instanceof PlayerEntity)
    entity.getPersistentData().putBoolean("cancelrendering", true)
    ((PlayerEntity)entity).getCooldownTracker().setCooldown(((itemstack)).getItem(), (int) 200);
    while((        (Tic)
<200)) {if ((        (Tic)
<80)) {if(world instanceof ServerWorld) {
        ((ServerWorld)world).spawnParticle(ParticleTypes.CLOUD,         (X)
,         (Y)
,         (Z)
,
        (int)500, 1, 1, 1, 0.01);
}if(world instanceof ServerWorld) {
        ((ServerWorld)world).spawnParticle(ParticleTypes.CLOUD,         (X)
, (        (Y)
+1),         (Z)
,
        (int)500, 1, 1, 1, 0.01);
}}        Tic =(double)(        (Tic)
+1);
} entity.getPersistentData().putBoolean("cancelrendering", false); 
    }
    @SubscribeEvent
    public void renderPlayerPre(RenderPlayerEvent.Pre event)
    {
        if (event.getPlayer().getPersistentData().getBoolean("cancelrendering") == true)
        {
            event.setCanceled(true);
        }
    }
}

 

1. You can't use;

event.getPlayer().getPersistentData().getBoolean("cancelrendering")

or alternatively putBoolean because you aren't provided with the variable event.

But MCreators procedure provides you with the "dependency" entity.

So we can use;

entity.getPersistentData().putBoolean("cancelrendering", false);

 

2. The code is hard to read for me on the forum, so I fixed it up as best I could. But I think it may be better to set everything up first (the NBT and etc) in the MCreator Procedure editor. And then adding the RenderPlayerEvent last.

Last seen on 04:25, 19. Mar 2023
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
package net.mcreator…
Thu, 06/18/2020 - 03:25
package net.mcreator.smokebombs.procedures;

import net.minecraftforge.registries.ForgeRegistries;

import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.World;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.potion.Effects;
import net.minecraft.potion.EffectInstance;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.Entity;

import net.mcreator.smokebombs.SmokeBombsModElements;

@SmokeBombsModElements.ModElement.Tag
public class SplashSmokeBombPotionStartedappliedProcedure extends SmokeBombsModElements.ModElement {
	public SplashSmokeBombPotionStartedappliedProcedure(SmokeBombsModElements instance) {
		super(instance, 2);
	}

	public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			System.err.println("Failed to load dependency entity for procedure SplashSmokeBombPotionStartedapplied!");
			return;
		}
		if (dependencies.get("x") == null) {
			System.err.println("Failed to load dependency x for procedure SplashSmokeBombPotionStartedapplied!");
			return;
		}
		if (dependencies.get("y") == null) {
			System.err.println("Failed to load dependency y for procedure SplashSmokeBombPotionStartedapplied!");
			return;
		}
		if (dependencies.get("z") == null) {
			System.err.println("Failed to load dependency z for procedure SplashSmokeBombPotionStartedapplied!");
			return;
		}
		if (dependencies.get("itemstack") == null) {
			System.err.println("Failed to load dependency itemstack for procedure SplashSmokeBombPotionStartedapplied!");
			return;
		}
		if (dependencies.get("world") == null) {
			System.err.println("Failed to load dependency world for procedure SplashSmokeBombPotionStartedapplied!");
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		int x = (int) dependencies.get("x");
		int y = (int) dependencies.get("y");
		int z = (int) dependencies.get("z");
		ItemStack itemstack = (ItemStack) dependencies.get("itemstack");
		World world = (World) dependencies.get("world");
		double X = 0;
		double Y = 0;
		double Z = 0;
		double Tic = 0;
		double BombNum = 0;
		((itemstack)).shrink((int) 1);
		if (entity instanceof PlayerEntity)
			((PlayerEntity) entity).getCooldownTracker().setCooldown(((itemstack)).getItem(), (int) 200);
		Tic = (double) 0;
		X = (double) (entity.getPosX());
		Y = (double) (entity.getPosY());
		Z = (double) (entity.getPosZ());
		world.playSound((PlayerEntity) null, x, y, z,
				(net.minecraft.util.SoundEvent) ForgeRegistries.SOUND_EVENTS.getValue(new ResourceLocation("entity.ghast.shoot")),
				SoundCategory.NEUTRAL, (float) 1, (float) 1);
		if (entity instanceof LivingEntity)
			((LivingEntity) entity).addPotionEffect(new EffectInstance(Effects.SPEED, (int) 200, (int) 1, (false), (false)));
		while (((Tic) < 200)) {
			if (((Tic) < 80)) {
				if (world instanceof ServerWorld) {
					((ServerWorld) world).spawnParticle(ParticleTypes.CLOUD, (X), (Y), (Z), (int) 500, 1, 1, 1, 0.01);
				}
				if (world instanceof ServerWorld) {
					((ServerWorld) world).spawnParticle(ParticleTypes.CLOUD, (X), ((Y) + 1), (Z), (int) 500, 1, 1, 1, 0.01);
				}
			}
			Tic = (double) ((Tic) + 1);
		}
	}
}

I was thinking the invisibility would get applied after the speed, then would be revoked after the while loop ends.

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sounds great! What happens…
Thu, 06/18/2020 - 03:29

Sounds great! What happens when you run the code now?

Last seen on 04:25, 19. Mar 2023
Joined Jun 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
With or without the special…
Thu, 06/18/2020 - 03:31

With or without the special code?