Skip to content

Commit

Permalink
getParameter to retrieves runtime values via API. (#350)
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/mod/chiselsandbits/api/IChiselAndBitsAPI.java
  • Loading branch information
AlgorithmX2 committed Dec 21, 2017
1 parent 9a7153b commit 3bf6fda
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/mod/chiselsandbits/api/IChiselAndBitsAPI.java
Expand Up @@ -164,8 +164,24 @@ IBitBag getBitbag(
ItemStack itemstack );

/**
* Begins an undo operation, starting two operations without ending the
* previous operation will throw a runtime exception.
* Example: int stackSize =
* api.getParameter(IntegerParam.BIT_BAG_MAX_STACK_SIZE );
*
* @param which
* - refer to ParameterType for list of possible values.
* @return value of specified parameter.
*/
public <T extends Object> T getParameter(
ParameterType<T> which );

/**
* Begins an undo group, starting two operations without ending the previous
* operation will throw a runtime exception.
*
* This is used to merge multiple blocks into a single operation, undo steps
* will be recorded regardless of usage of this method, however its
* suggested to use groups in any case where a change well affect more then
* one block.
*
* @formatter:off
*
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/mod/chiselsandbits/api/ParameterType.java
@@ -0,0 +1,66 @@
package mod.chiselsandbits.api;

/**
* use these Enums to retrieve various settings or runtime values via
* {@link IChiselAndBitsAPI}.getParameter
*/
public interface ParameterType<T extends Object>
{

public ParamTypes getType();

public static enum ParamTypes
{
BOOLEAN,
FLOAT,
DOUBLE,
INTEGER
};

public static enum BooleanParam implements ParameterType<Boolean>
{
ENABLE_MCMP(/* enableMCMultipart */),
ENABLE_DAMAGE_TOOLS(/* damageTools */),
ENABLE_BIT_LIGHT_SOURCE(/* enableBitLightSource */);

@Override
public mod.chiselsandbits.api.ParameterType.ParamTypes getType()
{
return ParamTypes.BOOLEAN;
}
};

public static enum FloatParam implements ParameterType<Float>
{
BLOCK_FULL_LIGHT_PERCENTAGE(/* bitLightPercentage */);

@Override
public mod.chiselsandbits.api.ParameterType.ParamTypes getType()
{
return ParamTypes.FLOAT;
}
}

public static enum DoubleParam implements ParameterType<Double>
{
BIT_MAX_DRAWN_REGION_SIZE(/* maxDrawnRegionSize */);

@Override
public mod.chiselsandbits.api.ParameterType.ParamTypes getType()
{
return ParamTypes.DOUBLE;
}
}

public static enum IntegerParam implements ParameterType<Integer>
{
BIT_BAG_MAX_STACK_SIZE(/* bagStackSize */);

@Override
public mod.chiselsandbits.api.ParameterType.ParamTypes getType()
{
return ParamTypes.INTEGER;
}
}

}
55 changes: 55 additions & 0 deletions src/main/java/mod/chiselsandbits/core/api/ChiselAndBitsAPI.java
Expand Up @@ -9,12 +9,17 @@
import mod.chiselsandbits.api.IChiselAndBitsAPI;
import mod.chiselsandbits.api.ItemType;
import mod.chiselsandbits.api.ModKeyBinding;
import mod.chiselsandbits.api.ParameterType;
import mod.chiselsandbits.api.ParameterType.DoubleParam;
import mod.chiselsandbits.api.ParameterType.FloatParam;
import mod.chiselsandbits.api.ParameterType.IntegerParam;
import mod.chiselsandbits.chiseledblock.BlockBitInfo;
import mod.chiselsandbits.chiseledblock.ItemBlockChiseled;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseled;
import mod.chiselsandbits.chiseledblock.data.BitLocation;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.client.UndoTracker;
import mod.chiselsandbits.config.ModConfig;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.core.ClientSide;
import mod.chiselsandbits.helpers.BitOperation;
Expand Down Expand Up @@ -385,4 +390,54 @@ public KeyBinding getKeyBinding(
}
}

@SuppressWarnings( { "rawtypes", "unchecked" } )
@Override
public Object getParameter(
ParameterType which )
{
ModConfig config = ChiselsAndBits.getConfig();

switch ( (ParameterType.ParamTypes) which.getType() )
{
case BOOLEAN:
switch ( (ParameterType.BooleanParam) which )
{
case ENABLE_MCMP:
return true;
case ENABLE_DAMAGE_TOOLS:
return config.damageTools;
case ENABLE_BIT_LIGHT_SOURCE:
return config.enableBitLightSource;
}
break;

case DOUBLE:
switch ( (DoubleParam) which )
{
case BIT_MAX_DRAWN_REGION_SIZE:
return config.maxDrawnRegionSize;
}
break;

case FLOAT:
switch ( (FloatParam) which )
{
case BLOCK_FULL_LIGHT_PERCENTAGE:
return config.bitLightPercentage;
}
break;

case INTEGER:
switch ( (IntegerParam) which )
{
case BIT_BAG_MAX_STACK_SIZE:
return config.bagStackSize;
}
break;

}

return null;
}

}

0 comments on commit 3bf6fda

Please sign in to comment.