Bugfixes, warp perfomance improvement, isolation

Fixed critical ship duplication bug
Added checking for intersection of warp-fields of ships
Improved block movement perfomance
Added warp-isolation blocks to hide warp core from radars
Fixed TileEntity movement bug
This commit is contained in:
Anus 2013-06-18 17:12:21 +04:00
parent 95bc6cf0d9
commit 409b812061
8 changed files with 508 additions and 115 deletions

View file

@ -98,5 +98,15 @@ public class BlockReactor extends BlockContainer {
if (reactor != null){
par5EntityPlayer.sendChatToPlayer(reactor.getCoreState());
}
}
}
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te instanceof TileEntityReactor) {
WarpDrive.instance.registry.removeFromRegistry((TileEntityReactor)te);
}
}
}

View file

@ -0,0 +1,59 @@
package cr0s.WarpDrive;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class BlockWarpIsolation extends BlockContainer {
private Icon[] iconBuffer;
BlockWarpIsolation(int id, int texture, Material material) {
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[1];
iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:warpIsolation");
}
@Override
public Icon getIcon(int side, int metadata)
{
return iconBuffer[0];
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileEntityProtocol();
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random)
{
return 1;
}
/**
* Returns the ID of the items to drop on destruction.
*/
@Override
public int idDropped(int par1, Random par2Random, int par3)
{
return this.blockID;
}
}

View file

@ -15,6 +15,8 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraftforge.common.DimensionManager;
public class EntityJump extends Entity {
@ -51,7 +53,7 @@ public class EntityJump extends Entity {
boolean isJumping = false;
int currentIndexInShip = 0;
private final int BLOCKS_PER_TICK = 1250;
private final int BLOCKS_PER_TICK = 3000;
private List entityOnShip;
@ -62,6 +64,8 @@ public class EntityJump extends Entity {
int destX, destZ;
boolean isCoordJump;
long msCounter = 0;
public EntityJump(World world) {
super(world);
}
@ -87,15 +91,15 @@ public class EntityJump extends Entity {
this.dz = _dz;
Xmax = Zmax = maxY = Xmin = Zmin = minY = 0;
System.out.println("[JE] Entity created");
this.reactor = parReactor;
this.isJumping = false;
}
public void killEntity(String reason) {
System.out.println("[JE] Tick:");
if (!on) { return; }
on = false;
@ -117,14 +121,14 @@ public class EntityJump extends Entity {
@SideOnly(Side.SERVER)
@Override
public void onUpdate() {
if (!on) {
if (!on || worldObj.getBlockId(xCoord, yCoord, zCoord) != WarpDrive.WARP_CORE_BLOCKID) {
unlockWorlds();
worldObj.removeEntity(this);
return;
}
if (minY < 0 || maxY > 255) {
this.killEntity("Y-coord error!");
if (minY < 0 || maxY > 256) {
killEntity("Y-coord error!");
return;
}
@ -200,11 +204,11 @@ public class EntityJump extends Entity {
if (entity instanceof EntityPlayer) {
if (!removeBlocks) {
worldObj.setBlock(me.oldX, me.oldY - 2, me.oldZ, Block.dirt.blockID);
mySetBlock(worldObj, me.oldX, me.oldY - 2, me.oldZ, Block.dirt.blockID, 0, 1 + 2);
} else
{
if (worldObj.getBlockId(me.oldX, me.oldY - 2, me.oldZ) == Block.dirt.blockID) {
worldObj.setBlock(me.oldX, me.oldY - 2, me.oldZ, 0);
mySetBlock(worldObj, me.oldX, me.oldY - 2, me.oldZ, 0, 0, 1 + 2);
}
}
}
@ -309,7 +313,9 @@ public class EntityJump extends Entity {
setBlocksUnderPlayers(false);
isJumping = true;
this.currentIndexInShip = 0;
this.currentIndexInShip = 0;
msCounter = System.currentTimeMillis();
}
/**
@ -321,6 +327,8 @@ public class EntityJump extends Entity {
removeShip();
System.out.println("[JE] Finished. Jump took " + ((System.currentTimeMillis() - msCounter) / 1000F) + " seconds");
// Прыжок окончен
killEntity("");
}
@ -386,7 +394,7 @@ public class EntityJump extends Entity {
*/
public void moveShip() {
int blocksToMove = Math.min(BLOCKS_PER_TICK, ship.length - this.currentIndexInShip);
System.out.println("[JE] Moving ship part: " + currentIndexInShip + "/" + ship.length + " [btm: " + blocksToMove + "]");
// 1. Jump to space
@ -995,51 +1003,60 @@ public class EntityJump extends Entity {
if (!toSpace && !fromSpace)
{
worldObj.setBlock(newX, newY, newZ, blockID, blockMeta, 2);
mySetBlock(worldObj, newX, newY, newZ, blockID, blockMeta, 2);
} else if (toSpace)
{
spaceWorld.setBlock(newX, newY, newZ, blockID, blockMeta, 2);
mySetBlock(spaceWorld, newX, newY, newZ, blockID, blockMeta, 2);
} else if (fromSpace) {
surfaceWorld.setBlock(newX, newY, newZ, blockID, blockMeta, 2);
mySetBlock(surfaceWorld, newX, newY, newZ, blockID, blockMeta, 2);
}
NBTTagCompound oldnbt = new NBTTagCompound();
if (shipBlock.blockTileEntity != null && blockID != 159 && blockID != 149 && blockID != 156 && blockID != 146 && blockID != 145) {
shipBlock.blockTileEntity.writeToNBT(oldnbt);
TileEntity newTileEntity = null;
oldnbt.setInteger("x", newX);
oldnbt.setInteger("y", newY);
oldnbt.setInteger("z", newZ);
// CC's computers and turtles moving workaround
if (blockID == 1225 || blockID == 1227 || blockID == 1228) {
oldnbt.setInteger("x", newX);
oldnbt.setInteger("y", newY);
oldnbt.setInteger("z", newZ);
newTileEntity = TileEntity.createAndLoadEntity(oldnbt);
newTileEntity.invalidate();
/*if (!toSpace && !fromSpace) {
newTileEntity = worldObj.getBlockTileEntity(newX, newY, newZ);
} else if (toSpace) {
newTileEntity = spaceWorld.getBlockTileEntity(newX, newY, newZ);
} else if (fromSpace) {
newTileEntity = surfaceWorld.getBlockTileEntity(newX, newY, newZ);
}*/
if (newTileEntity == null) {
System.out.println("PIZDEC!!!");
return false; // PIZDEC!!!
newTileEntity = TileEntity.createAndLoadEntity(oldnbt);
newTileEntity.invalidate();
} else {
if (!toSpace && !fromSpace) {
newTileEntity = worldObj.getBlockTileEntity(newX, newY, newZ);
} else if (toSpace) {
newTileEntity = spaceWorld.getBlockTileEntity(newX, newY, newZ);
} else if (fromSpace) {
newTileEntity = surfaceWorld.getBlockTileEntity(newX, newY, newZ);
}
if (newTileEntity == null) {
System.out.println("[EJ] Error moving tileEntity! TE is null");
return false;
}
newTileEntity.invalidate();
newTileEntity.readFromNBT(oldnbt);
if (!toSpace && !fromSpace)
{
worldObj.setBlockTileEntity(newX, newY, newZ, newTileEntity);
} else if (toSpace)
{
//newTileEntity.worldObj = spaceWorld;
spaceWorld.setBlockTileEntity(newX, newY, newZ, newTileEntity);
} else if (fromSpace) {
//newTileEntity.worldObj = surfaceWorld;
surfaceWorld.setBlockTileEntity(newX, newY, newZ, newTileEntity);
}
}
/*
newTileEntity.invalidate();
newTileEntity.readFromNBT(oldnbt);
newTileEntity.xCoord = newX;
newTileEntity.yCoord = newY;
newTileEntity.zCoord = newZ;
*/
newTileEntity.worldObj = getTargetWorld();
newTileEntity.worldObj = getTargetWorld();
newTileEntity.validate();
if (!toSpace && !fromSpace)
@ -1047,20 +1064,12 @@ public class EntityJump extends Entity {
worldObj.setBlockTileEntity(newX, newY, newZ, newTileEntity);
} else if (toSpace)
{
//newTileEntity.worldObj = spaceWorld;
spaceWorld.setBlockTileEntity(newX, newY, newZ, newTileEntity);
} else if (fromSpace) {
//newTileEntity.worldObj = surfaceWorld;
surfaceWorld.setBlockTileEntity(newX, newY, newZ, newTileEntity);
}
worldObj.removeBlockTileEntity(oldX, oldY, oldZ);
if (newTileEntity.getClass().getName().contains("TileEntityComputer") && newTileEntity instanceof IPeripheral)
{
System.out.println(((IPeripheral)newTileEntity).getMethodNames());
}
}
} catch (Exception exception) {
exception.printStackTrace();
@ -1075,26 +1084,150 @@ public class EntityJump extends Entity {
}
@Override
protected void entityInit() {
//onUpdate();
protected void entityInit() {
}
@Override
protected void writeEntityToNBT(NBTTagCompound var1) {
}
/*
@Override
protected void entityInit() {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected void readEntityFromNBT(NBTTagCompound var1) {
throw new UnsupportedOperationException("Not supported yet.");
}
// Own implementation of setting blocks withow light recalculation in optimization purposes
public boolean mySetBlock(World w, int par1, int par2, int par3, int par4, int par5, int par6)
{
if (par1 >= -30000000 && par3 >= -30000000 && par1 < 30000000 && par3 < 30000000)
{
if (par2 < 0)
{
return false;
}
else if (par2 >= 256)
{
return false;
}
else
{
w.markBlockForUpdate(par1, par2, par3);
Chunk chunk = w.getChunkFromChunkCoords(par1 >> 4, par3 >> 4);
@Override
protected void writeEntityToNBT(NBTTagCompound var1) {
throw new UnsupportedOperationException("Not supported yet.");
}*/
return myChunkSBIDWMT(chunk, par1 & 15, par2, par3 & 15, par4, par5);
}
}
else
{
return false;
}
}
// Incapsulation violation warning:
// field Chunk.storageArrays has been turned from private to public in class Chunk.java
public boolean myChunkSBIDWMT(Chunk c, int par1, int par2, int par3, int par4, int par5)
{
int j1 = par3 << 4 | par1;
if (par2 >= c.precipitationHeightMap[j1] - 1)
{
c.precipitationHeightMap[j1] = -999;
}
int k1 = c.heightMap[j1];
int l1 = c.getBlockID(par1, par2, par3);
int i2 = c.getBlockMetadata(par1, par2, par3);
if (l1 == par4 && i2 == par5)
{
return false;
}
else
{
ExtendedBlockStorage extendedblockstorage = c.storageArrays[par2 >> 4];
if (extendedblockstorage == null)
{
if (par4 == 0)
{
return false;
}
extendedblockstorage = c.storageArrays[par2 >> 4] = new ExtendedBlockStorage(par2 >> 4 << 4, !c.worldObj.provider.hasNoSky);
}
int j2 = c.xPosition * 16 + par1;
int k2 = c.zPosition * 16 + par3;
extendedblockstorage.setExtBlockID(par1, par2 & 15, par3, par4);
if (l1 != 0)
{
if (!c.worldObj.isRemote)
{
Block.blocksList[l1].breakBlock(c.worldObj, j2, par2, k2, l1, i2);
}
else if (Block.blocksList[l1] != null && Block.blocksList[l1].hasTileEntity(i2))
{
TileEntity te = worldObj.getBlockTileEntity(j2, par2, k2);
if (te != null && te.shouldRefresh(l1, par4, i2, par5, worldObj, j2, par2, k2))
{
c.worldObj.removeBlockTileEntity(j2, par2, k2);
}
}
}
if (extendedblockstorage.getExtBlockID(par1, par2 & 15, par3) != par4)
{
return false;
}
else
{
extendedblockstorage.setExtBlockMetadata(par1, par2 & 15, par3, par5);
// Removed light recalcalations
/*if (flag)
{
c.generateSkylightMap();
}
else
{
if (c.getBlockLightOpacity(par1, par2, par3) > 0)
{
if (par2 >= k1)
{
c.relightBlock(par1, par2 + 1, par3);
}
}
else if (par2 == k1 - 1)
{
c.relightBlock(par1, par2, par3);
}
c.propagateSkylightOcclusion(par1, par3);
}*/
TileEntity tileentity;
if (par4 != 0)
{
if (Block.blocksList[par4] != null && Block.blocksList[par4].hasTileEntity(par5))
{
tileentity = c.getChunkBlockTileEntity(par1, par2, par3);
if (tileentity == null)
{
tileentity = Block.blocksList[par4].createTileEntity(c.worldObj, par5);
c.worldObj.setBlockTileEntity(j2, par2, k2, tileentity);
}
if (tileentity != null)
{
tileentity.updateContainingBlockInfo();
tileentity.blockMetadata = par5;
}
}
}
c.isModified = true;
return true;
}
}
}
}

View file

@ -49,7 +49,7 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral {
"get_x", "get_y", "get_z", // 10, 11, 12
"get_energy_level", "do_jump", "get_ship_size", // 13, 14, 15
"set_beacon_frequency", "get_dx", "get_dz", // 16, 17, 18
"set_core_frequency", // 19
"set_core_frequency", "is_in_space", // 19, 20
};
private int ticks = 0;
@ -92,7 +92,9 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral {
}
private void doJump() {
//System.out.println("Jumping!");
if (core != null && core instanceof TileEntityReactor) {
((TileEntityReactor)core).randomCooldownAddition = worldObj.rand.nextInt(60); // Adding random ticks to cooldown
}
setJumpFlag(true);
}
@ -497,7 +499,11 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral {
{
((TileEntityReactor)core).coreFrequency = ((String)arguments[0]);
}
break;
break;
case 20: // is_in_space
return new Boolean[] { worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID };
}
return new Integer[] { 0 };

View file

@ -17,11 +17,13 @@ public class TileEntityRadar extends TileEntity implements IPeripheral, IEnergyS
private int currentEnergyValue = 0;
private String[] methodsArray = {
"scanRay", // 0
"scanRadiusW", // 1
"getResultsCountW", // 2
"getResultW", // 3
"getEnergyLevel" // 4
"scanRay", // 0
"scanRadiusW", // 1
"getResultsCountW", // 2
"getResultW", // 3
"getEnergyLevel", // 4
"getRadarX", "getRadarY", "getRadarZ", // 5, 6, 7
};
private ArrayList<TileEntityReactor> results;
@ -38,15 +40,18 @@ public class TileEntityRadar extends TileEntity implements IPeripheral, IEnergyS
@SideOnly(Side.SERVER)
@Override
public void updateEntity() {
if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 2) {
if (cooldownTime++ > (20 * ((scanRadius / 1000) + 1))) {
//System.out.println("Scanning...");
results = WarpDrive.instance.registry.searchWarpCoresInRadius(xCoord, yCoord, zCoord, scanRadius);
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 + 2);
cooldownTime = 0;
try {
if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 2) {
if (cooldownTime++ > (20 * ((scanRadius / 1000) + 1))) {
//System.out.println("Scanning...");
WarpDrive.instance.registry.removeDeadCores();
results = WarpDrive.instance.registry.searchWarpCoresInRadius(xCoord, yCoord, zCoord, scanRadius);
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 + 2);
cooldownTime = 0;
}
}
}
} catch (Exception e) { e.printStackTrace(); }
}
@Override
@ -128,9 +133,18 @@ public class TileEntityRadar extends TileEntity implements IPeripheral, IEnergyS
}
}
case 4:
case 4: // getEnergyLevel
return new Integer[] { this.getCurrentEnergyValue()};
case 5: // getRadarX
return new Integer[] { this.xCoord };
case 6: // getRadarY
return new Integer[] { this.yCoord };
case 7: // getRadarZ
return new Integer[] { this.zCoord };
}
return new Object[] { 0 };

View file

@ -76,32 +76,37 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
private final byte MODE_BEACON_JUMP = 4; // Jump ship by beacon
private final byte MODE_TELEPORT = 0; // Телепортация игроков в космос
private final int MAX_JUMP_DISTANCE_BY_COUNTER = 128; // Максимальное значение длинны прыжка с счётчика длинны
private final int MAX_SHIP_VOLUME_ON_SURFACE = 50000; // Максимальный объем корабля для прыжков не в космосе (50k блоков)
private final int MAX_SHIP_SIDE = 100; // Максимальная длинна одного из измерений корабля (ширина, высота, длина)
private final int MAX_SHIP_VOLUME_ON_SURFACE = 10000; // Максимальный объем корабля для прыжков не в космосе (10k блоков)
public final int MAX_SHIP_SIDE = 100; // Максимальная длинна одного из измерений корабля (ширина, высота, длина)
int cooldownTime = 0;
private final int COOLDOWN_INTERVAL_SECONDS = 5;
private final int COOLDOWN_INTERVAL_SECONDS = 3;
public int randomCooldownAddition = 0;
private final int CORES_REGISTRY_UPDATE_INTERVAL_SECONDS = 10;
private int registryUpdateTicks = 0;
public String coreFrequency = "default";
// = Привязка игроков =
public String coreState = "";
public int isolationBlocksCount = 0;
public int isolationUpdateTicks = 0;
private final int ISOLATION_UPDATE_INTARVAL_SECONDS = 10;
public String coreState = "";
public TileEntityProtocol controller;
@SideOnly(Side.SERVER)
@Override
public void updateEntity() {
// Update warp core in cores registry
if (registryUpdateTicks++ > CORES_REGISTRY_UPDATE_INTERVAL_SECONDS * 20) {
if (++registryUpdateTicks > CORES_REGISTRY_UPDATE_INTERVAL_SECONDS * 20) {
registryUpdateTicks = 0;
WarpDrive.instance.registry.addToRegistry(this);
WarpDrive.instance.registry.updateInRegistry(this);
}
if (++isolationUpdateTicks > ISOLATION_UPDATE_INTARVAL_SECONDS * 20) {
isolationUpdateTicks = 0;
updateIsolationState();
}
TileEntity c = findControllerBlock();
@ -145,34 +150,108 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
// Set up activated animation
if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0)
{
// TODO: check for "warpcore turns into dirt" bug
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 + 2); // Set block state to "active"
makePlayersOnShipDrunk();
}
// Awaiting cooldown time
if ((currentMode != MODE_BASIC_JUMP) && cooldownTime++ < COOLDOWN_INTERVAL_SECONDS * 20)
if (currentMode != MODE_BASIC_JUMP && cooldownTime++ < ((COOLDOWN_INTERVAL_SECONDS) * 20) + randomCooldownAddition)
{
return;
}
cooldownTime = 0; // Reset cooldown
cooldownTime = 0;
if (!prepareToJump()) {
return;
}
if (WarpDrive.instance.registry.isWarpCoreIntersectsWithOthers(this)) {
this.controller.setJumpFlag(false);
messageToAllPlayersOnShip("Warp field intersects with other ship's field. Cannot jump.");
return;
}
System.out.println("[W-C] Jumping!");
prepareToJump();
doJump(currentMode == MODE_LONG_JUMP);
controller.setJumpFlag(false);
} else
{
// TODO: check to "warpcore turns into dirt" bug
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 + 2); // Deactivate block animation
}
break;
}
}
public void messageToAllPlayersOnShip(String msg) {
AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, axisalignedbb);
for (Object o : list) {
if (o == null || !(o instanceof EntityPlayer)) {
continue;
}
// Set "drunk" effect
((EntityPlayer)o).sendChatToPlayer("[WarpCore] " + msg);
}
}
public void updateIsolationState() {
// Search block in cube around core with side 10
int xmax, ymax, zmax, x1, x2, z1, z2;
int xmin, ymin, zmin;
final int ISOLATION_CUBE_SIDE = 6;
x1 = xCoord + ((ISOLATION_CUBE_SIDE / 2) -1);
x2 = xCoord - ((ISOLATION_CUBE_SIDE / 2) -1);
if (x1 < x2) {
xmin = x1;
xmax = x2;
} else
{
xmin = x2;
xmax = x1;
}
z1 = zCoord + ((ISOLATION_CUBE_SIDE / 2) -1);
z2 = zCoord - ((ISOLATION_CUBE_SIDE / 2) -1);
if (z1 < z2) {
zmin = z1;
zmax = z2;
} else
{
zmin = z2;
zmax = z1;
}
ymax = yCoord + ((ISOLATION_CUBE_SIDE / 2) -1);
ymin = yCoord - ((ISOLATION_CUBE_SIDE / 2) -1);
this.isolationBlocksCount = 0;
// Search for warp isolation blocks
for (int y = ymin; y <= ymax; y++) {
for (int x = xmin; x <= xmax; x++) {
for (int z = zmin; z <= zmax; z++) {
if (worldObj.getBlockId(x, y, z) == WarpDrive.ISOLATION_BLOCKID) {
this.isolationBlocksCount++;
}
}
}
}
}
public void makePlayersOnShipDrunk() {
prepareToJump();
if (!prepareToJump()) { return; }
AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, axisalignedbb);
@ -227,7 +306,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
}
}
public void prepareToJump() {
public boolean prepareToJump() {
this.direction = controller.getDirection();
this.shipFront = controller.getFront();
@ -238,13 +317,15 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
this.shipLeft = controller.getLeft();
this.shipDown = controller.getDown();
this.distance = Math.min(128, controller.getDistance());
this.distance = Math.min(this.MAX_JUMP_DISTANCE_BY_COUNTER, controller.getDistance());
calculateSpatialShipParameters();
return calculateSpatialShipParameters();
}
public void calculateSpatialShipParameters() {
public boolean calculateSpatialShipParameters() {
boolean res = false;
int x1 = 0, x2 = 0, z1 = 0, z2 = 0;
if (Math.abs(dx) > 0) {
@ -316,7 +397,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
this.coreState += "\n * Ship is too big (w: " + shipWidth + "; h: " + shipHeight + "; l: " + shipLength + ")";
System.out.println(coreState);
this.controller.setJumpFlag(false);
return;
return false;
}
this.shipVolume = getRealShipVolume();
@ -324,7 +405,11 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
if (shipVolume > MAX_SHIP_VOLUME_ON_SURFACE && worldObj.provider.dimensionId != WarpDrive.instance.spaceDimID) {
coreState = "Energy: " + currentEnergyValue + "; Ship blocks: " + shipVolume + "\n";
this.coreState += "\n * Ship is too big (w: " + shipWidth + "; h: " + shipHeight + "; l: " + shipLength + ")";
}
this.controller.setJumpFlag(false);
return false;
}
return true;
}
private void doBeaconJump() {
@ -688,6 +773,10 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
// Сколько нужно энергии
@Override
public int demandsEnergy() {
if (this.controller != null && controller.getMode() == 0) {
return 0;
}
return (maxEnergyValue - currentEnergyValue);
}
@ -731,8 +820,8 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
super.readFromNBT(tag);
currentEnergyValue = tag.getInteger("energy");
coreFrequency = tag.getString("corefrequency");
WarpDrive.instance.registry.addToRegistry(this);
isolationBlocksCount = tag.getInteger("isolation");
WarpDrive.instance.registry.updateInRegistry(this);
}
@Override
@ -741,6 +830,8 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
tag.setInteger("energy", currentEnergyValue);
tag.setString("corefrequency", coreFrequency);
tag.setInteger("isolation", this.isolationBlocksCount);
}
@Override
@ -754,6 +845,6 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
public void validate() {
super.validate();
WarpDrive.instance.registry.addToRegistry(this);
WarpDrive.instance.registry.updateInRegistry(this);
}
}

View file

@ -5,6 +5,7 @@
package cr0s.WarpDrive;
import java.util.ArrayList;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
/**
@ -13,13 +14,14 @@ import net.minecraft.util.MathHelper;
*/
public class WarpCoresRegistry {
private ArrayList<TileEntityReactor> registry;
public WarpCoresRegistry() {
registry = new ArrayList<TileEntityReactor>();
}
public int searchCoreInRegistry(TileEntityReactor core) {
int res = -1;
for (int i = 0; i < registry.size(); i++) {
TileEntityReactor c = registry.get(i);
@ -35,8 +37,14 @@ public class WarpCoresRegistry {
return (searchCoreInRegistry(core) != -1);
}
public void addToRegistry(TileEntityReactor core) {
if (!isCoreInRegistry(core)) {
public void updateInRegistry(TileEntityReactor core) {
int idx = searchCoreInRegistry(core);
// update
if (idx != -1) {
registry.set(idx, core);
} else
{
registry.add(core);
}
}
@ -59,9 +67,8 @@ public class WarpCoresRegistry {
double distance = MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
if (distance <= radius)
if (distance <= radius && !(c.controller == null || c.controller.getMode() == 0) && !isCoreHidden(c))
{
System.out.println("Scan: " + MathHelper.floor_double(distance) + " <= " + radius);
res.add(c);
}
}
@ -71,9 +78,71 @@ public class WarpCoresRegistry {
public void printRegistry() {
System.out.println("WarpCores registry:");
removeDeadCores();
for (TileEntityReactor c : registry) {
System.out.println(c.coreFrequency + " (" + c.xCoord + "; " + c.yCoord + "; " + c.zCoord + ")");
}
}
final int LOWER_HIDE_POINT = 18;
private boolean isCoreHidden(TileEntityReactor core) {
if (core.isolationBlocksCount > 5) {
int randomNumber = core.worldObj.rand.nextInt(150);
if (randomNumber < LOWER_HIDE_POINT + core.isolationBlocksCount)
{
return true;
}
}
return false;
}
public boolean isWarpCoreIntersectsWithOthers(TileEntityReactor core) {
AxisAlignedBB aabb1, aabb2;
for (TileEntityReactor c : registry) {
// Skip self
if(c.xCoord == core.xCoord && c.yCoord == core.yCoord && c.zCoord == core.zCoord) {
continue;
}
// Skip offline warp cores
if (c.controller == null || c.controller.getMode() == 0) {
continue;
}
// Search for nearest warp cores
double d3 = c.xCoord - core.xCoord;
double d4 = c.yCoord - core.yCoord;
double d5 = c.zCoord - core.zCoord;
double distance = MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
if (distance <= (2 * core.MAX_SHIP_SIDE) - 1)
{
// Check for warpfields intersections
core.prepareToJump(); // calculate spatial parameters
c.prepareToJump();
// Compare warp-fields for intersection
aabb1 = AxisAlignedBB.getBoundingBox(core.minX, core.minY, core.minZ, core.maxX, core.maxY, core.maxZ);
aabb2 = AxisAlignedBB.getBoundingBox(c.minX, c.minY, c.minZ, c.maxX, c.maxY, c.maxZ);
if (aabb1.intersectsWith(aabb2)) {
return true;
}
}
}
return false;
}
public void removeDeadCores() {
for (TileEntityReactor c : registry) {
if (c != null && c.worldObj != null && c.worldObj.getBlockId(c.xCoord, c.yCoord, c.zCoord) != WarpDrive.WARP_CORE_BLOCKID) {
this.removeFromRegistry(c);
return;
}
}
}
}

View file

@ -32,6 +32,7 @@ public class WarpDrive {
public final static int WARP_CORE_BLOCKID = 500;
public final static int PROTOCOL_BLOCK_BLOCKID = 501;
public final static int RADAR_BLOCK_BLOCKID = 502;
public final static int ISOLATION_BLOCKID = 503;
public final static Block warpCore = new BlockReactor(WARP_CORE_BLOCKID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
@ -44,6 +45,10 @@ public class WarpDrive {
public final static Block radarBlock = new BlockRadar(RADAR_BLOCK_BLOCKID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("W-Radar");
public final static Block isolationBlock = new BlockWarpIsolation(ISOLATION_BLOCKID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Warp-Field Isolation Block");
/**
*
*/
@ -78,6 +83,9 @@ public class WarpDrive {
LanguageRegistry.addName(radarBlock, "W-Radar");
GameRegistry.registerBlock(radarBlock, "radarBlock");
GameRegistry.registerTileEntity(TileEntityRadar.class, "radarBlock");
LanguageRegistry.addName(isolationBlock, "Warp-Field Isolation Block");
GameRegistry.registerBlock(isolationBlock, "isolationBlock");
proxy.registerRenderers();
@ -103,7 +111,10 @@ public class WarpDrive {
'i', Items.getItem("iridiumPlate"), 'm', Items.getItem("advancedMachine"), 'c', Items.getItem("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(radarBlock), "ifi", "imi", "imi",
'i', Items.getItem("iridiumPlate"), 'm', Items.getItem("advancedMachine"), 'f', Items.getItem("frequencyTransmitter"));
'i', Items.getItem("iridiumPlate"), 'm', Items.getItem("advancedMachine"), 'f', Items.getItem("frequencyTransmitter"));
GameRegistry.addRecipe(new ItemStack(isolationBlock), "iii", "idi", "iii",
'i', Items.getItem("iridiumPlate"), 'm', Items.getItem("advancedMachine"), 'd', Block.blockDiamond);
registry = new WarpCoresRegistry();
}