From 7ee580ed4012969c22348376a4fc3a6138ae9cea Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 24 May 2019 23:21:16 +0200 Subject: [PATCH] Code cleanup --- .../cr0s/warpdrive/FastSetBlockState.java | 209 ++++++++++++++++++ .../block/BlockAbstractOmnipanel.java | 2 +- .../block/BlockAbstractRotatingContainer.java | 2 +- .../warpdrive/block/BlockChunkLoader.java | 2 +- .../warpdrive/block/BlockLaserMedium.java | 2 +- .../cr0s/warpdrive/block/TileEntityLaser.java | 11 +- .../atomic/BlockAcceleratorControlPoint.java | 2 +- .../atomic/BlockAcceleratorController.java | 2 +- .../warpdrive/block/atomic/BlockChiller.java | 2 +- .../block/atomic/BlockParticlesCollider.java | 2 +- .../block/atomic/BlockParticlesInjector.java | 2 +- .../block/breathing/BlockAirSource.java | 2 +- .../block/building/BlockShipScanner.java | 2 +- .../block/building/TileEntityShipScanner.java | 10 +- .../block/collection/BlockLaserTreeFarm.java | 2 +- .../block/collection/BlockMiningLaser.java | 2 +- .../collection/TileEntityAbstractMiner.java | 5 +- .../collection/TileEntityLaserTreeFarm.java | 3 +- .../collection/TileEntityMiningLaser.java | 4 +- .../block/decoration/BlockAbstractLamp.java | 2 +- .../block/decoration/BlockDecorative.java | 2 +- .../warpdrive/block/decoration/BlockGas.java | 2 +- .../block/detection/BlockCloakingCoil.java | 2 +- .../warpdrive/block/detection/BlockRadar.java | 2 +- .../block/energy/BlockCapacitor.java | 2 +- .../energy/BlockEnanReactorController.java | 2 +- .../block/energy/BlockEnanReactorCore.java | 2 +- .../energy/TileEntityEnanReactorLaser.java | 2 + .../block/forcefield/BlockForceField.java | 2 +- .../forcefield/BlockForceFieldProjector.java | 2 +- .../forcefield/BlockForceFieldRelay.java | 2 +- .../warpdrive/block/hull/BlockHullPlain.java | 2 +- .../warpdrive/block/hull/BlockHullSlab.java | 14 +- .../warpdrive/block/movement/BlockLift.java | 2 +- .../block/movement/BlockShipController.java | 2 +- .../movement/BlockTransporterBeacon.java | 2 +- .../block/movement/BlockTransporterCore.java | 2 +- .../movement/BlockTransporterScanner.java | 2 +- .../java/cr0s/warpdrive/config/Filler.java | 3 +- .../java/cr0s/warpdrive/config/Recipes.java | 3 +- .../warpdrive/config/WarpDriveConfig.java | 14 +- .../config/structures/MetaOrbInstance.java | 3 +- .../java/cr0s/warpdrive/data/JumpBlock.java | 209 +----------------- .../cr0s/warpdrive/event/JumpSequencer.java | 5 +- .../cr0s/warpdrive/world/EntitySphereGen.java | 3 +- 45 files changed, 292 insertions(+), 266 deletions(-) create mode 100644 src/main/java/cr0s/warpdrive/FastSetBlockState.java diff --git a/src/main/java/cr0s/warpdrive/FastSetBlockState.java b/src/main/java/cr0s/warpdrive/FastSetBlockState.java new file mode 100644 index 00000000..5b9e8ca8 --- /dev/null +++ b/src/main/java/cr0s/warpdrive/FastSetBlockState.java @@ -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; + } + } + } +} diff --git a/src/main/java/cr0s/warpdrive/block/BlockAbstractOmnipanel.java b/src/main/java/cr0s/warpdrive/block/BlockAbstractOmnipanel.java index b69850bf..748b318d 100644 --- a/src/main/java/cr0s/warpdrive/block/BlockAbstractOmnipanel.java +++ b/src/main/java/cr0s/warpdrive/block/BlockAbstractOmnipanel.java @@ -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(); } diff --git a/src/main/java/cr0s/warpdrive/block/BlockAbstractRotatingContainer.java b/src/main/java/cr0s/warpdrive/block/BlockAbstractRotatingContainer.java index c83b46d9..5f5144b5 100644 --- a/src/main/java/cr0s/warpdrive/block/BlockAbstractRotatingContainer.java +++ b/src/main/java/cr0s/warpdrive/block/BlockAbstractRotatingContainer.java @@ -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()); } diff --git a/src/main/java/cr0s/warpdrive/block/BlockChunkLoader.java b/src/main/java/cr0s/warpdrive/block/BlockChunkLoader.java index d71d994f..e4cbd5e0 100644 --- a/src/main/java/cr0s/warpdrive/block/BlockChunkLoader.java +++ b/src/main/java/cr0s/warpdrive/block/BlockChunkLoader.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/BlockLaserMedium.java b/src/main/java/cr0s/warpdrive/block/BlockLaserMedium.java index 2049d281..46139b5a 100644 --- a/src/main/java/cr0s/warpdrive/block/BlockLaserMedium.java +++ b/src/main/java/cr0s/warpdrive/block/BlockLaserMedium.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java b/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java index f6202d48..18d9110e 100644 --- a/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java +++ b/src/main/java/cr0s/warpdrive/block/TileEntityLaser.java @@ -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); } } diff --git a/src/main/java/cr0s/warpdrive/block/atomic/BlockAcceleratorControlPoint.java b/src/main/java/cr0s/warpdrive/block/atomic/BlockAcceleratorControlPoint.java index ca359423..5e194ce2 100644 --- a/src/main/java/cr0s/warpdrive/block/atomic/BlockAcceleratorControlPoint.java +++ b/src/main/java/cr0s/warpdrive/block/atomic/BlockAcceleratorControlPoint.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/atomic/BlockAcceleratorController.java b/src/main/java/cr0s/warpdrive/block/atomic/BlockAcceleratorController.java index 09495f41..e79e711e 100644 --- a/src/main/java/cr0s/warpdrive/block/atomic/BlockAcceleratorController.java +++ b/src/main/java/cr0s/warpdrive/block/atomic/BlockAcceleratorController.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/atomic/BlockChiller.java b/src/main/java/cr0s/warpdrive/block/atomic/BlockChiller.java index 5244d364..b2bfa4ca 100644 --- a/src/main/java/cr0s/warpdrive/block/atomic/BlockChiller.java +++ b/src/main/java/cr0s/warpdrive/block/atomic/BlockChiller.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/atomic/BlockParticlesCollider.java b/src/main/java/cr0s/warpdrive/block/atomic/BlockParticlesCollider.java index 43c2d0ed..ae785180 100644 --- a/src/main/java/cr0s/warpdrive/block/atomic/BlockParticlesCollider.java +++ b/src/main/java/cr0s/warpdrive/block/atomic/BlockParticlesCollider.java @@ -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); } } diff --git a/src/main/java/cr0s/warpdrive/block/atomic/BlockParticlesInjector.java b/src/main/java/cr0s/warpdrive/block/atomic/BlockParticlesInjector.java index 0ad1a339..fbeba510 100644 --- a/src/main/java/cr0s/warpdrive/block/atomic/BlockParticlesInjector.java +++ b/src/main/java/cr0s/warpdrive/block/atomic/BlockParticlesInjector.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/breathing/BlockAirSource.java b/src/main/java/cr0s/warpdrive/block/breathing/BlockAirSource.java index 9bd890ea..56fb664f 100644 --- a/src/main/java/cr0s/warpdrive/block/breathing/BlockAirSource.java +++ b/src/main/java/cr0s/warpdrive/block/breathing/BlockAirSource.java @@ -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(); } } \ No newline at end of file diff --git a/src/main/java/cr0s/warpdrive/block/building/BlockShipScanner.java b/src/main/java/cr0s/warpdrive/block/building/BlockShipScanner.java index 44e2afd8..113fa66f 100644 --- a/src/main/java/cr0s/warpdrive/block/building/BlockShipScanner.java +++ b/src/main/java/cr0s/warpdrive/block/building/BlockShipScanner.java @@ -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; } diff --git a/src/main/java/cr0s/warpdrive/block/building/TileEntityShipScanner.java b/src/main/java/cr0s/warpdrive/block/building/TileEntityShipScanner.java index 56f73332..de13a12b 100644 --- a/src/main/java/cr0s/warpdrive/block/building/TileEntityShipScanner.java +++ b/src/main/java/cr0s/warpdrive/block/building/TileEntityShipScanner.java @@ -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 diff --git a/src/main/java/cr0s/warpdrive/block/collection/BlockLaserTreeFarm.java b/src/main/java/cr0s/warpdrive/block/collection/BlockLaserTreeFarm.java index 69e207cc..bf7e11f5 100644 --- a/src/main/java/cr0s/warpdrive/block/collection/BlockLaserTreeFarm.java +++ b/src/main/java/cr0s/warpdrive/block/collection/BlockLaserTreeFarm.java @@ -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(); } diff --git a/src/main/java/cr0s/warpdrive/block/collection/BlockMiningLaser.java b/src/main/java/cr0s/warpdrive/block/collection/BlockMiningLaser.java index b9b23fda..10c2dd3a 100644 --- a/src/main/java/cr0s/warpdrive/block/collection/BlockMiningLaser.java +++ b/src/main/java/cr0s/warpdrive/block/collection/BlockMiningLaser.java @@ -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(); } diff --git a/src/main/java/cr0s/warpdrive/block/collection/TileEntityAbstractMiner.java b/src/main/java/cr0s/warpdrive/block/collection/TileEntityAbstractMiner.java index 0a468c56..cdcbd5ee 100644 --- a/src/main/java/cr0s/warpdrive/block/collection/TileEntityAbstractMiner.java +++ b/src/main/java/cr0s/warpdrive/block/collection/TileEntityAbstractMiner.java @@ -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 getItemStackFromBlock(final BlockPos blockPos, final IBlockState blockState) { if (blockState == null) { WarpDrive.logger.error(String.format("%s Invalid block %s", diff --git a/src/main/java/cr0s/warpdrive/block/collection/TileEntityLaserTreeFarm.java b/src/main/java/cr0s/warpdrive/block/collection/TileEntityLaserTreeFarm.java index ddab70cd..8e4f0e19 100644 --- a/src/main/java/cr0s/warpdrive/block/collection/TileEntityLaserTreeFarm.java +++ b/src/main/java/cr0s/warpdrive/block/collection/TileEntityLaserTreeFarm.java @@ -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 comparator = ((TileEntityLaserTreeFarm) tileEntity)::comparatorSortLogsAndLeaves; + //noinspection UnusedAssignment tileEntity = null; if (WarpDriveConfig.LOGGING_COLLECTION) { diff --git a/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java b/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java index 7100bbd3..1bee27a3 100644 --- a/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java +++ b/src/main/java/cr0s/warpdrive/block/collection/TileEntityMiningLaser.java @@ -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]); diff --git a/src/main/java/cr0s/warpdrive/block/decoration/BlockAbstractLamp.java b/src/main/java/cr0s/warpdrive/block/decoration/BlockAbstractLamp.java index 2337da14..cadce9e9 100644 --- a/src/main/java/cr0s/warpdrive/block/decoration/BlockAbstractLamp.java +++ b/src/main/java/cr0s/warpdrive/block/decoration/BlockAbstractLamp.java @@ -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()); } diff --git a/src/main/java/cr0s/warpdrive/block/decoration/BlockDecorative.java b/src/main/java/cr0s/warpdrive/block/decoration/BlockDecorative.java index 465ee5db..598b75c1 100644 --- a/src/main/java/cr0s/warpdrive/block/decoration/BlockDecorative.java +++ b/src/main/java/cr0s/warpdrive/block/decoration/BlockDecorative.java @@ -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(); } diff --git a/src/main/java/cr0s/warpdrive/block/decoration/BlockGas.java b/src/main/java/cr0s/warpdrive/block/decoration/BlockGas.java index 67b72a74..3787edeb 100644 --- a/src/main/java/cr0s/warpdrive/block/decoration/BlockGas.java +++ b/src/main/java/cr0s/warpdrive/block/decoration/BlockGas.java @@ -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(); } diff --git a/src/main/java/cr0s/warpdrive/block/detection/BlockCloakingCoil.java b/src/main/java/cr0s/warpdrive/block/detection/BlockCloakingCoil.java index 16d9f46a..3a8392a0 100644 --- a/src/main/java/cr0s/warpdrive/block/detection/BlockCloakingCoil.java +++ b/src/main/java/cr0s/warpdrive/block/detection/BlockCloakingCoil.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/detection/BlockRadar.java b/src/main/java/cr0s/warpdrive/block/detection/BlockRadar.java index e9acd202..22ae87bb 100644 --- a/src/main/java/cr0s/warpdrive/block/detection/BlockRadar.java +++ b/src/main/java/cr0s/warpdrive/block/detection/BlockRadar.java @@ -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(); } diff --git a/src/main/java/cr0s/warpdrive/block/energy/BlockCapacitor.java b/src/main/java/cr0s/warpdrive/block/energy/BlockCapacitor.java index 9dd6dfdc..0c133f73 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/BlockCapacitor.java +++ b/src/main/java/cr0s/warpdrive/block/energy/BlockCapacitor.java @@ -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; } diff --git a/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorController.java b/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorController.java index 31991e52..feea60b2 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorController.java +++ b/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorController.java @@ -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; } diff --git a/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorCore.java b/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorCore.java index 0432e76a..1db2aa1e 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorCore.java +++ b/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorCore.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java index 61325543..94abc737 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java +++ b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java @@ -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; diff --git a/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceField.java b/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceField.java index 7990954c..249b11d0 100644 --- a/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceField.java +++ b/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceField.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceFieldProjector.java b/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceFieldProjector.java index d5eb6c6f..03f348a3 100644 --- a/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceFieldProjector.java +++ b/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceFieldProjector.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceFieldRelay.java b/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceFieldRelay.java index cb301d0d..5933197d 100644 --- a/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceFieldRelay.java +++ b/src/main/java/cr0s/warpdrive/block/forcefield/BlockForceFieldRelay.java @@ -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; } diff --git a/src/main/java/cr0s/warpdrive/block/hull/BlockHullPlain.java b/src/main/java/cr0s/warpdrive/block/hull/BlockHullPlain.java index 6b2ea8d9..43a3322f 100644 --- a/src/main/java/cr0s/warpdrive/block/hull/BlockHullPlain.java +++ b/src/main/java/cr0s/warpdrive/block/hull/BlockHullPlain.java @@ -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(); } diff --git a/src/main/java/cr0s/warpdrive/block/hull/BlockHullSlab.java b/src/main/java/cr0s/warpdrive/block/hull/BlockHullSlab.java index 24b7d471..6f60f518 100644 --- a/src/main/java/cr0s/warpdrive/block/hull/BlockHullSlab.java +++ b/src/main/java/cr0s/warpdrive/block/hull/BlockHullSlab.java @@ -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 list) { + public void getSubBlocks(final CreativeTabs creativeTab, @Nonnull final NonNullList 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; } diff --git a/src/main/java/cr0s/warpdrive/block/movement/BlockLift.java b/src/main/java/cr0s/warpdrive/block/movement/BlockLift.java index 175e2e06..dafc7e3d 100644 --- a/src/main/java/cr0s/warpdrive/block/movement/BlockLift.java +++ b/src/main/java/cr0s/warpdrive/block/movement/BlockLift.java @@ -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(); } diff --git a/src/main/java/cr0s/warpdrive/block/movement/BlockShipController.java b/src/main/java/cr0s/warpdrive/block/movement/BlockShipController.java index 52e2609b..8385e987 100644 --- a/src/main/java/cr0s/warpdrive/block/movement/BlockShipController.java +++ b/src/main/java/cr0s/warpdrive/block/movement/BlockShipController.java @@ -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(); } diff --git a/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterBeacon.java b/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterBeacon.java index 04286191..a2b3c9b3 100644 --- a/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterBeacon.java +++ b/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterBeacon.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterCore.java b/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterCore.java index 45cb525a..a0e9b309 100644 --- a/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterCore.java +++ b/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterCore.java @@ -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(); } } \ No newline at end of file diff --git a/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterScanner.java b/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterScanner.java index f3bb4bf8..5c17dec9 100644 --- a/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterScanner.java +++ b/src/main/java/cr0s/warpdrive/block/movement/BlockTransporterScanner.java @@ -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; } diff --git a/src/main/java/cr0s/warpdrive/config/Filler.java b/src/main/java/cr0s/warpdrive/config/Filler.java index cdb011f9..f5691f9a 100644 --- a/src/main/java/cr0s/warpdrive/config/Filler.java +++ b/src/main/java/cr0s/warpdrive/config/Filler.java @@ -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())); diff --git a/src/main/java/cr0s/warpdrive/config/Recipes.java b/src/main/java/cr0s/warpdrive/config/Recipes.java index 64fcab7c..5a2641fd 100644 --- a/src/main/java/cr0s/warpdrive/config/Recipes.java +++ b/src/main/java/cr0s/warpdrive/config/Recipes.java @@ -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); } diff --git a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java index 8c2b9e24..833af826 100644 --- a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java +++ b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java @@ -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))); diff --git a/src/main/java/cr0s/warpdrive/config/structures/MetaOrbInstance.java b/src/main/java/cr0s/warpdrive/config/structures/MetaOrbInstance.java index 6faa889b..825b9fb8 100644 --- a/src/main/java/cr0s/warpdrive/config/structures/MetaOrbInstance.java +++ b/src/main/java/cr0s/warpdrive/config/structures/MetaOrbInstance.java @@ -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); } } diff --git a/src/main/java/cr0s/warpdrive/data/JumpBlock.java b/src/main/java/cr0s/warpdrive/data/JumpBlock.java index 6b4698df..026b556c 100644 --- a/src/main/java/cr0s/warpdrive/data/JumpBlock.java +++ b/src/main/java/cr0s/warpdrive/data/JumpBlock.java @@ -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; - } - } - } - } diff --git a/src/main/java/cr0s/warpdrive/event/JumpSequencer.java b/src/main/java/cr0s/warpdrive/event/JumpSequencer.java index a9373581..43e31ef8 100644 --- a/src/main/java/cr0s/warpdrive/event/JumpSequencer.java +++ b/src/main/java/cr0s/warpdrive/event/JumpSequencer.java @@ -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)); diff --git a/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java b/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java index 12cf1b8c..f9f521b7 100644 --- a/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java +++ b/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java @@ -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++; }