Code cleanup

This commit is contained in:
Unknown 2019-05-24 23:21:16 +02:00 committed by unknown
parent 2f0cd4adb2
commit 7ee580ed40
45 changed files with 292 additions and 266 deletions

View 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;
}
}
}
}

View file

@ -109,7 +109,7 @@ public abstract class BlockAbstractOmnipanel extends BlockAbstractBase {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(BlockColored.COLOR).getMetadata(); return blockState.getValue(BlockColored.COLOR).getMetadata();
} }

View file

@ -37,7 +37,7 @@ public abstract class BlockAbstractRotatingContainer extends BlockAbstractContai
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 0x8 : 0x0) return (blockState.getValue(BlockProperties.ACTIVE) ? 0x8 : 0x0)
| (blockState.getValue(BlockProperties.FACING).getIndex()); | (blockState.getValue(BlockProperties.FACING).getIndex());
} }

View file

@ -38,7 +38,7 @@ public class BlockChunkLoader extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0); return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
} }

View file

@ -40,7 +40,7 @@ public class BlockLaserMedium extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(LEVEL); return blockState.getValue(LEVEL);
} }

View file

@ -28,7 +28,6 @@ import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -710,11 +709,11 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
private void playSoundCorrespondsEnergy(final int energy) { private void playSoundCorrespondsEnergy(final int energy) {
if (energy <= 500000) { if (energy <= 500000) {
world.playSound(null, pos, SoundEvents.LASER_LOW, SoundCategory.HOSTILE, 4F, 1F); world.playSound(null, pos, SoundEvents.LASER_LOW, SoundCategory.HOSTILE, 4.0F, 1.0F);
} else if (energy > 500000 && energy <= 1000000) { } else if (energy <= 1000000) {
world.playSound(null, pos, SoundEvents.LASER_MEDIUM, SoundCategory.HOSTILE, 4F, 1F); world.playSound(null, pos, SoundEvents.LASER_MEDIUM, SoundCategory.HOSTILE, 4.0F, 1.0F);
} else if (energy > 1000000) { } else {
world.playSound(null, pos, SoundEvents.LASER_HIGH, SoundCategory.HOSTILE, 4F, 1F); world.playSound(null, pos, SoundEvents.LASER_HIGH, SoundCategory.HOSTILE, 4.0F, 1.0F);
} }
} }

View file

@ -42,7 +42,7 @@ public class BlockAcceleratorControlPoint extends BlockAbstractAccelerator imple
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0); return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
} }

View file

@ -39,7 +39,7 @@ public class BlockAcceleratorController extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0); return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
} }

View file

@ -54,7 +54,7 @@ public class BlockChiller extends BlockAbstractAccelerator {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0); return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
} }

View file

@ -35,7 +35,7 @@ public class BlockParticlesCollider extends BlockAbstractAccelerator {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0); return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
} }
} }

View file

@ -37,7 +37,7 @@ public class BlockParticlesInjector extends BlockAcceleratorControlPoint {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0); return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0);
} }

View file

@ -34,7 +34,7 @@ public class BlockAirSource extends BlockAbstractAir {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(BlockProperties.FACING).getIndex(); return blockState.getValue(BlockProperties.FACING).getIndex();
} }
} }

View file

@ -52,7 +52,7 @@ public class BlockShipScanner extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(BlockProperties.ACTIVE) ? 0x8 : 0; return blockState.getValue(BlockProperties.ACTIVE) ? 0x8 : 0;
} }

View file

@ -100,7 +100,7 @@ public class TileEntityShipScanner extends TileEntityAbstractMachine implements
return; return;
} }
// @TODO inmplement ShipScanner.isEnabled // @TODO implement ShipScanner.isEnabled
searchTicks++; searchTicks++;
if (searchTicks > WarpDriveConfig.SS_SEARCH_INTERVAL_TICKS) { if (searchTicks > WarpDriveConfig.SS_SEARCH_INTERVAL_TICKS) {
@ -252,7 +252,7 @@ public class TileEntityShipScanner extends TileEntityAbstractMachine implements
TileEntityShipCore tileEntityShipCore = null; TileEntityShipCore tileEntityShipCore = null;
// Search for ship cores above // 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++) { for (int newY = pos.getY() + 1; newY <= 255; newY++) {
mutableBlockPos.setY(newY); mutableBlockPos.setY(newY);
if (world.getBlockState(mutableBlockPos).getBlock() instanceof BlockShipCore) { // found ship core above 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); schematic.setTag("ship", tagCompoundShip);
// Storage collections // Storage collections
final String stringBlockRegistryNames[] = new String[size]; final String[] stringBlockRegistryNames = new String[size];
final byte byteMetadatas[] = new byte[size]; final byte[] byteMetadatas = new byte[size];
final NBTTagList tileEntitiesList = new NBTTagList(); final NBTTagList tileEntitiesList = new NBTTagList();
// Scan the whole area // Scan the whole area
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) { 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); IBlockState blockState = world.getBlockState(blockPos);
// Skip leftBehind and anchor blocks // Skip leftBehind and anchor blocks

View file

@ -43,7 +43,7 @@ public class BlockLaserTreeFarm extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(MODE).ordinal(); return blockState.getValue(MODE).ordinal();
} }

View file

@ -43,7 +43,7 @@ public class BlockMiningLaser extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(MODE).ordinal(); return blockState.getValue(MODE).ordinal();
} }

View file

@ -4,7 +4,6 @@ import cr0s.warpdrive.CommonProxy;
import cr0s.warpdrive.Commons; import cr0s.warpdrive.Commons;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.block.TileEntityAbstractLaser; import cr0s.warpdrive.block.TileEntityAbstractLaser;
import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.FluidWrapper; import cr0s.warpdrive.data.FluidWrapper;
import cr0s.warpdrive.data.InventoryWrapper; import cr0s.warpdrive.data.InventoryWrapper;
import cr0s.warpdrive.data.Vector3; import cr0s.warpdrive.data.Vector3;
@ -13,6 +12,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; 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); 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)) { if (blockState.getBlock().isAir(blockState, world, blockPos)) {
return; return;
} }
@ -77,6 +77,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser {
} }
} }
@Nullable
private NonNullList<ItemStack> getItemStackFromBlock(final BlockPos blockPos, final IBlockState blockState) { private NonNullList<ItemStack> getItemStackFromBlock(final BlockPos blockPos, final IBlockState blockState) {
if (blockState == null) { if (blockState == null) {
WarpDrive.logger.error(String.format("%s Invalid block %s", WarpDrive.logger.error(String.format("%s Invalid block %s",

View file

@ -705,7 +705,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
return blockStatePosList; 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 // first, we clear central from bottom to top
if (o1.blockPos.getX() == pos.getX() && o1.blockPos.getZ() == pos.getZ()) { if (o1.blockPos.getX() == pos.getX() && o1.blockPos.getZ() == pos.getZ()) {
if (o2.blockPos.getX() == pos.getX() && o2.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 boolean breakLeaves = ((TileEntityLaserTreeFarm) tileEntity).breakLeaves;
final int maxDistance = ((TileEntityLaserTreeFarm) tileEntity).maxDistance; final int maxDistance = ((TileEntityLaserTreeFarm) tileEntity).maxDistance;
final Comparator<BlockStatePos> comparator = ((TileEntityLaserTreeFarm) tileEntity)::comparatorSortLogsAndLeaves; final Comparator<BlockStatePos> comparator = ((TileEntityLaserTreeFarm) tileEntity)::comparatorSortLogsAndLeaves;
//noinspection UnusedAssignment
tileEntity = null; tileEntity = null;
if (WarpDriveConfig.LOGGING_COLLECTION) { if (WarpDriveConfig.LOGGING_COLLECTION) {

View file

@ -500,7 +500,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
return new Object[] { !mineAllBlocks }; return new Object[] { !mineAllBlocks };
} }
private Object[] offset(final Object[] arguments) { private Object[] offset(@Nonnull final Object[] arguments) {
if (arguments.length == 1 && arguments[0] != null) { if (arguments.length == 1 && arguments[0] != null) {
try { try {
layerOffset = Math.min(256, Math.abs(Commons.toInt(arguments[0]))); layerOffset = Math.min(256, Math.abs(Commons.toInt(arguments[0])));
@ -512,7 +512,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
return new Integer[] { layerOffset }; return new Integer[] { layerOffset };
} }
private Object[] silktouch(final Object[] arguments) { private Object[] silktouch(@Nonnull final Object[] arguments) {
if (arguments.length == 1 && arguments[0] != null) { if (arguments.length == 1 && arguments[0] != null) {
try { try {
enableSilktouch = Commons.toBool(arguments[0]); enableSilktouch = Commons.toBool(arguments[0]);

View file

@ -63,7 +63,7 @@ public class BlockAbstractLamp extends BlockAbstractBase {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 0x8 : 0x0) return (blockState.getValue(BlockProperties.ACTIVE) ? 0x8 : 0x0)
| (blockState.getValue(BlockProperties.FACING).getIndex()); | (blockState.getValue(BlockProperties.FACING).getIndex());
} }

View file

@ -58,7 +58,7 @@ public class BlockDecorative extends BlockAbstractBase {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(TYPE).ordinal(); return blockState.getValue(TYPE).ordinal();
} }

View file

@ -62,7 +62,7 @@ public class BlockGas extends BlockAbstractBase {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(COLOR).ordinal(); return blockState.getValue(COLOR).ordinal();
} }

View file

@ -65,7 +65,7 @@ public class BlockCloakingCoil extends BlockAbstractBase {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0) return (blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0)
+ (blockState.getValue(OUTER) ? 1 + blockState.getValue(BlockProperties.FACING).ordinal() : 0); + (blockState.getValue(OUTER) ? 1 + blockState.getValue(BlockProperties.FACING).ordinal() : 0);
} }

View file

@ -43,7 +43,7 @@ public class BlockRadar extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(MODE).ordinal(); return blockState.getValue(MODE).ordinal();
} }

View file

@ -86,7 +86,7 @@ public class BlockCapacitor extends BlockAbstractContainer implements IExplosion
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return 0; return 0;
} }

View file

@ -39,7 +39,7 @@ public class BlockEnanReactorController extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0; return blockState.getValue(BlockProperties.ACTIVE) ? 8 : 0;
} }

View file

@ -51,7 +51,7 @@ public class BlockEnanReactorCore extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(ENERGY) + (blockState.getValue(INSTABILITY) << 2); return blockState.getValue(ENERGY) + (blockState.getValue(INSTABILITY) << 2);
} }

View file

@ -15,6 +15,7 @@ import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context; import li.cil.oc.api.machine.Context;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -122,6 +123,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen
} }
} }
@Nullable
private TileEntityEnanReactorCore getReactorCore() { private TileEntityEnanReactorCore getReactorCore() {
if (reactorFace == ReactorFace.UNKNOWN) { if (reactorFace == ReactorFace.UNKNOWN) {
return null; return null;

View file

@ -121,7 +121,7 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(FREQUENCY); return blockState.getValue(FREQUENCY);
} }

View file

@ -85,7 +85,7 @@ public class BlockForceFieldProjector extends BlockAbstractForceField {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(BlockProperties.FACING).getIndex() return blockState.getValue(BlockProperties.FACING).getIndex()
+ (blockState.getValue(IS_DOUBLE_SIDED) ? 8 : 0); + (blockState.getValue(IS_DOUBLE_SIDED) ? 8 : 0);
} }

View file

@ -52,7 +52,7 @@ public class BlockForceFieldRelay extends BlockAbstractForceField {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return 0; return 0;
} }

View file

@ -88,7 +88,7 @@ public class BlockHullPlain extends BlockAbstractBase implements IDamageReceiver
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(BlockColored.COLOR).getMetadata(); return blockState.getValue(BlockColored.COLOR).getMetadata();
} }

View file

@ -61,7 +61,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
final EnumTier enumTier; final EnumTier enumTier;
private final IBlockState blockStateHull; 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); super(Material.ROCK);
this.enumTier = enumTier; this.enumTier = enumTier;
@ -94,7 +94,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(VARIANT).ordinal(); return blockState.getValue(VARIANT).ordinal();
} }
@ -107,7 +107,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
@Override @Override
@SideOnly(Side.CLIENT) @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, 0));
list.add(new ItemStack(this, 1, 2)); list.add(new ItemStack(this, 1, 2));
list.add(new ItemStack(this, 1, 6)); list.add(new ItemStack(this, 1, 6));
@ -171,13 +171,13 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public boolean isFullBlock(final IBlockState blockState) { public boolean isFullBlock(@Nonnull final IBlockState blockState) {
return ((BlockSlab) blockState.getBlock()).isDouble(); return ((BlockSlab) blockState.getBlock()).isDouble();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public boolean isFullCube(final IBlockState blockState) { public boolean isFullCube(@Nonnull final IBlockState blockState) {
return ((BlockSlab) blockState.getBlock()).isDouble(); return ((BlockSlab) blockState.getBlock()).isDouble();
} }
@ -270,7 +270,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
} }
@Override @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()) { if (blockState.isOpaqueCube()) {
return true; return true;
} }
@ -281,7 +281,7 @@ public class BlockHullSlab extends BlockSlab implements IBlockBase, IDamageRecei
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @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(); final EnumFacing enumFacing = blockState.getValue(VARIANT).getFacing();
return enumFacing == side; return enumFacing == side;
} }

View file

@ -42,7 +42,7 @@ public class BlockLift extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(MODE).ordinal(); return blockState.getValue(MODE).ordinal();
} }

View file

@ -50,7 +50,7 @@ public class BlockShipController extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(COMMAND).ordinal(); return blockState.getValue(COMMAND).ordinal();
} }

View file

@ -73,7 +73,7 @@ public class BlockTransporterBeacon extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return (blockState.getValue(BlockProperties.ACTIVE) ? 2 : 0) return (blockState.getValue(BlockProperties.ACTIVE) ? 2 : 0)
+ (blockState.getValue(DEPLOYED) ? 1 : 0); + (blockState.getValue(DEPLOYED) ? 1 : 0);
} }

View file

@ -48,7 +48,7 @@ public class BlockTransporterCore extends BlockAbstractContainer {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(VARIANT).getMetadata(); return blockState.getValue(VARIANT).getMetadata();
} }
} }

View file

@ -51,7 +51,7 @@ public class BlockTransporterScanner extends BlockAbstractBase {
} }
@Override @Override
public int getMetaFromState(final IBlockState blockState) { public int getMetaFromState(@Nonnull final IBlockState blockState) {
return blockState.getValue(BlockProperties.ACTIVE) ? 1 : 0; return blockState.getValue(BlockProperties.ACTIVE) ? 1 : 0;
} }

View file

@ -1,6 +1,7 @@
package cr0s.warpdrive.config; package cr0s.warpdrive.config;
import cr0s.warpdrive.Commons; import cr0s.warpdrive.Commons;
import cr0s.warpdrive.FastSetBlockState;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IXmlRepresentableUnit; import cr0s.warpdrive.api.IXmlRepresentableUnit;
import cr0s.warpdrive.data.JumpBlock; import cr0s.warpdrive.data.JumpBlock;
@ -149,7 +150,7 @@ public class Filler implements IXmlRepresentableUnit {
final IBlockState blockState; final IBlockState blockState;
try { try {
blockState = block.getStateFromMeta(metadata); blockState = block.getStateFromMeta(metadata);
JumpBlock.setBlockStateNoLight(world, blockPos, blockState, 2); FastSetBlockState.setBlockStateNoLight(world, blockPos, blockState, 2);
} catch (final Throwable throwable) { } catch (final Throwable throwable) {
WarpDrive.logger.error(String.format("Throwable detected in Filler.setBlock(%s), check your configuration for that block!", WarpDrive.logger.error(String.format("Throwable detected in Filler.setBlock(%s), check your configuration for that block!",
getName())); getName()));

View file

@ -15,6 +15,7 @@ import cr0s.warpdrive.item.ItemForceFieldShape;
import cr0s.warpdrive.item.ItemForceFieldUpgrade; import cr0s.warpdrive.item.ItemForceFieldUpgrade;
import cr0s.warpdrive.item.ItemTuningDriver; import cr0s.warpdrive.item.ItemTuningDriver;
import javax.annotation.Nonnull;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; 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()) { if (!itemStack.isEmpty()) {
OreDictionary.registerOre(name, itemStack); OreDictionary.registerOre(name, itemStack);
} }

View file

@ -86,6 +86,7 @@ import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@ -573,7 +574,8 @@ public class WarpDriveConfig {
return getItemStackOrFire(registryName, meta, ""); 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(":"); assert registryName.contains(":");
if (registryName.startsWith("ore:")) { if (registryName.startsWith("ore:")) {
@ -608,7 +610,7 @@ public class WarpDriveConfig {
} }
public static Object getOreOrItemStack(final String registryName1, final int meta1, public static Object getOreOrItemStack(final String registryName1, final int meta1,
final Object... args) { @Nonnull final Object... args) {
// always validate parameters in dev space // always validate parameters in dev space
assert args.length % 2 == 0; assert args.length % 2 == 0;
for (int index = 0; index < args.length; index += 2) { for (int index = 0; index < args.length; index += 2) {
@ -649,7 +651,7 @@ public class WarpDriveConfig {
return itemStacks.get(0); 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(); double[] valuesRead = config.get(category, key, valuesDefault, comment).getDoubleList();
if (valuesRead.length != valuesDefault.length) { if (valuesRead.length != valuesDefault.length) {
valuesRead = valuesDefault.clone(); valuesRead = valuesDefault.clone();
@ -1268,7 +1270,7 @@ public class WarpDriveConfig {
config.save(); 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) { 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!", 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))); EnumTier.length, values.length, Arrays.toString(values)));
@ -1281,7 +1283,7 @@ public class WarpDriveConfig {
values[3] = Commons.clamp(values[2], max , values[3]); 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) { 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!", 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))); EnumTier.length, values.length, Arrays.toString(values)));
@ -1294,7 +1296,7 @@ public class WarpDriveConfig {
values[3] = Commons.clamp(values[2], max , values[3]); 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) { 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!", 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))); EnumTier.length, names.length, Arrays.toString(names)));

View file

@ -1,6 +1,7 @@
package cr0s.warpdrive.config.structures; package cr0s.warpdrive.config.structures;
import cr0s.warpdrive.Commons; import cr0s.warpdrive.Commons;
import cr0s.warpdrive.FastSetBlockState;
import cr0s.warpdrive.LocalProfiler; import cr0s.warpdrive.LocalProfiler;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.GenericSet; import cr0s.warpdrive.config.GenericSet;
@ -175,7 +176,7 @@ public class MetaOrbInstance extends OrbInstance {
if (isSurface && jumpBlock.x % 4 == 0 && jumpBlock.z % 4 == 0) { if (isSurface && jumpBlock.x % 4 == 0 && jumpBlock.z % 4 == 0) {
world.setBlockState(blockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2); world.setBlockState(blockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
} else { } else {
JumpBlock.setBlockStateNoLight(world, blockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2); FastSetBlockState.setBlockStateNoLight(world, blockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
} }
} }

View file

@ -1,6 +1,7 @@
package cr0s.warpdrive.data; package cr0s.warpdrive.data;
import cr0s.warpdrive.Commons; import cr0s.warpdrive.Commons;
import cr0s.warpdrive.FastSetBlockState;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.IBlockBase; import cr0s.warpdrive.api.IBlockBase;
import cr0s.warpdrive.api.IBlockTransformer; import cr0s.warpdrive.api.IBlockTransformer;
@ -17,7 +18,6 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ConcurrentModificationException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -60,11 +60,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraft.world.World; 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;
import net.minecraftforge.common.util.Constants.NBT; import net.minecraftforge.common.util.Constants.NBT;
@ -83,7 +79,7 @@ public class JumpBlock {
public 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.x = blockPos.getX();
this.y = blockPos.getY(); this.y = blockPos.getY();
this.z = blockPos.getZ(); 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) { if (filler.block == null) {
WarpDrive.logger.info(String.format("Forcing glass for invalid filler with null block at (%d %d %d)", WarpDrive.logger.info(String.format("Forcing glass for invalid filler with null block at (%d %d %d)",
x, y, z)); x, y, z));
@ -127,7 +123,7 @@ public class JumpBlock {
this.z = z; this.z = z;
} }
public TileEntity getTileEntity(final World worldSource) { public TileEntity getTileEntity(@Nonnull final World worldSource) {
if (weakTileEntity == null) { if (weakTileEntity == null) {
return null; return null;
} }
@ -140,7 +136,7 @@ public class JumpBlock {
return worldSource.getTileEntity(new BlockPos(x, y, z)); return worldSource.getTileEntity(new BlockPos(x, y, z));
} }
private NBTTagCompound getBlockNBT(final World worldSource) { private NBTTagCompound getBlockNBT(@Nonnull final World worldSource) {
if (weakTileEntity == null) { if (weakTileEntity == null) {
return blockNBT == null ? null : blockNBT.copy(); return blockNBT == null ? null : blockNBT.copy();
} }
@ -309,7 +305,7 @@ public class JumpBlock {
block, newBlockMeta, nbtToDeploy)); block, newBlockMeta, nbtToDeploy));
} }
final IBlockState blockState = block.getStateFromMeta(newBlockMeta); final IBlockState blockState = block.getStateFromMeta(newBlockMeta);
setBlockStateNoLight(worldTarget, target, blockState, 2); FastSetBlockState.setBlockStateNoLight(worldTarget, target, blockState, 2);
if (nbtToDeploy != null) { if (nbtToDeploy != null) {
nbtToDeploy.setInteger("x", target.getX()); nbtToDeploy.setInteger("x", target.getX());
@ -374,7 +370,7 @@ public class JumpBlock {
return null; 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); final TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity != null) { if (tileEntity != null) {
final Class<?> teClass = tileEntity.getClass(); 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 // BuildCraft
if (tagCompound.hasKey("battery", NBT.TAG_COMPOUND)) { if (tagCompound.hasKey("battery", NBT.TAG_COMPOUND)) {
final NBTTagCompound tagCompoundBattery = tagCompound.getCompoundTag("battery"); final NBTTagCompound tagCompoundBattery = tagCompound.getCompoundTag("battery");
@ -681,193 +677,4 @@ public class JumpBlock {
weakTileEntity == null ? null : weakTileEntity.get(), weakTileEntity == null ? null : weakTileEntity.get(),
blockNBT); 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;
}
}
}
} }

View file

@ -2,6 +2,7 @@ package cr0s.warpdrive.event;
import cr0s.warpdrive.CommonProxy; import cr0s.warpdrive.CommonProxy;
import cr0s.warpdrive.Commons; import cr0s.warpdrive.Commons;
import cr0s.warpdrive.FastSetBlockState;
import cr0s.warpdrive.LocalProfiler; import cr0s.warpdrive.LocalProfiler;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.api.EventWarpDrive.Ship.JumpResult; import cr0s.warpdrive.api.EventWarpDrive.Ship.JumpResult;
@ -1262,11 +1263,11 @@ public class JumpSequencer extends AbstractSequencer {
} }
try { try {
final BlockPos blockPos = new BlockPos(jumpBlock.x, jumpBlock.y, jumpBlock.z); 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) { if (!isRemoved) {
WarpDrive.logger.info(String.format("Failed to remove %s@%d at (%d %d %d), retrying...", 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)); 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) { if (!isRemoved) {
WarpDrive.logger.error(String.format("Failed to remove %s@%d at (%d %d %d), still failing?", 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)); jumpBlock.block, jumpBlock.blockMeta, jumpBlock.x, jumpBlock.y, jumpBlock.z));

View file

@ -1,5 +1,6 @@
package cr0s.warpdrive.world; package cr0s.warpdrive.world;
import cr0s.warpdrive.FastSetBlockState;
import cr0s.warpdrive.LocalProfiler; import cr0s.warpdrive.LocalProfiler;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.Filler; 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) { if (isSurfaces.get(currentIndex) && jumpBlock.x % 4 == 0 && jumpBlock.z % 4 == 0) {
world.setBlockState(mutableBlockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2); world.setBlockState(mutableBlockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
} else { } else {
JumpBlock.setBlockStateNoLight(world, mutableBlockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2); FastSetBlockState.setBlockStateNoLight(world, mutableBlockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2);
} }
currentIndex++; currentIndex++;
} }