Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into 1.10
  • Loading branch information
AlgorithmX2 committed Aug 7, 2016
2 parents 0f8656f + fd6c583 commit dd13e08
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ Downloads: http://minecraft.curseforge.com/projects/chisels-bits/files

Discussion Thread: http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2576750

Jenkins
-------

[![Build Status](https://dvs1.progwml6.com/jenkins/job/Chisels-and-Bits/badge/icon)](https://dvs1.progwml6.com/jenkins/job/Chisels-and-Bits/)

Jenkins builds are for testing and development purposes; Do not use builds from the jenkins unless specifically directed to do so. Builds for play are available above at curseforge.

Contributing
------------

If your interested in adding a feature, localization, or fixing a bug feel free to submit a PR, if you are unsure if it fits you can open an issue to discuss it first.
If your interested in adding a feature, localization, or fixing a bug feel free to submit a PR, if you are unsure if it fits you can open an issue to discuss it first.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package mod.chiselsandbits.chiseledblock;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.zip.InflaterInputStream;

import io.netty.buffer.Unpooled;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob.BlobStats;
import mod.chiselsandbits.chiseledblock.data.VoxelBlobStateReference;
Expand All @@ -15,7 +12,6 @@
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;

public class NBTBlobConverter
{
Expand Down Expand Up @@ -95,7 +91,7 @@ public NBTBlobConverter(
isNormalCube = tile.isNormalCube;
primaryBlockState = Block.getStateId( tile.getBlockState( Blocks.COBBLESTONE ) );
voxelBlobRef = tile.getBlobStateReference();
format = getFormat( voxelBlobRef );
format = voxelBlobRef == null ? -1 : voxelBlobRef.getFormat();
}

public void fillWith(
Expand All @@ -109,7 +105,7 @@ public void setBlob(
final VoxelBlob vb )
{
voxelBlobRef = new VoxelBlobStateReference( vb, 0 );
format = getFormat( voxelBlobRef );
format = voxelBlobRef.getFormat();
updateFromBlob();
}

Expand Down Expand Up @@ -170,7 +166,7 @@ public final boolean readChisleData(
}

voxelBlobRef = new VoxelBlobStateReference( v, 0 );
format = getFormat( voxelBlobRef );
format = voxelBlobRef.getFormat();

if ( tile != null )
{
Expand All @@ -180,29 +176,6 @@ public final boolean readChisleData(
return true;
}

private int getFormat(
final VoxelBlobStateReference v )
{
if ( v == null || v.getByteArray() == null || v.getByteArray().length == 0 )
{
return -1;
}

try
{
final InflaterInputStream arrayPeek = new InflaterInputStream( new ByteArrayInputStream( v.getByteArray() ) );
final byte[] peekBytes = new byte[5];
arrayPeek.read( peekBytes );

final PacketBuffer header = new PacketBuffer( Unpooled.wrappedBuffer( peekBytes ) );
return header.readVarIntFromBuffer();
}
catch ( final IOException e )
{
return 0;
}
}

public void updateFromBlob()
{
final VoxelBlob vb = getRef().getVoxelBlob();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package mod.chiselsandbits.chiseledblock.data;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.zip.InflaterInputStream;

import io.netty.buffer.Unpooled;
import mod.chiselsandbits.chiseledblock.BoxCollection;
import mod.chiselsandbits.chiseledblock.BoxType;
import mod.chiselsandbits.core.Log;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.AxisAlignedBB;

public final class VoxelBlobStateInstance implements Comparable<VoxelBlobStateInstance>
Expand Down Expand Up @@ -216,4 +221,36 @@ private AxisAlignedBB[] generateBoxes(

return cache.toArray( new AxisAlignedBB[cache.size()] );
}

// cache the format after reading it once.
private int format = Integer.MIN_VALUE;

public int getFormat()
{
if ( format == Integer.MIN_VALUE )
{
if ( voxelBytes == null || voxelBytes.length == 0 )
{
format = -1;
}
else
{
try
{
final InflaterInputStream arrayPeek = new InflaterInputStream( new ByteArrayInputStream( voxelBytes ) );
final byte[] peekBytes = new byte[5];
arrayPeek.read( peekBytes );

final PacketBuffer header = new PacketBuffer( Unpooled.wrappedBuffer( peekBytes ) );
format = header.readVarIntFromBuffer();
}
catch ( final IOException e )
{
format = 0;
}
}
}

return format;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,9 @@ public Collection<AxisAlignedBB> getBoxes(
return data.getBoxes( type );
}

public int getFormat()
{
return data.getFormat();
}

}

0 comments on commit dd13e08

Please sign in to comment.