Skip to content

Commit

Permalink
Added NBTTagCompound writeTileEntityToTag( NBTTagCompound tag, boolea…
Browse files Browse the repository at this point in the history
…n crossWorld );

# Conflicts:
#	src/main/java/mod/chiselsandbits/chiseledblock/TileEntityBlockChiseled.java
#	src/main/java/mod/chiselsandbits/client/CreativeClipboardTab.java
#	src/main/java/mod/chiselsandbits/core/ClientSide.java
#	src/main/java/mod/chiselsandbits/crafting/StackableCrafting.java
  • Loading branch information
AlgorithmX2 committed Jan 6, 2017
1 parent cb0b67b commit 563abcf
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 15 deletions.
25 changes: 25 additions & 0 deletions src/main/java/mod/chiselsandbits/api/IChiseledBlockTileEntity.java
@@ -0,0 +1,25 @@
package mod.chiselsandbits.api;

import net.minecraft.nbt.NBTTagCompound;

/**
* This interface is implemented by Chiseled Block Tile Entities.
*/
public interface IChiseledBlockTileEntity
{

/**
* Used to write Tile Data into cross world format, can be invoked via
* interface or via reflection on the tile itself.
*
* functions identically to writeToNBT(...)
*
* @param tag
* @param crossWorld
* @return modified input tag.
*/
public NBTTagCompound writeTileEntityToTag(
final NBTTagCompound tag,
final boolean crossWorld );

}
Expand Up @@ -430,7 +430,7 @@ public String getItemStackDisplayName(
if ( BlockEntityTag != null )
{
final NBTBlobConverter c = new NBTBlobConverter();
c.readChisleData( BlockEntityTag );
c.readChisleData( BlockEntityTag, VoxelBlob.VERSION_ANY );

final IBlockState state = c.getPrimaryBlockState();
final Block blk = state.getBlock();
Expand Down
Expand Up @@ -131,7 +131,8 @@ public final void writeChisleData(
}

public final boolean readChisleData(
final NBTTagCompound compound )
final NBTTagCompound compound,
final int preferedFormat )
{
if ( compound == null )
{
Expand Down Expand Up @@ -181,8 +182,25 @@ public final boolean readChisleData(
voxelBlobRef = new VoxelBlobStateReference( v, 0 );
format = voxelBlobRef.getFormat();

boolean formatChanged = false;

if ( preferedFormat != format && preferedFormat != VoxelBlob.VERSION_ANY )
{
formatChanged = true;
v = voxelBlobRef.getVoxelBlob().blobToBytes( preferedFormat );
voxelBlobRef = new VoxelBlobStateReference( v, 0 );
format = voxelBlobRef.getFormat();
}

if ( tile != null )
{
if ( formatChanged )
{
// this only works on already loaded tiles, so i'm not sure
// there is much point in it.
tile.markDirty();
}

return tile.updateBlob( this, triggerUpdates );
}

Expand Down
Expand Up @@ -5,6 +5,7 @@

import mod.chiselsandbits.api.EventBlockBitPostModification;
import mod.chiselsandbits.api.EventFullBlockRestoration;
import mod.chiselsandbits.api.IChiseledBlockTileEntity;
import mod.chiselsandbits.api.ItemType;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob.BlobStats;
Expand Down Expand Up @@ -44,7 +45,7 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class TileEntityBlockChiseled extends TileEntity implements IChiseledTileContainer
public class TileEntityBlockChiseled extends TileEntity implements IChiseledTileContainer, IChiseledBlockTileEntity
{

private IExtendedBlockState state;
Expand Down Expand Up @@ -353,7 +354,8 @@ private void triggerDynamicUpdates()
public boolean readChisleData(
final NBTTagCompound tag )
{
final boolean changed = new NBTBlobConverter( false, this ).readChisleData( tag );
final NBTBlobConverter converter = new NBTBlobConverter( false, this );
final boolean changed = converter.readChisleData( tag, VoxelBlob.VERSION_COMPACT );

final VoxelNeighborRenderTracker vns = state.getValue( BlockChiseled.UProperty_VoxelNeighborState );

Expand Down Expand Up @@ -388,6 +390,17 @@ public void readFromNBT(
readChisleData( compound );
}

@Override
public NBTTagCompound writeTileEntityToTag(
final NBTTagCompound tag,
final boolean crossWorld )
{
super.writeToNBT( tag );
new NBTBlobConverter( false, this ).writeChisleData( tag, crossWorld );
tag.setBoolean( "cw", crossWorld );
return tag;
}

@Override
public void func_189668_a(
final Mirror p_189668_1_ )
Expand Down
Expand Up @@ -899,9 +899,10 @@ public boolean filter(
return hasValues;
}

public static int VERSION_COMPACT = 0;
public static int VERSION_CROSSWORLD_LEGACY = 1; // stored meta.
public static int VERSION_CROSSWORLD = 2;
public static final int VERSION_ANY = -1;
public static final int VERSION_COMPACT = 0;
public static final int VERSION_CROSSWORLD_LEGACY = 1; // stored meta.
public static final int VERSION_CROSSWORLD = 2;

public void blobFromBytes(
final byte[] bytes ) throws IOException
Expand Down
Expand Up @@ -7,6 +7,7 @@
import mod.chiselsandbits.api.IBitAccess;
import mod.chiselsandbits.api.ItemType;
import mod.chiselsandbits.chiseledblock.NBTBlobConverter;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.interfaces.ICacheClearable;
Expand Down Expand Up @@ -108,7 +109,7 @@ public void displayAllRelevantItems(
for ( final ItemStack is : myCrossItems )
{
final NBTBlobConverter c = new NBTBlobConverter();
c.readChisleData( is.getSubCompound( ModUtil.NBT_BLOCKENTITYTAG, true ) );
c.readChisleData( is.getSubCompound( ModUtil.NBT_BLOCKENTITYTAG, true ), VoxelBlob.VERSION_ANY );

// recalculate.
c.updateFromBlob();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mod/chiselsandbits/core/ClientSide.java
Expand Up @@ -1235,7 +1235,7 @@ private void showGhost(
lastPartial = partial;

final NBTBlobConverter c = new NBTBlobConverter();
c.readChisleData( item.getSubCompound( ModUtil.NBT_BLOCKENTITYTAG, false ) );
c.readChisleData( item.getSubCompound( ModUtil.NBT_BLOCKENTITYTAG, false ), VoxelBlob.VERSION_ANY );
VoxelBlob blob = c.getBlob();

while ( rotations-- > 0 )
Expand Down
Expand Up @@ -105,7 +105,7 @@ else if ( f.getItem() == ChiselsAndBits.getItems().itemPositiveprint )
}

final NBTBlobConverter tmp = new NBTBlobConverter();
tmp.readChisleData( targetA.getTagCompound() );
tmp.readChisleData( targetA.getTagCompound(), VoxelBlob.VERSION_ANY );

final VoxelBlob bestBlob = tmp.getBlob();

Expand Down
Expand Up @@ -72,7 +72,7 @@ public ItemStack analzyeCraftingInventory(
}

final NBTBlobConverter tmp = new NBTBlobConverter();
tmp.readChisleData( targetA.getTagCompound() );
tmp.readChisleData( targetA.getTagCompound(), VoxelBlob.VERSION_ANY );

final VoxelBlob bestBlob = tmp.getBlob();
bestBlob.binaryReplacement( ModUtil.getStateId( Blocks.STONE.getDefaultState() ), 0 );
Expand Down
Expand Up @@ -82,7 +82,7 @@ private ItemStack getSortedVersion(
final ItemStack stack )
{
final NBTBlobConverter tmp = new NBTBlobConverter();
tmp.readChisleData( stack.getSubCompound( ModUtil.NBT_BLOCKENTITYTAG, false ) );
tmp.readChisleData( stack.getSubCompound( ModUtil.NBT_BLOCKENTITYTAG, false ), VoxelBlob.VERSION_ANY );

VoxelBlob bestBlob = tmp.getBlob();
byte[] bestValue = bestBlob.toLegacyByteArray();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mod/chiselsandbits/helpers/ModUtil.java
Expand Up @@ -511,7 +511,7 @@ public static VoxelBlob getBlobFromStack(
cData = stack.getTagCompound();
}

tmp.readChisleData( cData );
tmp.readChisleData( cData, VoxelBlob.VERSION_ANY );
VoxelBlob blob = tmp.getBlob();

if ( rotationPlayer != null )
Expand Down
Expand Up @@ -148,7 +148,7 @@ public ItemStack getPatternedItem(

// Detect and provide full blocks if pattern solid full and solid.
final NBTBlobConverter conv = new NBTBlobConverter();
conv.readChisleData( tag );
conv.readChisleData( tag, VoxelBlob.VERSION_ANY );

final IBlockState blk = conv.getPrimaryBlockState();
final ItemStack itemstack = new ItemStack( ChiselsAndBits.getBlocks().getConversionWithDefault( blk ), 1 );
Expand Down
Expand Up @@ -234,7 +234,7 @@ public ItemStack getPatternedItem(

// Detect and provide full blocks if pattern solid full and solid.
final NBTBlobConverter conv = new NBTBlobConverter();
conv.readChisleData( tag );
conv.readChisleData( tag, VoxelBlob.VERSION_ANY );

if ( craftingBlocks && ChiselsAndBits.getConfig().fullBlockCrafting )
{
Expand Down

0 comments on commit 563abcf

Please sign in to comment.