More Progress on Rewrite

Fixed the code in DDTeleporter and made minor changes to other classes
that depended on those fixes. Ensured that PocketManager's load, save,
and unload methods are called appropriately and rewrote some of their
code. Made various changes in other classes (e.g. EventHookContainer,
PlayerRespawnTracker) to pass them references to DDProperties through
their constructors instead of having them rely on
DDProperties.instance() - this is a better programming practice in the
long run.

Renamed initialization methods in mod_pocketDim to make it clear that
they're called on events. Commented out command registration in
mod_pocketDim so that we can test DD as soon as PacketHandler is fixed,
without worrying about fixing the command classes.
This commit is contained in:
SenseiKiwi 2013-09-01 09:21:27 -04:00
parent b795885f1c
commit 4086e75ead
12 changed files with 239 additions and 293 deletions

View file

@ -56,7 +56,7 @@ public class DDProperties
* Crafting Flags
*/
public final boolean CraftingDimensionaDoorAllowed;
public final boolean CraftingDimensionalDoorAllowed;
public final boolean CraftingWarpDoorAllowed;
public final boolean CraftingRiftSignatureAllowed;
public final boolean CraftingRiftRemoverAllowed;
@ -129,7 +129,7 @@ public class DDProperties
Configuration config = new Configuration(configFile);
config.load();
CraftingDimensionaDoorAllowed = config.get(CATEGORY_CRAFTING, "Allow Crafting Dimensional Door", true).getBoolean(true);
CraftingDimensionalDoorAllowed = config.get(CATEGORY_CRAFTING, "Allow Crafting Dimensional Door", true).getBoolean(true);
CraftingWarpDoorAllowed = config.get(CATEGORY_CRAFTING, "Allow Crafting Warp Door", true).getBoolean(true);
CraftingUnstableDoorAllowed = config.get(CATEGORY_CRAFTING, "Allow Crafting Unstable Door", true).getBoolean(true);
CraftingTransTrapdoorAllowed = config.get(CATEGORY_CRAFTING, "Allow Crafting Transdimensional Trapdoor", true).getBoolean(true);

View file

@ -1,7 +1,7 @@
package StevenDimDoors.mod_pocketDim;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.item.EntityMinecart;
@ -19,36 +19,27 @@ import net.minecraftforge.common.DimensionManager;
import StevenDimDoors.mod_pocketDim.core.IDimLink;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.util.Point4D;
import StevenDimDoors.mod_pocketDim.world.PocketBuilder;
import cpw.mods.fml.common.registry.GameRegistry;
public class DDTeleporter
{
private static final Random random = new Random();
public static int cooldown = 0;
private DDTeleporter() { }
/**
* Create a new portal near an entity.
*/
public static void placeInPortal(Entity par1Entity, WorldServer world, IDimLink link)
private static void placeInPortal(Entity entity, WorldServer world, Point4D destination, DDProperties properties)
{
Point4D destination = link.destination();
int x = destination.getX();
int y = destination.getY();
int z = destination.getZ();
//TODO Temporary workaround for mismatched door/rift metadata cases. Gives priority to the door.
int orientation = PocketManager.getDestinationOrientation(link);
int receivingDoorMeta = world.getBlockMetadata(x, y - 1, z);
int receivingDoorID = world.getBlockId(x, y, z);
if (receivingDoorMeta != orientation)
{
if (receivingDoorID == mod_pocketDim.dimDoor.blockID || receivingDoorID == mod_pocketDim.ExitDoor.blockID)
{
orientation = receivingDoorMeta;
}
}
int orientation = getDestinationOrientation(destination, properties);
if (par1Entity instanceof EntityPlayer)
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) par1Entity;
EntityPlayer player = (EntityPlayer) entity;
player.rotationYaw=(orientation*90)+90;
if(orientation==2||orientation==6)
{
@ -71,65 +62,65 @@ public class DDTeleporter
player.setPositionAndUpdate(x, y-1, z);
}
}
else if (par1Entity instanceof EntityMinecart)
else if (entity instanceof EntityMinecart)
{
par1Entity.motionX=0;
par1Entity.motionZ=0;
par1Entity.motionY=0;
par1Entity.rotationYaw=(orientation*90)+90;
entity.motionX=0;
entity.motionZ=0;
entity.motionY=0;
entity.rotationYaw=(orientation*90)+90;
if(orientation==2||orientation==6)
{
DDTeleporter.setEntityPosition(par1Entity, x+1.5, y, z+.5 );
par1Entity.motionX =.39;
par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false);
DDTeleporter.setEntityPosition(entity, x+1.5, y, z+.5 );
entity.motionX =.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
}
else if(orientation==3||orientation==7)
{
DDTeleporter.setEntityPosition(par1Entity, x+.5, y, z+1.5 );
par1Entity.motionZ =.39;
par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false);
DDTeleporter.setEntityPosition(entity, x+.5, y, z+1.5 );
entity.motionZ =.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
}
else if(orientation==0||orientation==4)
{
DDTeleporter.setEntityPosition(par1Entity,x-.5, y, z+.5);
par1Entity.motionX =-.39;
par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false);
DDTeleporter.setEntityPosition(entity,x-.5, y, z+.5);
entity.motionX =-.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
}
else if(orientation==1||orientation==5)
{
DDTeleporter.setEntityPosition(par1Entity,x+.5, y, z-.5);
par1Entity.motionZ =-.39;
par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false);
DDTeleporter.setEntityPosition(entity,x+.5, y, z-.5);
entity.motionZ =-.39;
entity.worldObj.updateEntityWithOptionalForce(entity, false);
}
else
{
DDTeleporter.setEntityPosition(par1Entity,x, y, z);
DDTeleporter.setEntityPosition(entity,x, y, z);
}
}
else if (par1Entity instanceof Entity)
else if (entity instanceof Entity)
{
par1Entity.rotationYaw=(orientation*90)+90;
entity.rotationYaw=(orientation*90)+90;
if(orientation==2||orientation==6)
{
DDTeleporter.setEntityPosition(par1Entity, x+1.5, y, z+.5 );
DDTeleporter.setEntityPosition(entity, x+1.5, y, z+.5 );
}
else if(orientation==3||orientation==7)
{
DDTeleporter.setEntityPosition(par1Entity, x+.5, y, z+1.5 );
DDTeleporter.setEntityPosition(entity, x+.5, y, z+1.5 );
}
else if(orientation==0||orientation==4)
{
DDTeleporter.setEntityPosition(par1Entity,x-.5, y, z+.5);
DDTeleporter.setEntityPosition(entity,x-.5, y, z+.5);
}
else if(orientation==1||orientation==5)
{
DDTeleporter.setEntityPosition(par1Entity,x+.5, y, z-.5);
DDTeleporter.setEntityPosition(entity,x+.5, y, z-.5);
}
else
{
DDTeleporter.setEntityPosition(par1Entity,x, y, z);
DDTeleporter.setEntityPosition(entity,x, y, z);
}
}
}
@ -142,18 +133,49 @@ public class DDTeleporter
entity.setPosition(x, y, z);
}
public static Entity teleportEntity(World world, Entity entity, IDimLink link)
{
private static int getDestinationOrientation(Point4D door, DDProperties properties)
{
World world = DimensionManager.getWorld(door.getDimension());
if (world == null)
{
throw new IllegalStateException("The destination world should be loaded!");
}
//Check if the block at that point is actually a door
int blockID = world.getBlockId(door.getX(), door.getY(), door.getZ());
if (blockID != properties.DimensionalDoorID && blockID != properties.WarpDoorID &&
blockID != properties.TransientDoorID && blockID != properties.UnstableDoorID)
{
//Return the pocket's orientation instead
return PocketManager.getDimensionData(door.getDimension()).orientation();
}
//Return the orientation portion of its metadata
return world.getBlockMetadata(door.getX(), door.getY(), door.getZ()) & 3;
}
public static Entity teleportEntity(Entity entity, Point4D destination)
{
if (entity == null)
{
throw new IllegalArgumentException("entity cannot be null.");
}
if (destination == null)
{
throw new IllegalArgumentException("destination cannot be null.");
}
//This beautiful teleport method is based off of xCompWiz's teleport function.
WorldServer oldWorld = (WorldServer)world;
WorldServer oldWorld = (WorldServer) entity.worldObj;
WorldServer newWorld;
EntityPlayerMP player = (entity instanceof EntityPlayerMP) ? (EntityPlayerMP)entity : null;
EntityPlayerMP player = (entity instanceof EntityPlayerMP) ? (EntityPlayerMP) entity : null;
DDProperties properties = DDProperties.instance();
// Is something riding? Handle it first.
if(entity.riddenByEntity != null)
if (entity.riddenByEntity != null)
{
return teleportEntity(oldWorld, entity.riddenByEntity, link);
return teleportEntity(entity.riddenByEntity, destination);
}
// Are we riding something? Dismount and tell the mount to go first.
@ -161,22 +183,21 @@ public class DDTeleporter
if (cart != null)
{
entity.mountEntity(null);
cart = teleportEntity(oldWorld, cart, link);
cart = teleportEntity(cart, destination);
// We keep track of both so we can remount them on the other side.
}
// Destination doesn't exist? We need to make it.
if (DimensionManager.getWorld(link.destination().getDimension()) == null)
{
//FIXME: I think this is where I need to add initialization code for pockets!!! REALLY IMPORTANT!!!
DimensionManager.initDimension(link.destination().getDimension());
}
// Determine if our destination's in another realm.
boolean difDest = link.source().getDimension() != link.destination().getDimension();
// Determine if our destination is in another realm.
boolean difDest = entity.dimension == destination.getDimension();
if (difDest)
{
newWorld = DimensionManager.getWorld(link.destination().getDimension());
// Destination isn't loaded? Then we need to load it.
newWorld = DimensionManager.getWorld(destination.getDimension());
if (newWorld == null)
{
DimensionManager.initDimension(destination.getDimension());
}
newWorld = DimensionManager.getWorld(destination.getDimension());
}
else
{
@ -185,7 +206,7 @@ public class DDTeleporter
// GreyMaria: What is this even accomplishing? We're doing the exact same thing at the end of this all.
// TODO Check to see if this is actually vital.
DDTeleporter.placeInPortal(entity, newWorld, link);
DDTeleporter.placeInPortal(entity, newWorld, destination, properties);
if (difDest) // Are we moving our target to a new dimension?
{
@ -194,7 +215,7 @@ public class DDTeleporter
// We need to do all this special stuff to move a player between dimensions.
// Set the new dimension and inform the client that it's moving to a new world.
player.dimension = link.destination().getDimension();
player.dimension = destination.getDimension();
player.playerNetServerHandler.sendPacketToPlayer(new Packet9Respawn(player.dimension, (byte)player.worldObj.difficultySetting, newWorld.getWorldInfo().getTerrainType(), newWorld.getHeight(), player.theItemInWorldManager.getGameType()));
// GreyMaria: Used the safe player entity remover before.
@ -203,7 +224,7 @@ public class DDTeleporter
// for a pocket dimension, causing all sleeping players
// to remain asleep instead of progressing to day.
oldWorld.removePlayerEntityDangerously(player);
player.isDead=false;
player.isDead = false;
// Creates sanity by ensuring that we're only known to exist where we're supposed to be known to exist.
oldWorld.getPlayerManager().removePlayer(player);
@ -243,7 +264,8 @@ public class DDTeleporter
entity = EntityList.createEntityFromNBT(entityNBT, newWorld);
if (entity == null)
{ // TODO FIXME IMPLEMENT NULL CHECKS THAT ACTUALLY DO SOMETHING.
{
// TODO FIXME IMPLEMENT NULL CHECKS THAT ACTUALLY DO SOMETHING.
/*
* shit ourselves in an organized fashion, preferably
* in a neat pile instead of all over our users' games
@ -270,107 +292,84 @@ public class DDTeleporter
}
// Did we teleport a player? Load the chunk for them.
if(player != null)
if (player != null)
{
WorldServer.class.cast(newWorld).getChunkProvider().loadChunk(MathHelper.floor_double(entity.posX) >> 4, MathHelper.floor_double(entity.posZ) >> 4);
newWorld.getChunkProvider().loadChunk(MathHelper.floor_double(entity.posX) >> 4, MathHelper.floor_double(entity.posZ) >> 4);
// Tell Forge we're moving its players so everyone else knows.
// Let's try doing this down here in case this is what's killing NEI.
GameRegistry.onPlayerChangedDimension((EntityPlayer)entity);
}
DDTeleporter.placeInPortal(entity, newWorld, link);
DDTeleporter.placeInPortal(entity, newWorld, destination, properties);
return entity;
}
/**
* Primary function used to teleport the player using doors. Performs numerous null checks, and also generates the destination door/pocket if it has not done so already.
* Also ensures correct orientation relative to the door using DDTeleporter.
* @param world- world the player is currently in
* @param linkData- the link the player is using to teleport, sends the player to its dest information.
* @param player- the instance of the player to be teleported
* @param orientation- the orientation of the door used to teleport, determines player orientation and door placement on arrival
* @Return
* Also ensures correct orientation relative to the door.
* @param world - world the player is currently in
* @param link - the link the player is using to teleport; sends the player to its destination
* @param player - the instance of the player to be teleported
*/
public static void traverseDimDoor(World world, IDimLink linkData, Entity entity)
public static void traverseDimDoor(World world, IDimLink link, Entity entity)
{
DDProperties properties = DDProperties.instance();
if (world == null)
{
throw new IllegalArgumentException("world cannot be null.");
}
if (link == null)
{
throw new IllegalArgumentException("link cannot be null.");
}
if (entity == null)
{
throw new IllegalArgumentException("entity cannot be null.");
}
if (world.isRemote)
{
return;
}
if (linkData != null)
if (cooldown == 0 || entity instanceof EntityPlayer)
{
int destinationID = link.destination().getDimension();
if(PocketManager.dimList.containsKey(destinationID) && PocketManager.dimList.containsKey(world.provider.dimensionId))
{
this.generatePocket(linkData);
if(mod_pocketDim.teleTimer==0||entity instanceof EntityPlayer)
{
mod_pocketDim.teleTimer=2+rand.nextInt(2);
}
else
{
return;
}
if(!world.isRemote)
{
entity = this.teleportEntity(world, entity, linkData);
}
entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F);
int playerXCoord=MathHelper.floor_double(entity.posX);
int playerYCoord=MathHelper.floor_double(entity.posY);
int playerZCoord=MathHelper.floor_double(entity.posZ);
if(!entity.worldObj.isBlockOpaqueCube(playerXCoord, playerYCoord-1,playerZCoord )&&PocketManager.instance.getDimData(linkData.locDimID).isDimRandomRift&&!linkData.hasGennedDoor)
{
for(int count=0;count<20;count++)
{
if(!entity.worldObj.isAirBlock(playerXCoord, playerYCoord-2-count,playerZCoord))
{
if(Block.blocksList[entity.worldObj.getBlockId(playerXCoord, playerYCoord-2-count,playerZCoord)].blockMaterial.isLiquid())
{
entity.worldObj.setBlock(playerXCoord, playerYCoord-1, playerZCoord, properties.FabricBlockID);
break;
}
}
if(entity.worldObj.isBlockOpaqueCube(playerXCoord, playerYCoord-1-count,playerZCoord))
{
break;
}
if(count==19)
{
entity.worldObj.setBlock(playerXCoord, playerYCoord-1, playerZCoord, properties.FabricBlockID);
}
}
}
this.generateDoor(world,linkData);
if(!entity.worldObj.isAirBlock(playerXCoord,playerYCoord+1,playerZCoord))
{
if(Block.blocksList[entity.worldObj.getBlockId(playerXCoord,playerYCoord+1,playerZCoord)].isOpaqueCube() &&
!mod_pocketDim.blockRift.isBlockImmune(entity.worldObj, playerXCoord+1,playerYCoord,playerZCoord))
{
entity.worldObj.setBlock(playerXCoord,playerYCoord+1,playerZCoord,0);
}
}
if (!entity.worldObj.isAirBlock(playerXCoord,playerYCoord,playerZCoord))
{
if(Block.blocksList[entity.worldObj.getBlockId(playerXCoord,playerYCoord,playerZCoord)].isOpaqueCube() &&
!mod_pocketDim.blockRift.isBlockImmune(entity.worldObj, playerXCoord,playerYCoord,playerZCoord))
{
entity.worldObj.setBlock(playerXCoord,playerYCoord,playerZCoord,0);
}
}
}
cooldown = 2 + random.nextInt(2);
}
else
{
return;
}
if (!initializeDestination(link, DDProperties.instance()))
{
return;
}
entity = teleportEntity(entity, link.destination());
entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F);
}
private static boolean initializeDestination(IDimLink link, DDProperties properties)
{
//FIXME: Change this later to support rooms that have been wiped and must be regenerated.
if (link.hasDestination())
{
return true;
}
//Check the destination type and respond accordingly
//FIXME: Add missing link types.
//FIXME: Add code for restoring the destination-side door.
switch (link.linkType())
{
case IDimLink.TYPE_DUNGEON:
return PocketBuilder.generateNewDungeonPocket(link, properties);
case IDimLink.TYPE_POCKET:
return PocketBuilder.generateNewPocket(link, properties);
case IDimLink.TYPE_NORMAL:
return true;
default:
throw new IllegalArgumentException("link has an unrecognized link type.");
}
return;
}
}

View file

@ -12,12 +12,11 @@ import cpw.mods.fml.relauncher.SideOnly;
public class EventHookContainer
{
private static DDProperties properties = null;
private final DDProperties properties;
public EventHookContainer()
public EventHookContainer(DDProperties properties)
{
if (properties == null)
properties = DDProperties.instance();
this.properties = properties;
}
@SideOnly(Side.CLIENT)
@ -56,7 +55,7 @@ public class EventHookContainer
@ForgeSubscribe
public void onWorldsave(WorldEvent.Save event)
{
if (PocketManager.isInitialized() && event.world.provider.dimensionId == 0)
if (event.world.provider.dimensionId == 0)
{
PocketManager.save();
}

View file

@ -10,6 +10,7 @@ import java.util.HashSet;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import StevenDimDoors.mod_pocketDim.core.IDimLink;
import StevenDimDoors.mod_pocketDim.core.NewDimData;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
@ -23,11 +24,9 @@ import cpw.mods.fml.common.network.Player;
public class PacketHandler implements IPacketHandler
{
public static byte DIM_UPDATE_PACKET_ID = 1;
public static byte REGISTER_DIM_PACKET_ID = 3;
public static byte REGISTER_LINK_PACKET_ID = 4;
public static byte REMOVE_LINK_PACKET_ID = 5;
public static byte DIM_PACKET_ID = 6;
public static byte LINK_KEY_PACKET_ID = 7;
public static byte REGISTER_DIM_PACKET_ID = 2;
public static byte REGISTER_LINK_PACKET_ID = 3;
public static byte REMOVE_LINK_PACKET_ID = 4;
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
@ -71,7 +70,7 @@ public class PacketHandler implements IPacketHandler
{
NewDimData dimDataToAddLink= PocketManager.instance.getDimData(dimId);
ILinkData linkToAdd = new ILinkData(dimId, data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readBoolean(),data.readInt());
IDimLink linkToAdd = new IDimLink(dimId, data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readBoolean(),data.readInt());
linkToAdd.hasGennedDoor=data.readBoolean();
PocketManager.instance.createLink(linkToAdd);
@ -90,7 +89,7 @@ public class PacketHandler implements IPacketHandler
{
NewDimData dimDataToRemoveFrom= PocketManager.instance.getDimData(dimId);
ILinkData linkToAdd = new ILinkData(dimId, data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readBoolean(),data.readInt());
IDimLink linkToAdd = new IDimLink(dimId, data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readBoolean(),data.readInt());
dimDataToRemoveFrom.removeLinkAtCoords(linkToAdd.locDimID, linkToAdd.locXCoord,linkToAdd.locYCoord, linkToAdd.locZCoord);
}
catch (Exception e)
@ -99,11 +98,6 @@ public class PacketHandler implements IPacketHandler
e.printStackTrace();
}
}
else if (id == LINK_KEY_PACKET_ID)
{
ILinkData link = new ILinkData(data.readInt(), data.readInt(), data.readInt(), data.readInt());
dimHelper.PocketManager.interDimLinkList.put(data.readInt(), link);
}
}
private static void processRegisterDimPacket()
@ -136,16 +130,16 @@ public class PacketHandler implements IPacketHandler
{
manager.addToSendQueue(PacketHandler.onDimCreatedPacket(data));
Collection <HashMap<Integer, HashMap<Integer, ILinkData>>> linkList = data.linksInThisDim.values();
Collection <HashMap<Integer, HashMap<Integer, IDimLink>>> linkList = data.linksInThisDim.values();
for(HashMap map : linkList )
{
Collection <HashMap<Integer, ILinkData>> linkList2 = map.values();
Collection <HashMap<Integer, IDimLink>> linkList2 = map.values();
for(HashMap map2 : linkList2)
{
Collection <ILinkData> linkList3 = map2.values();
Collection <IDimLink> linkList3 = map2.values();
for(ILinkData link : linkList3)
for(IDimLink link : linkList3)
{
packetsToSend.add(( PacketHandler.onLinkCreatedPacket(link)));
}
@ -159,7 +153,7 @@ public class PacketHandler implements IPacketHandler
}
}
public static void sendLinkCreatedPacket(ILinkData link)
public static void sendLinkCreatedPacket(IDimLink link)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(bos);
@ -193,36 +187,7 @@ public class PacketHandler implements IPacketHandler
return packet;
}
public static void sendlinkKeyPacket(ILinkData link, int key)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(bos);
try
{
dataOut.writeByte(PacketHandler.linkKeyPacketID);
dataOut.writeInt(link.destDimID);
dataOut.writeInt(link.destXCoord);
dataOut.writeInt(link.destYCoord);
dataOut.writeInt(link.destZCoord);
dataOut.writeInt(key);
}
catch (IOException e)
{
e.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel="DimDoorPackets";
packet.data = bos.toByteArray();
packet.length = bos.size();;
PacketDispatcher.sendPacketToAllPlayers(packet);
}
public static void sendLinkRemovedPacket(ILinkData link)
public static void sendLinkRemovedPacket(IDimLink link)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(bos);

View file

@ -12,14 +12,13 @@ import cpw.mods.fml.common.IPlayerTracker;
public class PlayerRespawnTracker implements IPlayerTracker
{
public PlayerRespawnTracker()
private final DDProperties properties;
public PlayerRespawnTracker(DDProperties properties)
{
if (properties == null)
properties = DDProperties.instance();
this.properties = properties;
}
private static DDProperties properties = null;
@Override
public void onPlayerLogin(EntityPlayer player) {
// TODO Auto-generated method stub

View file

@ -67,7 +67,7 @@ public class BlockDimWallPerm extends Block
//FIXME: Shouldn't we make the player's destination safe BEFORE teleporting him?!
//player.setPositionAndUpdate( x, y, z );
Point4D destination = new Point4D(destinationX, destinationY, destinationZ, 0);
DDTeleporter.teleport(player, destination);
DDTeleporter.teleportEntity(player, destination);
//player.setPositionAndUpdate( x, y, z );

View file

@ -34,7 +34,7 @@ public class CommandCreatePocket extends DDCommandBase
}
//Place a door leading to a pocket dimension where the player is standing.
//The pocket dimension will be serve as a room for the player to build a dungeon.
//The pocket dimension will serve as a room for the player to build a dungeon.
int x = (int) sender.posX;
int y = (int) sender.posY;
int z = (int) sender.posZ;

View file

@ -41,47 +41,37 @@ public class PocketManager
private static int OVERWORLD_DIMENSION_ID = 0;
private static boolean isInitialized = false;
private static boolean isLoaded = false;
private static boolean isSaving = false;
//HashMap containing all the dims registered with DimDoors, sorted by dim ID. loaded on startup
//HashMap that maps all the dimension IDs registered with DimDoors to their DD data.
private static HashMap<Integer, NewDimData> dimensionData = new HashMap<Integer, NewDimData>();
public static boolean isInitialized()
public static boolean isLoaded()
{
return isInitialized;
return isLoaded;
}
/**
* simple method called on startup to register all dims saved in the dim list. Only tries to register pocket dims, though. Also calls load()
* @return
*/
public static void initPockets()
public static void load()
{
if (isInitialized)
if (isLoaded)
{
throw new IllegalStateException("Pocket dimensions have already been initialized!");
throw new IllegalStateException("Pocket dimensions have already been loaded!");
}
isLoaded = true;
loadInternal();
//Register Limbo
DDProperties properties = DDProperties.instance();
registerDimension(properties.LimboDimensionID, null, false, false);
isInitialized = true;
load();
for (NewDimData dimension : dimensionData.values())
{
if (dimension.isPocketDimension())
{
try
{
DimensionManager.registerDimension(dimension.id(), properties.PocketProviderID);
}
catch (Exception e)
{
System.err.println("Could not register pocket dimension #" + dimension.id() + ". Probably caused by a version update/save data corruption/other mods.");
e.printStackTrace();
}
}
}
//Register pocket dimensions
registerPockets(properties);
}
public boolean clearPocket(NewDimData dimension)
@ -120,8 +110,27 @@ public class PocketManager
return false;
}
}
private static void registerPockets(DDProperties properties)
{
for (NewDimData dimension : dimensionData.values())
{
if (dimension.isPocketDimension())
{
try
{
DimensionManager.registerDimension(dimension.id(), properties.PocketProviderID);
}
catch (Exception e)
{
System.err.println("Could not register pocket dimension #" + dimension.id() + ". Probably caused by a version update/save data corruption/other mods.");
e.printStackTrace();
}
}
}
}
private static void unregisterDimensions()
private static void unregisterPockets()
{
for (NewDimData dimension : dimensionData.values())
{
@ -149,6 +158,10 @@ public class PocketManager
//TODO change from saving serialized objects to just saving data for compatabilies sake.
//TODO If saving is multithreaded as the concurrent modification exception implies, you should be synchronizing access. ~SenseiKiwi
if (!isLoaded)
{
return;
}
if (isSaving)
{
return;
@ -188,7 +201,10 @@ public class PocketManager
e.printStackTrace();
System.err.println("Could not save data-- SEVERE");
}
isSaving = false;
finally
{
isSaving = false;
}
}
}
@ -197,7 +213,7 @@ public class PocketManager
* @return
*/
@SuppressWarnings("unchecked")
public static void load()
private static void loadInternal()
{
//FIXME: There are a lot of things to fix here... First, we shouldn't be created so many File instances
//when we could just hold references and reuse them. Second, duplicate code is BAD. Loading stuff should
@ -353,7 +369,7 @@ public class PocketManager
public static void unload()
{
save();
unregisterDimensions();
unregisterPockets();
dimensionData.clear();
}

View file

@ -25,26 +25,16 @@ import StevenDimDoors.mod_pocketDim.blocks.TransientDoor;
import StevenDimDoors.mod_pocketDim.blocks.UnstableDoor;
import StevenDimDoors.mod_pocketDim.blocks.WarpDoor;
import StevenDimDoors.mod_pocketDim.blocks.dimHatch;
import StevenDimDoors.mod_pocketDim.commands.CommandCreateDungeonRift;
import StevenDimDoors.mod_pocketDim.commands.CommandCreatePocket;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteAllLinks;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteDimensionData;
import StevenDimDoors.mod_pocketDim.commands.CommandDeleteRifts;
import StevenDimDoors.mod_pocketDim.commands.CommandExportDungeon;
import StevenDimDoors.mod_pocketDim.commands.CommandPrintDimensionData;
import StevenDimDoors.mod_pocketDim.commands.CommandPruneDimensions;
import StevenDimDoors.mod_pocketDim.commands.CommandResetDungeons;
import StevenDimDoors.mod_pocketDim.commands.CommandTeleportPlayer;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
import StevenDimDoors.mod_pocketDim.items.ItemBlockDimWall;
import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor;
import StevenDimDoors.mod_pocketDim.items.ItemRiftBlade;
import StevenDimDoors.mod_pocketDim.items.ItemRiftSignature;
import StevenDimDoors.mod_pocketDim.items.ItemStabilizedRiftSignature;
import StevenDimDoors.mod_pocketDim.items.ItemStableFabric;
import StevenDimDoors.mod_pocketDim.items.ItemUnstableDoor;
import StevenDimDoors.mod_pocketDim.items.ItemWarpDoor;
import StevenDimDoors.mod_pocketDim.items.ItemRiftSignature;
import StevenDimDoors.mod_pocketDim.items.itemRiftRemover;
import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler;
import StevenDimDoors.mod_pocketDim.ticking.LimboDecay;
@ -135,9 +125,6 @@ public class mod_pocketDim
public static DDProperties properties;
public static MonolithSpawner spawner; //Added this field temporarily. Will be refactored out later.
public static GatewayGenerator riftGen;
public static long genTime;
public static int teleTimer = 0;
public static CreativeTabs dimDoorsCreativeTab = new CreativeTabs("dimDoorsCreativeTab")
{
@ -157,22 +144,20 @@ public class mod_pocketDim
@PreInit
public void PreInit(FMLPreInitializationEvent event)
public void onPreInitialization(FMLPreInitializationEvent event)
{
//This should be the FIRST thing that gets done.
properties = DDProperties.initialize(event.getSuggestedConfigurationFile());
//Now do other stuff
MinecraftForge.EVENT_BUS.register(new EventHookContainer());
MinecraftForge.EVENT_BUS.register(new EventHookContainer(properties));
//These fields MUST be initialized after properties are loaded to prevent
//instances from holding onto null references to the properties.
tracker = new PlayerRespawnTracker();
riftGen = new GatewayGenerator();
tracker = new PlayerRespawnTracker(properties);
riftGen = new GatewayGenerator(properties);
}
@Init
public void Init(FMLInitializationEvent event)
public void onInitialization(FMLInitializationEvent event)
{
CommonTickHandler commonTickHandler = new CommonTickHandler();
TickRegistry.registerTickHandler(new ClientTickHandler(), Side.CLIENT);
@ -255,8 +240,6 @@ public class mod_pocketDim
LanguageRegistry.instance().addStringLocalization("itemGroup.dimDoorsCustomTab", "en_US", "Dimensional Doors Items");
//GameRegistry.registerTileEntity(TileEntityDimDoor.class, "TileEntityDimRail");
GameRegistry.registerTileEntity(TileEntityDimDoor.class, "TileEntityDimDoor");
GameRegistry.registerTileEntity(TileEntityRift.class, "TileEntityRift");
@ -268,7 +251,7 @@ public class mod_pocketDim
//GameRegistry.addBiome(this.limboBiome);
//GameRegistry.addBiome(this.pocketBiome);
if (properties.CraftingDimensionaDoorAllowed)
if (properties.CraftingDimensionalDoorAllowed)
{
GameRegistry.addRecipe(new ItemStack(itemDimDoor, 1), new Object[]
{
@ -280,22 +263,6 @@ public class mod_pocketDim
" ", "yxy", " ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.doorIron
});
}
/**
if(this.enableDimRail)
{
GameRegistry.addRecipe(new ItemStack(dimRail, 1), new Object[]
{
" ", "yxy", " ", 'x', this.itemDimDoor, 'y', Block.rail
});
GameRegistry.addRecipe(new ItemStack(dimRail, 1), new Object[]
{
" ", "yxy", " ", 'x', this.itemExitDoor, 'y', Block.rail
});
}
**/
if(properties.CraftingUnstableDoorAllowed)
{
GameRegistry.addRecipe(new ItemStack(itemChaosDoor, 1), new Object[]
@ -385,28 +352,29 @@ public class mod_pocketDim
@PostInit
public void PostInit(FMLPostInitializationEvent event)
public void onPostInitialization(FMLPostInitializationEvent event)
{
//Register loot chests
DDLoot.registerInfo();
}
@ServerStopping
public void serverStopping(FMLServerStoppingEvent event)
public void onServerStopping(FMLServerStoppingEvent event)
{
try
{
PocketManager.unload();
}
catch(Exception e)
catch (Exception e)
{
e.printStackTrace();
}
}
@ServerStarting
public void serverStarting(FMLServerStartingEvent event)
public void onServerStarting(FMLServerStartingEvent event)
{
/*
CommandResetDungeons.instance().register(event);
CommandCreateDungeonRift.instance().register(event);
CommandDeleteAllLinks.instance().register(event);
@ -417,6 +385,7 @@ public class mod_pocketDim
CommandPruneDimensions.instance().register(event);
CommandCreatePocket.instance().register(event);
CommandTeleportPlayer.instance().register(event);
*/
PocketManager.load();
}
}

View file

@ -3,7 +3,7 @@ package StevenDimDoors.mod_pocketDim.ticking;
import java.util.ArrayList;
import java.util.EnumSet;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.DDTeleporter;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
@ -43,9 +43,9 @@ public class CommonTickHandler implements ITickHandler, IRegularTickSender
//TODO: Stuck this in here because it's already rather hackish.
//We should standardize this as an IRegularTickReceiver in the future. ~SenseiKiwi
if (mod_pocketDim.teleTimer > 0)
if (DDTeleporter.cooldown > 0)
{
mod_pocketDim.teleTimer--;
DDTeleporter.cooldown--;
}
}

View file

@ -150,7 +150,7 @@ public class MobMonolith extends EntityFlying implements IMob
(int) this.posY + 500,
(int) this.posZ + MathHelper.getRandomIntegerInRange(rand, -250, 250),
properties.LimboDimensionID);
DDTeleporter.teleport(entityPlayer, destination);
DDTeleporter.teleportEntity(entityPlayer, destination);
this.aggro = 0;
entityPlayer.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.crack",13, 1);

View file

@ -29,12 +29,12 @@ public class GatewayGenerator implements IWorldGenerator
private static final int NETHER_CHANCE_CORRECTION = 4;
private static final int OVERWORLD_DIMENSION_ID = 0;
private static final int NETHER_DIMENSION_ID = -1;
private static DDProperties properties = null;
public GatewayGenerator()
private final DDProperties properties;
public GatewayGenerator(DDProperties properties)
{
if (properties == null)
properties = DDProperties.instance();
this.properties = properties;
}
@Override
@ -141,7 +141,7 @@ public class GatewayGenerator implements IWorldGenerator
}
else
{
createLimboGateway(world, x, y, z);
createLimboGateway(world, x, y, z, properties.LimboBlockID);
}
//Place the shiny transient door into a dungeon
@ -190,11 +190,10 @@ public class GatewayGenerator implements IWorldGenerator
world.setBlock(x, y, z + 1, blockID, 0, 3);
}
private static void createLimboGateway(World world, int x, int y, int z)
private static void createLimboGateway(World world, int x, int y, int z, int blockID)
{
//Build the gateway out of Unraveled Fabric. Since nearly all the blocks in Limbo are of
//that type, there is no point replacing the ground.
final int blockID = properties.LimboBlockID;
world.setBlock(x, y + 2, z + 1, blockID, 0, 3);
world.setBlock(x, y + 2, z - 1, blockID, 0, 3);