Skip to content

Commit

Permalink
Replacement Option + Material Modes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithmX2 committed Nov 5, 2016
1 parent e9f842d commit 8232759
Show file tree
Hide file tree
Showing 23 changed files with 442 additions and 51 deletions.
Expand Up @@ -17,6 +17,7 @@
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.core.ClientSide;
import mod.chiselsandbits.core.Log;
import mod.chiselsandbits.helpers.BitOperation;
import mod.chiselsandbits.helpers.ChiselToolType;
import mod.chiselsandbits.helpers.ExceptionNoTileEntity;
import mod.chiselsandbits.helpers.ModUtil;
Expand Down Expand Up @@ -457,7 +458,7 @@ public ItemStack getPickBlock(
{
final VoxelBlob vb = te.getBlob();

final BitLocation bitLoc = new BitLocation( target, true, ChiselToolType.CHISEL );
final BitLocation bitLoc = new BitLocation( target, true, BitOperation.CHISEL );

final int itemBlock = vb.get( bitLoc.bitX, bitLoc.bitY, bitLoc.bitZ );
if ( itemBlock == 0 )
Expand Down
Expand Up @@ -10,7 +10,7 @@
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.core.ClientSide;
import mod.chiselsandbits.core.Log;
import mod.chiselsandbits.helpers.ChiselToolType;
import mod.chiselsandbits.helpers.BitOperation;
import mod.chiselsandbits.helpers.DeprecationHelper;
import mod.chiselsandbits.helpers.ExceptionNoTileEntity;
import mod.chiselsandbits.helpers.LocalStrings;
Expand Down Expand Up @@ -180,6 +180,7 @@ public EnumActionResult onItemUse(
return doItemUse( stack, playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ );
}

@Override
public EnumActionResult doItemUse(
final ItemStack stack,
final EntityPlayer playerIn,
Expand Down Expand Up @@ -264,7 +265,7 @@ public boolean placeBlockAt(
{
if ( player.isSneaking() )
{
final BitLocation bl = new BitLocation( new RayTraceResult( RayTraceResult.Type.BLOCK, new Vec3d( hitX, hitY, hitZ ), side, pos ), false, ChiselToolType.BIT );
final BitLocation bl = new BitLocation( new RayTraceResult( RayTraceResult.Type.BLOCK, new Vec3d( hitX, hitY, hitZ ), side, pos ), false, BitOperation.PLACE );
return tryPlaceBlockAt( block, stack, player, world, bl.blockPos, side, EnumHand.MAIN_HAND, new BlockPos( bl.bitX, bl.bitY, bl.bitZ ), true );
}
else
Expand Down
@@ -1,7 +1,7 @@
package mod.chiselsandbits.chiseledblock.data;

import mod.chiselsandbits.api.IBitLocation;
import mod.chiselsandbits.helpers.ChiselToolType;
import mod.chiselsandbits.helpers.BitOperation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;

Expand Down Expand Up @@ -47,11 +47,11 @@ public int snapToValid(
public BitLocation(
final RayTraceResult mop,
final boolean absHit,
final ChiselToolType type )
final BitOperation type )
{
final BlockPos absOffset = absHit ? mop.getBlockPos() : BlockPos.ORIGIN;

if ( type == ChiselToolType.CHISEL )
if ( !type.usePlacementOffset() )
{
blockPos = mop.getBlockPos();

Expand Down
Expand Up @@ -17,6 +17,46 @@

public class ChiselExtrudeIterator extends BaseChiselIterator implements ChiselIterator
{
public static class ChiselExtrudeMaterialIterator extends ChiselExtrudeIterator
{

int material = 0;

public ChiselExtrudeMaterialIterator(
final int dim,
final int sx,
final int sy,
final int sz,
final IVoxelSrc source,
final ChiselMode mode,
final EnumFacing side,
final boolean place )
{
super( dim, sx, sy, sz, source, mode, side, place );
}

@Override
protected void readyMatching(
final IVoxelSrc source,
final int x,
final int y,
final int z )
{
material = source.getSafe( x, y, z );
}

@Override
protected boolean isMatch(
final IVoxelSrc source,
final int x,
final int y,
final int z )
{
return source.getSafe( x, y, z ) == material;
}

};

final int INDEX_X = 0;
final int INDEX_Y = 8;
final int INDEX_Z = 16;
Expand Down Expand Up @@ -78,6 +118,8 @@ public ChiselExtrudeIterator(
placeoffset = side.getAxisDirection() == AxisDirection.POSITIVE ? 1 : -1;
}

readyMatching( source, x, y, z );

for ( int b = 0; b < dim; ++b )
{
for ( int a = 0; a < dim; ++a )
Expand All @@ -86,21 +128,21 @@ public ChiselExtrudeIterator(
{
case DOWN:
case UP:
if ( source.getSafe( a, y, b ) != 0 && source.getSafe( a + tx, y + ty, b + tz ) == 0 )
if ( isMatch( source, a, y, b ) && source.getSafe( a + tx, y + ty, b + tz ) == 0 )
{
possiblepositions.add( createPos( a, y + placeoffset, b ) );
}
break;
case EAST:
case WEST:
if ( source.getSafe( x, a, b ) != 0 && source.getSafe( x + tx, a + ty, b + tz ) == 0 )
if ( isMatch( source, x, a, b ) && source.getSafe( x + tx, a + ty, b + tz ) == 0 )
{
possiblepositions.add( createPos( x + placeoffset, a, b ) );
}
break;
case NORTH:
case SOUTH:
if ( source.getSafe( a, b, z ) != 0 && source.getSafe( a + tx, b + ty, z + tz ) == 0 )
if ( isMatch( source, a, b, z ) && source.getSafe( a + tx, b + ty, z + tz ) == 0 )
{
possiblepositions.add( createPos( a, b, z + placeoffset ) );
}
Expand Down Expand Up @@ -144,6 +186,24 @@ public int compare(
list = selectedpositions.iterator();
}

protected void readyMatching(
final IVoxelSrc source,
final int x,
final int y,
final int z )
{

}

protected boolean isMatch(
final IVoxelSrc source,
final int x,
final int y,
final int z )
{
return source.getSafe( x, y, z ) != 0;
}

private void floodFill(
final int sx,
final int sy,
Expand Down
@@ -0,0 +1,155 @@
package mod.chiselsandbits.chiseledblock.iterators;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import mod.chiselsandbits.chiseledblock.data.BitIterator;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.helpers.IVoxelSrc;
import mod.chiselsandbits.modes.ChiselMode;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.EnumFacing.AxisDirection;

public class ChiselMaterialIterator extends BaseChiselIterator implements ChiselIterator
{

final int INDEX_X = 0;
final int INDEX_Y = 8;
final int INDEX_Z = 16;

// future state.
Iterator<Integer> list;

// present state.
EnumFacing side;
int value;

private int setValue(
final int pos,
final int idx )
{
return ( (byte) pos & 0xff ) << idx;
}

private int getValue(
final int value,
final int idx )
{
return (byte) ( value >>> idx & 0xff );
}

private int createPos(
final int x,
final int y,
final int z )
{
return setValue( x, INDEX_X ) | setValue( y, INDEX_Y ) | setValue( z, INDEX_Z );
}

public ChiselMaterialIterator(
final int dim,
final int sx,
final int sy,
final int sz,
final IVoxelSrc source,
final ChiselMode mode,
final EnumFacing side,
final boolean place )
{
this.side = side;
final List<Integer> selectedpositions = new ArrayList<Integer>();

final int tx = side.getFrontOffsetX(), ty = side.getFrontOffsetY(), tz = side.getFrontOffsetZ();

int x = sx, y = sy, z = sz;

int placeoffsetX = 0;
int placeoffsetY = 0;
int placeoffsetZ = 0;

if ( place )
{
x -= tx;
y -= ty;
z -= tz;
placeoffsetX = side.getAxis() == Axis.X ? side.getAxisDirection() == AxisDirection.POSITIVE ? 1 : -1 : 0;
placeoffsetY = side.getAxis() == Axis.Y ? side.getAxisDirection() == AxisDirection.POSITIVE ? 1 : -1 : 0;
placeoffsetZ = side.getAxis() == Axis.Z ? side.getAxisDirection() == AxisDirection.POSITIVE ? 1 : -1 : 0;
}

final int target = source.getSafe( x, y, z );

final BitIterator bi = new BitIterator();
while ( bi.hasNext() )
{
if ( source.getSafe( bi.x - tx, bi.y - ty, bi.z - tz ) == target )
{
final int xx = placeoffsetX + bi.x - tx;
final int yy = placeoffsetY + bi.y - ty;
final int zz = placeoffsetZ + bi.z - tz;

if ( xx >= 0 && xx < VoxelBlob.dim &&
yy >= 0 && yy < VoxelBlob.dim &&
zz >= 0 && zz < VoxelBlob.dim )
{
selectedpositions.add( createPos( xx, yy, zz ) );
}
}

if ( source.getSafe( bi.x, bi.y, bi.z ) == target )
{
final int xx = placeoffsetX + bi.x;
final int yy = placeoffsetY + bi.y;
final int zz = placeoffsetZ + bi.z;

if ( xx >= 0 && xx < VoxelBlob.dim &&
yy >= 0 && yy < VoxelBlob.dim &&
zz >= 0 && zz < VoxelBlob.dim )
{
selectedpositions.add( createPos( xx, yy, zz ) );
}
}
}

// we are done, drop the list and keep an iterator.
list = selectedpositions.iterator();
}

@Override
public boolean hasNext()
{
if ( list.hasNext() )
{
value = list.next();
return true;
}

return false;
}

@Override
public EnumFacing side()
{
return side;
}

@Override
public int x()
{
return getValue( value, INDEX_X );
}

@Override
public int y()
{
return getValue( value, INDEX_Y );
}

@Override
public int z()
{
return getValue( value, INDEX_Z );
}
}
@@ -1,5 +1,6 @@
package mod.chiselsandbits.chiseledblock.iterators;

import mod.chiselsandbits.chiseledblock.iterators.ChiselExtrudeIterator.ChiselExtrudeMaterialIterator;
import mod.chiselsandbits.helpers.IVoxelSrc;
import mod.chiselsandbits.modes.ChiselMode;
import net.minecraft.util.EnumFacing;
Expand Down Expand Up @@ -60,11 +61,21 @@ public static ChiselIterator create(
final EnumFacing side,
final boolean place )
{
if ( mode == ChiselMode.CONNECTED_MATERIAL )
{
return new ChiselExtrudeMaterialIterator( dim, x, y, z, source, mode, side, place );
}

if ( mode == ChiselMode.CONNECTED_PLANE )
{
return new ChiselExtrudeIterator( dim, x, y, z, source, mode, side, place );
}

if ( mode == ChiselMode.SAME_MATERIAL )
{
return new ChiselMaterialIterator( dim, x, y, z, source, mode, side, place );
}

return new ChiselTypeIterator( dim, x, y, z, source, mode, side );
}

Expand Down
Expand Up @@ -5,6 +5,8 @@ public enum ButtonAction
UNDO,
REDO,

REPLACE_TOGGLE,

WHITE,
BLACK,
CYAN,
Expand All @@ -20,5 +22,5 @@ public enum ButtonAction
LIME,
PURPLE,
BLUE,
GREEN
GREEN,
}

0 comments on commit 8232759

Please sign in to comment.