Updated more blocks and related entities

This commit is contained in:
Francesco Macagno 2015-07-15 23:09:08 -07:00
parent a64b8da1ae
commit 63b05ea5eb
6 changed files with 87 additions and 71 deletions

View file

@ -4,7 +4,8 @@ import net.minecraft.world.ChunkCoordIntPair;
import net.minecraftforge.event.world.ChunkWatchEvent;
public class CloakChunkWatcher {
@ForgeSubscribe
//TODO: register as event reciever
public void chunkLoaded(ChunkWatchEvent event) {
ChunkCoordIntPair chunk = event.chunk;

View file

@ -1,5 +1,7 @@
package cr0s.warpdrive;
import ic2.api.network.NetworkHelper;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@ -12,10 +14,13 @@ import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MathHelper;
import net.minecraft.world.ChunkCoordIntPair;
@ -297,7 +302,7 @@ public class EntityJump extends Entity
WarpDrive.print("" + this + " messageToAllPlayersOnShip: " + msg);
for (MovingEntity me : entitiesOnShip) {
if (me.entity instanceof EntityPlayer) {
((EntityPlayer)me.entity).addChatMessage("[" + ((reactor != null && reactor.coreFrequency.length() > 0) ? reactor.coreFrequency : "WarpCore") + "] " + msg);
((EntityPlayer)me.entity).addChatMessage(new ChatComponentText("[" + ((reactor != null && reactor.coreFrequency.length() > 0) ? reactor.coreFrequency : "WarpCore") + "] " + msg));
}
}
}
@ -550,11 +555,11 @@ public class EntityJump extends Entity
if (jb.blockTileEntity != null) {
// WarpDrive.debugPrint("Removing tile entity at " + jb.x + ", " + jb.y + ", " + jb.z);
worldObj.removeBlockTileEntity(jb.x, jb.y, jb.z);
worldObj.removeTileEntity(jb.x, jb.y, jb.z);
}
worldObj.setBlock(jb.x, jb.y, jb.z, 0, 0, 2);
worldObj.setBlock(jb.x, jb.y, jb.z, Blocks.air, 0, 2);
te = targetWorld.getBlockTileEntity(jb.x + moveX, jb.y + moveY, jb.z + moveZ);
te = targetWorld.getTileEntity(jb.x + moveX, jb.y + moveY, jb.z + moveZ);
if (te != null) {
teClass = te.getClass();
// WarpDrive.debugPrint("Tile at " + jb.x + ", " + jb.y + ", " + jb.z + " is " + teClass + " derived from " + teClass.getSuperclass());
@ -608,7 +613,7 @@ public class EntityJump extends Entity
private void saveShip(int shipSize) {
LocalProfiler.start("EntityJump.saveShip");
try {
int reactorChamber = WarpDriveConfig.isICLoaded ? WarpDriveConfig.getIC2Item("reactorChamber").itemID : 0;
ItemStack reactorChamber = WarpDriveConfig.isICLoaded ? WarpDriveConfig.getIC2Item("reactorChamber") : null;
ship = new JumpBlock[shipSize];
JumpBlock placeAfter[] = new JumpBlock[shipSize]; // blocks and tile entities to be placed at the end, and removed first
@ -631,18 +636,18 @@ public class EntityJump extends Entity
for (int y = minY; y <= maxY; y++) {
for (int x = x1; x <= x2; x++) {
for (int z = z1; z <= z2; z++) {
int blockID = worldObj.getBlockId(x, y, z);
Block block = worldObj.getBlock(x, y, z);
// Skip air blocks
if (worldObj.isAirBlock(x, y, z) && (blockID != WarpDriveConfig.airID)) {
if (worldObj.isAirBlock(x, y, z) && (block.isAssociatedBlock(WarpDrive.airBlock))) {
continue;
}
int blockMeta = worldObj.getBlockMetadata(x, y, z);
TileEntity tileEntity = worldObj.getBlockTileEntity(x, y, z);
JumpBlock jumpBlock = new JumpBlock(blockID, blockMeta, tileEntity, x, y, z);
TileEntity tileEntity = worldObj.getTileEntity(x, y, z);
JumpBlock jumpBlock = new JumpBlock(block, blockMeta, tileEntity, x, y, z);
if (tileEntity == null || blockID != reactorChamber) {
if (tileEntity == null || block.isAssociatedBlock(Block.getBlockFromItem(reactorChamber.getItem()))) {
ship[indexPlaceNormal] = jumpBlock;
indexPlaceNormal++;
} else {
@ -686,8 +691,8 @@ public class EntityJump extends Entity
JumpBlock jb = ship[currentIndexInShip];
if (jb != null) {
jb.deploy(targetWorld, moveX, moveY, moveZ);
if (jb.blockID != WarpDriveConfig.CC_peripheral || (jb.blockMeta != 2 && jb.blockMeta != 4)) {
worldObj.removeBlockTileEntity(jb.x, jb.y, jb.z);
if (jb.block != WarpDriveConfig.CC_peripheral || (jb.blockMeta != 2 && jb.blockMeta != 4)) {
worldObj.removeTileEntity(jb.x, jb.y, jb.z);
}
}
currentIndexInShip++;
@ -817,10 +822,10 @@ public class EntityJump extends Entity
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
for (int y = minY; y <= maxY; y++) {
int blockID = worldObj.getBlockId(x, y, z);
Block block = worldObj.getBlock(x, y, z);
// Skipping vanilla air & WarpDrive gas blocks, keep WarpDrive air block
if (worldObj.isAirBlock(x, y, z) && (blockID != WarpDriveConfig.airID)) {// whitelist
if (worldObj.isAirBlock(x, y, z) && (block.isAssociatedBlock(WarpDrive.airBlock))) {// whitelist
continue;
}
@ -834,7 +839,8 @@ public class EntityJump extends Entity
WarpDrive.debugPrint("Block(" + x + ", " + y + ", " + z + ") is " + item.getUnlocalizedName() + ":" + worldObj.getBlockMetadata(x, y, z));
/**/
if ((blockID == Block.bedrock.blockID) || (blockID == 2702)) {// Blacklist
//TODO: What is block 2702?!?
if ((block.isAssociatedBlock(Blocks.bedrock)) /*|| (block == 2702)*/) {// Blacklist
reason.append("Bedrock detected onboard at " + x + ", " + y + ", " + z + ". Aborting.");
LocalProfiler.stop();
return -1;
@ -855,7 +861,7 @@ public class EntityJump extends Entity
if (!(xBorder || yBorder || zBorder))
continue;
int blockID = worldObj.getBlockId(x, y, z);
Block block = worldObj.getBlock(x, y, z);
// Skipping air blocks
if (worldObj.isAirBlock(x, y, z)) {
@ -863,11 +869,11 @@ public class EntityJump extends Entity
}
// Skipping unmovable blocks
if ((blockID == Block.bedrock.blockID) || (blockID == 2702)) {// Blacklist
if ((block.isAssociatedBlock(Blocks.bedrock)) /*|| (block == 2702)*/) {// Blacklist
continue;
}
TileEntity te = worldObj.getBlockTileEntity(x, y, z);
TileEntity te = worldObj.getTileEntity(x, y, z);
if (te == null) {
continue;
}
@ -1059,7 +1065,9 @@ public class EntityJump extends Entity
int lmoveY = movementVector[1] * testDistance;
int lmoveZ = movementVector[2] * testDistance;
int x, y, z, newX, newY, newZ, blockOnShipID, blockID;
int x, y, z, newX, newY, newZ;
Block blockOnShip;
Block block;
for (y = minY; y <= maxY; y++) {
newY = y + lmoveY;
for (x = minX; x <= maxX; x++) {
@ -1067,25 +1075,25 @@ public class EntityJump extends Entity
for (z = minZ; z <= maxZ; z++) {
newZ = z + lmoveZ;
blockID = worldObj.getBlockId(newX, newY, newZ);
if ((blockID == Block.bedrock.blockID) || (blockID == 2702)) {// Blacklist
block = worldObj.getBlock(newX, newY, newZ);
if ((block.isAssociatedBlock(Blocks.bedrock))/* || (block == 2702)*/) {// Blacklist
result.add(x, y, z,
newX + 0.5D - movementVector[0] * 1.0D,
newY + 0.5D - movementVector[1] * 1.0D,
newZ + 0.5D - movementVector[2] * 1.0D,
true, "Unpassable block " + blockID + " detected at destination (" + newX + ";" + newY + ";" + newZ + ")");
true, "Unpassable block " + block + " detected at destination (" + newX + ";" + newY + ";" + newZ + ")");
if (!fullCollisionDetails) {
return result;
}
}
blockOnShipID = worldObj.getBlockId(x, y, z);
if (blockOnShipID != 0 && blockID != 0 && blockID != WarpDriveConfig.airID && blockID != WarpDriveConfig.gasID && blockID != 18) {
blockOnShip = worldObj.getBlock(x, y, z);
if (!blockOnShip.isAssociatedBlock(Blocks.air) && !block.isAssociatedBlock(Blocks.air) && !block.isAssociatedBlock(WarpDrive.airBlock) && !block.isAssociatedBlock(WarpDrive.gasBlock)/* && block != 18* TODO: */) {
result.add(x, y, z,
newX + 0.5D + movementVector[0] * 0.1D,
newY + 0.5D + movementVector[1] * 0.1D,
newZ + 0.5D + movementVector[2] * 0.1D,
true, "Obstacle block #" + blockID + " detected at (" + newX + ", " + newY + ", " + newZ + ")");
true, "Obstacle block #" + block + " detected at (" + newX + ", " + newY + ", " + newZ + ")");
if (!fullCollisionDetails) {
return result;
}
@ -1218,7 +1226,7 @@ public class EntityJump extends Entity
public String toString() {
return String.format("%s/%d \'%s\' @ \'%s\' %.2f, %.2f, %.2f", new Object[] {
getClass().getSimpleName(),
Integer.valueOf(entityId),
Integer.valueOf(getEntityId()),
reactor == null ? "~NULL~" : reactor.coreFrequency,
worldObj == null ? "~NULL~" : worldObj.getWorldInfo().getWorldName(),
Double.valueOf(posX), Double.valueOf(posY), Double.valueOf(posZ)});

View file

@ -49,7 +49,7 @@ public class GravityManager
if (player.isSneaking())
{
if (player.getCurrentArmor(2) != null && WarpDriveConfig.jetpacks.contains(player.getCurrentArmor(2).itemID))
if (player.getCurrentArmor(2) != null && WarpDriveConfig.jetpacks.contains(player.getCurrentArmor(2)))
{
return SPACE_VOID_GRAVITY_JETPACKSNEAK;
}

View file

@ -1,6 +1,7 @@
package cr0s.warpdrive.data;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -10,7 +11,7 @@ import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.WarpDriveConfig;
public class JumpBlock {
public int blockID;
public Block block;
public int blockMeta;
public TileEntity blockTileEntity;
public NBTTagCompound blockNBT;
@ -21,8 +22,8 @@ public class JumpBlock {
public JumpBlock() {
}
public JumpBlock(int i, int j, int k, int l, int i1) {
blockID = i;
public JumpBlock(Block b, int j, int k, int l, int i1) {
block = b;
blockMeta = j;
blockTileEntity = null;
x = k;
@ -30,8 +31,8 @@ public class JumpBlock {
z = i1;
}
public JumpBlock(int i, int j, TileEntity tileentity, int k, int l, int i1) {
blockID = i;
public JumpBlock(Block block, int j, TileEntity tileentity, int k, int l, int i1) {
this.block = block;
blockMeta = j;
blockTileEntity = tileentity;
x = k;
@ -44,12 +45,12 @@ public class JumpBlock {
int newX = x + offsetX;
int newY = y + offsetY;
int newZ = z + offsetZ;
mySetBlock(targetWorld, newX, newY, newZ, blockID, blockMeta, 2);
mySetBlock(targetWorld, newX, newY, newZ, block, blockMeta, 2);
// Re-schedule air blocks update
if (blockID == WarpDriveConfig.airID) {
if (block.isAssociatedBlock(WarpDrive.airBlock)) {
targetWorld.markBlockForUpdate(newX, newY, newZ);
targetWorld.scheduleBlockUpdate(newX, newY, newZ, blockID, 40 + targetWorld.rand.nextInt(20));
targetWorld.scheduleBlockUpdate(newX, newY, newZ, block, 40 + targetWorld.rand.nextInt(20));
}
NBTTagCompound oldnbt = new NBTTagCompound();
@ -72,11 +73,11 @@ public class JumpBlock {
isForgeMultipart = true;
newTileEntity = (TileEntity) WarpDriveConfig.forgeMultipart_helper_createTileFromNBT.invoke(null, targetWorld, oldnbt);
} else if (blockID == WarpDriveConfig.CC_Computer || blockID == WarpDriveConfig.CC_peripheral || blockID == WarpDriveConfig.CCT_Turtle || blockID == WarpDriveConfig.CCT_Upgraded || blockID == WarpDriveConfig.CCT_Advanced) {
} else if (block == WarpDriveConfig.CC_Computer || block == WarpDriveConfig.CC_peripheral || block == WarpDriveConfig.CCT_Turtle || block == WarpDriveConfig.CCT_Upgraded || block == WarpDriveConfig.CCT_Advanced) {
newTileEntity = TileEntity.createAndLoadEntity(oldnbt);
newTileEntity.invalidate();
} else if (blockID == WarpDriveConfig.AS_Turbine) {
} /*else if (block == WarpDriveConfig.AS_Turbine) {
if (oldnbt.hasKey("zhuYao")) {
NBTTagCompound nbt1 = oldnbt.getCompoundTag("zhuYao");
nbt1.setDouble("x", newX);
@ -85,23 +86,23 @@ public class JumpBlock {
oldnbt.setTag("zhuYao", nbt1);
}
newTileEntity = TileEntity.createAndLoadEntity(oldnbt);
}
}*/ //No 1.7.10 version
if (newTileEntity == null) {
newTileEntity = TileEntity.createAndLoadEntity(oldnbt);
}
if (newTileEntity != null) {
newTileEntity.worldObj = targetWorld;
newTileEntity.setWorldObj(targetWorld);
newTileEntity.validate();
targetWorld.setBlockTileEntity(newX, newY, newZ, newTileEntity);
targetWorld.setTileEntity(newX, newY, newZ, newTileEntity);
if (isForgeMultipart) {
WarpDriveConfig.forgeMultipart_tileMultipart_onChunkLoad.invoke(newTileEntity);
WarpDriveConfig.forgeMultipart_helper_sendDescPacket.invoke(null, targetWorld, newTileEntity);
}
} else {
WarpDrive.print(" moveBlockSimple failed to create new tile entity at " + x + ", " + y + ", " + z + " blockId " + blockID + ":" + blockMeta);
WarpDrive.print(" moveBlockSimple failed to create new tile entity at " + x + ", " + y + ", " + z + " blockId " + block + ":" + blockMeta);
WarpDrive.print("NBT data was " + ((oldnbt == null) ? "null" : oldnbt.toString()));
}
}
@ -109,7 +110,7 @@ public class JumpBlock {
exception.printStackTrace();
String coordinates = "";
try {
coordinates = " at " + x + ", " + y + ", " + z + " blockId " + blockID + ":" + blockMeta;
coordinates = " at " + x + ", " + y + ", " + z + " blockId " + block + ":" + blockMeta;
} catch (Exception dropMe) {
coordinates = " (unknown coordinates)";
}
@ -120,8 +121,8 @@ public class JumpBlock {
return true;
}
// This code is a straight copy from Vanilla to remove lighting computations
public static boolean mySetBlock(World w, int x, int y, int z, int blockId, int blockMeta, int par6) {
// This code is a straight copy from Vanilla to remove lighting computations //TODO: Copy in new code
public static boolean mySetBlock(World w, int x, int y, int z, Block block, int blockMeta, int par6) {
if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000) {
if (y < 0) {
return false;
@ -130,7 +131,7 @@ public class JumpBlock {
} else {
w.markBlockForUpdate(x, y, z);
Chunk chunk = w.getChunkFromChunkCoords(x >> 4, z >> 4);
return myChunkSBIDWMT(chunk, x & 15, y, z & 15, blockId, blockMeta);
return myChunkSBIDWMT(chunk, x & 15, y, z & 15, block, blockMeta);
}
} else {
return false;
@ -138,7 +139,11 @@ public class JumpBlock {
}
// This code is a straight copy from Vanilla to remove lighting computations
public static boolean myChunkSBIDWMT(Chunk c, int x, int y, int z, int blockId, int blockMeta) {
public static boolean myChunkSBIDWMT(Chunk c, int x, int y, int z, Block block, int blockMeta) {
return true;
//TODO: Find where this came from and copy in new code
/*
int j1 = z << 4 | x;
if (y >= c.precipitationHeightMap[j1] - 1) {
@ -146,17 +151,17 @@ public class JumpBlock {
}
//int k1 = c.heightMap[j1];
int l1 = c.getBlockID(x, y, z);
int i2 = c.getBlockMetadata(x, y, z);
Block bl = c.getBlock(x, y, z);
int blMeta = c.getBlockMetadata(x, y, z);
if (l1 == blockId && i2 == blockMeta) {
if (bl.isAssociatedBlock(block) && blMeta == blockMeta) {
return false;
} else {
ExtendedBlockStorage[] storageArrays = c.getBlockStorageArray();
ExtendedBlockStorage extendedblockstorage = storageArrays[y >> 4];
if (extendedblockstorage == null) {
if (blockId == 0) {
if (block.isAssociatedBlock(Blocks.air)) {
return false;
}
@ -165,21 +170,22 @@ public class JumpBlock {
int j2 = c.xPosition * 16 + x;
int k2 = c.zPosition * 16 + z;
extendedblockstorage.setExtBlockID(x, y & 15, z, blockId);
//TODO: Fix this
//extendedblockstorage.setExtBlock(x, y & 15, z, block);
if (l1 != 0) {
if (bl != 0) {
if (!c.worldObj.isRemote) {
Block.blocksList[l1].breakBlock(c.worldObj, j2, y, k2, l1, i2);
} else if (Block.blocksList[l1] != null && Block.blocksList[l1].hasTileEntity(i2)) {
Block.blocksList[bl].breakBlock(c.worldObj, j2, y, k2, bl, blMeta);
} else if (Block.blocksList[bl] != null && Block.blocksList[bl].hasTileEntity(blMeta)) {
TileEntity te = c.worldObj.getBlockTileEntity(j2, y, k2);
if (te != null && te.shouldRefresh(l1, blockId, i2, blockMeta, c.worldObj, j2, y, k2)) {
if (te != null && te.shouldRefresh(bl, block, blMeta, blockMeta, c.worldObj, j2, y, k2)) {
c.worldObj.removeBlockTileEntity(j2, y, k2);
}
}
}
if (extendedblockstorage.getExtBlockID(x, y & 15, z) != blockId) {
if (extendedblockstorage.getExtBlockID(x, y & 15, z) != block) {
return false;
} else {
extendedblockstorage.setExtBlockMetadata(x, y & 15, z, blockMeta);
@ -198,16 +204,16 @@ public class JumpBlock {
c.propagateSkylightOcclusion(par1, par3);
}
/**/
//
TileEntity tileentity;
if (blockId != 0) {
if (Block.blocksList[blockId] != null && Block.blocksList[blockId].hasTileEntity(blockMeta)) {
if (block != 0) {
if (Block.blocksList[block] != null && Block.blocksList[block].hasTileEntity(blockMeta)) {
tileentity = c.getChunkBlockTileEntity(x, y, z);
if (tileentity == null) {
tileentity = Block.blocksList[blockId].createTileEntity(c.worldObj, blockMeta);
c.worldObj.setBlockTileEntity(j2, y, k2, tileentity);
tileentity = Block.blocksList[block].createTileEntity(c.worldObj, blockMeta);
c.worldObj.setTileEntity(j2, y, k2, tileentity);
}
if (tileentity != null) {
@ -221,5 +227,6 @@ public class JumpBlock {
return true;
}
}
*/
}
}

View file

@ -155,8 +155,8 @@ public class TileEntityShipScanner extends WarpEnergyTE {
JumpBlock jb = blocksToDeploy[currentDeployIndex];
if (jb != null &&
jb.blockID != Block.bedrock.blockID &&
!WarpDriveConfig.scannerIgnoreBlocks.contains(jb.blockID) &&
jb.block != Block.bedrock.blockID &&
!WarpDriveConfig.scannerIgnoreBlocks.contains(jb.block) &&
worldObj.isAirBlock(targetX + jb.x, targetY + jb.y, targetZ + jb.z)) {
jb.deploy(worldObj, targetX, targetY, targetZ);
@ -499,18 +499,18 @@ public class TileEntityShipScanner extends WarpEnergyTE {
jb.x = x;
jb.y = y;
jb.z = z;
jb.blockID = (localBlocks[index]) & 0xFF;
jb.block = (localBlocks[index]) & 0xFF;
if (extraBlocks != null) {
jb.blockID |= ((extraBlocks[index]) & 0xFF) << 8;
jb.block |= ((extraBlocks[index]) & 0xFF) << 8;
}
jb.blockMeta = (localMetadata[index]) & 0xFF;
jb.blockNBT = tileEntities[index];
if (jb.blockID != 0 && Block.blocksList[jb.blockID] != null) {
if (jb.block != 0 && Block.blocksList[jb.block] != null) {
if (tileEntities[index] == null) {
WarpDrive.debugPrint("[ShipScanner] Adding block to deploy: " + Block.blocksList[jb.blockID].getUnlocalizedName() + " (no tile entity)");
WarpDrive.debugPrint("[ShipScanner] Adding block to deploy: " + Block.blocksList[jb.block].getUnlocalizedName() + " (no tile entity)");
} else {
WarpDrive.debugPrint("[ShipScanner] Adding block to deploy: " + Block.blocksList[jb.blockID].getUnlocalizedName() + " with tile entity " + tileEntities[index].getString("id"));
WarpDrive.debugPrint("[ShipScanner] Adding block to deploy: " + Block.blocksList[jb.block].getUnlocalizedName() + " with tile entity " + tileEntities[index].getString("id"));
}
blocksToDeploy[index] = jb;

View file

@ -134,7 +134,7 @@ public final class EntitySphereGen extends Entity
break;
notifyFlag = (currentIndex % 1000 == 0 ? 2 : 0);
JumpBlock jb = blocks.get(currentIndex);
JumpBlock.mySetBlock(worldObj, jb.x, jb.y, jb.z, jb.blockID, jb.blockMeta, notifyFlag);
JumpBlock.mySetBlock(worldObj, jb.x, jb.y, jb.z, jb.block, jb.blockMeta, notifyFlag);
currentIndex++;
}
@ -206,7 +206,7 @@ public final class EntitySphereGen extends Entity
if (worldObj.getBlockId(jb.x, jb.y, jb.z) == Block.leaves.blockID) {
if (worldObj.rand.nextInt(50) != 1)
{
jb.blockID = WarpDriveConfig.gasID;
jb.block = WarpDriveConfig.gasID;
jb.blockMeta = gasColor;
}
blocks.add(jb);