Merge pull request #124 from SenseiKiwi/master

Various Fixes
This commit is contained in:
StevenRS11
2014-01-05 20:16:28 -08:00
9 changed files with 144 additions and 175 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;
} }
@@ -129,7 +129,6 @@ public class BlockRift extends BlockContainer
{ {
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)
@@ -204,7 +200,7 @@ public class BlockRift extends BlockContainer
if (!isBlockImmune(world, current.getX(), current.getY(), current.getZ()) && if (!isBlockImmune(world, current.getX(), current.getY(), current.getZ()) &&
random.nextInt(MAX_BLOCK_DESTRUCTION_CHANCE) < BLOCK_DESTRUCTION_CHANCE) random.nextInt(MAX_BLOCK_DESTRUCTION_CHANCE) < BLOCK_DESTRUCTION_CHANCE)
{ {
world.setBlockToAir(current.getX(), current.getY(), current.getZ()); world.destroyBlock(current.getX(), current.getY(), current.getZ(), false);
} }
} }
} }
@@ -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

@@ -15,7 +15,6 @@ import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
@SuppressWarnings("deprecation")
public class CommandCreateDungeonRift extends DDCommandBase public class CommandCreateDungeonRift extends DDCommandBase
{ {
private static CommandCreateDungeonRift instance = null; private static CommandCreateDungeonRift instance = null;
@@ -34,7 +33,8 @@ public class CommandCreateDungeonRift extends DDCommandBase
} }
@Override @Override
public String getCommandUsage(ICommandSender sender) { public String getCommandUsage(ICommandSender sender)
{
return "Usage: /dd-rift <dungeon name>\r\n" + return "Usage: /dd-rift <dungeon name>\r\n" +
" /dd-rift list\r\n" + " /dd-rift list\r\n" +
" /dd-rift random"; " /dd-rift random";
@@ -64,9 +64,9 @@ public class CommandCreateDungeonRift extends DDCommandBase
Collection<String> dungeonNames = dungeonHelper.getDungeonNames(); Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
for (String name : dungeonNames) for (String name : dungeonNames)
{ {
sendChat(sender,(name)); sendChat(sender, name);
} }
sendChat(sender,("")); sendChat(sender, "");
} }
else else
{ {
@@ -84,7 +84,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation); link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID, 0, 3); sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID, 0, 3);
sendChat(sender,("Created a rift to a random dungeon.")); sendChat(sender, "Created a rift to a random dungeon.");
} }
else else
{ {
@@ -103,7 +103,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result); PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result);
sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3); sender.worldObj.setBlock(x, y + 1, z, mod_pocketDim.blockRift.blockID, 0, 3);
sendChat(sender,("Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ").")); sendChat(sender, "Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination().getDimension() + ").");
} }
else else
{ {

View File

@@ -68,7 +68,7 @@ public class DungeonSchematic extends Schematic {
public Point3D getEntranceDoorLocation() public Point3D getEntranceDoorLocation()
{ {
return entranceDoorLocation.clone(); return (entranceDoorLocation != null) ? entranceDoorLocation.clone() : null;
} }
private DungeonSchematic() private DungeonSchematic()

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,23 +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 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;
public boolean hasGrownRifts=false;
public boolean shouldClose = false; public boolean shouldClose = false;
private int count=0;
private int count2 = 0;
public int age = 0;
private boolean hasUpdated = false; private boolean hasUpdated = false;
private boolean hasGrownRifts = false;
public HashMap<Integer, double[]> renderingCenters = new HashMap<Integer, double[]>();
@SuppressWarnings("deprecation")
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()
@@ -69,10 +74,6 @@ public class TileEntityRift extends TileEntity
return; return;
} }
//The code for the new rift rendering hooks in here, as well as in the ClientProxy to bind the TESR to the rift. //The code for the new rift rendering hooks in here, as well as in the ClientProxy to bind the TESR to the rift.
//It is inactive for now. //It is inactive for now.
/** /**
@@ -90,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();
} }
@@ -109,32 +108,29 @@ public class TileEntityRift extends TileEntity
return true; return true;
} }
private void clearBlocksOnRift()
public 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);
} }
} }
} }
public void spawnEndermen() private void spawnEndermen()
{ {
if (worldObj.isRemote) if (worldObj.isRemote)
{ {
@@ -151,12 +147,10 @@ public class TileEntityRift extends TileEntity
} }
//enderman will only spawn in groups of rifts //enderman will only spawn in groups of rifts
nearestRiftData = dimension.findNearestRift(worldObj, 5, xCoord, yCoord, zCoord); if (random.nextInt(MAX_ENDERMAN_SPAWNING_CHANCE) < ENDERMAN_SPAWNING_CHANCE)
if (nearestRiftData != null)
{ {
if (random.nextInt(30) == 0) if (updateNearestRift())
{ {
@SuppressWarnings("unchecked")
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));
@@ -170,7 +164,13 @@ public class TileEntityRift extends TileEntity
} }
} }
public void closeRift() public boolean updateNearestRift()
{
nearestRiftData = PocketManager.getDimensionData(worldObj).findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord);
return (nearestRiftData != null);
}
private void closeRift()
{ {
NewDimData dimension = PocketManager.getDimensionData(worldObj); NewDimData dimension = PocketManager.getDimensionData(worldObj);
if (count2 > 20 && count2 < 22) if (count2 > 20 && count2 < 22)
@@ -208,9 +208,9 @@ public class TileEntityRift extends TileEntity
} }
public 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();
@@ -228,7 +228,7 @@ public class TileEntityRift extends TileEntity
this.onInventoryChanged(); this.onInventoryChanged();
} }
public void calculateNextRenderQuad(float age, Random rand) private void calculateNextRenderQuad(float age, Random rand)
{ {
int maxSize = MathHelper.floor_double((Math.log(Math.pow(age+1,2)))); int maxSize = MathHelper.floor_double((Math.log(Math.pow(age+1,2))));
int iteration=0; int iteration=0;
@@ -285,83 +285,68 @@ 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;
}
} }
} }
} }
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) public void readFromNBT(NBTTagCompound nbt)
@@ -383,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);
@@ -409,14 +393,4 @@ public class TileEntityRift extends TileEntity
{ {
readFromNBT(pkt.data); readFromNBT(pkt.data);
} }
public boolean isNearRift()
{
if(PocketManager.getDimensionData(worldObj).findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord)==null)
{
return false;
}
return true;
}
} }