mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 14:52:58 +00:00
Formatting and code readability cleanup (#5467)
* First pass reformatting code to be more readable (common still not done) * Replace google common collect calls with Java calls where possible * Remove a bunch of unnecessary parenthesis leaving clarifying ones * Add some missing @Nonnull annotations * Fix checking wrong type * Remove unnecessary continue/return statements and simplify comparision check * Pass exception instead of directly printing stack trace * Work on cleaning up common, through config so far * Work on cleaning up common, through integration so far * Work on cleaning up common, through network so far * Work on cleaning up common, through tier so far * Remove empty constructors that get created by default anyways * Work on cleaning up common, through transmitters so far * Work on cleaning up common, through utils so far * Finish cleaning up spacing for common
This commit is contained in:
1 parent
91ef2a5c3d
commit
0d4b50908f
909 files changed
+6234
-15623
No files matched your search
@@ -87,8 +87,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
*/
|
||||
public final class MekanismUtils {
|
||||
|
||||
public static final EnumFacing[] SIDE_DIRS = new EnumFacing[]{EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.WEST,
|
||||
EnumFacing.EAST};
|
||||
public static final EnumFacing[] SIDE_DIRS = new EnumFacing[]{EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.EAST};
|
||||
|
||||
public static final Map<String, Class<?>> classesFound = new HashMap<>();
|
||||
|
||||
@@ -101,8 +100,7 @@ public final class MekanismUtils {
|
||||
static {
|
||||
for (int blockFacing = 0; blockFacing < EnumFacing.VALUES.length; blockFacing++) {
|
||||
for (int side = 0; side < EnumFacing.VALUES.length; side++) {
|
||||
baseOrientations[blockFacing][side] = getBaseOrientation(EnumFacing.VALUES[side],
|
||||
EnumFacing.VALUES[blockFacing]);
|
||||
baseOrientations[blockFacing][side] = getBaseOrientation(EnumFacing.VALUES[side], EnumFacing.VALUES[blockFacing]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +118,6 @@ public final class MekanismUtils {
|
||||
ItemStack stack = new ItemStack(MekanismBlocks.Transmitter, amount, type.ordinal());
|
||||
ItemBlockTransmitter itemTransmitter = (ItemBlockTransmitter) stack.getItem();
|
||||
itemTransmitter.setBaseTier(stack, tier);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@@ -129,11 +126,11 @@ public final class MekanismUtils {
|
||||
*
|
||||
* @param tier - tier to add to the Factory
|
||||
* @param type - recipe type to add to the Factory
|
||||
*
|
||||
* @return factory with defined tier and recipe type
|
||||
*/
|
||||
public static ItemStack getFactory(FactoryTier tier, RecipeType type) {
|
||||
ItemStack itemstack = new ItemStack(MekanismBlocks.MachineBlock, 1,
|
||||
MachineType.BASIC_FACTORY.ordinal() + tier.ordinal());
|
||||
ItemStack itemstack = new ItemStack(MekanismBlocks.MachineBlock, 1, MachineType.BASIC_FACTORY.ordinal() + tier.ordinal());
|
||||
((IFactory) itemstack.getItem()).setRecipeType(type.ordinal(), itemstack);
|
||||
return itemstack;
|
||||
}
|
||||
@@ -142,18 +139,17 @@ public final class MekanismUtils {
|
||||
* Checks if a machine is in it's active state.
|
||||
*
|
||||
* @param world World of the machine to check
|
||||
* @param pos The position of the machine
|
||||
* @param pos The position of the machine
|
||||
*
|
||||
* @return if machine is active
|
||||
*/
|
||||
public static boolean isActive(IBlockAccess world, BlockPos pos) {
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
|
||||
if (tileEntity != null) {
|
||||
if (tileEntity instanceof IActiveState) {
|
||||
return ((IActiveState) tileEntity).getActive();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -161,6 +157,7 @@ public final class MekanismUtils {
|
||||
* Gets the left side of a certain orientation.
|
||||
*
|
||||
* @param orientation Current orientation of the machine
|
||||
*
|
||||
* @return left side
|
||||
*/
|
||||
public static EnumFacing getLeft(EnumFacing orientation) {
|
||||
@@ -171,6 +168,7 @@ public final class MekanismUtils {
|
||||
* Gets the right side of a certain orientation.
|
||||
*
|
||||
* @param orientation Current orientation of the machine
|
||||
*
|
||||
* @return right side
|
||||
*/
|
||||
public static EnumFacing getRight(EnumFacing orientation) {
|
||||
@@ -181,6 +179,7 @@ public final class MekanismUtils {
|
||||
* Gets the opposite side of a certain orientation.
|
||||
*
|
||||
* @param orientation Current orientation of the machine
|
||||
*
|
||||
* @return opposite side
|
||||
*/
|
||||
public static EnumFacing getBack(EnumFacing orientation) {
|
||||
@@ -191,6 +190,7 @@ public final class MekanismUtils {
|
||||
* Returns the sides in the modified order relative to the machine-based orientation.
|
||||
*
|
||||
* @param blockFacing - what orientation the block is facing
|
||||
*
|
||||
* @return EnumFacing.VALUES, translated to machine orientation
|
||||
*/
|
||||
public static EnumFacing[] getBaseOrientations(EnumFacing blockFacing) {
|
||||
@@ -200,8 +200,9 @@ public final class MekanismUtils {
|
||||
/**
|
||||
* Returns an integer facing that converts a world-based orientation to a machine-based orientation.
|
||||
*
|
||||
* @param side - world based
|
||||
* @param side - world based
|
||||
* @param blockFacing - what orientation the block is facing
|
||||
*
|
||||
* @return machine orientation
|
||||
*/
|
||||
public static EnumFacing getBaseOrientation(EnumFacing side, EnumFacing blockFacing) {
|
||||
@@ -235,36 +236,31 @@ public final class MekanismUtils {
|
||||
if (side.getAxis() == Axis.Z) {
|
||||
return side.getOpposite();
|
||||
}
|
||||
|
||||
return side;
|
||||
} else if (blockFacing == EnumFacing.NORTH) {
|
||||
if (side.getAxis() == Axis.Z) {
|
||||
return side;
|
||||
}
|
||||
|
||||
return side.getOpposite();
|
||||
} else if (blockFacing == EnumFacing.WEST) {
|
||||
if (side.getAxis() == Axis.Z) {
|
||||
return getRight(side);
|
||||
}
|
||||
|
||||
return getLeft(side);
|
||||
} else if (blockFacing == EnumFacing.EAST) {
|
||||
if (side.getAxis() == Axis.Z) {
|
||||
return getLeft(side);
|
||||
}
|
||||
|
||||
return getRight(side);
|
||||
}
|
||||
|
||||
return side;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the output type of a machine's side.
|
||||
*
|
||||
* @param config - configurable machine
|
||||
* @param type - the TransmissionType to modify
|
||||
* @param config - configurable machine
|
||||
* @param type - the TransmissionType to modify
|
||||
* @param direction - side to increment output of
|
||||
*/
|
||||
public static void incrementOutput(ISideConfiguration config, TransmissionType type, EnumFacing direction) {
|
||||
@@ -272,13 +268,11 @@ public final class MekanismUtils {
|
||||
SideConfig sideConfig = config.getConfig().getConfig(type);
|
||||
int max = outputs.size() - 1;
|
||||
int current = outputs.indexOf(outputs.get(sideConfig.get(direction)));
|
||||
|
||||
if (current < max) {
|
||||
sideConfig.set(direction, (byte) (current + 1));
|
||||
} else if (current == max) {
|
||||
sideConfig.set(direction, (byte) 0);
|
||||
}
|
||||
|
||||
assert config instanceof TileEntity;
|
||||
TileEntity tile = (TileEntity) config;
|
||||
tile.markDirty();
|
||||
@@ -287,8 +281,8 @@ public final class MekanismUtils {
|
||||
/**
|
||||
* Decrements the output type of a machine's side.
|
||||
*
|
||||
* @param config - configurable machine
|
||||
* @param type - the TransmissionType to modify
|
||||
* @param config - configurable machine
|
||||
* @param type - the TransmissionType to modify
|
||||
* @param direction - side to increment output of
|
||||
*/
|
||||
public static void decrementOutput(ISideConfiguration config, TransmissionType type, EnumFacing direction) {
|
||||
@@ -296,13 +290,11 @@ public final class MekanismUtils {
|
||||
SideConfig sideConfig = config.getConfig().getConfig(type);
|
||||
int max = outputs.size() - 1;
|
||||
int current = outputs.indexOf(outputs.get(sideConfig.get(direction)));
|
||||
|
||||
if (current > 0) {
|
||||
sideConfig.set(direction, (byte) (current - 1));
|
||||
} else if (current == 0) {
|
||||
sideConfig.set(direction, (byte) max);
|
||||
}
|
||||
|
||||
assert config instanceof TileEntity;
|
||||
TileEntity tile = (TileEntity) config;
|
||||
tile.markDirty();
|
||||
@@ -316,79 +308,77 @@ public final class MekanismUtils {
|
||||
* Gets the operating ticks required for a machine via it's upgrades.
|
||||
*
|
||||
* @param mgmt - tile containing upgrades
|
||||
* @param def - the original, default ticks required
|
||||
* @param def - the original, default ticks required
|
||||
*
|
||||
* @return required operating ticks
|
||||
*/
|
||||
public static int getTicks(IUpgradeTile mgmt, int def) {
|
||||
return (int) (def * Math.pow(
|
||||
MekanismConfig.current().general.maxUpgradeMultiplier.val(), -fractionUpgrades(mgmt, Upgrade.SPEED)));
|
||||
return (int) (def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(), -fractionUpgrades(mgmt, Upgrade.SPEED)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the energy required per tick for a machine via it's upgrades.
|
||||
*
|
||||
* @param mgmt - tile containing upgrades
|
||||
* @param def - the original, default energy required
|
||||
* @param def - the original, default energy required
|
||||
*
|
||||
* @return required energy per tick
|
||||
*/
|
||||
public static double getEnergyPerTick(IUpgradeTile mgmt, double def) {
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(),
|
||||
2 * fractionUpgrades(mgmt, Upgrade.SPEED) - fractionUpgrades(mgmt, Upgrade.ENERGY));
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(), 2 * fractionUpgrades(mgmt, Upgrade.SPEED) - fractionUpgrades(mgmt, Upgrade.ENERGY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the energy required per tick for a machine via it's upgrades, not taking into account speed upgrades.
|
||||
*
|
||||
* @param mgmt - tile containing upgrades
|
||||
* @param def - the original, default energy required
|
||||
* @param def - the original, default energy required
|
||||
*
|
||||
* @return required energy per tick
|
||||
*/
|
||||
public static double getBaseEnergyPerTick(IUpgradeTile mgmt, double def) {
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(),
|
||||
-fractionUpgrades(mgmt, Upgrade.ENERGY));
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(), -fractionUpgrades(mgmt, Upgrade.ENERGY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the secondary energy required per tick for a machine via upgrades.
|
||||
*
|
||||
* @param mgmt - tile containing upgrades
|
||||
* @param def - the original, default secondary energy required
|
||||
* @param def - the original, default secondary energy required
|
||||
*
|
||||
* @return max secondary energy per tick
|
||||
*/
|
||||
public static double getSecondaryEnergyPerTickMean(IUpgradeTile mgmt, int def) {
|
||||
if (mgmt.getComponent().supports(Upgrade.GAS)) {
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(),
|
||||
2 * fractionUpgrades(mgmt, Upgrade.SPEED) - fractionUpgrades(mgmt, Upgrade.GAS));
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(), 2 * fractionUpgrades(mgmt, Upgrade.SPEED) - fractionUpgrades(mgmt, Upgrade.GAS));
|
||||
}
|
||||
|
||||
return def * Math
|
||||
.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(), fractionUpgrades(mgmt, Upgrade.SPEED));
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(), fractionUpgrades(mgmt, Upgrade.SPEED));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum energy for a machine via it's upgrades.
|
||||
*
|
||||
* @param mgmt - tile containing upgrades - best known for "Kids", 2008
|
||||
* @param def - original, default max energy
|
||||
* @param def - original, default max energy
|
||||
*
|
||||
* @return max energy
|
||||
*/
|
||||
public static double getMaxEnergy(IUpgradeTile mgmt, double def) {
|
||||
return def * Math
|
||||
.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(), fractionUpgrades(mgmt, Upgrade.ENERGY));
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(), fractionUpgrades(mgmt, Upgrade.ENERGY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum energy for a machine's item form via it's upgrades.
|
||||
*
|
||||
* @param itemStack - stack holding energy upgrades
|
||||
* @param def - original, default max energy
|
||||
* @param def - original, default max energy
|
||||
*
|
||||
* @return max energy
|
||||
*/
|
||||
public static double getMaxEnergy(ItemStack itemStack, double def) {
|
||||
Map<Upgrade, Integer> upgrades = Upgrade.buildMap(ItemDataUtils.getDataMap(itemStack));
|
||||
float numUpgrades = upgrades.get(Upgrade.ENERGY) == null ? 0 : (float) upgrades.get(Upgrade.ENERGY);
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(),
|
||||
numUpgrades / (float) Upgrade.ENERGY.getMax());
|
||||
return def * Math.pow(MekanismConfig.current().general.maxUpgradeMultiplier.val(), numUpgrades / (float) Upgrade.ENERGY.getMax());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,16 +386,15 @@ public final class MekanismUtils {
|
||||
*
|
||||
* @param world - the world to perform the check in
|
||||
* @param coord - the coordinate of the block performing the check
|
||||
*
|
||||
* @return if the block is indirectly getting powered by LOADED chunks
|
||||
*/
|
||||
public static boolean isGettingPowered(World world, Coord4D coord) {
|
||||
for (EnumFacing side : EnumFacing.VALUES) {
|
||||
Coord4D sideCoord = coord.offset(side);
|
||||
|
||||
if (sideCoord.exists(world) && sideCoord.offset(side).exists(world)) {
|
||||
IBlockState blockState = sideCoord.getBlockState(world);
|
||||
boolean weakPower = blockState.getBlock().shouldCheckWeakPower(blockState, world, coord.getPos(), side);
|
||||
|
||||
if (weakPower && isDirectlyGettingPowered(world, sideCoord)) {
|
||||
return true;
|
||||
} else if (!weakPower && blockState.getWeakPower(world, sideCoord.getPos(), side) > 0) {
|
||||
@@ -413,7 +402,6 @@ public final class MekanismUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -422,19 +410,18 @@ public final class MekanismUtils {
|
||||
*
|
||||
* @param world - the world to perform the check in
|
||||
* @param coord - the Coord4D of the block to check
|
||||
*
|
||||
* @return if the block is directly getting powered
|
||||
*/
|
||||
public static boolean isDirectlyGettingPowered(World world, Coord4D coord) {
|
||||
for (EnumFacing side : EnumFacing.VALUES) {
|
||||
Coord4D sideCoord = coord.offset(side);
|
||||
|
||||
if (sideCoord.exists(world)) {
|
||||
if (world.getRedstonePower(coord.getPos(), side) > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -447,16 +434,12 @@ public final class MekanismUtils {
|
||||
public static void notifyLoadedNeighborsOfTileChange(World world, Coord4D coord) {
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
Coord4D offset = coord.offset(dir);
|
||||
|
||||
if (offset.exists(world)) {
|
||||
notifyNeighborofChange(world, offset, coord.getPos());
|
||||
|
||||
if (offset.getBlockState(world).isNormalCube()) {
|
||||
offset = offset.offset(dir);
|
||||
|
||||
if (offset.exists(world)) {
|
||||
Block block1 = offset.getBlock(world);
|
||||
|
||||
if (block1.getWeakChanges(world, offset.getPos())) {
|
||||
block1.onNeighborChange(world, offset.getPos(), coord.getPos());
|
||||
}
|
||||
@@ -469,8 +452,8 @@ public final class MekanismUtils {
|
||||
/**
|
||||
* Calls BOTH neighbour changed functions because nobody can decide on which one to implement.
|
||||
*
|
||||
* @param world world the change exists in
|
||||
* @param coord neighbor to notify
|
||||
* @param world world the change exists in
|
||||
* @param coord neighbor to notify
|
||||
* @param fromPos pos of our block that updated
|
||||
*/
|
||||
public static void notifyNeighborofChange(World world, Coord4D coord, BlockPos fromPos) {
|
||||
@@ -482,9 +465,9 @@ public final class MekanismUtils {
|
||||
/**
|
||||
* Calls BOTH neighbour changed functions because nobody can decide on which one to implement.
|
||||
*
|
||||
* @param world world the change exists in
|
||||
* @param world world the change exists in
|
||||
* @param neighborSide The side the neighbor to notify is on
|
||||
* @param fromPos pos of our block that updated
|
||||
* @param fromPos pos of our block that updated
|
||||
*/
|
||||
public static void notifyNeighborOfChange(World world, EnumFacing neighborSide, BlockPos fromPos) {
|
||||
BlockPos neighbor = fromPos.offset(neighborSide);
|
||||
@@ -496,13 +479,12 @@ public final class MekanismUtils {
|
||||
/**
|
||||
* Places a fake bounding block at the defined location.
|
||||
*
|
||||
* @param world - world to place block in
|
||||
* @param world - world to place block in
|
||||
* @param boundingLocation - coordinates of bounding block
|
||||
* @param orig - original block
|
||||
* @param orig - original block
|
||||
*/
|
||||
public static void makeBoundingBlock(World world, BlockPos boundingLocation, Coord4D orig) {
|
||||
world.setBlockState(boundingLocation, MekanismBlocks.BoundingBlock.getStateFromMeta(0));
|
||||
|
||||
if (!world.isRemote) {
|
||||
((TileEntityBoundingBlock) world.getTileEntity(boundingLocation)).setMainLocation(orig.getPos());
|
||||
}
|
||||
@@ -511,13 +493,12 @@ public final class MekanismUtils {
|
||||
/**
|
||||
* Places a fake advanced bounding block at the defined location.
|
||||
*
|
||||
* @param world - world to place block in
|
||||
* @param world - world to place block in
|
||||
* @param boundingLocation - coordinates of bounding block
|
||||
* @param orig - original block
|
||||
* @param orig - original block
|
||||
*/
|
||||
public static void makeAdvancedBoundingBlock(World world, BlockPos boundingLocation, Coord4D orig) {
|
||||
world.setBlockState(boundingLocation, MekanismBlocks.BoundingBlock.getStateFromMeta(1));
|
||||
|
||||
if (!world.isRemote) {
|
||||
((TileEntityAdvancedBoundingBlock) world.getTileEntity(boundingLocation)).setMainLocation(orig.getPos());
|
||||
}
|
||||
@@ -527,7 +508,7 @@ public final class MekanismUtils {
|
||||
* Updates a block's light value and marks it for a render update.
|
||||
*
|
||||
* @param world - world the block is in
|
||||
* @param pos Position of the block
|
||||
* @param pos Position of the block
|
||||
*/
|
||||
public static void updateBlock(World world, BlockPos pos) {
|
||||
//Schedule a render update regardless of it is an IActiveState with IActiveState#renderUpdate() as true
|
||||
@@ -535,10 +516,8 @@ public final class MekanismUtils {
|
||||
// anyways here in case IActiveState#renderUpdate() is false and we just had the block rotate.
|
||||
// For example the laser, or charge pad.
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
if (!(tileEntity instanceof IActiveState) || ((IActiveState) tileEntity).lightUpdate() && MekanismConfig
|
||||
.current().client.machineEffects.val()) {
|
||||
if (!(tileEntity instanceof IActiveState) || ((IActiveState) tileEntity).lightUpdate() && MekanismConfig.current().client.machineEffects.val()) {
|
||||
updateAllLightTypes(world, pos);
|
||||
}
|
||||
}
|
||||
@@ -547,7 +526,7 @@ public final class MekanismUtils {
|
||||
* Updates all light types at the given coordinates.
|
||||
*
|
||||
* @param world - the world to perform the lighting update in
|
||||
* @param pos - coordinates of the block to update
|
||||
* @param pos - coordinates of the block to update
|
||||
*/
|
||||
public static void updateAllLightTypes(World world, BlockPos pos) {
|
||||
world.checkLightFor(EnumSkyBlock.BLOCK, pos);
|
||||
@@ -558,7 +537,8 @@ public final class MekanismUtils {
|
||||
* Whether or not a certain block is considered a fluid.
|
||||
*
|
||||
* @param world - world the block is in
|
||||
* @param pos - coordinates
|
||||
* @param pos - coordinates
|
||||
*
|
||||
* @return if the block is a fluid
|
||||
*/
|
||||
public static boolean isFluid(World world, Coord4D pos) {
|
||||
@@ -569,29 +549,26 @@ public final class MekanismUtils {
|
||||
* Gets a fluid from a certain location.
|
||||
*
|
||||
* @param world - world the block is in
|
||||
* @param pos - location of the block
|
||||
* @param pos - location of the block
|
||||
*
|
||||
* @return the fluid at the certain location, null if it doesn't exist
|
||||
*/
|
||||
public static FluidStack getFluid(World world, Coord4D pos, boolean filter) {
|
||||
IBlockState state = pos.getBlockState(world);
|
||||
Block block = state.getBlock();
|
||||
|
||||
if ((block == Blocks.WATER || block == Blocks.FLOWING_WATER) && state.getValue(BlockLiquid.LEVEL) == 0) {
|
||||
if (!filter) {
|
||||
return new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME);
|
||||
} else {
|
||||
return new FluidStack(MekanismFluids.HeavyWater, 10);
|
||||
}
|
||||
return new FluidStack(MekanismFluids.HeavyWater, 10);
|
||||
} else if ((block == Blocks.LAVA || block == Blocks.FLOWING_LAVA) && state.getValue(BlockLiquid.LEVEL) == 0) {
|
||||
return new FluidStack(FluidRegistry.LAVA, Fluid.BUCKET_VOLUME);
|
||||
} else if (block instanceof IFluidBlock) {
|
||||
IFluidBlock fluid = (IFluidBlock) block;
|
||||
|
||||
if (state.getProperties().containsKey(BlockFluidBase.LEVEL) && state.getValue(BlockFluidBase.LEVEL) == 0) {
|
||||
return fluid.drain(world, pos.getPos(), false);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -599,17 +576,16 @@ public final class MekanismUtils {
|
||||
* Whether or not a block is a dead fluid.
|
||||
*
|
||||
* @param world - world the block is in
|
||||
* @param pos - coordinates
|
||||
* @param pos - coordinates
|
||||
*
|
||||
* @return if the block is a dead fluid
|
||||
*/
|
||||
public static boolean isDeadFluid(World world, Coord4D pos) {
|
||||
IBlockState state = pos.getBlockState(world);
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block.getMetaFromState(state) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return block instanceof BlockLiquid || block instanceof IFluidBlock;
|
||||
|
||||
}
|
||||
@@ -618,6 +594,7 @@ public final class MekanismUtils {
|
||||
* Gets the flowing block type from a Forge-based fluid. Incorporates the MC system of fliuds as well.
|
||||
*
|
||||
* @param fluid - the fluid type
|
||||
*
|
||||
* @return the block corresponding to the given fluid
|
||||
*/
|
||||
public static Block getFlowingBlock(Fluid fluid) {
|
||||
@@ -627,36 +604,28 @@ public final class MekanismUtils {
|
||||
return Blocks.FLOWING_WATER;
|
||||
} else if (fluid == FluidRegistry.LAVA) {
|
||||
return Blocks.FLOWING_LAVA;
|
||||
} else {
|
||||
return fluid.getBlock();
|
||||
}
|
||||
return fluid.getBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* FML doesn't really do GUIs the way it's supposed to -- opens Electric Chest GUI on client and server. Call this
|
||||
* method server-side only!
|
||||
* FML doesn't really do GUIs the way it's supposed to -- opens Electric Chest GUI on client and server. Call this method server-side only!
|
||||
*
|
||||
* @param player - player to open GUI
|
||||
* @param player - player to open GUI
|
||||
* @param tileEntity - TileEntity of the chest, if it's not an item
|
||||
* @param inventory - IInventory of the item, if it's not a block
|
||||
* @param isBlock - whether or not this electric chest is in it's block form
|
||||
* @param inventory - IInventory of the item, if it's not a block
|
||||
* @param isBlock - whether or not this electric chest is in it's block form
|
||||
*/
|
||||
public static void openPersonalChestGui(EntityPlayerMP player, TileEntityPersonalChest tileEntity,
|
||||
InventoryPersonalChest inventory, boolean isBlock) {
|
||||
public static void openPersonalChestGui(EntityPlayerMP player, TileEntityPersonalChest tileEntity, InventoryPersonalChest inventory, boolean isBlock) {
|
||||
player.getNextWindowId();
|
||||
player.closeContainer();
|
||||
int id = player.currentWindowId;
|
||||
|
||||
if (isBlock) {
|
||||
Mekanism.packetHandler.sendTo(
|
||||
new PersonalChestMessage(PersonalChestPacketType.CLIENT_OPEN, true, 0, id, Coord4D.get(tileEntity),
|
||||
null), player);
|
||||
Mekanism.packetHandler.sendTo(new PersonalChestMessage(PersonalChestPacketType.CLIENT_OPEN, true, 0, id, Coord4D.get(tileEntity), null), player);
|
||||
} else {
|
||||
Mekanism.packetHandler.sendTo(
|
||||
new PersonalChestMessage(PersonalChestPacketType.CLIENT_OPEN, false, 0, id, null,
|
||||
inventory.currentHand), player);
|
||||
Mekanism.packetHandler.sendTo(new PersonalChestMessage(PersonalChestPacketType.CLIENT_OPEN, false, 0, id, null, inventory.currentHand), player);
|
||||
}
|
||||
|
||||
player.openContainer = new ContainerPersonalChest(player.inventory, tileEntity, inventory, isBlock);
|
||||
player.openContainer.windowId = id;
|
||||
player.openContainer.addListener(player);
|
||||
@@ -667,6 +636,7 @@ public final class MekanismUtils {
|
||||
*
|
||||
* @param type - type of resource to retrieve
|
||||
* @param name - simple name of file to retrieve as a ResourceLocation
|
||||
*
|
||||
* @return the corresponding ResourceLocation
|
||||
*/
|
||||
public static ResourceLocation getResource(ResourceType type, String name) {
|
||||
@@ -674,8 +644,7 @@ public final class MekanismUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the chunk this TileEntity is in as modified. Call this method to be sure NBT is written by the defined tile
|
||||
* entity.
|
||||
* Marks the chunk this TileEntity is in as modified. Call this method to be sure NBT is written by the defined tile entity.
|
||||
*
|
||||
* @param tileEntity - TileEntity to save
|
||||
*/
|
||||
@@ -683,24 +652,21 @@ public final class MekanismUtils {
|
||||
if (tileEntity == null || tileEntity.isInvalid() || tileEntity.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
tileEntity.getWorld().markChunkDirty(tileEntity.getPos(), tileEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not a certain TileEntity can function with redstone logic. Illogical to use unless the defined
|
||||
* TileEntity implements IRedstoneControl.
|
||||
* Whether or not a certain TileEntity can function with redstone logic. Illogical to use unless the defined TileEntity implements IRedstoneControl.
|
||||
*
|
||||
* @param tileEntity - TileEntity to check
|
||||
*
|
||||
* @return if the TileEntity can function with redstone logic
|
||||
*/
|
||||
public static boolean canFunction(TileEntity tileEntity) {
|
||||
if (!(tileEntity instanceof IRedstoneControl)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
IRedstoneControl control = (IRedstoneControl) tileEntity;
|
||||
|
||||
switch (control.getControlType()) {
|
||||
case DISABLED:
|
||||
return true;
|
||||
@@ -711,24 +677,22 @@ public final class MekanismUtils {
|
||||
case PULSE:
|
||||
return control.isPowered() && !control.wasPowered();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ray-traces what block a player is looking at.
|
||||
*
|
||||
* @param world - world the player is in
|
||||
* @param world - world the player is in
|
||||
* @param player - player to raytrace
|
||||
*
|
||||
* @return raytraced value
|
||||
*/
|
||||
public static RayTraceResult rayTrace(World world, EntityPlayer player) {
|
||||
double reach = Mekanism.proxy.getReach(player);
|
||||
|
||||
Vec3d headVec = getHeadVec(player);
|
||||
Vec3d lookVec = player.getLook(1);
|
||||
Vec3d endVec = headVec.add(lookVec.x * reach, lookVec.y * reach, lookVec.z * reach);
|
||||
|
||||
return world.rayTraceBlocks(headVec, endVec, true);
|
||||
}
|
||||
|
||||
@@ -736,21 +700,19 @@ public final class MekanismUtils {
|
||||
* Gets the head vector of a player for a ray trace.
|
||||
*
|
||||
* @param player - player to check
|
||||
*
|
||||
* @return head location
|
||||
*/
|
||||
private static Vec3d getHeadVec(EntityPlayer player) {
|
||||
double posX = player.posX;
|
||||
double posY = player.posY;
|
||||
double posZ = player.posZ;
|
||||
|
||||
if (!player.world.isRemote) {
|
||||
posY += player.getEyeHeight();
|
||||
|
||||
if (player instanceof EntityPlayerMP && player.isSneaking()) {
|
||||
posY -= 0.08;
|
||||
}
|
||||
}
|
||||
|
||||
return new Vec3d(posX, posY, posZ);
|
||||
}
|
||||
|
||||
@@ -758,27 +720,23 @@ public final class MekanismUtils {
|
||||
* Gets a rounded energy display of a defined amount of energy.
|
||||
*
|
||||
* @param energy - energy to display
|
||||
*
|
||||
* @return rounded energy display
|
||||
*/
|
||||
public static String getEnergyDisplay(double energy) {
|
||||
if (energy == Double.MAX_VALUE) {
|
||||
return LangUtils.localize("gui.infinite");
|
||||
}
|
||||
|
||||
switch (MekanismConfig.current().general.energyUnit.val()) {
|
||||
case J:
|
||||
return UnitDisplayUtils.getDisplayShort(energy, ElectricUnit.JOULES);
|
||||
case RF:
|
||||
return UnitDisplayUtils.getDisplayShort(energy * MekanismConfig.current().general.TO_RF.val(),
|
||||
ElectricUnit.REDSTONE_FLUX);
|
||||
return UnitDisplayUtils.getDisplayShort(energy * MekanismConfig.current().general.TO_RF.val(), ElectricUnit.REDSTONE_FLUX);
|
||||
case EU:
|
||||
return UnitDisplayUtils.getDisplayShort(energy * MekanismConfig.current().general.TO_IC2.val(),
|
||||
ElectricUnit.ELECTRICAL_UNITS);
|
||||
return UnitDisplayUtils.getDisplayShort(energy * MekanismConfig.current().general.TO_IC2.val(), ElectricUnit.ELECTRICAL_UNITS);
|
||||
case T:
|
||||
return UnitDisplayUtils
|
||||
.getDisplayShort(energy * MekanismConfig.current().general.TO_TESLA.val(), ElectricUnit.TESLA);
|
||||
return UnitDisplayUtils.getDisplayShort(energy * MekanismConfig.current().general.TO_TESLA.val(), ElectricUnit.TESLA);
|
||||
}
|
||||
|
||||
return "error";
|
||||
}
|
||||
|
||||
@@ -786,10 +744,8 @@ public final class MekanismUtils {
|
||||
if (energy == Double.MAX_VALUE) {
|
||||
return LangUtils.localize("gui.infinite");
|
||||
}
|
||||
|
||||
String energyString = getEnergyDisplay(energy);
|
||||
String maxString = getEnergyDisplay(max);
|
||||
|
||||
return energyString + "/" + maxString;
|
||||
}
|
||||
|
||||
@@ -797,6 +753,7 @@ public final class MekanismUtils {
|
||||
* Convert from the unit defined in the configuration to joules.
|
||||
*
|
||||
* @param energy - energy to convert
|
||||
*
|
||||
* @return energy converted to joules
|
||||
*/
|
||||
public static double convertToJoules(double energy) {
|
||||
@@ -816,6 +773,7 @@ public final class MekanismUtils {
|
||||
* Convert from joules to the unit defined in the configuration.
|
||||
*
|
||||
* @param energy - energy to convert
|
||||
*
|
||||
* @return energy converted to configured unit
|
||||
*/
|
||||
public static double convertToDisplay(double energy) {
|
||||
@@ -835,11 +793,11 @@ public final class MekanismUtils {
|
||||
* Gets a rounded energy display of a defined amount of energy.
|
||||
*
|
||||
* @param T - temperature to display
|
||||
*
|
||||
* @return rounded energy display
|
||||
*/
|
||||
public static String getTemperatureDisplay(double T, TemperatureUnit unit) {
|
||||
double TK = unit.convertToK(T, true);
|
||||
|
||||
switch (MekanismConfig.current().general.tempUnit.val()) {
|
||||
case K:
|
||||
return UnitDisplayUtils.getDisplayShort(TK, TemperatureUnit.KELVIN);
|
||||
@@ -852,19 +810,16 @@ public final class MekanismUtils {
|
||||
case STP:
|
||||
return UnitDisplayUtils.getDisplayShort(TK, TemperatureUnit.AMBIENT);
|
||||
}
|
||||
|
||||
return "error";
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not IC2 power should be used, taking into account whether or not it is installed or another mod is
|
||||
* providing its API.
|
||||
* Whether or not IC2 power should be used, taking into account whether or not it is installed or another mod is providing its API.
|
||||
*
|
||||
* @return if IC2 power should be used
|
||||
*/
|
||||
public static boolean useIC2() {
|
||||
return Mekanism.hooks.IC2Loaded && EnergyNet.instance != null && !MekanismConfig.current().general.blacklistIC2
|
||||
.val();
|
||||
return Mekanism.hooks.IC2Loaded && EnergyNet.instance != null && !MekanismConfig.current().general.blacklistIC2.val();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -898,6 +853,7 @@ public final class MekanismUtils {
|
||||
* Gets a clean view of a coordinate value without the dimension ID.
|
||||
*
|
||||
* @param obj - coordinate to check
|
||||
*
|
||||
* @return coordinate display
|
||||
*/
|
||||
public static String getCoordDisplay(Coord4D obj) {
|
||||
@@ -907,30 +863,27 @@ public final class MekanismUtils {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static List<String> splitTooltip(String s, ItemStack stack) {
|
||||
s = s.trim();
|
||||
|
||||
FontRenderer renderer = (FontRenderer) Mekanism.proxy.getFontRenderer();
|
||||
if (!stack.isEmpty() && stack.getItem().getFontRenderer(stack) != null) {
|
||||
renderer = stack.getItem().getFontRenderer(stack);
|
||||
}
|
||||
|
||||
if (renderer != null) {
|
||||
return renderer.listFormattedStringToWidth(s, 200);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a full gas tank with the specified gas type.
|
||||
*
|
||||
* @param gas - gas to fill the tank with
|
||||
*
|
||||
* @return filled gas tank
|
||||
*/
|
||||
public static ItemStack getFullGasTank(GasTankTier tier, Gas gas) {
|
||||
ItemStack tank = getEmptyGasTank(tier);
|
||||
ItemBlockGasTank item = (ItemBlockGasTank) tank.getItem();
|
||||
item.setGas(tank, new GasStack(gas, item.MAX_GAS));
|
||||
|
||||
return tank;
|
||||
}
|
||||
|
||||
@@ -941,20 +894,19 @@ public final class MekanismUtils {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return new InventoryCrafting(tempContainer, 3, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the output of a defined InventoryCrafting grid.
|
||||
*
|
||||
* @param inv - InventoryCrafting to check
|
||||
* @param inv - InventoryCrafting to check
|
||||
* @param world - world reference
|
||||
*
|
||||
* @return output ItemStack
|
||||
*/
|
||||
public static ItemStack findMatchingRecipe(InventoryCrafting inv, World world) {
|
||||
NonNullList<ItemStack> dmgItems = NonNullList.withSize(2, ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
if (!inv.getStackInSlot(i).isEmpty()) {
|
||||
if (dmgItems.get(0).isEmpty()) {
|
||||
@@ -970,18 +922,15 @@ public final class MekanismUtils {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if ((!dmgItems.get(1).isEmpty()) && (dmgItems.get(0).getItem() == dmgItems.get(1).getItem()) && (
|
||||
dmgItems.get(0).getCount() == 1) && (dmgItems.get(1).getCount() == 1) && dmgItems.get(0).getItem()
|
||||
.isRepairable()) {
|
||||
if (!dmgItems.get(1).isEmpty() && (dmgItems.get(0).getItem() == dmgItems.get(1).getItem()) &&
|
||||
(dmgItems.get(0).getCount() == 1) && (dmgItems.get(1).getCount() == 1) && dmgItems.get(0).getItem().isRepairable()) {
|
||||
Item theItem = dmgItems.get(0).getItem();
|
||||
int dmgDiff0 = theItem.getMaxDamage() - dmgItems.get(0).getItemDamage();
|
||||
int dmgDiff1 = theItem.getMaxDamage() - dmgItems.get(1).getItemDamage();
|
||||
int value = dmgDiff0 + dmgDiff1 + theItem.getMaxDamage() * 5 / 100;
|
||||
int solve = Math.max(0, theItem.getMaxDamage() - value);
|
||||
|
||||
return new ItemStack(dmgItems.get(0).getItem(), 1, solve);
|
||||
}
|
||||
|
||||
IRecipe potentialResult = CraftingManager.findMatchingRecipe(inv, world);
|
||||
return potentialResult != null ? potentialResult.getRecipeOutput() : ItemStack.EMPTY;
|
||||
}
|
||||
@@ -990,6 +939,7 @@ public final class MekanismUtils {
|
||||
* Whether or not the provided chunk is being vibrated by a Seismic Vibrator.
|
||||
*
|
||||
* @param chunk - chunk to check
|
||||
*
|
||||
* @return if the chunk is being vibrated
|
||||
*/
|
||||
public static boolean isChunkVibrated(Chunk3D chunk) {
|
||||
@@ -998,7 +948,6 @@ public final class MekanismUtils {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1006,30 +955,28 @@ public final class MekanismUtils {
|
||||
* Whether or not a given EntityPlayer is considered an Op.
|
||||
*
|
||||
* @param p - player to check
|
||||
*
|
||||
* @return if the player has operator privileges
|
||||
*/
|
||||
public static boolean isOp(EntityPlayer p) {
|
||||
if (!(p instanceof EntityPlayerMP)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityPlayerMP player = (EntityPlayerMP) p;
|
||||
|
||||
return MekanismConfig.current().general.opsBypassRestrictions.val() && player.server.getPlayerList()
|
||||
.canSendCommands(player.getGameProfile());
|
||||
return MekanismConfig.current().general.opsBypassRestrictions.val() && player.server.getPlayerList().canSendCommands(player.getGameProfile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item ID from a given ItemStack
|
||||
*
|
||||
* @param itemStack - ItemStack to check
|
||||
*
|
||||
* @return item ID of the ItemStack
|
||||
*/
|
||||
public static int getID(ItemStack itemStack) {
|
||||
if (itemStack.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return Item.getIdFromItem(itemStack.getItem());
|
||||
}
|
||||
|
||||
@@ -1037,23 +984,18 @@ public final class MekanismUtils {
|
||||
if (classesFound.containsKey(className)) {
|
||||
return classesFound.get(className) != null;
|
||||
}
|
||||
|
||||
Class<?> found;
|
||||
|
||||
try {
|
||||
found = Class.forName(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
found = null;
|
||||
}
|
||||
|
||||
classesFound.put(className, found);
|
||||
|
||||
return found != null;
|
||||
}
|
||||
|
||||
public static boolean existsAndInstance(Object obj, String className) {
|
||||
Class<?> theClass;
|
||||
|
||||
if (classesFound.containsKey(className)) {
|
||||
theClass = classesFound.get(className);
|
||||
} else {
|
||||
@@ -1065,7 +1007,6 @@ public final class MekanismUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return theClass != null && theClass.isInstance(obj);
|
||||
}
|
||||
|
||||
@@ -1081,65 +1022,51 @@ public final class MekanismUtils {
|
||||
* Whether or not the player has a usable wrench for a block at the coordinates given.
|
||||
*
|
||||
* @param player - the player using the wrench
|
||||
* @param pos - the coordinate of the block being wrenched
|
||||
* @param pos - the coordinate of the block being wrenched
|
||||
*
|
||||
* @return if the player can use the wrench
|
||||
*
|
||||
* @deprecated use {@link mekanism.common.integration.wrenches.Wrenches#getHandler(ItemStack)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean hasUsableWrench(EntityPlayer player, BlockPos pos) {
|
||||
ItemStack tool = player.inventory.getCurrentItem();
|
||||
|
||||
if (tool.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (tool.getItem() instanceof IMekWrench && ((IMekWrench) tool.getItem()).canUseWrench(tool, player, pos)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (isBCWrench(tool.getItem())) //TODO too much hassle to check BC wrench-ability
|
||||
{
|
||||
if (isBCWrench(tool.getItem())) { //TODO too much hassle to check BC wrench-ability
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isCoFHHammer(
|
||||
tool.getItem())) // TODO Implement CoFH Hammer && ((IToolHammer)tool.getItem()).isUsable(tool, player, pos))
|
||||
{
|
||||
if (isCoFHHammer(tool.getItem())) { // TODO Implement CoFH Hammer && ((IToolHammer)tool.getItem()).isUsable(tool, player, pos))
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String getLastKnownUsername(UUID uuid) {
|
||||
String ret = UsernameCache.getLastKnownUsername(uuid);
|
||||
|
||||
if (ret == null && !warnedFails.contains(uuid) && FMLCommonHandler.instance().getEffectiveSide()
|
||||
== Side.SERVER) { // see if MC/Yggdrasil knows about it?!
|
||||
GameProfile gp = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerProfileCache()
|
||||
.getProfileByUUID(uuid);
|
||||
|
||||
if (ret == null && !warnedFails.contains(uuid) && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { // see if MC/Yggdrasil knows about it?!
|
||||
GameProfile gp = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerProfileCache().getProfileByUUID(uuid);
|
||||
if (gp != null) {
|
||||
ret = gp.getName();
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == null && !warnedFails.contains(uuid)) {
|
||||
Mekanism.logger
|
||||
.warn("Failed to retrieve username for UUID {}, you might want to add it to the JSON cache", uuid);
|
||||
Mekanism.logger.warn("Failed to retrieve username for UUID {}, you might want to add it to the JSON cache", uuid);
|
||||
warnedFails.add(uuid);
|
||||
}
|
||||
|
||||
return ret != null ? ret : "<???>";
|
||||
}
|
||||
|
||||
public static TileEntity getTileEntitySafe(IBlockAccess worldIn, BlockPos pos) {
|
||||
return worldIn instanceof ChunkCache ? ((ChunkCache) worldIn)
|
||||
.getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : worldIn.getTileEntity(pos);
|
||||
return worldIn instanceof ChunkCache ? ((ChunkCache) worldIn).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : worldIn.getTileEntity(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1151,26 +1078,25 @@ public final class MekanismUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp a double to int without using Math.min due to double representation issues. Primary use: power systems that
|
||||
* use int, where Mek uses doubles internally
|
||||
* Clamp a double to int without using Math.min due to double representation issues. Primary use: power systems that use int, where Mek uses doubles internally
|
||||
*
|
||||
* <code>
|
||||
* double d = 1e300; // way bigger than longs, so the long should always be what's returned by Math.min
|
||||
* System.out.println((long)Math.min(123456781234567812L, d)); // result is 123456781234567808 - 4 less than what
|
||||
* you'd expect System.out.println((long)Math.min(123456789012345678L, d)); // result is 123456789012345680 - 2 more
|
||||
* double d = 1e300; // way bigger than longs, so the long should always be what's returned by Math.min System.out.println((long)Math.min(123456781234567812L, d)); //
|
||||
* result is 123456781234567808 - 4 less than what you'd expect System.out.println((long)Math.min(123456789012345678L, d)); // result is 123456789012345680 - 2 more
|
||||
* than what you'd expect
|
||||
* </code>
|
||||
*
|
||||
* @param d double to clamp
|
||||
*
|
||||
* @return an int clamped to Integer.MAX_VALUE
|
||||
*
|
||||
* @see <a href="https://github.com/aidancbrady/Mekanism/pull/5203">Original PR</a>
|
||||
*/
|
||||
public static int clampToInt(double d) {
|
||||
if (d < Integer.MAX_VALUE) {
|
||||
return (int) d;
|
||||
} else {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public enum ResourceType {
|
||||
@@ -1193,4 +1119,4 @@ public final class MekanismUtils {
|
||||
return prefix + "/";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user