Skip to content

Commit

Permalink
More Non-Null Shenanigans.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgorithmX2 committed Dec 26, 2016
1 parent d3d772f commit 66273a7
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ public boolean canRenderInLayer(
}

public static @Nonnull TileEntityBlockChiseled getTileEntity(
final IBlockAccess world,
final BlockPos pos ) throws ExceptionNoTileEntity
final @Nonnull IBlockAccess world,
final @Nonnull BlockPos pos ) throws ExceptionNoTileEntity
{
return getTileEntity( ModUtil.getTileEntitySafely( world, pos ) );
}
Expand Down Expand Up @@ -671,6 +671,7 @@ public void addCollisionBoxesToList(
*
* @return if the method results in a non-full cube box.
*/
@Nonnull
private AxisAlignedBB setBounds(
final TileEntityBlockChiseled tec,
final BlockPos pos,
Expand Down Expand Up @@ -782,6 +783,7 @@ public AxisAlignedBB getSelectedBoundingBox(
return super.getSelectedBoundingBox( state, worldIn, pos );
}

@Nonnull
public AxisAlignedBB getSelectedBoundingBox(
final TileEntityBlockChiseled tec,
final BlockPos pos )
Expand Down Expand Up @@ -940,8 +942,8 @@ public boolean rotateBlock(
}

public static boolean replaceWithChisled(
final World world,
final BlockPos pos,
final @Nonnull World world,
final @Nonnull BlockPos pos,
final IBlockState originalState,
final int fragmentBlockStateID,
final boolean triggerUpdate )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;

import mod.chiselsandbits.api.EventBlockBitModification;
import mod.chiselsandbits.chiseledblock.data.BitLocation;
import mod.chiselsandbits.chiseledblock.data.IntegerBox;
Expand Down Expand Up @@ -95,9 +97,9 @@ public boolean canPlaceBlockOnSide(
}

public boolean vanillaStylePlacementTest(
final World worldIn,
BlockPos pos,
EnumFacing side,
final @Nonnull World worldIn,
@Nonnull BlockPos pos,
@Nonnull EnumFacing side,
final EntityPlayer player,
final ItemStack stack )
{
Expand All @@ -116,9 +118,9 @@ else if ( !block.isReplaceable( worldIn, pos ) )
}

public boolean canPlaceBlockHere(
final World worldIn,
final BlockPos pos,
final EnumFacing side,
final @Nonnull World worldIn,
final @Nonnull BlockPos pos,
final @Nonnull EnumFacing side,
final EntityPlayer player,
final ItemStack stack )
{
Expand Down Expand Up @@ -275,13 +277,13 @@ public boolean placeBlockAt(
}

static public boolean tryPlaceBlockAt(
final Block block,
final ItemStack stack,
final EntityPlayer player,
final World world,
BlockPos pos,
final EnumFacing side,
final EnumHand hand,
final @Nonnull Block block,
final @Nonnull ItemStack stack,
final @Nonnull EntityPlayer player,
final @Nonnull World world,
@Nonnull BlockPos pos,
final @Nonnull EnumFacing side,
final @Nonnull EnumHand hand,
final BlockPos partial,
final boolean modulateWorld )
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mod.chiselsandbits.chiseledblock.data;

import javax.annotation.Nonnull;

import mod.chiselsandbits.api.IBitLocation;
import mod.chiselsandbits.helpers.BitOperation;
import net.minecraft.util.math.BlockPos;
Expand All @@ -9,6 +11,7 @@ public class BitLocation implements IBitLocation
{
private static final double One32nd = 0.5 / VoxelBlob.dim;

@Nonnull
public final BlockPos blockPos;
public final int bitX, bitY, bitZ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public void update(

for ( final EnumFacing f : EnumFacing.VALUES )
{
assert f != null;

final TileEntityBlockChiseled tebc = ModUtil.getChiseledTileEntity( access, pos.offset( f ) );
if ( tebc != null )
{
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/mod/chiselsandbits/core/ChiselsAndBits.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nonnull;

import mod.chiselsandbits.api.IChiselAndBitsAPI;
import mod.chiselsandbits.chiseledblock.BlockBitInfo;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
Expand Down Expand Up @@ -54,9 +56,9 @@
guiFactory = "mod.chiselsandbits.client.gui.ModConfigGuiFactory" )
public class ChiselsAndBits
{
public static final String MODNAME = "Chisels & Bits";
public static final String MODID = "chiselsandbits";
public static final String VERSION = "@VERSION@";
public static final @Nonnull String MODNAME = "Chisels & Bits";
public static final @Nonnull String MODID = "chiselsandbits";
public static final @Nonnull String VERSION = "@VERSION@";

public static final String DEPENDENCIES = "required-after:Forge@[12.17.0.1909,);after:mcmultipart;after:JEI@[3.7.8.234,)"; // buildVersion

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/mod/chiselsandbits/core/ClientSide.java
Original file line number Diff line number Diff line change
Expand Up @@ -1461,9 +1461,9 @@ public BitLocation getStartPos()
}

public void pointAt(
final ChiselToolType type,
final BitLocation pos,
final EnumHand hand )
@Nonnull final ChiselToolType type,
@Nonnull final BitLocation pos,
@Nonnull final EnumHand hand )
{
if ( drawStart == null )
{
Expand All @@ -1473,7 +1473,10 @@ public void pointAt(
}
}

@Nonnull
ChiselToolType lastTool = ChiselToolType.CHISEL;

@Nonnull
EnumHand lastHand = EnumHand.MAIN_HAND;

KeyBinding getToolKey()
Expand All @@ -1489,8 +1492,8 @@ KeyBinding getToolKey()
}

public boolean addBlockDestroyEffects(
final World world,
final BlockPos pos,
@Nonnull final World world,
@Nonnull final BlockPos pos,
IBlockState state,
final ParticleManager effectRenderer )
{
Expand Down
34 changes: 20 additions & 14 deletions src/main/java/mod/chiselsandbits/core/api/BitAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,27 @@ public void setBitAt(
public void commitChanges(
final boolean triggerUpdates )
{
TileEntityBlockChiseled tile = ModUtil.getChiseledTileEntity( world, pos, true );
final BlobStats cb = blob.getVoxelStats();
final World w = world;
final BlockPos p = pos;

if ( tile == null && BlockChiseled.replaceWithChisled( world, pos, world.getBlockState( pos ), cb.mostCommonState, false ) )
if ( w != null && p != null )
{
tile = ModUtil.getChiseledTileEntity( world, pos, true );
}
TileEntityBlockChiseled tile = ModUtil.getChiseledTileEntity( w, p, true );
final BlobStats cb = blob.getVoxelStats();

if ( tile != null )
{
final VoxelBlobStateReference before = tile.getBlobStateReference();
tile.setBlob( blob, triggerUpdates );
final VoxelBlobStateReference after = tile.getBlobStateReference();
if ( tile == null && BlockChiseled.replaceWithChisled( w, p, world.getBlockState( p ), cb.mostCommonState, false ) )
{
tile = ModUtil.getChiseledTileEntity( w, p, true );
}

if ( tile != null )
{
final VoxelBlobStateReference before = tile.getBlobStateReference();
tile.setBlob( blob, triggerUpdates );
final VoxelBlobStateReference after = tile.getBlobStateReference();

UndoTracker.getInstance().add( world, pos, before, after );
UndoTracker.getInstance().add( w, p, before, after );
}
}
}

Expand Down Expand Up @@ -171,13 +177,13 @@ public ItemStack getBitsAsItem(
switch ( type )
{
case MIRROR_DESIGN:
stack = new ItemStack( ChiselsAndBits.getItems().itemMirrorprint );
stack = ModUtil.makeStack( ChiselsAndBits.getItems().itemMirrorprint );
break;
case NEGATIVE_DESIGN:
stack = new ItemStack( ChiselsAndBits.getItems().itemNegativeprint );
stack = ModUtil.makeStack( ChiselsAndBits.getItems().itemNegativeprint );
break;
case POSITIVE_DESIGN:
stack = new ItemStack( ChiselsAndBits.getItems().itemPositiveprint );
stack = ModUtil.makeStack( ChiselsAndBits.getItems().itemPositiveprint );
break;
default:
return ModUtil.getEmptyStack();
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/mod/chiselsandbits/helpers/ActingPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public ItemStack getCurrentEquippedItem()
Boolean permissionResult = null;

public boolean canPlayerManipulate(
final BlockPos pos,
final EnumFacing side,
final ItemStack is,
final @Nonnull BlockPos pos,
final @Nonnull EnumFacing side,
final @Nonnull ItemStack is,
final boolean placement )
{
// only re-test if something changes.
Expand Down Expand Up @@ -111,13 +111,15 @@ public void playerDestroyItem(
}
}

@Nonnull
public static ActingPlayer actingAs(
final EntityPlayer player,
final EnumHand hand )
{
return new ActingPlayer( player, true, hand );
}

@Nonnull
public static ActingPlayer testingAs(
final EntityPlayer player,
final EnumHand hand )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.HashMap;
import java.util.List;

import javax.annotation.Nonnull;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;

Expand All @@ -25,9 +27,9 @@ public class ContinousChisels implements IContinuousInventory
private final boolean canEdit;

public ContinousChisels(
final ActingPlayer who,
final BlockPos pos,
final EnumFacing side )
final @Nonnull ActingPlayer who,
final @Nonnull BlockPos pos,
final @Nonnull EnumFacing side )
{
this.who = who;
final ItemStack inHand = who.getCurrentEquippedItem();
Expand Down

0 comments on commit 66273a7

Please sign in to comment.