Jump to content

Glitches with TileEntitys


Jantomedes

Recommended Posts

Hi there.

First, I wanted to make a simple tool for copying and replacing blocks, so I can easily copy a chest or something else and place copy it somewhere else.

 

This seems so easy but I have some terrible problems. It looks Java bites me when I want to make a copy of something but it's a link not a copy. When I am copying a block everything is ok but when I set another block, the TileEntity of the original block disappears and the new block also don't have a TileEntity. When I set a block to another it even doesn't set the metadata... -.-

 

Wrench of copying:

 

package jantomedes.maptools.wrenches;

import jantomedes.maptools.chainreactivity.ChainSettings;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class WrenchOfCopying extends Item{

public WrenchOfCopying(int par1) {
	super(par1);
	setMaxStackSize(1);
}

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10){
	ChainSettings.idForSetting = par3World.getBlockId(par4, par5, par6);
	ChainSettings.metadataForSetting = par3World.getBlockMetadata(par4, par5, par6);
	ChainSettings.tileEntityForSetting = par3World.getBlockTileEntity(par4, par5, par6);
	return true;
}

@SideOnly(Side.CLIENT)
public boolean isFull3D()
    {
        return true;
    }

@SideOnly(Side.CLIENT)
public void updateIcons(IconRegister par){
	this.iconIndex = par.registerIcon("maptools:wrench");
}

}

 

 

Wrench of setting:

 

package jantomedes.maptools.wrenches;

import jantomedes.maptools.chainreactivity.ChainSettings;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class WrenchOfSetting extends Item{

public WrenchOfSetting(int par1) {
	super(par1);
	setMaxStackSize(1);
}

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10){
	par3World.removeBlockTileEntity(par4, par5, par6);
	par3World.setBlock(par4, par5, par6, ChainSettings.idForSetting, ChainSettings.metadataForSetting, 3);
	TileEntity te = ChainSettings.tileEntityForSetting;
	te.xCoord = par4;
	te.yCoord = par5;
	te.zCoord = par6;
	te.worldObj = par3World;
	par3World.setBlockTileEntity(par4, par5, par6, te);
	par3World.markBlockForRenderUpdate(par4, par5, par6);
	return true;
}

@SideOnly(Side.CLIENT)
public boolean isFull3D()
    {
        return true;
    }

@SideOnly(Side.CLIENT)
public void updateIcons(IconRegister par){
	this.iconIndex = par.registerIcon("maptools:wrench");
}

}

 

 

ChainSettings:

 

package jantomedes.maptools.chainreactivity;

import net.minecraft.tileentity.TileEntity;

public class ChainSettings {
public static int textureID = 1;
public static int textureMetadata = 0;
public static boolean isSimple = true;
public static boolean isVerySimple = true;
public static EnumChainReactionType type = EnumChainReactionType.breakBlock;
public static int wait = 6;
public static boolean spreadReaction = true;
public static int idForBlock;
public static int metadataForBlock;
public static boolean shouldReactOnExp, shouldReactOnBreaking = true;
public static boolean shouldReactOnGettingPowered, shouldReactOnRightClick = false;

public static int idForSetting = 1;
public static int metadataForSetting = 0;
public static TileEntity tileEntityForSetting = null;
}

 

 

Regards. Jantomedes

Link to comment
Share on other sites

another "learn java" thread?

Oh, you didn't read my post carefully. YES, this exactly a "learn java" thread.

 

Many of you already have a reflex 'if it's a Java question, we have to hate it immediately'. But I believe there are some kind people who don't have it and know the difference between a question from a noob who doesn't learn Java at all or he does it 'by modding' and a question from a person who know the basics of Java but sometimes also has some problems.

 

http://en.wikipedia.org/wiki/Reference_type

you'd have to do a deep copy.

 

Thanks for saying me exactly what I wrote in my post. Very helpful and clever.

 

That's very practical if I can ask a question on a forum and get the precise name of my problem. I also believe that there are some of these kind people who can give me a little explanation and write an example. Thanks.

 

---------------------

If I've gone too far, sorry - emotions.

Link to comment
Share on other sites

You asked about "glitch", but it's not a glitch - it's a feature of programming language you're working with. If you want to know how to do a deep copy of TE, I'm not sure that it's possible in some general way (like be compatible with TEs from all mods).

 

And yes, when it's a basic Java question, you shouldn't be asking here (and I probably shoudn't have answered). I'm sorry if I'm underestimating you, but from the quesion it didn't seem that you know what a term "reference type" means.

 

I wrote it before, it's not that I don't want to help, it's just that this forum is filled with basic modding questions described in detail on wiki and with basic java questions which are here offtopic (without decent OO background it's a terrible idea to learn Java by modding). It's just that more complex problems which needs more advanced modders in order to be answered are buried. And those advanced modders just stop going on the forum, because it's all trivial for them, just repeating same basic issues over and over again.

 

PS: The question "how to clone a TE" is interesting, I'm curious about how it could be done. Maybe serialize wanted entity into NBT, modifying coordinates and recreating it on the other place?

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

First off, there is a difference between asking how to program in Java, and not knowing enough to know if it's a Java issue or a Forge issue. Yes it is an essential part of Java that any Forge programmer ought to know, but he is also asking a valid question regardless of his aptitude for the language.

 

Now, on to your question:

Usually when you want to do something that is already done in the game, or another forge mod, the best thing to do is to look in the source code:

if (!this.worldObj.isRemote)
{
    Block.blocksList[par4].onBlockAdded(this.worldObj, j2, par2, k2);
}

if (Block.blocksList[par4] != null && Block.blocksList[par4].hasTileEntity(par5))
{
    tileentity = this.getChunkBlockTileEntity(par1, par2, par3);
    
    if (tileentity == null)
    {
        tileentity = Block.blocksList[par4].createTileEntity(this.worldObj, par5);
        this.worldObj.setBlockTileEntity(j2, par2, k2, tileentity);
    }

    if (tileentity != null)
    {
        tileentity.updateContainingBlockInfo();
        tileentity.blockMetadata = par5;
    }
}

These are lines 765-785 in Chunk.java (net.minecraft.world.chunk)

 

I'd suggest you use the code that this uses, seeing as how it obviously works. This means that you first check if the block you are adding has a tile entity with

hasTileEntity(int metadata)

Note that the metadata value doesn't actually matter unless it is overridden in the block. Once you've confirmed that the block has a tile entity, call

TileEntity tileentity = blockToCopy.createTileEntity(worldObj, metadata);
worldObj.setBlockTileEntity(x, y, z, tileentity);

or

worldObj.setBlockTileEntity(x, y, z, blockToCopy.createTileEntity(worldObj, metadata));

if you want to shorten it and don't need to reference the TileEntity again, which you will if you're going to copy nbt data as I'll show below.

 


 

As for copying the NBT data out of the block and into a new one, add an NBTTagCompound variable (let's call it "nbt" for the following example) to ChainSettings for storage. When you copy the block, simply call

copiedBlockTileEntity.writeToNBT(nbt)

That will set your nbt data to be passed into the pasted block (assuming that the block has a tile entity. Make sure to check for this as well.) After you create your new block and ensure that a new TileEntity is in place, use the converse nbt storage method:

pastedBlockTileEntity.readFromNBT(ChainSettings.nbt)

Make sure to check if ChainSettings.nbt is null before doing this or you could run into problems. If it's null, then you don't have any data to copy and we can assume that the copied block doesn't have any nbt data (no tile entity.) Also make sure to clear ChainSettings.nbt by setting it to null after reading it, for safety.

 

Please note that I haven't tested any of the above code, but it should work or give you good start to getting your wrenches working.

 

If I helped you, please give me some karma :P

width=336 height=83http://img836.imageshack.us/img836/1237/cooltext624963071.png[/img]

I make games, minecraft mods/plugins, and some graphic art.

 

Current Project: LoECraft - An industrial minecraft server with its own modpack and custom launcher.

Link to comment
Share on other sites

First off, there is a difference between asking how to program in Java, and not knowing enough to know if it's a Java issue or a Forge issue. Yes it is an essential part of Java that any Forge programmer ought to know

It's the same thing - he wrote that it magically uses some link. If he don't know what a "reference type" (or "static" or "value type" or "method" or "field") means, he should stop trying to mod and go back to learning Java. If he don't uderstand it and just copy-paste your code, he'll be back tomorrow with similar "learn java" issue. Also it will be frustrating for him, becuase in the end he ends up with code which is impossible to maintain - copied pieces together without any knowledge why it works.

 

but he is also asking a valid question regardless of his aptitude for the language.

I did write that on the end of my post...

 

I wonder how machines from BC, IC2 or computers from RP or CC wound react on this copying. *thinking about multiblock structures* I don't think that a lot (if any) modders were considering this when writing their TE.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

First off, there is a difference between asking how to program in Java, and not knowing enough to know if it's a Java issue or a Forge issue. Yes it is an essential part of Java that any Forge programmer ought to know

It's the same thing - he wrote that it magically uses some link. If he don't know what a "reference type" (or "static" or "value type" or "method" or "field") means, he should stop trying to mod and go back to learning Java. If he don't uderstand it and just copy-paste your code, he'll be back tomorrow with similar "learn java" issue. Also it will be frustrating for him, becuase in the end he ends up with code which is impossible to maintain - copied pieces together without any knowledge why it works.

 

but he is also asking a valid question regardless of his aptitude for the language.

I did write that on the end of my post...

 

I wonder how machines from BC, IC2 or computers from RP or CC wound react on this copying. *thinking about multiblock structures* I don't think that a lot (if any) modders were considering this when writing their TE.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

You asked about "glitch", but it's not a glitch - it's a feature of programming language you're working with. If you want to know how to do a deep copy of TE, I'm not sure that it's possible in some general way (like be compatible with TEs from all mods).

 

And yes, when it's a basic Java question, you shouldn't be asking here (and I probably shoudn't have answered). I'm sorry if I'm underestimating you, but from the quesion it didn't seem that you know what a term "reference type" means.

 

I wrote it before, it's not that I don't want to help, it's just that this forum is filled with basic modding questions described in detail on wiki and with basic java questions which are here offtopic (without decent OO background it's a terrible idea to learn Java by modding). It's just that more complex problems which needs more advanced modders in order to be answered are buried. And those advanced modders just stop going on the forum, because it's all trivial for them, just repeating same basic issues over and over again.

 

PS: The question "how to clone a TE" is interesting, I'm curious about how it could be done. Maybe serialize wanted entity into NBT, modifying coordinates and recreating it on the other place?

 

I knew what a reference type is but didn't know that all not primitive types are reference types automatically. And your answer helped me - I've read on the wiki about that. I have to say it wasn't true that you didn't helped me.

 

First off, there is a difference between asking how to program in Java, and not knowing enough to know if it's a Java issue or a Forge issue. Yes it is an essential part of Java that any Forge programmer ought to know, but he is also asking a valid question regardless of his aptitude for the language.

 

Now, on to your question:

Usually when you want to do something that is already done in the game, or another forge mod, the best thing to do is to look in the source code:

if (!this.worldObj.isRemote)
{
    Block.blocksList[par4].onBlockAdded(this.worldObj, j2, par2, k2);
}

if (Block.blocksList[par4] != null && Block.blocksList[par4].hasTileEntity(par5))
{
    tileentity = this.getChunkBlockTileEntity(par1, par2, par3);
    
    if (tileentity == null)
    {
        tileentity = Block.blocksList[par4].createTileEntity(this.worldObj, par5);
        this.worldObj.setBlockTileEntity(j2, par2, k2, tileentity);
    }

    if (tileentity != null)
    {
        tileentity.updateContainingBlockInfo();
        tileentity.blockMetadata = par5;
    }
}

These are lines 765-785 in Chunk.java (net.minecraft.world.chunk)

 

I'd suggest you use the code that this uses, seeing as how it obviously works. This means that you first check if the block you are adding has a tile entity with

hasTileEntity(int metadata)

Note that the metadata value doesn't actually matter unless it is overridden in the block. Once you've confirmed that the block has a tile entity, call

TileEntity tileentity = blockToCopy.createTileEntity(worldObj, metadata);
worldObj.setBlockTileEntity(x, y, z, tileentity);

or

worldObj.setBlockTileEntity(x, y, z, blockToCopy.createTileEntity(worldObj, metadata));

if you want to shorten it and don't need to reference the TileEntity again, which you will if you're going to copy nbt data as I'll show below.

 


 

As for copying the NBT data out of the block and into a new one, add an NBTTagCompound variable (let's call it "nbt" for the following example) to ChainSettings for storage. When you copy the block, simply call

copiedBlockTileEntity.writeToNBT(nbt)

That will set your nbt data to be passed into the pasted block (assuming that the block has a tile entity. Make sure to check for this as well.) After you create your new block and ensure that a new TileEntity is in place, use the converse nbt storage method:

pastedBlockTileEntity.readFromNBT(ChainSettings.nbt)

Make sure to check if ChainSettings.nbt is null before doing this or you could run into problems. If it's null, then you don't have any data to copy and we can assume that the copied block doesn't have any nbt data (no tile entity.) Also make sure to clear ChainSettings.nbt by setting it to null after reading it, for safety.

 

Please note that I haven't tested any of the above code, but it should work or give you good start to getting your wrenches working.

 

If I helped you, please give me some karma :P

 

You didn't have to write the first part so precisely because I know how to create a new TE of good type. But thanks for the last lines with neat way of saving TE to NBT. Without that and without mnm saying it could be done like this, I would have made it with manually saving important values from TEs. Oh, or I even wouldn't because they are private.

 

And grab some karma for this NBT ;-)

 

First off, there is a difference between asking how to program in Java, and not knowing enough to know if it's a Java issue or a Forge issue. Yes it is an essential part of Java that any Forge programmer ought to know

It's the same thing - he wrote that it magically uses some link. If he don't know what a "reference type" (or "static" or "value type" or "method" or "field") means, he should stop trying to mod and go back to learning Java. If he don't uderstand it and just copy-paste your code, he'll be back tomorrow with similar "learn java" issue. Also it will be frustrating for him, becuase in the end he ends up with code which is impossible to maintain - copied pieces together without any knowledge why it works.

 

but he is also asking a valid question regardless of his aptitude for the language.

I did write that on the end of my post...

 

I wonder how machines from BC, IC2 or computers from RP or CC wound react on this copying. *thinking about multiblock structures* I don't think that a lot (if any) modders were considering this when writing their TE.

 

Mnn, you're making a little mistake. I have to say I didn't know how reference types are working but I know the basic Java. Of course I know what static/value type/method/field means. I am not somebody who thinks that learning Java by modding is a good way to do that. It isn't a way at all.

 

So why if I know Java I have such simple problem? Well, I know the basic Java. And basic means much more than just 'static' or 'field'. The point is that I have sometimes some gaps in my knowledge. The main reason is probably that I didn't understand something and forgot to get back to it. Maybe sounds dumb but that's it.

 

I don't learn Java by modding. At most just realize what I've missed or what I have to remind.

 

Anyway, this was a Java question so sorry for 'offtopicing'. And thanks fro your answers.

 

I will worry later about multiblock structures.

 

And these emotions were because of comparing me to noobs which think that they can learn Java by modding.

 

Regards. Jantomedes

 

@Down: Argh... So embarrassing...

PS. assert this.nativeLanguage != Languages.ENGLISH; ;-)

Link to comment
Share on other sites

You asked about "glitch", but it's not a glitch - it's a feature of programming language you're working with. If you want to know how to do a deep copy of TE, I'm not sure that it's possible in some general way (like be compatible with TEs from all mods).

 

And yes, when it's a basic Java question, you shouldn't be asking here (and I probably shoudn't have answered). I'm sorry if I'm underestimating you, but from the quesion it didn't seem that you know what a term "reference type" means.

 

I wrote it before, it's not that I don't want to help, it's just that this forum is filled with basic modding questions described in detail on wiki and with basic java questions which are here offtopic (without decent OO background it's a terrible idea to learn Java by modding). It's just that more complex problems which needs more advanced modders in order to be answered are buried. And those advanced modders just stop going on the forum, because it's all trivial for them, just repeating same basic issues over and over again.

 

PS: The question "how to clone a TE" is interesting, I'm curious about how it could be done. Maybe serialize wanted entity into NBT, modifying coordinates and recreating it on the other place?

 

I knew what a reference type is but didn't know that all not primitive types are reference types automatically. And your answer helped me - I've read on the wiki about that. I have to say it wasn't true that you didn't helped me.

 

First off, there is a difference between asking how to program in Java, and not knowing enough to know if it's a Java issue or a Forge issue. Yes it is an essential part of Java that any Forge programmer ought to know, but he is also asking a valid question regardless of his aptitude for the language.

 

Now, on to your question:

Usually when you want to do something that is already done in the game, or another forge mod, the best thing to do is to look in the source code:

if (!this.worldObj.isRemote)
{
    Block.blocksList[par4].onBlockAdded(this.worldObj, j2, par2, k2);
}

if (Block.blocksList[par4] != null && Block.blocksList[par4].hasTileEntity(par5))
{
    tileentity = this.getChunkBlockTileEntity(par1, par2, par3);
    
    if (tileentity == null)
    {
        tileentity = Block.blocksList[par4].createTileEntity(this.worldObj, par5);
        this.worldObj.setBlockTileEntity(j2, par2, k2, tileentity);
    }

    if (tileentity != null)
    {
        tileentity.updateContainingBlockInfo();
        tileentity.blockMetadata = par5;
    }
}

These are lines 765-785 in Chunk.java (net.minecraft.world.chunk)

 

I'd suggest you use the code that this uses, seeing as how it obviously works. This means that you first check if the block you are adding has a tile entity with

hasTileEntity(int metadata)

Note that the metadata value doesn't actually matter unless it is overridden in the block. Once you've confirmed that the block has a tile entity, call

TileEntity tileentity = blockToCopy.createTileEntity(worldObj, metadata);
worldObj.setBlockTileEntity(x, y, z, tileentity);

or

worldObj.setBlockTileEntity(x, y, z, blockToCopy.createTileEntity(worldObj, metadata));

if you want to shorten it and don't need to reference the TileEntity again, which you will if you're going to copy nbt data as I'll show below.

 


 

As for copying the NBT data out of the block and into a new one, add an NBTTagCompound variable (let's call it "nbt" for the following example) to ChainSettings for storage. When you copy the block, simply call

copiedBlockTileEntity.writeToNBT(nbt)

That will set your nbt data to be passed into the pasted block (assuming that the block has a tile entity. Make sure to check for this as well.) After you create your new block and ensure that a new TileEntity is in place, use the converse nbt storage method:

pastedBlockTileEntity.readFromNBT(ChainSettings.nbt)

Make sure to check if ChainSettings.nbt is null before doing this or you could run into problems. If it's null, then you don't have any data to copy and we can assume that the copied block doesn't have any nbt data (no tile entity.) Also make sure to clear ChainSettings.nbt by setting it to null after reading it, for safety.

 

Please note that I haven't tested any of the above code, but it should work or give you good start to getting your wrenches working.

 

If I helped you, please give me some karma :P

 

You didn't have to write the first part so precisely because I know how to create a new TE of good type. But thanks for the last lines with neat way of saving TE to NBT. Without that and without mnm saying it could be done like this, I would have made it with manually saving important values from TEs. Oh, or I even wouldn't because they are private.

 

And grab some karma for this NBT ;-)

 

First off, there is a difference between asking how to program in Java, and not knowing enough to know if it's a Java issue or a Forge issue. Yes it is an essential part of Java that any Forge programmer ought to know

It's the same thing - he wrote that it magically uses some link. If he don't know what a "reference type" (or "static" or "value type" or "method" or "field") means, he should stop trying to mod and go back to learning Java. If he don't uderstand it and just copy-paste your code, he'll be back tomorrow with similar "learn java" issue. Also it will be frustrating for him, becuase in the end he ends up with code which is impossible to maintain - copied pieces together without any knowledge why it works.

 

but he is also asking a valid question regardless of his aptitude for the language.

I did write that on the end of my post...

 

I wonder how machines from BC, IC2 or computers from RP or CC wound react on this copying. *thinking about multiblock structures* I don't think that a lot (if any) modders were considering this when writing their TE.

 

Mnn, you're making a little mistake. I have to say I didn't know how reference types are working but I know the basic Java. Of course I know what static/value type/method/field means. I am not somebody who thinks that learning Java by modding is a good way to do that. It isn't a way at all.

 

So why if I know Java I have such simple problem? Well, I know the basic Java. And basic means much more than just 'static' or 'field'. The point is that I have sometimes some gaps in my knowledge. The main reason is probably that I didn't understand something and forgot to get back to it. Maybe sounds dumb but that's it.

 

I don't learn Java by modding. At most just realize what I've missed or what I have to remind.

 

Anyway, this was a Java question so sorry for 'offtopicing'. And thanks fro your answers.

 

I will worry later about multiblock structures.

 

And these emotions were because of comparing me to noobs which think that they can learn Java by modding.

 

Regards. Jantomedes

 

@Down: Argh... So embarrassing...

PS. assert this.nativeLanguage != Languages.ENGLISH; ;-)

Link to comment
Share on other sites

I am not somebody who thinks that learning Java by modding is a good way to do that. It isn't a way at all.

Glad to hear this. I might have judged you too quickly, my fault. (Also parts of my posts were meant in a general way. I'm probably not very good at expressing this sort of things in English.) And looking at posts I wonder if I shoudn't have picked a better nick, a lot of people is misspelling it ;D.

 

See you around and happy modding o/.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

I am not somebody who thinks that learning Java by modding is a good way to do that. It isn't a way at all.

Glad to hear this. I might have judged you too quickly, my fault. (Also parts of my posts were meant in a general way. I'm probably not very good at expressing this sort of things in English.) And looking at posts I wonder if I shoudn't have picked a better nick, a lot of people is misspelling it ;D.

 

See you around and happy modding o/.

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

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.