Jump to content

[1.8.9] While Holding Item Get Potion Effect?


Monstrous_Apple

Recommended Posts

Okay so at the moment my gemstone gives the person regeneration 1 while it's in their inventory but what I want to happen is only while the player is holding the gemstone it will give the potion effect, does anyone know how to do this?

 

package com.MonstrousApple.mod.gemstones;

import com.MonstrousApple.mod.MAGlobal;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;

public class MAVitalityGemstone extends Item {

public MAVitalityGemstone(String unlocalizedName) {
	super();
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(MAGlobal.maCreativeTabGemstones);
	this.setMaxStackSize(1);
}

@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	if(stack.getItem() == MAGemstones.VitalityGemstone) {
		effectPlayer(entityIn, Potion.regeneration, 1 - 1);
	super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
}
}
	private void effectPlayer(Entity entityIn, Potion potion, int amplifier) {

		//((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(potion.id, 40, amplifier, true, true));
		EntityLivingBase player = (EntityLivingBase) entityIn;
		if (player.getActivePotionEffect(potion)== null || player.getActivePotionEffect(potion).getDuration() <=0)
			player.addPotionEffect(new PotionEffect(potion.id, 40 /** Duration */, amplifier, true, true));
}

}

Link to comment
Share on other sites

Regeneration works based on ticks remaining. If that value doesn't change, then no effect is actually granted.

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

The

boolean

argument of

Item#onUpdate

is whether the item is currently selected (held).

 

If you update to 1.9 (which you should) and want it to work in the off hand as well, you'll need to check if the entity's off hand item is the

ItemStack

argument (like

ItemMap

does).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Regeneration works based on ticks remaining. If that value doesn't change, then no effect is actually granted.

 

No it does regenerate but I want it to only work if holding it in your hand rather than in your inventory without being selected, if that makes sense?

 

Regeneration works based on ticks remaining. If that value doesn't change, then no effect is actually granted.

 

No it does regenerate but I want it to only work if holding it in your hand rather than in your inventory without being selected, if that makes sense?

Yeah but it still gives regeneration 1 even when not selected how do I change this?

 

Also I would update to 1.9 but I just don't like the combat system changes :P just my preference haha thanks though. :)

Link to comment
Share on other sites

Regeneration works based on ticks remaining. If that value doesn't change, then no effect is actually granted.

 

No it does regenerate but I want it to only work if holding it in your hand rather than in your inventory without being selected, if that makes sense?

 

Regeneration works based on ticks remaining. If that value doesn't change, then no effect is actually granted.

 

No it does regenerate but I want it to only work if holding it in your hand rather than in your inventory without being selected, if that makes sense?

Yeah but it still gives regeneration 1 even when not selected how do I change this?

 

Also I would update to 1.9 but I just don't like the combat system changes :P just my preference haha thanks though. :)

 

because you using the method which is always true, onUpdate is' executed every tick while the item is in the inventory.

 

you could simply make a if statement if the player is currently holding the item, like you know if the current holding item is the current itemstack, which activates this effect.

"My Crew is World Wide." 「ヤング • エルトウ」

Link to comment
Share on other sites

Okay now I have it so that when you hold the item then you will have the potion effects but now I need the timer to tick down so I can effects like regeneration to work, how would I do this?

 

Here's my code:

 

package com.MonstrousApple.mod.gemstones;

import com.MonstrousApple.mod.MAGlobal;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;

public class MAVitalityGemstone extends Item {

public MAVitalityGemstone(String unlocalizedName) {
	super();
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(MAGlobal.maCreativeTabGemstones);
	this.setMaxStackSize(1);
}

private void effectPlayer(EntityPlayer player, Potion potion, int amplifier) {
	if (player.getActivePotionEffect(potion)== null || player.getActivePotionEffect(potion).getDuration() <=40)
		player.addPotionEffect(new PotionEffect(potion.id, 40 /** Duration */, amplifier, true, true));
}

public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag)
{
     if (entity instanceof EntityPlayer)
    	 
     {          EntityPlayer Player = (EntityPlayer) entity;
          if(Player.getCurrentEquippedItem() != null && Player.getCurrentEquippedItem().getItem() instanceof MAVitalityGemstone)
          {
        	  Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 1 - 1));
          }
          else
          { 
        	  Player.removePotionEffect(i);
          }
     }	 

/**@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	if(stack.getItem() == MAGemstones.VitalityGemstone) {
		effectPlayer(entityIn, Potion.regeneration, 1 - 1);
	super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
}
}
	private void effectPlayer(Entity entityIn, Potion potion, int amplifier) {

		//((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(potion.id, 40, amplifier, true, true));
		EntityLivingBase player = (EntityLivingBase) entityIn;
		if (player.getActivePotionEffect(potion)== null || player.getActivePotionEffect(potion).getDuration() <=0)
			player.addPotionEffect(new PotionEffect(potion.id, 40 /** Duration *///, amplifier, true, true));
}
}

Link to comment
Share on other sites

Also, why are you adding the duration as

1 - 1

?

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

Also, why are you adding the duration as

1 - 1

?

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

  • Why are you still checking manually if the currently selected item is yours? Use the parameter to the onUpdate method, like you have been told already.
  • Do not add the potion effect every time.
  • The part where you remove the potion effect is useless, since when the item is no longer in your inventory, onUpdate will not be called anymore.

 

  • This doesn't need changing because at the moment if I am not holding my item the effect goes, well at least I don't think it needs changing?
  • Why? Or at least clarify what you mean?
  • No it's not useless because what I want to happen is only give the effect when held, so that means it can still be in your inventory and then it will not give the effect.

 

 

Also, why are you adding the duration as

1 - 1

?

 

Was testing something lol

Link to comment
Share on other sites

  • Why are you still checking manually if the currently selected item is yours? Use the parameter to the onUpdate method, like you have been told already.
  • Do not add the potion effect every time.
  • The part where you remove the potion effect is useless, since when the item is no longer in your inventory, onUpdate will not be called anymore.

 

  • This doesn't need changing because at the moment if I am not holding my item the effect goes, well at least I don't think it needs changing?
  • Why? Or at least clarify what you mean?
  • No it's not useless because what I want to happen is only give the effect when held, so that means it can still be in your inventory and then it will not give the effect.

 

 

Also, why are you adding the duration as

1 - 1

?

 

Was testing something lol

Link to comment
Share on other sites

Okay I'll say what I need to do at this moment, I need it so that when I am not holding the item, the potion effect goes completely, even if it starts at 4 seconds, ends at 0 seconds, and currently is on 2 seconds duration left, it will disappear.

 

I also need it so that when holding the item the duration of the potion effect still ticks even while holding the item, so that regeneration will work, so for example I hold the gem it gives 4 seconds of regeneration, it ticks down to 0 and then refreshes to 4 again, but of course if the item is not held at any point, the regeneration effect completely goes even if it's not reached 0 seconds yet.

 

 

This is what my code looks like at the moment:

 

package com.MonstrousApple.mod.gemstones;

import com.MonstrousApple.mod.MAGlobal;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;

public class MAVitalityGemstone extends Item {

public MAVitalityGemstone(String unlocalizedName) {
	super();
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(MAGlobal.maCreativeTabGemstones);
	this.setMaxStackSize(1);
}

public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag)
{
     if (entity instanceof EntityPlayer)
    	 
     {          EntityPlayer Player = (EntityPlayer) entity;
          if(Player.getCurrentEquippedItem() != null && Player.getCurrentEquippedItem().getItem() instanceof MAVitalityGemstone)
        	  
          {
        	  Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 50, 1 - 1));
          }
          else
          { 
        	  Player.removePotionEffect(i);
          }
     }	 
}
     }
}

Link to comment
Share on other sites

Okay I'll say what I need to do at this moment, I need it so that when I am not holding the item, the potion effect goes completely, even if it starts at 4 seconds, ends at 0 seconds, and currently is on 2 seconds duration left, it will disappear.

 

I also need it so that when holding the item the duration of the potion effect still ticks even while holding the item, so that regeneration will work, so for example I hold the gem it gives 4 seconds of regeneration, it ticks down to 0 and then refreshes to 4 again, but of course if the item is not held at any point, the regeneration effect completely goes even if it's not reached 0 seconds yet.

 

 

This is what my code looks like at the moment:

 

package com.MonstrousApple.mod.gemstones;

import com.MonstrousApple.mod.MAGlobal;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;

public class MAVitalityGemstone extends Item {

public MAVitalityGemstone(String unlocalizedName) {
	super();
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(MAGlobal.maCreativeTabGemstones);
	this.setMaxStackSize(1);
}

public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag)
{
     if (entity instanceof EntityPlayer)
    	 
     {          EntityPlayer Player = (EntityPlayer) entity;
          if(Player.getCurrentEquippedItem() != null && Player.getCurrentEquippedItem().getItem() instanceof MAVitalityGemstone)
        	  
          {
        	  Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 50, 1 - 1));
          }
          else
          { 
        	  Player.removePotionEffect(i);
          }
     }	 
}
     }
}

Link to comment
Share on other sites

Jeus H Chirst on a fucking stick.

 

public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean am_I_holding_this_item) {
    if(am_I_holding_this_item) {
        Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 50, 0));
    }
}

 

Fuck.

 

Was it really that hard?

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

Jeus H Chirst on a fucking stick.

 

public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean am_I_holding_this_item) {
    if(am_I_holding_this_item) {
        Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 50, 0));
    }
}

 

Fuck.

 

Was it really that hard?

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

Jeus H Chirst on a fucking stick.

 

public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean am_I_holding_this_item) {
    if(am_I_holding_this_item) {
        Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 50, 0));
    }
}

 

Fuck.

 

Was it really that hard?

 

Removed my code and tried yours, doesn't work, says I get an error at ".addPotionEffect" saying that "The method addPotionEffect(PotionEffect) is undefined for the type player"?

Link to comment
Share on other sites

Jeus H Chirst on a fucking stick.

 

public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean am_I_holding_this_item) {
    if(am_I_holding_this_item) {
        Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 50, 0));
    }
}

 

Fuck.

 

Was it really that hard?

 

Removed my code and tried yours, doesn't work, says I get an error at ".addPotionEffect" saying that "The method addPotionEffect(PotionEffect) is undefined for the type player"?

Link to comment
Share on other sites

Hi

 

Did you really just copy the code?

If you would have posted your code, we could better see why it's not working.

I for my self had 3 minutes after reading this post an item giving any potion effect upon beeing held in the offhand for mc 1.9

 

Sincerely -pick

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

Link to comment
Share on other sites

Hi

 

Did you really just copy the code?

If you would have posted your code, we could better see why it's not working.

I for my self had 3 minutes after reading this post an item giving any potion effect upon beeing held in the offhand for mc 1.9

 

Sincerely -pick

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

Link to comment
Share on other sites

I did post my code on post #9 :) I'll post it again here:

 

package com.MonstrousApple.mod.gemstones;

import com.MonstrousApple.mod.MAGlobal;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;

public class MAVitalityGemstone extends Item {

public MAVitalityGemstone(String unlocalizedName) {
	super();
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(MAGlobal.maCreativeTabGemstones);
	this.setMaxStackSize(1);
}

public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag)
{
     if (entity instanceof EntityPlayer)
    	 
     {          EntityPlayer Player = (EntityPlayer) entity;
          if(Player.getCurrentEquippedItem() != null && Player.getCurrentEquippedItem().getItem() instanceof MAVitalityGemstone)
        	  
          {
        	  Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 50, 1 - 1));
          }
          else
          { 
        	  Player.removePotionEffect(i);
          }
     }	 
}
     }
}

Link to comment
Share on other sites

I did post my code on post #9 :) I'll post it again here:

 

package com.MonstrousApple.mod.gemstones;

import com.MonstrousApple.mod.MAGlobal;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.stats.StatList;
import net.minecraft.world.World;

public class MAVitalityGemstone extends Item {

public MAVitalityGemstone(String unlocalizedName) {
	super();
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(MAGlobal.maCreativeTabGemstones);
	this.setMaxStackSize(1);
}

public void onUpdate(ItemStack itemstack, World world, Entity entity, int i, boolean flag)
{
     if (entity instanceof EntityPlayer)
    	 
     {          EntityPlayer Player = (EntityPlayer) entity;
          if(Player.getCurrentEquippedItem() != null && Player.getCurrentEquippedItem().getItem() instanceof MAVitalityGemstone)
        	  
          {
        	  Player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 50, 1 - 1));
          }
          else
          { 
        	  Player.removePotionEffect(i);
          }
     }	 
}
     }
}

Link to comment
Share on other sites

Was it really that hard?

 

Apparently. :|

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

Was it really that hard?

 

Apparently. :|

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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