More Rift Fixes

--Changed BlockRift to use ITileEntityProvider instead of BlockContainer
--Reorganized some of the code in TileEntityRift to improve performance
and readability
This commit is contained in:
SenseiKiwi
2014-01-05 02:51:18 -04:00
parent a5e5ea3921
commit 25f446a05b
3 changed files with 75 additions and 90 deletions

View File

@@ -8,6 +8,7 @@ import java.util.Random;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@@ -28,7 +29,7 @@ import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
public class BlockRift extends BlockContainer public class BlockRift extends Block implements ITileEntityProvider
{ {
private static final float MIN_IMMUNE_HARDNESS = 200.0F; private static final float MIN_IMMUNE_HARDNESS = 200.0F;
private static final int BLOCK_DESTRUCTION_RANGE = 4; private static final int BLOCK_DESTRUCTION_RANGE = 4;
@@ -107,7 +108,6 @@ public class BlockRift extends BlockContainer
@Override @Override
public boolean canCollideCheck(int par1, boolean par2) public boolean canCollideCheck(int par1, boolean par2)
{ {
return par2; return par2;
} }
@@ -125,11 +125,10 @@ public class BlockRift extends BlockContainer
@Override @Override
public int getRenderType() public int getRenderType()
{ {
if(mod_pocketDim.isPlayerWearingGoogles) if (mod_pocketDim.isPlayerWearingGoogles)
{ {
return 0; return 0;
} }
return 8; return 8;
} }
@@ -154,8 +153,6 @@ public class BlockRift extends BlockContainer
return null; return null;
} }
//function that regulates how many blocks it eats/ how fast it eats them. //function that regulates how many blocks it eats/ how fast it eats them.
@Override @Override
public void updateTick(World world, int x, int y, int z, Random random) public void updateTick(World world, int x, int y, int z, Random random)
@@ -166,12 +163,11 @@ public class BlockRift extends BlockContainer
//Randomly decide whether to search for blocks to destroy. This reduces the frequency of search operations, //Randomly decide whether to search for blocks to destroy. This reduces the frequency of search operations,
//moderates performance impact, and controls the apparent speed of block destruction. //moderates performance impact, and controls the apparent speed of block destruction.
if (random.nextInt(MAX_BLOCK_SEARCH_CHANCE) < BLOCK_SEARCH_CHANCE && if (random.nextInt(MAX_BLOCK_SEARCH_CHANCE) < BLOCK_SEARCH_CHANCE &&
((TileEntityRift) world.getBlockTileEntity(x, y, z)).isNearRift() ) ((TileEntityRift) world.getBlockTileEntity(x, y, z)).updateNearestRift() )
{ {
destroyNearbyBlocks(world, x, y, z, random); destroyNearbyBlocks(world, x, y, z, random);
} }
} }
} }
private void destroyNearbyBlocks(World world, int x, int y, int z, Random random) private void destroyNearbyBlocks(World world, int x, int y, int z, Random random)
@@ -368,7 +364,7 @@ public class BlockRift extends BlockContainer
} }
@Override @Override
public TileEntity createNewTileEntity(World var1) public TileEntity createNewTileEntity(World world)
{ {
return new TileEntityRift(); return new TileEntityRift();
} }

View File

@@ -15,7 +15,6 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
@SuppressWarnings("deprecation")
public class TransientDoor extends BaseDimDoor public class TransientDoor extends BaseDimDoor
{ {
public TransientDoor(int blockID, Material material, DDProperties properties) public TransientDoor(int blockID, Material material, DDProperties properties)

View File

@@ -21,6 +21,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.ServerPacketHandler; import StevenDimDoors.mod_pocketDim.ServerPacketHandler;
import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.DimLink;
@@ -30,25 +31,27 @@ import StevenDimDoors.mod_pocketDim.util.Point4D;
public class TileEntityRift extends TileEntity public class TileEntityRift extends TileEntity
{ {
private static final int MAX_SPREAD_ATTEMPTS = 3;
private static final int MAX_SEARCH_ATTEMPTS = 50;
private static final int MAX_ANCESTOR_LINKS = 3;
private static final int ENDERMAN_SPAWNING_CHANCE = 1; private static final int ENDERMAN_SPAWNING_CHANCE = 1;
private static final int MAX_ENDERMAN_SPAWNING_CHANCE = 32; private static final int MAX_ENDERMAN_SPAWNING_CHANCE = 32;
private static Random random = new Random(); private static Random random = new Random();
private int age = 0;
private int count = 0;
private int count2 = 0;
public int xOffset = 0; public int xOffset = 0;
public int yOffset = 0; public int yOffset = 0;
public int zOffset = 0; public int zOffset = 0;
private boolean hasGrownRifts = false;
public boolean shouldClose = false; public boolean shouldClose = false;
private int count = 0;
private int count2 = 0;
private int age = 0;
private boolean hasUpdated = false; private boolean hasUpdated = false;
private boolean hasGrownRifts = false;
public HashMap<Integer, double[]> renderingCenters = new HashMap<Integer, double[]>();
public DimLink nearestRiftData; public DimLink nearestRiftData;
public int spawnedEndermenID = 0; public int spawnedEndermenID = 0;
DataWatcher watcher = new DataWatcher(); public HashMap<Integer, double[]> renderingCenters = new HashMap<Integer, double[]>();
@Override @Override
public void updateEntity() public void updateEntity()
@@ -88,14 +91,12 @@ public class TileEntityRift extends TileEntity
{ {
this.spawnEndermen(); this.spawnEndermen();
this.calculateOldParticleOffset(); //this also calculates the distance for the particle stuff. this.calculateOldParticleOffset(); //this also calculates the distance for the particle stuff.
if (mod_pocketDim.properties.RiftSpreadEnabled && !this.hasGrownRifts) //only grow if rifts are nearby this.grow(mod_pocketDim.properties);
{
this.grow();
}
count = 0; count = 0;
} }
if (this.shouldClose) //Determines if rift should render white closing particles and spread closing effect to other rifts nearby //Determines if rift should render white closing particles and spread closing effect to other rifts nearby
if (this.shouldClose)
{ {
closeRift(); closeRift();
} }
@@ -110,20 +111,21 @@ public class TileEntityRift extends TileEntity
private void clearBlocksOnRift() private void clearBlocksOnRift()
{ {
//clears blocks for the new rending effect //clears blocks for the new rending effect
for(double[] coord: this.renderingCenters.values()) for (double[] coord : this.renderingCenters.values())
{ {
int x = MathHelper.floor_double(coord[0]+.5); int x = MathHelper.floor_double(coord[0] + 0.5);
int y = MathHelper.floor_double(coord[1]+.5); int y = MathHelper.floor_double(coord[1] + 0.5);
int z = MathHelper.floor_double(coord[2]+.5); int z = MathHelper.floor_double(coord[2] + 0.5);
if (!mod_pocketDim.blockRift.isBlockImmune(worldObj,this.xCoord + x, this.yCoord + y, this.zCoord + z)) //right side // Right side
if (!mod_pocketDim.blockRift.isBlockImmune(worldObj, this.xCoord + x, this.yCoord + y, this.zCoord + z))
{ {
worldObj.setBlockToAir(this.xCoord+x, this.yCoord+y, this.zCoord+z); worldObj.setBlockToAir(this.xCoord + x, this.yCoord + y, this.zCoord + z);
} }
// Left side
if (!mod_pocketDim.blockRift.isBlockImmune(worldObj,this.xCoord - x, this.yCoord - y, this.zCoord - z)) //left side if (!mod_pocketDim.blockRift.isBlockImmune(worldObj, this.xCoord - x, this.yCoord - y, this.zCoord - z))
{ {
worldObj.setBlockToAir(this.xCoord-x, this.yCoord-y, this.zCoord-z); worldObj.setBlockToAir(this.xCoord - x, this.yCoord - y, this.zCoord - z);
} }
} }
} }
@@ -147,7 +149,7 @@ public class TileEntityRift extends TileEntity
//enderman will only spawn in groups of rifts //enderman will only spawn in groups of rifts
if (random.nextInt(MAX_ENDERMAN_SPAWNING_CHANCE) < ENDERMAN_SPAWNING_CHANCE) if (random.nextInt(MAX_ENDERMAN_SPAWNING_CHANCE) < ENDERMAN_SPAWNING_CHANCE)
{ {
if (isNearRift()) if (updateNearestRift())
{ {
List<Entity> list = worldObj.getEntitiesWithinAABB(EntityEnderman.class, List<Entity> list = worldObj.getEntitiesWithinAABB(EntityEnderman.class,
AxisAlignedBB.getBoundingBox(xCoord - 9, yCoord - 3, zCoord - 9, xCoord + 9, yCoord + 3, zCoord + 9)); AxisAlignedBB.getBoundingBox(xCoord - 9, yCoord - 3, zCoord - 9, xCoord + 9, yCoord + 3, zCoord + 9));
@@ -162,7 +164,7 @@ public class TileEntityRift extends TileEntity
} }
} }
public boolean isNearRift() public boolean updateNearestRift()
{ {
nearestRiftData = PocketManager.getDimensionData(worldObj).findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord); nearestRiftData = PocketManager.getDimensionData(worldObj).findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord);
return (nearestRiftData != null); return (nearestRiftData != null);
@@ -208,7 +210,7 @@ public class TileEntityRift extends TileEntity
private void calculateOldParticleOffset() private void calculateOldParticleOffset()
{ {
nearestRiftData = PocketManager.getDimensionData(worldObj).findNearestRift(worldObj, 5, xCoord, yCoord, zCoord); updateNearestRift();
if (nearestRiftData != null) if (nearestRiftData != null)
{ {
Point4D location = nearestRiftData.source(); Point4D location = nearestRiftData.source();
@@ -283,75 +285,64 @@ public class TileEntityRift extends TileEntity
return pass == 1; return pass == 1;
} }
public int countParents(DimLink link) public int countAncestorLinks(DimLink link)
{ {
if(link.parent()!=null) if (link.parent() != null)
{ {
return 1 + countParents(link.parent()); return countAncestorLinks(link.parent()) + 1;
}
else
{
return 0;
} }
return 1;
} }
public void grow() public void grow(DDProperties properties)
{ {
if (worldObj.isRemote || this.hasGrownRifts || random.nextInt(3) == 0) if (worldObj.isRemote || hasGrownRifts || !properties.RiftSpreadEnabled || random.nextInt(3) == 0)
{ {
return; return;
} }
NewDimData dimension = PocketManager.getDimensionData(worldObj); NewDimData dimension = PocketManager.getDimensionData(worldObj);
if (dimension.findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord) == null)
{
return;
}
int growCount=0;
DimLink link = dimension.getLink(xCoord, yCoord, zCoord); DimLink link = dimension.getLink(xCoord, yCoord, zCoord);
int x=0,y=0,z=0; if (countAncestorLinks(link) > MAX_ANCESTOR_LINKS)
while(growCount<100)
{ {
growCount++;
x=xCoord+(1-(random.nextInt(2)*2)*random.nextInt(6));
y=yCoord+(1-(random.nextInt(2)*2)*random.nextInt(4));
z=zCoord+(1-(random.nextInt(2)*2)*random.nextInt(6));
if(worldObj.isAirBlock(x, y, z))
{
break;
}
}
if (growCount < 100)
{
//look to see if there is a block inbetween the rift and the spread location that should interrupt the spread. With this change,
//rifts cannot spread if there are any blocks nearby that are invularble to rift destruction
//TODO- make this look for blocks breaking line of sight with the rift
if (link != null)
{
if ((this.countParents(link)<4))
{
MovingObjectPosition hit = this.worldObj.clip(this.worldObj.getWorldVec3Pool().getVecFromPool(this.xCoord,this.yCoord,this.zCoord), this.worldObj.getWorldVec3Pool().getVecFromPool(x,y,z),false);
if(hit!=null)
{
if(mod_pocketDim.blockRift.isBlockImmune(this.worldObj,hit.blockX,hit.blockY,hit.blockZ))
{
System.out.println(Block.blocksList[this.worldObj.getBlockId(hit.blockX,hit.blockY,hit.blockZ)].getLocalizedName()+" HIT");
return; return;
} }
System.out.println(Block.blocksList[this.worldObj.getBlockId(hit.blockX,hit.blockY,hit.blockZ)].getLocalizedName());
hit = this.worldObj.clip(this.worldObj.getWorldVec3Pool().getVecFromPool(this.xCoord,this.yCoord,this.zCoord), this.worldObj.getWorldVec3Pool().getVecFromPool(x,y,z),false);
System.out.println(Block.blocksList[this.worldObj.getBlockId(hit.blockX,hit.blockY,hit.blockZ)].getLocalizedName());
//FIXME: This condition would prevent people from creating rooms of densely packed rifts... ~SenseiKiwi
if (updateNearestRift())
{
return;
} }
int x, y, z;
int spreadAttempts = 0;
for (int searchAttempts = 0; searchAttempts < MAX_SEARCH_ATTEMPTS; searchAttempts++)
{
x = xCoord + MathHelper.getRandomIntegerInRange(random, -6, 6);
y = yCoord + MathHelper.getRandomIntegerInRange(random, -4, 4);
z = zCoord + MathHelper.getRandomIntegerInRange(random, -6, 6);
if (y >= 0 && y < worldObj.getActualHeight() && worldObj.isAirBlock(x, y, z))
{
Vec3 position = worldObj.getWorldVec3Pool().getVecFromPool(xCoord, yCoord, zCoord);
Vec3 spreadTarget = worldObj.getWorldVec3Pool().getVecFromPool(x, y, z);
MovingObjectPosition hit = worldObj.clip(position, spreadTarget, false);
if (hit == null || !mod_pocketDim.blockRift.isBlockImmune(worldObj, hit.blockX, hit.blockY, hit.blockZ))
{
dimension.createChildLink(x, y, z, link); dimension.createChildLink(x, y, z, link);
this.hasGrownRifts=true; hasGrownRifts = true;
} }
else else
{ {
System.out.println("allDone"); spreadAttempts++;
this.hasGrownRifts=true; if (spreadAttempts >= MAX_SPREAD_ATTEMPTS)
{
break;
}
} }
} }
} }
@@ -361,15 +352,15 @@ public class TileEntityRift extends TileEntity
public void readFromNBT(NBTTagCompound nbt) public void readFromNBT(NBTTagCompound nbt)
{ {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.renderingCenters= new HashMap<Integer, double[]>(); this.renderingCenters = new HashMap<Integer, double[]>();
this.count=nbt.getInteger("count"); this.count = nbt.getInteger("count");
this.count2=nbt.getInteger("count2"); this.count2 = nbt.getInteger("count2");
this.xOffset = nbt.getInteger("xOffset"); this.xOffset = nbt.getInteger("xOffset");
this.yOffset = nbt.getInteger("yOffset"); this.yOffset = nbt.getInteger("yOffset");
this.zOffset = nbt.getInteger("zOffset"); this.zOffset = nbt.getInteger("zOffset");
this.hasGrownRifts =nbt.getBoolean("grownRifts"); this.hasGrownRifts = nbt.getBoolean("grownRifts");
this.age=nbt.getInteger("age"); this.age = nbt.getInteger("age");
this.shouldClose=nbt.getBoolean("shouldClose"); this.shouldClose = nbt.getBoolean("shouldClose");
this.spawnedEndermenID = nbt.getInteger("spawnedEndermenID"); this.spawnedEndermenID = nbt.getInteger("spawnedEndermenID");
} }
@@ -377,7 +368,6 @@ public class TileEntityRift extends TileEntity
public void writeToNBT(NBTTagCompound nbt) public void writeToNBT(NBTTagCompound nbt)
{ {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setInteger("hashMapSize", this.renderingCenters.size());
nbt.setInteger("age", this.age); nbt.setInteger("age", this.age);
nbt.setInteger("count", this.count); nbt.setInteger("count", this.count);
nbt.setInteger("count2", this.count2); nbt.setInteger("count2", this.count2);