Skip to content

Commit

Permalink
Bit Nudge for Wrench.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithmX2 committed Dec 6, 2017
1 parent 72b26ad commit 9b6a5c5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 31 deletions.
4 changes: 4 additions & 0 deletions src/main/java/mod/chiselsandbits/config/ModConfig.java
Expand Up @@ -297,6 +297,9 @@ public class ModConfig extends Configuration
@Configured( category = "Balance Settings" )
public boolean enableSurvivalWrenchBlockNudging;

@Configured( category = "Balance Settings" )
public boolean enableSurvivalWrenchBitNudging;

@Configured( category = "Balance Settings" )
public boolean fullBlockCrafting;

Expand Down Expand Up @@ -396,6 +399,7 @@ private void setDefaults()
enableStackableCrafting = true;
enableNegativePrintInversionCrafting = true;
enableSurvivalWrenchBlockNudging = false;
enableSurvivalWrenchBitNudging = true;

enableChiselToolHarvestCheck = true;
enableToolHarvestLevels = true;
Expand Down
85 changes: 54 additions & 31 deletions src/main/java/mod/chiselsandbits/items/ItemWrench.java
Expand Up @@ -4,10 +4,13 @@

import mod.chiselsandbits.blueprints.EntityBlueprint;
import mod.chiselsandbits.chiseledblock.BlockChiseled;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseled;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.core.ClientSide;
import mod.chiselsandbits.helpers.ChiselModeManager;
import mod.chiselsandbits.helpers.ChiselToolType;
import mod.chiselsandbits.helpers.ExceptionNoTileEntity;
import mod.chiselsandbits.helpers.LocalStrings;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.integration.mcmultipart.MCMultipartProxy;
Expand Down Expand Up @@ -156,33 +159,26 @@ private boolean findAndInteractWithBlueprint(
return found;
}

private EnumActionResult nudgeBit(
final EntityPlayer player,
final EnumHand hand,
final IBlockState state,
final ItemStack stack,
final World world,
final BlockPos pos,
EnumFacing side )
private boolean canNudge(
World world,
BlockPos pos,
EntityPlayer player,
IBlockState state,
boolean whichSetting )
{
if ( player.isSneaking() )
{
side = side.getOpposite();
}

if ( state.getBlockHardness( world, pos ) == -1.0F || state.getMobilityFlag() == EnumPushReaction.BLOCK )
{
return EnumActionResult.FAIL;
return false;
}

if ( state.getMobilityFlag() == EnumPushReaction.DESTROY )
{
return EnumActionResult.FAIL;
return false;
}

if ( ChiselsAndBits.getConfig().enableSurvivalWrenchBlockNudging || player.isCreative() )
if ( whichSetting || player.isCreative() )
{
// TODO IMPLEMENT BIT NUDGE.
return true;
}
else
{
Expand All @@ -192,10 +188,10 @@ private EnumActionResult nudgeBit(
}
}

return EnumActionResult.FAIL;
return false;
}

private EnumActionResult nudgeBlock(
private EnumActionResult nudgeBit(
final EntityPlayer player,
final EnumHand hand,
final IBlockState state,
Expand All @@ -209,17 +205,51 @@ private EnumActionResult nudgeBlock(
side = side.getOpposite();
}

if ( state.getBlockHardness( world, pos ) == -1.0F || state.getMobilityFlag() == EnumPushReaction.BLOCK )
if ( canNudge( world, pos, player, state, ChiselsAndBits.getConfig().enableSurvivalWrenchBitNudging ) )
{
return EnumActionResult.FAIL;
if ( state.getBlock() instanceof BlockChiseled )
{
try
{
TileEntityBlockChiseled te = BlockChiseled.getTileEntity( world, pos );

VoxelBlob o = te.getBlob();

int edgeOffset = ( VoxelBlob.dim - 1 );
VoxelBlob overflow = o.offset( edgeOffset * side.getFrontOffsetX(), edgeOffset * side.getFrontOffsetY(), edgeOffset * side.getFrontOffsetZ() );

if ( overflow.filled() == 0 )
{
te.setBlob( o.offset( -side.getFrontOffsetX(), -side.getFrontOffsetY(), -side.getFrontOffsetZ() ), true );
stack.damageItem( 1, player );
return EnumActionResult.SUCCESS;
}
}
catch ( ExceptionNoTileEntity no_te )
{
// strange, no?
}
}
}

if ( state.getMobilityFlag() == EnumPushReaction.DESTROY )
return EnumActionResult.FAIL;
}

private EnumActionResult nudgeBlock(
final EntityPlayer player,
final EnumHand hand,
final IBlockState state,
final ItemStack stack,
final World world,
final BlockPos pos,
EnumFacing side )
{
if ( player.isSneaking() )
{
return EnumActionResult.FAIL;
side = side.getOpposite();
}

if ( ChiselsAndBits.getConfig().enableSurvivalWrenchBlockNudging || player.isCreative() )
if ( canNudge( world, pos, player, state, ChiselsAndBits.getConfig().enableSurvivalWrenchBlockNudging ) )
{
final BlockPos target = pos.offset( side.getOpposite() );
final IBlockState targetState = world.getBlockState( target );
Expand All @@ -246,13 +276,6 @@ else if ( state.getBlock() instanceof BlockChiseled )
}
}
}
else
{
if ( !world.isRemote )
{
player.addChatMessage( new TextComponentTranslation( LocalStrings.WrenchOnlyGhosts.toString() ) );
}
}

return EnumActionResult.FAIL;
}
Expand Down

0 comments on commit 9b6a5c5

Please sign in to comment.