Skip to content

Commit

Permalink
Added two new configuration options, voidExcessBits and requireBagSpace
Browse files Browse the repository at this point in the history
Implemented, A way to prevent 'bits' from spilling on the floor #365
  • Loading branch information
MineDaveXD authored and AlgorithmX2 committed Jan 31, 2018
1 parent 1c8d562 commit 0afca0b
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/main/java/mod/chiselsandbits/config/ModConfig.java
Expand Up @@ -299,6 +299,12 @@ public class ModConfig extends Configuration

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

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

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

// in game state
public boolean replaceingBits = false;
Expand Down Expand Up @@ -360,6 +366,8 @@ private void setDefaults()
compatabilityMode = true;
maxDrawnRegionSize = 4;
bagStackSize = 512;
requireBagSpace = false;
voidExcessBits = false;
maxUndoLevel = 32;
maxTapeMeasures = 5;

Expand Down
6 changes: 5 additions & 1 deletion src/main/java/mod/chiselsandbits/helpers/ModUtil.java
Expand Up @@ -411,7 +411,11 @@ public static void feedPlayer(
if ( is != null && !player.inventory.addItemStackToInventory( is ) )
{
ei.setEntityItemStack( is );
spawnItem( world, ei );
//Never spawn the items for dropped excess items if setting is enabled.
if ( !ChiselsAndBits.getConfig().voidExcessBits )
{
spawnItem( world, ei );
}
}
else
{
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/mod/chiselsandbits/items/ItemBitBag.java
Expand Up @@ -319,4 +319,23 @@ public double getDurabilityForDisplay(
return 0;
}

public static boolean hasBagSpace(
final EntityPlayer player,
final int blk )
{
final List<BagPos> bags = getBags( player.inventory );
for ( final BagPos bp : bags )
{
for ( int x = 0; x < bp.inv.getSizeInventory(); x++ )
{
final ItemStack is = bp.inv.getStackInSlot( x );
if( ( ItemChiseledBit.sameBit( is, blk ) && ModUtil.getStackSize( is ) < bp.inv.getInventoryStackLimit() ) || ModUtil.isEmpty( is ) )
{
return true;
}
}
}
return false;
}

}
20 changes: 20 additions & 0 deletions src/main/java/mod/chiselsandbits/items/ItemChisel.java
Expand Up @@ -52,6 +52,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
Expand Down Expand Up @@ -127,6 +128,9 @@ public boolean onBlockStartBreak(
return ItemChisel.fromBreakToChisel( ChiselMode.castMode( ChiselModeManager.getChiselMode( player, ChiselToolType.CHISEL, EnumHand.MAIN_HAND ) ), itemstack, pos, player, EnumHand.MAIN_HAND );
}

//The previous stateId, avoids spamming the require_bag message.
private static BlockPos lastPos = new BlockPos(0, -1, 0);

static public boolean fromBreakToChisel(
final ChiselMode mode,
final ItemStack itemstack,
Expand All @@ -135,6 +139,22 @@ static public boolean fromBreakToChisel(
final EnumHand hand )
{
final IBlockState state = player.getEntityWorld().getBlockState( pos );
if ( ChiselsAndBits.getConfig().requireBagSpace && !player.isCreative() )
{
//Cycle every item in any bag, if the player can't store the clicked block then
//send them a message.
final int stateId = ModUtil.getStateId( state );
if ( !ItemBitBag.hasBagSpace( player, stateId ) )
{
if( player.worldObj.isRemote && !pos.equals( lastPos ) )
{
//Only client should handle messaging.
player.addChatMessage( new TextComponentTranslation( "mod.chiselsandbits.result.require_bag" ) );
lastPos = pos;
}
return false;
}
}
if ( BlockBitInfo.canChisel( state ) || MCMultipartProxy.proxyMCMultiPart.isMultiPartTileEntity( player.getEntityWorld(), pos ) || LittleTiles.isLittleTilesBlock( player.getEntityWorld().getTileEntity( pos ) ) )
{
if ( itemstack != null && ( timer == null || timer.elapsed( TimeUnit.MILLISECONDS ) > 150 ) )
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/mod/chiselsandbits/items/ItemChiseledBit.java
Expand Up @@ -458,4 +458,19 @@ public static boolean placeBit(

return false;
}

public static boolean hasInventorySpace(
final EntityPlayer player,
final int blk )
{
for ( int x = 0; x < 36; x++ )
{
final ItemStack is = player.inventory.getStackInSlot( x );
if( ( ItemChiseledBit.sameBit( is, blk ) && ModUtil.getStackSize( is ) < is.getMaxStackSize() ) || ModUtil.isEmpty( is ) )
{
return true;
}
}
return ItemBitBag.hasBagSpace( player, blk );
}
}
24 changes: 24 additions & 0 deletions src/main/java/mod/chiselsandbits/items/ItemNegativePrint.java
Expand Up @@ -38,6 +38,7 @@
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -299,9 +300,32 @@ protected void applyPrint(
}
}

//The state id of the last item in spawnlist.
int entityItemState = 0;

for ( final EntityItem ei : spawnlist )
{
ModUtil.feedPlayer( world, who, ei );
entityItemState = ItemChiseledBit.getStackState( ei.getEntityItem() );
}

//entityItemState is always 0 when remote
if ( !world.isRemote && entityItemState != 0 )
{
if( ChiselsAndBits.getConfig().requireBagSpace )
{
if ( !ItemBitBag.hasBagSpace( who, entityItemState ) )
{
who.addChatMessage( new TextComponentTranslation( "mod.chiselsandbits.result.require_bag_full" ) );
}
}
else if( ChiselsAndBits.getConfig().voidExcessBits )
{
if( !ItemChiseledBit.hasInventorySpace( who, entityItemState ) )
{
who.addChatMessage( new TextComponentTranslation( "mod.chiselsandbits.result.void_excess" ) );
}
}
}
}

Expand Down
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;

Expand Down Expand Up @@ -206,13 +207,36 @@ else if ( extracted != null )
}
}
}


//The state id of the last item in spawnlist.
int entityItemState = 0;

for ( final EntityItem ei : spawnlist )
{
ModUtil.feedPlayer( world, who, ei );
ItemBitBag.cleanupInventory( who, ei.getEntityItem() );
entityItemState = ItemChiseledBit.getStackState( ei.getEntityItem() );
}

//entityItemState is always 0 when remote
if ( !world.isRemote && entityItemState != 0 )
{
if( ChiselsAndBits.getConfig().requireBagSpace )
{
if ( !ItemBitBag.hasBagSpace( who, entityItemState ) )
{
who.addChatMessage( new TextComponentTranslation( "mod.chiselsandbits.result.require_bag_full" ) );
}
}
else if( ChiselsAndBits.getConfig().voidExcessBits )
{
if( !ItemChiseledBit.hasInventorySpace( who, entityItemState ) )
{
who.addChatMessage( new TextComponentTranslation( "mod.chiselsandbits.result.void_excess" ) );
}
}
}

if ( place.usesBits() )
{
ItemBitBag.cleanupInventory( who, bitPlaced != null ? bitPlaced : new ItemStack( ChiselsAndBits.getItems().itemBlockBit, 1, OreDictionary.WILDCARD_VALUE ) );
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/assets/chiselsandbits/lang/en_us.lang
Expand Up @@ -70,6 +70,9 @@ mod.chiselsandbits.result.has_changed=Block has changed
mod.chiselsandbits.result.missing_bits=Not enough bits or chisel durability!
mod.chiselsandbits.result.nothing_to_undo=Nothing to Undo
mod.chiselsandbits.result.nothing_to_redo=Nothing to Redo
mod.chiselsandbits.result.require_bag=You need a bag with empty slots before you can use the chisel!
mod.chiselsandbits.result.require_bag_full=Your bag has filled up!
mod.chiselsandbits.result.void_excess=Your inventory has filled up, any excess bits have been voided!

mod.chiselsandbits.other.rotate.ccw=Rotate Held Counter Clockwise
mod.chiselsandbits.other.rotate.cw=Rotate Held Clockwise
Expand Down Expand Up @@ -255,3 +258,7 @@ mod.chiselsandbits.config.enableVivecraftCompatibility=Enable Vivecraft Compatib
mod.chiselsandbits.config.enableChiselCrafting=Enable Chiseling Blocks in Crafting Table
mod.chiselsandbits.config.dynamicRenderFullChunksOnly=Dynamic Renderer Full Chunks Only
mod.chiselsandbits.config.dynamicRenderFullChunksOnly.tooltip=Prevents Subdividing of dynamically rendered chunks into single blocks. This increases performance for most common cases ( chunks with a handful of complicated blocks ), but decreases performance for the worst cases ( chunks full of super complicated designs ).
mod.chiselsandbits.config.requireBagSpace=Require Bag Space
mod.chiselsandbits.config.requireBagSpace.tooltip=Requires there to be an empty slot in a bag in the player's inventory before allowing them to use the chisel.
mod.chiselsandbits.config.voidExcessBits=Void Excess Bits
mod.chiselsandbits.config.voidExcessBits.tooltip=Voids any bits that couldn't be fit into a bag or your inventory. Improves server performance. The undo action could have issues as some bits are voided.

0 comments on commit 0afca0b

Please sign in to comment.