Merge pull request #124 from SenseiKiwi/master

Various Fixes
This commit is contained in:
StevenRS11 2014-01-05 20:16:28 -08:00
commit 6a0cf4706a
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.BlockContainer;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
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.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 int BLOCK_DESTRUCTION_RANGE = 4;
@ -107,7 +108,6 @@ public class BlockRift extends BlockContainer
@Override
public boolean canCollideCheck(int par1, boolean par2)
{
return par2;
}
@ -125,11 +125,10 @@ public class BlockRift extends BlockContainer
@Override
public int getRenderType()
{
if(mod_pocketDim.isPlayerWearingGoogles)
if (mod_pocketDim.isPlayerWearingGoogles)
{
return 0;
}
return 8;
}
@ -154,8 +153,6 @@ public class BlockRift extends BlockContainer
return null;
}
//function that regulates how many blocks it eats/ how fast it eats them.
@Override
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,
//moderates performance impact, and controls the apparent speed of block destruction.
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);
}
}
}
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()) &&
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
public TileEntity createNewTileEntity(World var1)
public TileEntity createNewTileEntity(World world)
{
return new TileEntityRift();
}

View file

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

View file

@ -15,26 +15,26 @@ import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
@SuppressWarnings("deprecation")
public class CommandCreateDungeonRift extends DDCommandBase
{
private static CommandCreateDungeonRift instance = null;
private CommandCreateDungeonRift()
{
super("dd-rift", "<dungeon name | 'list' | 'random'>");
}
public static CommandCreateDungeonRift instance()
{
if (instance == null)
instance = new CommandCreateDungeonRift();
return instance;
}
@Override
public String getCommandUsage(ICommandSender sender) {
public String getCommandUsage(ICommandSender sender)
{
return "Usage: /dd-rift <dungeon name>\r\n" +
" /dd-rift list\r\n" +
" /dd-rift random";
@ -45,7 +45,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
{
NewDimData dimension;
DungeonHelper dungeonHelper = DungeonHelper.instance();
if (sender.worldObj.isRemote)
{
return DDCommandResult.SUCCESS;
@ -58,15 +58,15 @@ public class CommandCreateDungeonRift extends DDCommandBase
{
return DDCommandResult.TOO_MANY_ARGUMENTS;
}
if (command[0].equals("list"))
{
Collection<String> dungeonNames = dungeonHelper.getDungeonNames();
for (String name : dungeonNames)
{
sendChat(sender,(name));
sendChat(sender, name);
}
sendChat(sender,(""));
sendChat(sender, "");
}
else
{
@ -79,12 +79,12 @@ public class CommandCreateDungeonRift extends DDCommandBase
if (command[0].equals("random"))
{
dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,orientation);
sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID,0,3);
sendChat(sender,("Created a rift to a random dungeon."));
dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
sender.worldObj.setBlock(x, y + 1, z,mod_pocketDim.blockRift.blockID, 0, 3);
sendChat(sender, "Created a rift to a random dungeon.");
}
else
{
@ -94,17 +94,17 @@ public class CommandCreateDungeonRift extends DDCommandBase
result = findDungeonByPartialName(command[0], dungeonHelper.getUntaggedDungeons());
}
//Check if we found any matches
if (result != null)
{
//Create a rift to our selected dungeon and notify the player
//TODO currently crashes, need to create the dimension first
dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON,orientation);
PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result);
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() + ")."));
}
if (result != null)
{
//Create a rift to our selected dungeon and notify the player
//TODO currently crashes, need to create the dimension first
dimension = PocketManager.getDimensionData(sender.worldObj);
link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON, orientation);
PocketBuilder.generateSelectedDungeonPocket(link, mod_pocketDim.properties, result);
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() + ").");
}
else
{
//No matches!
@ -114,7 +114,7 @@ public class CommandCreateDungeonRift extends DDCommandBase
}
return DDCommandResult.SUCCESS;
}
private DungeonData findDungeonByPartialName(String query, Collection<DungeonData> dungeons)
{
//Search for the shortest dungeon name that contains the lowercase query string.
@ -122,12 +122,12 @@ public class CommandCreateDungeonRift extends DDCommandBase
String normalQuery = query.toLowerCase();
DungeonData bestMatch = null;
int matchLength = Integer.MAX_VALUE;
for (DungeonData dungeon : dungeons)
{
//We need to extract the file's name. Comparing against schematicPath could
//yield false matches if the query string is contained within the path.
dungeonName = dungeon.schematicName().toLowerCase();
if (dungeonName.length() < matchLength && dungeonName.contains(normalQuery))
{

View file

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

View file

@ -21,6 +21,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.ServerPacketHandler;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink;
@ -30,23 +31,27 @@ import StevenDimDoors.mod_pocketDim.util.Point4D;
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();
public int xOffset=0;
public int yOffset=0;
public int zOffset=0;
public boolean hasGrownRifts=false;
public boolean shouldClose=false;
private int count=0;
private int age = 0;
private int count = 0;
private int count2 = 0;
public int age = 0;
public int xOffset = 0;
public int yOffset = 0;
public int zOffset = 0;
public boolean shouldClose = false;
private boolean hasUpdated = false;
private boolean hasGrownRifts = false;
public HashMap<Integer, double[]> renderingCenters = new HashMap<Integer, double[]>();
@SuppressWarnings("deprecation")
public DimLink nearestRiftData;
public int spawnedEndermenID=0;
DataWatcher watcher = new DataWatcher();
public int spawnedEndermenID = 0;
public HashMap<Integer, double[]> renderingCenters = new HashMap<Integer, double[]>();
@Override
public void updateEntity()
@ -68,10 +73,6 @@ public class TileEntityRift extends TileEntity
this.invalidate();
return;
}
//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.
@ -90,14 +91,12 @@ public class TileEntityRift extends TileEntity
{
this.spawnEndermen();
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();
}
this.grow(mod_pocketDim.properties);
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();
}
@ -108,33 +107,30 @@ public class TileEntityRift extends TileEntity
{
return true;
}
public void clearBlocksOnRift()
private void clearBlocksOnRift()
{
//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 y = MathHelper.floor_double(coord[1]+.5);
int z = MathHelper.floor_double(coord[2]+.5);
if (!mod_pocketDim.blockRift.isBlockImmune(worldObj,this.xCoord+x, this.yCoord+y, this.zCoord+z))//right side
int x = MathHelper.floor_double(coord[0] + 0.5);
int y = MathHelper.floor_double(coord[1] + 0.5);
int z = MathHelper.floor_double(coord[2] + 0.5);
// 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);
}
if (!mod_pocketDim.blockRift.isBlockImmune(worldObj,this.xCoord-x, this.yCoord-y, this.zCoord-z))//left side
// 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)
{
@ -151,12 +147,10 @@ public class TileEntityRift extends TileEntity
}
//enderman will only spawn in groups of rifts
nearestRiftData = dimension.findNearestRift(worldObj, 5, xCoord, yCoord, zCoord);
if (nearestRiftData != null)
if (random.nextInt(MAX_ENDERMAN_SPAWNING_CHANCE) < ENDERMAN_SPAWNING_CHANCE)
{
if (random.nextInt(30) == 0)
if (updateNearestRift())
{
@SuppressWarnings("unchecked")
List<Entity> list = worldObj.getEntitiesWithinAABB(EntityEnderman.class,
AxisAlignedBB.getBoundingBox(xCoord - 9, yCoord - 3, zCoord - 9, xCoord + 9, yCoord + 3, zCoord + 9));
@ -169,8 +163,14 @@ public class TileEntityRift extends TileEntity
}
}
}
public boolean updateNearestRift()
{
nearestRiftData = PocketManager.getDimensionData(worldObj).findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord);
return (nearestRiftData != null);
}
public void closeRift()
private void closeRift()
{
NewDimData dimension = PocketManager.getDimensionData(worldObj);
if (count2 > 20 && count2 < 22)
@ -188,7 +188,7 @@ public class TileEntityRift extends TileEntity
rift.onInventoryChanged();
}
}
}
}
if (count2 > 40)
@ -205,12 +205,12 @@ public class TileEntityRift extends TileEntity
}
}
count2++;
}
public void calculateOldParticleOffset()
private void calculateOldParticleOffset()
{
nearestRiftData = PocketManager.getDimensionData(worldObj).findNearestRift(worldObj, 5, xCoord, yCoord, zCoord);
updateNearestRift();
if (nearestRiftData != null)
{
Point4D location = nearestRiftData.source();
@ -227,8 +227,8 @@ public class TileEntityRift extends TileEntity
}
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 iteration=0;
@ -284,106 +284,90 @@ public class TileEntityRift extends TileEntity
{
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;
}
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);
int x=0,y=0,z=0;
while(growCount<100)
if (countAncestorLinks(link) > MAX_ANCESTOR_LINKS)
{
return;
}
//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))
{
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))
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))
{
break;
dimension.createChildLink(x, y, z, link);
hasGrownRifts = true;
}
}
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)
else
{
if ((this.countParents(link)<4))
spreadAttempts++;
if (spreadAttempts >= MAX_SPREAD_ATTEMPTS)
{
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;
}
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());
}
dimension.createChildLink(x, y, z, link);
this.hasGrownRifts=true;
}
else
{
System.out.println("allDone");
this.hasGrownRifts=true;
break;
}
}
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.renderingCenters= new HashMap<Integer, double[]>();
this.count=nbt.getInteger("count");
this.count2=nbt.getInteger("count2");
this.renderingCenters = new HashMap<Integer, double[]>();
this.count = nbt.getInteger("count");
this.count2 = nbt.getInteger("count2");
this.xOffset = nbt.getInteger("xOffset");
this.yOffset = nbt.getInteger("yOffset");
this.zOffset = nbt.getInteger("zOffset");
this.hasGrownRifts =nbt.getBoolean("grownRifts");
this.age=nbt.getInteger("age");
this.shouldClose=nbt.getBoolean("shouldClose");
this.hasGrownRifts = nbt.getBoolean("grownRifts");
this.age = nbt.getInteger("age");
this.shouldClose = nbt.getBoolean("shouldClose");
this.spawnedEndermenID = nbt.getInteger("spawnedEndermenID");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("hashMapSize", this.renderingCenters.size());
super.writeToNBT(nbt);
nbt.setInteger("age", this.age);
nbt.setInteger("count", this.count);
nbt.setInteger("count2", this.count2);
@ -395,28 +379,18 @@ public class TileEntityRift extends TileEntity
nbt.setInteger("spawnedEndermenID", this.spawnedEndermenID);
}
public Packet getDescriptionPacket()
{
if(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj)!=null)
{
return ServerPacketHandler.createLinkPacket(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj).link());
}
return null;
}
public Packet getDescriptionPacket()
{
if (PocketManager.getLink(xCoord, yCoord, zCoord, worldObj) != null)
{
return ServerPacketHandler.createLinkPacket(PocketManager.getLink(xCoord, yCoord, zCoord, worldObj).link());
}
return null;
}
@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
{
readFromNBT(pkt.data);
}
public boolean isNearRift()
{
if(PocketManager.getDimensionData(worldObj).findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord)==null)
{
return false;
}
return true;
}
}

View file

@ -116,7 +116,7 @@ public class PocketBuilder
}
}
private static boolean buildDungeonPocket(DungeonData dungeon, NewDimData dimension, DimLink link, DungeonSchematic schematic,World world, DDProperties properties)
private static boolean buildDungeonPocket(DungeonData dungeon, NewDimData dimension, DimLink link, DungeonSchematic schematic, World world, DDProperties properties)
{
//Calculate the destination point
DungeonPackConfig packConfig = dungeon.dungeonType().Owner != null ? dungeon.dungeonType().Owner.getConfig() : null;
@ -145,7 +145,7 @@ public class PocketBuilder
return true;
}
public static boolean generateSelectedDungeonPocket(DimLink link, DDProperties properties,DungeonData data)
public static boolean generateSelectedDungeonPocket(DimLink link, DDProperties properties, DungeonData data)
{
if (link == null)
{
@ -183,7 +183,7 @@ public class PocketBuilder
System.err.println("Could not select a dungeon for generation!");
return false;
}
schematic = loadAndValidateDungeon(dungeon,properties);
schematic = loadAndValidateDungeon(dungeon, properties);
return PocketBuilder.buildDungeonPocket(dungeon, dimension, link, schematic, world, properties);