Code cleanup
This commit is contained in:
parent
2f0cd4adb2
commit
7ee580ed40
45 changed files with 292 additions and 266 deletions
209
src/main/java/cr0s/warpdrive/FastSetBlockState.java
Normal file
209
src/main/java/cr0s/warpdrive/FastSetBlockState.java
Normal file
|
@ -0,0 +1,209 @@
|
|||
package cr0s.warpdrive;
|
||||
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ConcurrentModificationException;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
public class FastSetBlockState {
|
||||
|
||||
// This code is a straight copy from Vanilla net.minecraft.world.World.setBlockState to remove lighting computations
|
||||
public static boolean setBlockStateNoLight(@Nonnull final World world, @Nonnull final BlockPos blockPosPassed, @Nonnull final IBlockState blockStateNew, final int flags) {
|
||||
assert !world.captureBlockSnapshots;
|
||||
if (!Commons.isSafeThread()) {
|
||||
throw new ConcurrentModificationException(String.format("setBlockstate %s to %s 0x%x",
|
||||
Commons.format(world, blockPosPassed), blockStateNew, flags));
|
||||
}
|
||||
|
||||
if (!WarpDriveConfig.G_ENABLE_FAST_SET_BLOCKSTATE) {
|
||||
return world.setBlockState(blockPosPassed, blockStateNew, flags);
|
||||
}
|
||||
|
||||
if (world.isOutsideBuildHeight(blockPosPassed)) {
|
||||
return false;
|
||||
} else if (!world.isRemote && world.getWorldInfo().getTerrainType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
|
||||
return false;
|
||||
} else {
|
||||
final Chunk chunk = world.getChunk(blockPosPassed);
|
||||
|
||||
/*
|
||||
final BlockPos blockPos = blockPosPassed.toImmutable(); // Forge - prevent mutable BlockPos leaks
|
||||
BlockSnapshot blockSnapshot = null;
|
||||
if (world.captureBlockSnapshots && !world.isRemote) {
|
||||
blockSnapshot = BlockSnapshot.getBlockSnapshot(world, blockPos, flags);
|
||||
world.capturedBlockSnapshots.add(blockSnapshot);
|
||||
}
|
||||
final IBlockState blockStateOld = world.getBlockState(blockPos);
|
||||
final int lightOld = blockStateOld.getLightValue(world, blockPos);
|
||||
final int opacityOld = blockStateOld.getLightOpacity(world, blockPos);
|
||||
/**/
|
||||
final BlockPos blockPos = blockPosPassed instanceof MutableBlockPos ? blockPosPassed.toImmutable() : blockPosPassed; // Forge - prevent mutable BlockPos leaks
|
||||
|
||||
|
||||
// final IBlockState blockStateEffective = chunk.setBlockState(blockPos, blockStateNew);
|
||||
final IBlockState blockStateEffective = chunk_setBlockState(chunk, blockPos, blockStateNew);
|
||||
|
||||
if (blockStateEffective == null) {
|
||||
/*
|
||||
if (blockSnapshot != null) {
|
||||
world.capturedBlockSnapshots.remove(blockSnapshot);
|
||||
}
|
||||
/**/
|
||||
return false;
|
||||
} else {
|
||||
/*
|
||||
if ( blockStateNew.getLightOpacity(world, blockPos) != opacityOld
|
||||
|| blockStateNew.getLightValue(world, blockPos) != lightOld ) {
|
||||
world.profiler.startSection("checkLight");
|
||||
world.checkLight(blockPos);
|
||||
world.profiler.endSection();
|
||||
}
|
||||
if (blockSnapshot == null) {// Don't notify clients or update physics while capturing blockstates
|
||||
world.markAndNotifyBlock(blockPos, chunk, blockStateEffective, blockStateNew, flags);
|
||||
}
|
||||
/**/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This code is a straight copy from Vanilla net.minecraft.world.chunk.Chunk.setBlockState to remove lighting computations
|
||||
@Nullable
|
||||
public static IBlockState chunk_setBlockState(@Nonnull final Chunk chunk, final BlockPos pos, final IBlockState state)
|
||||
{
|
||||
// report properties as locals
|
||||
final World world = chunk.getWorld();
|
||||
final ExtendedBlockStorage[] storageArrays = chunk.getBlockStorageArray();
|
||||
|
||||
final int i = pos.getX() & 15;
|
||||
final int j = pos.getY();
|
||||
final int k = pos.getZ() & 15;
|
||||
final int l = k << 4 | i;
|
||||
|
||||
/* FIXME
|
||||
if (j >= chunk.precipitationHeightMap[l] - 1)
|
||||
{
|
||||
chunk.precipitationHeightMap[l] = -999;
|
||||
}
|
||||
/**/
|
||||
|
||||
// final int i1 = chunk.heightMap[l];
|
||||
final IBlockState iblockstate = chunk.getBlockState(pos);
|
||||
|
||||
if (iblockstate == state)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
final Block block = state.getBlock();
|
||||
final Block block1 = iblockstate.getBlock();
|
||||
// final int k1 = iblockstate.getLightOpacity(world, pos); // Relocate old light value lookup here, so that it is called before TE is removed.
|
||||
ExtendedBlockStorage extendedblockstorage = storageArrays[j >> 4];
|
||||
// boolean flag = false;
|
||||
|
||||
if (extendedblockstorage == Chunk.NULL_BLOCK_STORAGE)
|
||||
{
|
||||
if (block == Blocks.AIR)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
extendedblockstorage = new ExtendedBlockStorage(j >> 4 << 4, chunk.getWorld().provider.hasSkyLight());
|
||||
storageArrays[j >> 4] = extendedblockstorage;
|
||||
// flag = j >= i1;
|
||||
}
|
||||
|
||||
extendedblockstorage.set(i, j & 15, k, state);
|
||||
|
||||
//if (block1 != block)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (block1 != block) //Only fire block breaks when the block changes.
|
||||
block1.breakBlock(world, pos, iblockstate);
|
||||
final TileEntity te = chunk.getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK);
|
||||
if (te != null && te.shouldRefresh(world, pos, iblockstate, state)) world.removeTileEntity(pos);
|
||||
}
|
||||
else if (block1.hasTileEntity(iblockstate))
|
||||
{
|
||||
final TileEntity te = chunk.getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK);
|
||||
if (te != null && te.shouldRefresh(world, pos, iblockstate, state))
|
||||
world.removeTileEntity(pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (extendedblockstorage.get(i, j & 15, k).getBlock() != block)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
if (flag)
|
||||
{
|
||||
chunk.generateSkylightMap();
|
||||
}
|
||||
else
|
||||
{
|
||||
final int j1 = state.getLightOpacity(world, pos);
|
||||
|
||||
if (j1 > 0)
|
||||
{
|
||||
if (j >= i1)
|
||||
{
|
||||
chunk.relightBlock(i, j + 1, k);
|
||||
}
|
||||
}
|
||||
else if (j == i1 - 1)
|
||||
{
|
||||
chunk.relightBlock(i, j, k);
|
||||
}
|
||||
|
||||
if (j1 != k1 && (j1 < k1 || chunk.getLightFor(EnumSkyBlock.SKY, pos) > 0 || chunk.getLightFor(EnumSkyBlock.BLOCK, pos) > 0))
|
||||
{
|
||||
chunk.propagateSkylightOcclusion(i, k);
|
||||
}
|
||||
}
|
||||
/**/
|
||||
|
||||
// If capturing blocks, only run block physics for TE's. Non-TE's are handled in ForgeHooks.onPlaceItemIntoWorld
|
||||
if (!world.isRemote && block1 != block && (!world.captureBlockSnapshots || block.hasTileEntity(state)))
|
||||
{
|
||||
block.onBlockAdded(world, pos, state);
|
||||
}
|
||||
|
||||
if (block.hasTileEntity(state))
|
||||
{
|
||||
TileEntity tileentity1 = chunk.getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK);
|
||||
|
||||
if (tileentity1 == null)
|
||||
{
|
||||
tileentity1 = block.createTileEntity(world, state);
|
||||
world.setTileEntity(pos, tileentity1);
|
||||
}
|
||||
|
||||
if (tileentity1 != null)
|
||||
{
|
||||
tileentity1.updateContainingBlockInfo();
|
||||
}
|
||||
}
|
||||
|
||||
chunk.markDirty();
|
||||
return iblockstate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -109,7 +109,7 @@ public abstract class BlockAbstractOmnipanel extends BlockAbstractBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(BlockColored.COLOR).getMetadata();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public abstract class BlockAbstractRotatingContainer extends BlockAbstractContai
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 0x8 : 0x0)
|
||||
| (blockState.getValue(BlockProperties.FACING).getIndex());
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class BlockChunkLoader extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class BlockLaserMedium extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(LEVEL);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -710,11 +709,11 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
|
|||
|
||||
private void playSoundCorrespondsEnergy(final int energy) {
|
||||
if (energy <= 500000) {
|
||||
world.playSound(null, pos, SoundEvents.LASER_LOW, SoundCategory.HOSTILE, 4F, 1F);
|
||||
} else if (energy > 500000 && energy <= 1000000) {
|
||||
world.playSound(null, pos, SoundEvents.LASER_MEDIUM, SoundCategory.HOSTILE, 4F, 1F);
|
||||
} else if (energy > 1000000) {
|
||||
world.playSound(null, pos, SoundEvents.LASER_HIGH, SoundCategory.HOSTILE, 4F, 1F);
|
||||
world.playSound(null, pos, SoundEvents.LASER_LOW, SoundCategory.HOSTILE, 4.0F, 1.0F);
|
||||
} else if (energy <= 1000000) {
|
||||
world.playSound(null, pos, SoundEvents.LASER_MEDIUM, SoundCategory.HOSTILE, 4.0F, 1.0F);
|
||||
} else {
|
||||
world.playSound(null, pos, SoundEvents.LASER_HIGH, SoundCategory.HOSTILE, 4.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public class BlockAcceleratorControlPoint extends BlockAbstractAccelerator imple
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class BlockAcceleratorController extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class BlockChiller extends BlockAbstractAccelerator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public class BlockParticlesCollider extends BlockAbstractAccelerator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class BlockParticlesInjector extends BlockAcceleratorControlPoint {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class BlockAirSource extends BlockAbstractAir {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(BlockProperties.FACING).getIndex();
|
||||
}
|
||||
}
|
|
@ -52,7 +52,7 @@ public class BlockShipScanner extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(BlockProperties.ACTIVE) ? 0x8 : 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ public class TileEntityShipScanner extends TileEntityAbstractMachine implements
|
|||
return;
|
||||
}
|
||||
|
||||
// @TODO inmplement ShipScanner.isEnabled
|
||||
// @TODO implement ShipScanner.isEnabled
|
||||
|
||||
searchTicks++;
|
||||
if (searchTicks > WarpDriveConfig.SS_SEARCH_INTERVAL_TICKS) {
|
||||
|
@ -252,7 +252,7 @@ public class TileEntityShipScanner extends TileEntityAbstractMachine implements
|
|||
TileEntityShipCore tileEntityShipCore = null;
|
||||
|
||||
// Search for ship cores above
|
||||
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(pos);
|
||||
final BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos(pos);
|
||||
for (int newY = pos.getY() + 1; newY <= 255; newY++) {
|
||||
mutableBlockPos.setY(newY);
|
||||
if (world.getBlockState(mutableBlockPos).getBlock() instanceof BlockShipCore) { // found ship core above
|
||||
|
@ -316,15 +316,15 @@ public class TileEntityShipScanner extends TileEntityAbstractMachine implements
|
|||
schematic.setTag("ship", tagCompoundShip);
|
||||
|
||||
// Storage collections
|
||||
final String stringBlockRegistryNames[] = new String[size];
|
||||
final byte byteMetadatas[] = new byte[size];
|
||||
final String[] stringBlockRegistryNames = new String[size];
|
||||
final byte[] byteMetadatas = new byte[size];
|
||||
final NBTTagList tileEntitiesList = new NBTTagList();
|
||||
|
||||
// Scan the whole area
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int z = 0; z < length; z++) {
|
||||
BlockPos blockPos = new BlockPos(shipCore.minX + x, shipCore.minY + y, shipCore.minZ + z);
|
||||
final BlockPos blockPos = new BlockPos(shipCore.minX + x, shipCore.minY + y, shipCore.minZ + z);
|
||||
IBlockState blockState = world.getBlockState(blockPos);
|
||||
|
||||
// Skip leftBehind and anchor blocks
|
||||
|
|
|
@ -43,7 +43,7 @@ public class BlockLaserTreeFarm extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(MODE).ordinal();
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public class BlockMiningLaser extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(MODE).ordinal();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import cr0s.warpdrive.CommonProxy;
|
|||
import cr0s.warpdrive.Commons;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.block.TileEntityAbstractLaser;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.FluidWrapper;
|
||||
import cr0s.warpdrive.data.InventoryWrapper;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
|
@ -13,6 +12,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
@ -47,7 +47,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser {
|
|||
laserOutput = new Vector3(this).translate(0.5D).translate(laserOutputSide, 0.5D);
|
||||
}
|
||||
|
||||
protected void harvestBlock(final BlockPos blockPos, final IBlockState blockState) {
|
||||
protected void harvestBlock(@Nonnull final BlockPos blockPos, @Nonnull final IBlockState blockState) {
|
||||
if (blockState.getBlock().isAir(blockState, world, blockPos)) {
|
||||
return;
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private NonNullList<ItemStack> getItemStackFromBlock(final BlockPos blockPos, final IBlockState blockState) {
|
||||
if (blockState == null) {
|
||||
WarpDrive.logger.error(String.format("%s Invalid block %s",
|
||||
|
|
|
@ -705,7 +705,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
return blockStatePosList;
|
||||
}
|
||||
|
||||
private int comparatorSortLogsAndLeaves(final BlockStatePos o1, final BlockStatePos o2) {
|
||||
private int comparatorSortLogsAndLeaves(@Nonnull final BlockStatePos o1, @Nonnull final BlockStatePos o2) {
|
||||
// first, we clear central from bottom to top
|
||||
if (o1.blockPos.getX() == pos.getX() && o1.blockPos.getZ() == pos.getZ()) {
|
||||
if (o2.blockPos.getX() == pos.getX() && o2.blockPos.getZ() == pos.getZ()) {
|
||||
|
@ -1002,6 +1002,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
final boolean breakLeaves = ((TileEntityLaserTreeFarm) tileEntity).breakLeaves;
|
||||
final int maxDistance = ((TileEntityLaserTreeFarm) tileEntity).maxDistance;
|
||||
final Comparator<BlockStatePos> comparator = ((TileEntityLaserTreeFarm) tileEntity)::comparatorSortLogsAndLeaves;
|
||||
//noinspection UnusedAssignment
|
||||
tileEntity = null;
|
||||
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
|
|
|
@ -500,7 +500,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
return new Object[] { !mineAllBlocks };
|
||||
}
|
||||
|
||||
private Object[] offset(final Object[] arguments) {
|
||||
private Object[] offset(@Nonnull final Object[] arguments) {
|
||||
if (arguments.length == 1 && arguments[0] != null) {
|
||||
try {
|
||||
layerOffset = Math.min(256, Math.abs(Commons.toInt(arguments[0])));
|
||||
|
@ -512,7 +512,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
|||
return new Integer[] { layerOffset };
|
||||
}
|
||||
|
||||
private Object[] silktouch(final Object[] arguments) {
|
||||
private Object[] silktouch(@Nonnull final Object[] arguments) {
|
||||
if (arguments.length == 1 && arguments[0] != null) {
|
||||
try {
|
||||
enableSilktouch = Commons.toBool(arguments[0]);
|
||||
|
|
|
@ -63,7 +63,7 @@ public class BlockAbstractLamp extends BlockAbstractBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 0x8 : 0x0)
|
||||
| (blockState.getValue(BlockProperties.FACING).getIndex());
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class BlockDecorative extends BlockAbstractBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(TYPE).ordinal();
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ public class BlockGas extends BlockAbstractBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(COLOR).ordinal();
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public class BlockCloakingCoil extends BlockAbstractBase {
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0)
|
||||
+ (blockState.getValue(OUTER) ? 1 + blockState.getValue(BlockProperties.FACING).ordinal() : 0);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class BlockRadar extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(MODE).ordinal();
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public class BlockCapacitor extends BlockAbstractContainer implements IExplosion
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ public class BlockEnanReactorController extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class BlockEnanReactorCore extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(ENERGY) + (blockState.getValue(INSTABILITY) << 2);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import li.cil.oc.api.machine.Callback;
|
|||
import li.cil.oc.api.machine.Context;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
@ -122,6 +123,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private TileEntityEnanReactorCore getReactorCore() {
|
||||
if (reactorFace == ReactorFace.UNKNOWN) {
|
||||
return null;
|
||||
|
|
|
@ -121,7 +121,7 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(FREQUENCY);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ public class BlockForceFieldProjector extends BlockAbstractForceField {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(BlockProperties.FACING).getIndex()
|
||||
+ (blockState.getValue(IS_DOUBLE_SIDED) ? 8 : 0);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class BlockForceFieldRelay extends BlockAbstractForceField {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ public class BlockHullPlain extends BlockAbstractBase implements IDamageReceiver
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(BlockColored.COLOR).getMetadata();
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
|
|||
final EnumTier enumTier;
|
||||
private final IBlockState blockStateHull;
|
||||
|
||||
public BlockHullSlab(final String registryName, final EnumTier enumTier, final IBlockState blockStateHull) {
|
||||
public BlockHullSlab(@Nonnull final String registryName, @Nonnull final EnumTier enumTier, @Nonnull final IBlockState blockStateHull) {
|
||||
super(Material.ROCK);
|
||||
|
||||
this.enumTier = enumTier;
|
||||
|
@ -94,7 +94,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(VARIANT).ordinal();
|
||||
}
|
||||
|
||||
|
@ -107,7 +107,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
|
|||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubBlocks(final CreativeTabs creativeTab, final NonNullList<ItemStack> list) {
|
||||
public void getSubBlocks(final CreativeTabs creativeTab, @Nonnull final NonNullList<ItemStack> list) {
|
||||
list.add(new ItemStack(this, 1, 0));
|
||||
list.add(new ItemStack(this, 1, 2));
|
||||
list.add(new ItemStack(this, 1, 6));
|
||||
|
@ -171,13 +171,13 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean isFullBlock(final IBlockState blockState) {
|
||||
public boolean isFullBlock(@Nonnull final IBlockState blockState) {
|
||||
return ((BlockSlab) blockState.getBlock()).isDouble();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean isFullCube(final IBlockState blockState) {
|
||||
public boolean isFullCube(@Nonnull final IBlockState blockState) {
|
||||
return ((BlockSlab) blockState.getBlock()).isDouble();
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean doesSideBlockRendering(final IBlockState blockState, final IBlockAccess blockAccess, final BlockPos blockPos, final EnumFacing side) {
|
||||
public boolean doesSideBlockRendering(@Nonnull final IBlockState blockState, final IBlockAccess blockAccess, final BlockPos blockPos, final EnumFacing side) {
|
||||
if (blockState.isOpaqueCube()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
|
|||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean isSideSolid(final IBlockState blockState, @Nonnull final IBlockAccess blockAccess, @Nonnull final BlockPos blockPos, final EnumFacing side) {
|
||||
public boolean isSideSolid(@Nonnull final IBlockState blockState, @Nonnull final IBlockAccess blockAccess, @Nonnull final BlockPos blockPos, final EnumFacing side) {
|
||||
final EnumFacing enumFacing = blockState.getValue(VARIANT).getFacing();
|
||||
return enumFacing == side;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class BlockLift extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(MODE).ordinal();
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class BlockShipController extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(COMMAND).ordinal();
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ public class BlockTransporterBeacon extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return (blockState.getValue(BlockProperties.ACTIVE) ? 2 : 0)
|
||||
+ (blockState.getValue(DEPLOYED) ? 1 : 0);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class BlockTransporterCore extends BlockAbstractContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(VARIANT).getMetadata();
|
||||
}
|
||||
}
|
|
@ -51,7 +51,7 @@ public class BlockTransporterScanner extends BlockAbstractBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(final IBlockState blockState) {
|
||||
public int getMetaFromState(@Nonnull final IBlockState blockState) {
|
||||
return blockState.getValue(BlockProperties.ACTIVE) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cr0s.warpdrive.config;
|
||||
|
||||
import cr0s.warpdrive.Commons;
|
||||
import cr0s.warpdrive.FastSetBlockState;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IXmlRepresentableUnit;
|
||||
import cr0s.warpdrive.data.JumpBlock;
|
||||
|
@ -149,7 +150,7 @@ public class Filler implements IXmlRepresentableUnit {
|
|||
final IBlockState blockState;
|
||||
try {
|
||||
blockState = block.getStateFromMeta(metadata);
|
||||
JumpBlock.setBlockStateNoLight(world, blockPos, blockState, 2);
|
||||
FastSetBlockState.setBlockStateNoLight(world, blockPos, blockState, 2);
|
||||
} catch (final Throwable throwable) {
|
||||
WarpDrive.logger.error(String.format("Throwable detected in Filler.setBlock(%s), check your configuration for that block!",
|
||||
getName()));
|
||||
|
|
|
@ -15,6 +15,7 @@ import cr0s.warpdrive.item.ItemForceFieldShape;
|
|||
import cr0s.warpdrive.item.ItemForceFieldUpgrade;
|
||||
import cr0s.warpdrive.item.ItemTuningDriver;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
@ -139,7 +140,7 @@ public class Recipes {
|
|||
}
|
||||
}
|
||||
|
||||
private static void registerOreDictionary(final String name, final ItemStack itemStack) {
|
||||
private static void registerOreDictionary(final String name, @Nonnull final ItemStack itemStack) {
|
||||
if (!itemStack.isEmpty()) {
|
||||
OreDictionary.registerOre(name, itemStack);
|
||||
}
|
||||
|
|
|
@ -86,6 +86,7 @@ import org.xml.sax.ErrorHandler;
|
|||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
@ -573,7 +574,8 @@ public class WarpDriveConfig {
|
|||
return getItemStackOrFire(registryName, meta, "");
|
||||
}
|
||||
|
||||
private static Object getOreOrItemStackOrNull(final String registryName, final int meta) {
|
||||
@Nullable
|
||||
private static Object getOreOrItemStackOrNull(@Nonnull final String registryName, final int meta) {
|
||||
assert registryName.contains(":");
|
||||
|
||||
if (registryName.startsWith("ore:")) {
|
||||
|
@ -608,7 +610,7 @@ public class WarpDriveConfig {
|
|||
}
|
||||
|
||||
public static Object getOreOrItemStack(final String registryName1, final int meta1,
|
||||
final Object... args) {
|
||||
@Nonnull final Object... args) {
|
||||
// always validate parameters in dev space
|
||||
assert args.length % 2 == 0;
|
||||
for (int index = 0; index < args.length; index += 2) {
|
||||
|
@ -649,7 +651,7 @@ public class WarpDriveConfig {
|
|||
return itemStacks.get(0);
|
||||
}
|
||||
|
||||
protected static double[] getDoubleList(final Configuration config, final String category, final String key, final String comment, final double[] valuesDefault) {
|
||||
protected static double[] getDoubleList(@Nonnull final Configuration config, final String category, final String key, final String comment, final double[] valuesDefault) {
|
||||
double[] valuesRead = config.get(category, key, valuesDefault, comment).getDoubleList();
|
||||
if (valuesRead.length != valuesDefault.length) {
|
||||
valuesRead = valuesDefault.clone();
|
||||
|
@ -1268,7 +1270,7 @@ public class WarpDriveConfig {
|
|||
config.save();
|
||||
}
|
||||
|
||||
public static void clampByTier(final int min, final int max, final int[] values) {
|
||||
public static void clampByTier(final int min, final int max, @Nonnull final int[] values) {
|
||||
if (values.length != EnumTier.length) {
|
||||
WarpDrive.logger.error(String.format("Invalid configuration value, expected %d values, got %d %s. Update your configuration and restart your game!",
|
||||
EnumTier.length, values.length, Arrays.toString(values)));
|
||||
|
@ -1281,7 +1283,7 @@ public class WarpDriveConfig {
|
|||
values[3] = Commons.clamp(values[2], max , values[3]);
|
||||
}
|
||||
|
||||
public static void clampByTier(final double min, final double max, final double[] values) {
|
||||
public static void clampByTier(final double min, final double max, @Nonnull final double[] values) {
|
||||
if (values.length != EnumTier.length) {
|
||||
WarpDrive.logger.error(String.format("Invalid configuration value, expected %d values, got %d %s. Update your configuration and restart your game!",
|
||||
EnumTier.length, values.length, Arrays.toString(values)));
|
||||
|
@ -1294,7 +1296,7 @@ public class WarpDriveConfig {
|
|||
values[3] = Commons.clamp(values[2], max , values[3]);
|
||||
}
|
||||
|
||||
public static void clampByEnergyTierName(final String nameMin, final String nameMax, final String[] names) {
|
||||
public static void clampByEnergyTierName(final String nameMin, final String nameMax, @Nonnull final String[] names) {
|
||||
if (names.length != EnumTier.length) {
|
||||
WarpDrive.logger.error(String.format("Invalid configuration value, expected %d string, got %d %s. Update your configuration and restart your game!",
|
||||
EnumTier.length, names.length, Arrays.toString(names)));
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cr0s.warpdrive.config.structures;
|
||||
|
||||
import cr0s.warpdrive.Commons;
|
||||
import cr0s.warpdrive.FastSetBlockState;
|
||||
import cr0s.warpdrive.LocalProfiler;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.config.GenericSet;
|
||||
|
@ -175,7 +176,7 @@ public class MetaOrbInstance extends OrbInstance {
|
|||
if (isSurface && jumpBlock.x % 4 == 0 && jumpBlock.z % 4 == 0) {
|
||||
world.setBlockState(blockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
|
||||
} else {
|
||||
JumpBlock.setBlockStateNoLight(world, blockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
|
||||
FastSetBlockState.setBlockStateNoLight(world, blockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cr0s.warpdrive.data;
|
||||
|
||||
import cr0s.warpdrive.Commons;
|
||||
import cr0s.warpdrive.FastSetBlockState;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockBase;
|
||||
import cr0s.warpdrive.api.IBlockTransformer;
|
||||
|
@ -17,7 +18,6 @@ import javax.annotation.Nonnull;
|
|||
import javax.annotation.Nullable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -60,11 +60,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
|
@ -83,7 +79,7 @@ public class JumpBlock {
|
|||
public JumpBlock() {
|
||||
}
|
||||
|
||||
public JumpBlock(final World world, final BlockPos blockPos, final IBlockState blockState, final TileEntity tileEntity) {
|
||||
public JumpBlock(@Nonnull final World world, @Nonnull final BlockPos blockPos, @Nonnull final IBlockState blockState, @Nullable final TileEntity tileEntity) {
|
||||
this.x = blockPos.getX();
|
||||
this.y = blockPos.getY();
|
||||
this.z = blockPos.getZ();
|
||||
|
@ -112,7 +108,7 @@ public class JumpBlock {
|
|||
}
|
||||
}
|
||||
|
||||
public JumpBlock(final Filler filler, final int x, final int y, final int z) {
|
||||
public JumpBlock(@Nonnull final Filler filler, final int x, final int y, final int z) {
|
||||
if (filler.block == null) {
|
||||
WarpDrive.logger.info(String.format("Forcing glass for invalid filler with null block at (%d %d %d)",
|
||||
x, y, z));
|
||||
|
@ -127,7 +123,7 @@ public class JumpBlock {
|
|||
this.z = z;
|
||||
}
|
||||
|
||||
public TileEntity getTileEntity(final World worldSource) {
|
||||
public TileEntity getTileEntity(@Nonnull final World worldSource) {
|
||||
if (weakTileEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -140,7 +136,7 @@ public class JumpBlock {
|
|||
return worldSource.getTileEntity(new BlockPos(x, y, z));
|
||||
}
|
||||
|
||||
private NBTTagCompound getBlockNBT(final World worldSource) {
|
||||
private NBTTagCompound getBlockNBT(@Nonnull final World worldSource) {
|
||||
if (weakTileEntity == null) {
|
||||
return blockNBT == null ? null : blockNBT.copy();
|
||||
}
|
||||
|
@ -309,7 +305,7 @@ public class JumpBlock {
|
|||
block, newBlockMeta, nbtToDeploy));
|
||||
}
|
||||
final IBlockState blockState = block.getStateFromMeta(newBlockMeta);
|
||||
setBlockStateNoLight(worldTarget, target, blockState, 2);
|
||||
FastSetBlockState.setBlockStateNoLight(worldTarget, target, blockState, 2);
|
||||
|
||||
if (nbtToDeploy != null) {
|
||||
nbtToDeploy.setInteger("x", target.getX());
|
||||
|
@ -374,7 +370,7 @@ public class JumpBlock {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static void refreshBlockStateOnClient(final World world, final BlockPos blockPos) {
|
||||
public static void refreshBlockStateOnClient(@Nonnull final World world, @Nonnull final BlockPos blockPos) {
|
||||
final TileEntity tileEntity = world.getTileEntity(blockPos);
|
||||
if (tileEntity != null) {
|
||||
final Class<?> teClass = tileEntity.getClass();
|
||||
|
@ -595,7 +591,7 @@ public class JumpBlock {
|
|||
}
|
||||
}
|
||||
|
||||
public static void emptyEnergyStorage(final NBTTagCompound tagCompound) {
|
||||
public static void emptyEnergyStorage(@Nonnull final NBTTagCompound tagCompound) {
|
||||
// BuildCraft
|
||||
if (tagCompound.hasKey("battery", NBT.TAG_COMPOUND)) {
|
||||
final NBTTagCompound tagCompoundBattery = tagCompound.getCompoundTag("battery");
|
||||
|
@ -681,193 +677,4 @@ public class JumpBlock {
|
|||
weakTileEntity == null ? null : weakTileEntity.get(),
|
||||
blockNBT);
|
||||
}
|
||||
|
||||
// This code is a straight copy from Vanilla net.minecraft.world.World.setBlockState to remove lighting computations
|
||||
public static boolean setBlockStateNoLight(final World world, final BlockPos blockPosPassed, final IBlockState blockStateNew, final int flags) {
|
||||
assert !world.captureBlockSnapshots;
|
||||
if (!Commons.isSafeThread()) {
|
||||
throw new ConcurrentModificationException(String.format("setBlockstate %s to %s 0x%x",
|
||||
Commons.format(world, blockPosPassed), blockStateNew, flags));
|
||||
}
|
||||
|
||||
if (!WarpDriveConfig.G_ENABLE_FAST_SET_BLOCKSTATE) {
|
||||
return world.setBlockState(blockPosPassed, blockStateNew, flags);
|
||||
}
|
||||
|
||||
if (world.isOutsideBuildHeight(blockPosPassed)) {
|
||||
return false;
|
||||
} else if (!world.isRemote && world.getWorldInfo().getTerrainType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
|
||||
return false;
|
||||
} else {
|
||||
final Chunk chunk = world.getChunk(blockPosPassed);
|
||||
|
||||
/*
|
||||
final BlockPos blockPos = blockPosPassed.toImmutable(); // Forge - prevent mutable BlockPos leaks
|
||||
BlockSnapshot blockSnapshot = null;
|
||||
if (world.captureBlockSnapshots && !world.isRemote) {
|
||||
blockSnapshot = BlockSnapshot.getBlockSnapshot(world, blockPos, flags);
|
||||
world.capturedBlockSnapshots.add(blockSnapshot);
|
||||
}
|
||||
final IBlockState blockStateOld = world.getBlockState(blockPos);
|
||||
final int lightOld = blockStateOld.getLightValue(world, blockPos);
|
||||
final int opacityOld = blockStateOld.getLightOpacity(world, blockPos);
|
||||
/**/
|
||||
final BlockPos blockPos = blockPosPassed instanceof MutableBlockPos ? blockPosPassed.toImmutable() : blockPosPassed; // Forge - prevent mutable BlockPos leaks
|
||||
|
||||
|
||||
// final IBlockState blockStateEffective = chunk.setBlockState(blockPos, blockStateNew);
|
||||
final IBlockState blockStateEffective = chunk_setBlockState(chunk, blockPos, blockStateNew);
|
||||
|
||||
if (blockStateEffective == null) {
|
||||
/*
|
||||
if (blockSnapshot != null) {
|
||||
world.capturedBlockSnapshots.remove(blockSnapshot);
|
||||
}
|
||||
/**/
|
||||
return false;
|
||||
} else {
|
||||
/*
|
||||
if ( blockStateNew.getLightOpacity(world, blockPos) != opacityOld
|
||||
|| blockStateNew.getLightValue(world, blockPos) != lightOld ) {
|
||||
world.profiler.startSection("checkLight");
|
||||
world.checkLight(blockPos);
|
||||
world.profiler.endSection();
|
||||
}
|
||||
if (blockSnapshot == null) {// Don't notify clients or update physics while capturing blockstates
|
||||
world.markAndNotifyBlock(blockPos, chunk, blockStateEffective, blockStateNew, flags);
|
||||
}
|
||||
/**/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This code is a straight copy from Vanilla net.minecraft.world.chunk.Chunk.setBlockState to remove lighting computations
|
||||
@Nullable
|
||||
public static IBlockState chunk_setBlockState(@Nonnull final Chunk chunk, final BlockPos pos, final IBlockState state)
|
||||
{
|
||||
// report properties as locals
|
||||
final World world = chunk.getWorld();
|
||||
final ExtendedBlockStorage[] storageArrays = chunk.getBlockStorageArray();
|
||||
|
||||
final int i = pos.getX() & 15;
|
||||
final int j = pos.getY();
|
||||
final int k = pos.getZ() & 15;
|
||||
final int l = k << 4 | i;
|
||||
|
||||
/* FIXME
|
||||
if (j >= chunk.precipitationHeightMap[l] - 1)
|
||||
{
|
||||
chunk.precipitationHeightMap[l] = -999;
|
||||
}
|
||||
/**/
|
||||
|
||||
// final int i1 = chunk.heightMap[l];
|
||||
final IBlockState iblockstate = chunk.getBlockState(pos);
|
||||
|
||||
if (iblockstate == state)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
final Block block = state.getBlock();
|
||||
final Block block1 = iblockstate.getBlock();
|
||||
// final int k1 = iblockstate.getLightOpacity(world, pos); // Relocate old light value lookup here, so that it is called before TE is removed.
|
||||
ExtendedBlockStorage extendedblockstorage = storageArrays[j >> 4];
|
||||
// boolean flag = false;
|
||||
|
||||
if (extendedblockstorage == Chunk.NULL_BLOCK_STORAGE)
|
||||
{
|
||||
if (block == Blocks.AIR)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
extendedblockstorage = new ExtendedBlockStorage(j >> 4 << 4, chunk.getWorld().provider.hasSkyLight());
|
||||
storageArrays[j >> 4] = extendedblockstorage;
|
||||
// flag = j >= i1;
|
||||
}
|
||||
|
||||
extendedblockstorage.set(i, j & 15, k, state);
|
||||
|
||||
//if (block1 != block)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (block1 != block) //Only fire block breaks when the block changes.
|
||||
block1.breakBlock(world, pos, iblockstate);
|
||||
final TileEntity te = chunk.getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK);
|
||||
if (te != null && te.shouldRefresh(world, pos, iblockstate, state)) world.removeTileEntity(pos);
|
||||
}
|
||||
else if (block1.hasTileEntity(iblockstate))
|
||||
{
|
||||
final TileEntity te = chunk.getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK);
|
||||
if (te != null && te.shouldRefresh(world, pos, iblockstate, state))
|
||||
world.removeTileEntity(pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (extendedblockstorage.get(i, j & 15, k).getBlock() != block)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
if (flag)
|
||||
{
|
||||
chunk.generateSkylightMap();
|
||||
}
|
||||
else
|
||||
{
|
||||
final int j1 = state.getLightOpacity(world, pos);
|
||||
|
||||
if (j1 > 0)
|
||||
{
|
||||
if (j >= i1)
|
||||
{
|
||||
chunk.relightBlock(i, j + 1, k);
|
||||
}
|
||||
}
|
||||
else if (j == i1 - 1)
|
||||
{
|
||||
chunk.relightBlock(i, j, k);
|
||||
}
|
||||
|
||||
if (j1 != k1 && (j1 < k1 || chunk.getLightFor(EnumSkyBlock.SKY, pos) > 0 || chunk.getLightFor(EnumSkyBlock.BLOCK, pos) > 0))
|
||||
{
|
||||
chunk.propagateSkylightOcclusion(i, k);
|
||||
}
|
||||
}
|
||||
/**/
|
||||
|
||||
// If capturing blocks, only run block physics for TE's. Non-TE's are handled in ForgeHooks.onPlaceItemIntoWorld
|
||||
if (!world.isRemote && block1 != block && (!world.captureBlockSnapshots || block.hasTileEntity(state)))
|
||||
{
|
||||
block.onBlockAdded(world, pos, state);
|
||||
}
|
||||
|
||||
if (block.hasTileEntity(state))
|
||||
{
|
||||
TileEntity tileentity1 = chunk.getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK);
|
||||
|
||||
if (tileentity1 == null)
|
||||
{
|
||||
tileentity1 = block.createTileEntity(world, state);
|
||||
world.setTileEntity(pos, tileentity1);
|
||||
}
|
||||
|
||||
if (tileentity1 != null)
|
||||
{
|
||||
tileentity1.updateContainingBlockInfo();
|
||||
}
|
||||
}
|
||||
|
||||
chunk.markDirty();
|
||||
return iblockstate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cr0s.warpdrive.event;
|
|||
|
||||
import cr0s.warpdrive.CommonProxy;
|
||||
import cr0s.warpdrive.Commons;
|
||||
import cr0s.warpdrive.FastSetBlockState;
|
||||
import cr0s.warpdrive.LocalProfiler;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.EventWarpDrive.Ship.JumpResult;
|
||||
|
@ -1262,11 +1263,11 @@ public class JumpSequencer extends AbstractSequencer {
|
|||
}
|
||||
try {
|
||||
final BlockPos blockPos = new BlockPos(jumpBlock.x, jumpBlock.y, jumpBlock.z);
|
||||
boolean isRemoved = JumpBlock.setBlockStateNoLight(sourceWorld, blockPos, Blocks.AIR.getDefaultState(), 2);
|
||||
boolean isRemoved = FastSetBlockState.setBlockStateNoLight(sourceWorld, blockPos, Blocks.AIR.getDefaultState(), 2);
|
||||
if (!isRemoved) {
|
||||
WarpDrive.logger.info(String.format("Failed to remove %s@%d at (%d %d %d), retrying...",
|
||||
jumpBlock.block, jumpBlock.blockMeta, jumpBlock.x, jumpBlock.y, jumpBlock.z));
|
||||
isRemoved = JumpBlock.setBlockStateNoLight(sourceWorld, blockPos, Blocks.AIR.getDefaultState(), 2);
|
||||
isRemoved = FastSetBlockState.setBlockStateNoLight(sourceWorld, blockPos, Blocks.AIR.getDefaultState(), 2);
|
||||
if (!isRemoved) {
|
||||
WarpDrive.logger.error(String.format("Failed to remove %s@%d at (%d %d %d), still failing?",
|
||||
jumpBlock.block, jumpBlock.blockMeta, jumpBlock.x, jumpBlock.y, jumpBlock.z));
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cr0s.warpdrive.world;
|
||||
|
||||
import cr0s.warpdrive.FastSetBlockState;
|
||||
import cr0s.warpdrive.LocalProfiler;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.config.Filler;
|
||||
|
@ -163,7 +164,7 @@ public final class EntitySphereGen extends Entity {
|
|||
if (isSurfaces.get(currentIndex) && jumpBlock.x % 4 == 0 && jumpBlock.z % 4 == 0) {
|
||||
world.setBlockState(mutableBlockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
|
||||
} else {
|
||||
JumpBlock.setBlockStateNoLight(world, mutableBlockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
|
||||
FastSetBlockState.setBlockStateNoLight(world, mutableBlockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
|
||||
}
|
||||
currentIndex++;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue