Lots of changes

Rerworked rift growth
Fixed teleport command
Fixed deleteRifts command
Fixed Rift rendering
This commit is contained in:
StevenRS11 2013-12-25 14:16:10 -06:00
parent 06d2dcaa74
commit c3b3db4ca0
8 changed files with 244 additions and 75 deletions

View file

@ -27,9 +27,17 @@ public class ConnectionHandler implements IConnectionHandler
{
for(NewDimData data : PocketManager.getDimensions())
{
try
{
Packet250CustomPayload[] pkt = ForgePacket.makePacketSet(new DimensionRegisterPacket(data.id(), DimensionManager.getProviderType(data.id())));
manager.addToSendQueue(pkt[0]);
}
catch(Exception E)
{
}
Packet250CustomPayload[] pkt = ForgePacket.makePacketSet(new DimensionRegisterPacket(data.id(), DimensionManager.getProviderType(data.id())));
manager.addToSendQueue(pkt[0]);
}
return null;

View file

@ -17,6 +17,8 @@ import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DDProperties;
import StevenDimDoors.mod_pocketDim.Point3D;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift;
import StevenDimDoors.mod_pocketDimClient.ClosingRiftFX;
@ -152,6 +154,8 @@ 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)
@ -162,11 +166,12 @@ 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)).isNearRift() )
{
destroyNearbyBlocks(world, x, y, z, random);
}
}
}
private void destroyNearbyBlocks(World world, int x, int y, int z, Random random)
@ -338,7 +343,7 @@ public class BlockRift extends BlockContainer
}
}
}
public boolean isBlockImmune(World world, int x, int y, int z)
{
Block block = Block.blocksList[world.getBlockId(x, y, z)];
@ -349,7 +354,7 @@ public class BlockRift extends BlockContainer
}
return false;
}
@Override
public int idPicked(World par1World, int par2, int par3, int par4)
{

View file

@ -60,15 +60,21 @@ public class CommandDeleteRifts extends DDCommandBase
for (DimLink link : linksInDim)
{
World targetWorld = PocketManager.loadDimension(targetDim);
if(sender.worldObj.getBlockId(link.source().getX(), link.source().getY(), link.source().getZ())==mod_pocketDim.blockRift.blockID)
if(!mod_pocketDim.blockRift.isBlockImmune(sender.worldObj,link.source().getX(), link.source().getY(), link.source().getZ())||
(targetWorld.getBlockId(link.source().getX(), link.source().getY(), link.source().getZ())==mod_pocketDim.blockRift.blockID))
{
targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0);
linksRemoved++;
targetWorld.setBlock(link.source().getX(), link.source().getY(), link.source().getZ(), 0);
dim.deleteLink(link);
}
//TODO Probably should check what the block is, but thats annoying so Ill do it later.
}
sendChat(sender,("Removed " + linksRemoved + " rifts."));
sendChat(sender,("Removed " + linksRemoved + " links."));
}
return DDCommandResult.SUCCESS; //TEMPORARY HACK

View file

@ -17,7 +17,7 @@ public class CommandTeleportPlayer extends DDCommandBase
private CommandTeleportPlayer()
{
super("dd-tp", new String[] {"<Player Name> <Dimension ID> <X Coord> <Y Coord> <Z Coord>"} );
super("dd-tp", new String[] {"<Player Name> <Dimension ID> <X Coord> <Y Coord> <Z Coord>","<Player Name> <Dimension ID>"} );
}
public static CommandTeleportPlayer instance()
@ -40,7 +40,6 @@ public class CommandTeleportPlayer extends DDCommandBase
@Override
protected DDCommandResult processCommand(EntityPlayer sender, String[] command)
{
List<Integer> dimensionIDs = Arrays.asList(DimensionManager.getStaticDimensionIDs()); //Gets list of all registered dimensions, regardless if loaded or not
EntityPlayer targetPlayer = sender;
int dimDestinationID = sender.worldObj.provider.dimensionId;
@ -63,7 +62,7 @@ public class CommandTeleportPlayer extends DDCommandBase
}
dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string
if(!dimensionIDs.contains(dimDestinationID))
if(!DimensionManager.isDimensionRegistered(dimDestinationID))
{
return DDCommandResult.INVALID_DIMENSION_ID;
}
@ -72,7 +71,56 @@ public class CommandTeleportPlayer extends DDCommandBase
Point4D destination = new Point4D(Integer.parseInt(command[2]),Integer.parseInt(command[3]),Integer.parseInt(command[4]),dimDestinationID);
DDTeleporter.teleportEntity(targetPlayer, destination, false);
}
else
else if(command.length == 2 && isInteger(command[1]))
{
if(sender.worldObj.getPlayerEntityByName(command[0])!=null) //Gets the targeted player
{
targetPlayer = sender.worldObj.getPlayerEntityByName(command[0]);
}
else
{
return DDCommandResult.INVALID_ARGUMENTS;
}
dimDestinationID=Integer.parseInt(command[1]);//gets the target dim ID from the command string
if(!DimensionManager.isDimensionRegistered(dimDestinationID))
{
return DDCommandResult.INVALID_DIMENSION_ID;
}
Point4D destination = PocketManager.getDimensionData(dimDestinationID).origin();
if(!PocketManager.getDimensionData(dimDestinationID).isPocketDimension())
{
destination = new Point4D(destination.getX(),PocketManager.loadDimension(dimDestinationID).getTopSolidOrLiquidBlock(
destination.getX(), destination.getZ()),
destination.getZ(),destination.getDimension());
}
DDTeleporter.teleportEntity(targetPlayer, destination, false);
}
else if(command.length == 1 && isInteger(command[0]))
{
targetPlayer = sender;
dimDestinationID=Integer.parseInt(command[0]);//gets the target dim ID from the command string
if(!DimensionManager.isDimensionRegistered(dimDestinationID))
{
return DDCommandResult.INVALID_DIMENSION_ID;
}
Point4D destination = PocketManager.getDimensionData(dimDestinationID).origin();
if(!PocketManager.getDimensionData(dimDestinationID).isPocketDimension())
{
destination = new Point4D(destination.getX(),PocketManager.loadDimension(dimDestinationID).getTopSolidOrLiquidBlock(
destination.getX(), destination.getZ()),
destination.getZ(),destination.getDimension());
}
DDTeleporter.teleportEntity(targetPlayer, destination, false);
}
else
{
return DDCommandResult.INVALID_ARGUMENTS;
}

View file

@ -31,6 +31,7 @@ import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor;
import StevenDimDoors.mod_pocketDim.schematic.BlockRotator;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;
import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.watcher.ClientDimData;
import StevenDimDoors.mod_pocketDim.world.PocketBuilder;
import cpw.mods.fml.common.registry.GameRegistry;
@ -319,10 +320,10 @@ public class DDTeleporter
if(player != null) // Are we working with a player?
{
// We need to do all this special stuff to move a player between dimensions.
//Register the dim on the client when we teleport to it.
Packet250CustomPayload[] pkt = ForgePacket.makePacketSet(new DimensionRegisterPacket(newWorld.provider.dimensionId, DimensionManager.getProviderType(newWorld.provider.dimensionId)));
player.playerNetServerHandler.sendPacketToPlayer(pkt[0]);
//Give the client the dimensionData for the destination
PocketManager.dimWatcher.onCreated(new ClientDimData(PocketManager.getDimensionData(destination.getDimension())));
// Set the new dimension and inform the client that it's moving to a new world.
player.dimension = destination.getDimension();

View file

@ -198,6 +198,7 @@ public abstract class NewDimData
this.root = root;
}
public DimLink findNearestRift(World world, int range, int x, int y, int z)
{
//TODO: Rewrite this later to use an octtree
@ -226,7 +227,7 @@ public abstract class NewDimData
for (k = -range; k <= range; k++)
{
distance = getAbsoluteSum(i, j, k);
if (distance > 1 && distance < minDistance && world.getBlockId(x + i, y + j, z + k) == properties.RiftBlockID)
if (distance > 0 && distance < minDistance && world.getBlockId(x + i, y + j, z + k) == properties.RiftBlockID)
{
link = getLink(x+i, y+j, z+k);
if (link != null)
@ -242,6 +243,48 @@ public abstract class NewDimData
return nearest;
}
public ArrayList<DimLink> findRiftsInRange(World world, int range, int x, int y, int z)
{
ArrayList<DimLink> links = new ArrayList<DimLink>();
//TODO: Rewrite this later to use an octtree
//Sanity check...
if (world.provider.dimensionId != id)
{
throw new IllegalArgumentException("Attempted to search for links in a World instance for a different dimension!");
}
//Note: Only detect rifts at a distance > 1, so we ignore the rift
//that called this function and any adjacent rifts.
DimLink link;
int distance;
int i, j, k;
DDProperties properties = DDProperties.instance();
for (i = -range; i <= range; i++)
{
for (j = -range; j <= range; j++)
{
for (k = -range; k <= range; k++)
{
distance = getAbsoluteSum(i, j, k);
if (distance > 0 && world.getBlockId(x + i, y + j, z + k) == properties.RiftBlockID)
{
link = getLink(x+i, y+j, z+k);
if (link != null)
{
links.add(link);
}
}
}
}
}
return links;
}
private static int getAbsoluteSum(int i, int j, int k)
{
return Math.abs(i) + Math.abs(j) + Math.abs(k);

View file

@ -9,6 +9,8 @@ import java.util.HashMap;
import java.util.List;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
@ -213,7 +215,7 @@ public class PocketManager
*/
public static volatile boolean isConnected = false;
public static final UpdateWatcherProxy<ClientLinkData> linkWatcher = new UpdateWatcherProxy<ClientLinkData>();
private static final UpdateWatcherProxy<ClientDimData> dimWatcher = new UpdateWatcherProxy<ClientDimData>();
static final UpdateWatcherProxy<ClientDimData> dimWatcher = new UpdateWatcherProxy<ClientDimData>();
private static ArrayList<NewDimData> rootDimensions = null;
//HashMap that maps all the dimension IDs registered with DimDoors to their DD data.
@ -528,6 +530,7 @@ public class PocketManager
return dimension;
}
@SideOnly(Side.CLIENT)
private static NewDimData registerClientDimension(int dimensionID, int rootID)
{
// No need to raise events heres since this code should only run on the client side
@ -552,10 +555,13 @@ public class PocketManager
{
dimension = root;
}
if(dimension.isPocketDimension())
if(dimension.isPocketDimension()&&!DimensionManager.isDimensionRegistered(dimension.id()))
{
//Im registering pocket dims here. I *think* we can assume that if its a pocket and we are
//registering its dim data, we also need to register it with forge.
//New packet stuff prevents this from always being true, unfortuantly. I send the dimdata to the client when they teleport.
//Steven
DimensionManager.registerDimension(dimensionID, mod_pocketDim.properties.PocketProviderID);
}
return dimension;

View file

@ -2,10 +2,12 @@ package StevenDimDoors.mod_pocketDim.tileentities;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.entity.DataWatcher;
import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityEnderman;
@ -16,6 +18,9 @@ import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.ServerPacketHandler;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.core.DimLink;
@ -30,10 +35,8 @@ public class TileEntityRift extends TileEntity
public int xOffset=0;
public int yOffset=0;
public int zOffset=0;
public int distance=0;
public boolean hasGrownRifts=false;
public boolean shouldClose=false;
public boolean isNearRift=false;
private int count=200;
private int count2 = 0;
public int age = 0;
@ -87,9 +90,9 @@ public class TileEntityRift extends TileEntity
{
this.spawnEndermen();
this.calculateOldParticleOffset(); //this also calculates the distance for the particle stuff.
if (distance > 1) //only grow if rifts are nearby
if (mod_pocketDim.properties.RiftSpreadEnabled&&!this.hasGrownRifts) //only grow if rifts are nearby
{
this.grow(distance);
this.grow();
}
count = 0;
}
@ -165,10 +168,6 @@ public class TileEntityRift extends TileEntity
}
}
}
else
{
this.isNearRift = false;
}
}
public void closeRift()
@ -176,16 +175,20 @@ public class TileEntityRift extends TileEntity
NewDimData dimension = PocketManager.getDimensionData(worldObj);
if (count2 > 20 && count2 < 22)
{
nearestRiftData = dimension.findNearestRift(worldObj, 10, xCoord, yCoord, zCoord);
if (this.nearestRiftData != null)
ArrayList<DimLink> rifts= dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord);
if (rifts.size()>0)
{
Point4D location = nearestRiftData.source();
TileEntityRift rift = (TileEntityRift) worldObj.getBlockTileEntity(location.getX(), location.getY(), location.getZ());
if (rift != null&&rift.shouldClose!=true)
for(DimLink riftToClose : rifts)
{
rift.shouldClose = true;
rift.onInventoryChanged();
Point4D location = riftToClose.source();
TileEntityRift rift = (TileEntityRift) worldObj.getBlockTileEntity(location.getX(), location.getY(), location.getZ());
if (rift != null&&rift.shouldClose!=true)
{
rift.shouldClose = true;
rift.onInventoryChanged();
}
}
}
}
if (count2 > 40)
@ -214,8 +217,7 @@ public class TileEntityRift extends TileEntity
this.xOffset = this.xCoord - location.getX();
this.yOffset = this.yCoord - location.getY();
this.zOffset = this.zCoord - location.getZ();
this.distance = Math.abs(xOffset) + Math.abs(yOffset) + Math.abs(zOffset);
this.isNearRift=true;
int distance = Math.abs(xOffset) + Math.abs(yOffset) + Math.abs(zOffset);
}
else
{
@ -226,44 +228,6 @@ public class TileEntityRift extends TileEntity
this.onInventoryChanged();
}
public void grow(int distance)
{
if(worldObj.isRemote)
{
return;
}
int growCount=0;
if(random.nextInt(distance*2)==0)
{
int x=0,y=0,z=0;
while(growCount<100)
{
growCount++;
x=this.xCoord+(1-(random.nextInt(2)*2)*random.nextInt(6));
y=this.yCoord+(1-(random.nextInt(2)*2)*random.nextInt(4));
z=this.zCoord+(1-(random.nextInt(2)*2)*random.nextInt(6));
if(worldObj.isAirBlock(x, y, z))
{
break;
}
}
if (growCount < 100)
{
NewDimData dimension = PocketManager.getDimensionData(worldObj);
DimLink link = dimension.getLink(xCoord, yCoord, zCoord);
if (link != null)
{
if (!this.hasGrownRifts && random.nextInt(3) == 0)
{
dimension.createChildLink(x, y, z, link);
this.hasGrownRifts = true;
}
}
}
}
}
public void calculateNextRenderQuad(float age, Random rand)
{
int maxSize = MathHelper.floor_double((Math.log(Math.pow(age+1,2))));
@ -320,6 +284,84 @@ public class TileEntityRift extends TileEntity
{
return pass == 1;
}
public int countParents(DimLink link)
{
if(link.parent()!=null)
{
return 1 + countParents(link.parent());
}
return 1;
}
public void grow()
{
if(worldObj.isRemote||this.hasGrownRifts)
{
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)
{
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;
}
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;
}
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
@ -367,4 +409,14 @@ public class TileEntityRift extends TileEntity
{
readFromNBT(pkt.data);
}
public boolean isNearRift()
{
if(PocketManager.getDimensionData(worldObj).findNearestRift(this.worldObj, 5, xCoord, yCoord, zCoord)==null)
{
return false;
}
return true;
}
}