From dd9b1f0c65de7a3cfa5473e232e6e6cfe5b4866d Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 23 Aug 2013 04:12:56 -0400 Subject: [PATCH 01/24] Started Rewriting LinkData Created NewLinkData and replaced references to the original LinkData. Moved it to the mod_pocketDim.core package. Added Point4D, an immutable point type for 3D integer coordinates with an added dimension ID. --- StevenDimDoors/mod_pocketDim/DimData.java | 52 +++---- .../mod_pocketDim/DungeonGenerator.java | 3 +- .../mod_pocketDim/EventHookContainer.java | 3 +- StevenDimDoors/mod_pocketDim/LinkData.java | 68 --------- .../mod_pocketDim/PacketHandler.java | 21 +-- .../mod_pocketDim/RiftGenerator.java | 7 +- .../mod_pocketDim/SchematicLoader.java | 5 +- .../mod_pocketDim/TileEntityRift.java | 5 +- .../mod_pocketDim/TransientDoor.java | 3 +- .../blocks/BlockDimWallPerm.java | 6 +- .../mod_pocketDim/blocks/ChaosDoor.java | 8 +- .../mod_pocketDim/blocks/ExitDoor.java | 2 +- .../mod_pocketDim/blocks/dimDoor.java | 12 +- .../mod_pocketDim/blocks/dimHatch.java | 4 +- .../commands/CommandCreateDungeonRift.java | 4 +- .../commands/CommandCreatePocket.java | 4 +- .../commands/CommandDeleteAllLinks.java | 6 +- .../commands/CommandDeleteDimensionData.java | 6 +- .../commands/CommandDeleteRifts.java | 6 +- .../commands/CommandPrintDimensionData.java | 6 +- .../commands/CommandPruneDimensions.java | 6 +- .../mod_pocketDim/core/NewLinkData.java | 36 +++++ .../dungeon/DungeonSchematic.java | 10 +- .../dungeon/pack/DungeonPack.java | 4 +- .../mod_pocketDim/helpers/DungeonHelper.java | 16 +-- .../mod_pocketDim/helpers/dimHelper.java | 76 +++++----- .../mod_pocketDim/helpers/yCoordHelper.java | 4 +- .../mod_pocketDim/items/ItemRiftBlade.java | 6 +- .../items/ItemStabilizedRiftSignature.java | 4 +- .../mod_pocketDim/items/ItemStableFabric.java | 4 +- .../mod_pocketDim/items/itemDimDoor.java | 4 +- .../items/itemLinkSignature.java | 4 +- .../mod_pocketDim/mod_pocketDim.java | 3 +- .../mod_pocketDim/pocketTeleporter.java | 5 +- .../mod_pocketDim/ticking/MobMonolith.java | 4 +- .../ticking/RiftRegenerator.java | 6 +- .../mod_pocketDim/util/Point4D.java | 131 ++++++++++++++++++ 37 files changed, 332 insertions(+), 222 deletions(-) delete mode 100644 StevenDimDoors/mod_pocketDim/LinkData.java create mode 100644 StevenDimDoors/mod_pocketDim/core/NewLinkData.java create mode 100644 StevenDimDoors/mod_pocketDim/util/Point4D.java diff --git a/StevenDimDoors/mod_pocketDim/DimData.java b/StevenDimDoors/mod_pocketDim/DimData.java index 043856c..bd56b84 100644 --- a/StevenDimDoors/mod_pocketDim/DimData.java +++ b/StevenDimDoors/mod_pocketDim/DimData.java @@ -8,6 +8,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; + import net.minecraft.util.MathHelper; import net.minecraft.world.World; @@ -19,7 +21,7 @@ public class DimData implements Serializable public World world; - public LinkData exitDimLink; + public NewLinkData exitDimLink; public boolean isPocket; public boolean hasBeenFilled=false; @@ -27,13 +29,13 @@ public class DimData implements Serializable public boolean isDimRandomRift=false; public DungeonGenerator dungeonGenerator = null; //public boolean isPrivatePocket = false; - public HashMap>> linksInThisDim = new HashMap(); - HashMap dimX; - HashMap> dimY ; + public HashMap>> linksInThisDim = new HashMap(); + HashMap dimX; + HashMap> dimY ; static final long serialVersionUID = 454342L; - public DimData(int dimID, boolean isPocket, int depth, LinkData exitLinkData) + public DimData(int dimID, boolean isPocket, int depth, NewLinkData exitLinkData) { this.dimID=dimID; this.depth=depth; @@ -44,12 +46,12 @@ public class DimData implements Serializable public DimData(int dimID, boolean isPocket, int depth, int exitLinkDimID, int exitX, int exitY, int exitZ) { - this(dimID, isPocket, depth, new LinkData(exitLinkDimID, exitX, exitY, exitZ)); + this(dimID, isPocket, depth, new NewLinkData(exitLinkDimID, exitX, exitY, exitZ)); } - public LinkData findNearestRift(World world, int range, int x, int y, int z) + public NewLinkData findNearestRift(World world, int range, int x, int y, int z) { - LinkData nearest=null; + NewLinkData nearest=null; float distance=range+1; int i=-range; int j=-range; @@ -89,7 +91,7 @@ public class DimData implements Serializable public ArrayList findRiftsInRange(World world, int range, int x, int y, int z) { - LinkData nearest=null; + NewLinkData nearest=null; ArrayList rifts = new ArrayList(); int i=-range; int j=-range; @@ -132,7 +134,7 @@ public class DimData implements Serializable - public LinkData addLinkToDim(LinkData link) + public NewLinkData addLinkToDim(NewLinkData link) { if(this.linksInThisDim.containsKey(link.locZCoord)) { @@ -144,13 +146,13 @@ public class DimData implements Serializable } else { - this.dimX=new HashMap(); + this.dimX=new HashMap(); } } else { - this.dimX=new HashMap(); - this.dimY=new HashMap>(); + this.dimX=new HashMap(); + this.dimY=new HashMap>(); } this.dimX.put(link.locXCoord, link); @@ -162,9 +164,9 @@ public class DimData implements Serializable } - public LinkData addLinkToDim( int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, int linkOrientation) + public NewLinkData addLinkToDim( int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, int linkOrientation) { - LinkData linkData= new LinkData(this.dimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord,destinationZCoord,this.isPocket,linkOrientation); + NewLinkData linkData= new NewLinkData(this.dimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord,destinationZCoord,this.isPocket,linkOrientation); return this.addLinkToDim(linkData); } @@ -174,7 +176,7 @@ public class DimData implements Serializable return (this.dimID == DDProperties.instance().LimboDimensionID); } - public void removeLinkAtCoords(LinkData link) + public void removeLinkAtCoords(NewLinkData link) { this.removeLinkAtCoords(link.locDimID, link.locXCoord, link.locYCoord, link.locZCoord); } @@ -191,13 +193,13 @@ public class DimData implements Serializable } else { - this.dimX=new HashMap(); + this.dimX=new HashMap(); } } else { - this.dimX=new HashMap(); - this.dimY=new HashMap>(); + this.dimX=new HashMap(); + this.dimY=new HashMap>(); } this.dimX.remove(locationXCoord); @@ -205,7 +207,7 @@ public class DimData implements Serializable this.linksInThisDim.put(locationZCoord, dimY); } - public LinkData findLinkAtCoords(int locationXCoord, int locationYCoord, int locationZCoord) + public NewLinkData findLinkAtCoords(int locationXCoord, int locationYCoord, int locationZCoord) { try { @@ -232,21 +234,21 @@ public class DimData implements Serializable return null; } - public ArrayList getLinksInDim() + public ArrayList getLinksInDim() { //TODO: We might want to modify this function, but I'm afraid of breaking something right now. //To begin with, the name is wrong. This doesn't print anything! >_o ~SenseiKiwi - ArrayList links = new ArrayList(); + ArrayList links = new ArrayList(); if (this.linksInThisDim == null) { return links; } - for (HashMap> first : this.linksInThisDim.values()) + for (HashMap> first : this.linksInThisDim.values()) { - for (HashMap second : first.values()) + for (HashMap second : first.values()) { - for (LinkData linkData : second.values()) + for (NewLinkData linkData : second.values()) { links.add(linkData); } diff --git a/StevenDimDoors/mod_pocketDim/DungeonGenerator.java b/StevenDimDoors/mod_pocketDim/DungeonGenerator.java index 0500e76..861bed7 100644 --- a/StevenDimDoors/mod_pocketDim/DungeonGenerator.java +++ b/StevenDimDoors/mod_pocketDim/DungeonGenerator.java @@ -5,6 +5,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -18,7 +19,7 @@ public class DungeonGenerator implements Serializable public int weight; public String schematicPath; public ArrayList sideRifts = new ArrayList(); - public LinkData exitLink; + public NewLinkData exitLink; public boolean isOpen; public int sideDoorsSoFar=0; diff --git a/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/StevenDimDoors/mod_pocketDim/EventHookContainer.java index d2e12b1..24f67b5 100644 --- a/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -6,6 +6,7 @@ import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.player.PlayerDropsEvent; import net.minecraftforge.event.world.WorldEvent; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -55,7 +56,7 @@ public class EventHookContainer if (dimHelper.dimList.containsKey(dimensionID)) { - for (LinkData link : dimHelper.instance.getDimData(dimensionID).getLinksInDim()) + for (NewLinkData link : dimHelper.instance.getDimData(dimensionID).getLinksInDim()) { if (!mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord)) { diff --git a/StevenDimDoors/mod_pocketDim/LinkData.java b/StevenDimDoors/mod_pocketDim/LinkData.java deleted file mode 100644 index eab4ec6..0000000 --- a/StevenDimDoors/mod_pocketDim/LinkData.java +++ /dev/null @@ -1,68 +0,0 @@ -package StevenDimDoors.mod_pocketDim; - -import java.io.Serializable; - -public class LinkData implements Serializable -{ - - public int locXCoord; - public int locYCoord; - public int locZCoord; - - public int destXCoord; - public int destYCoord; - public int destZCoord; - public int numberofChildren; - public boolean isLocPocket; - public int linkOrientation; - - public int destDimID; - public int locDimID; - - public boolean exists=false; - public boolean hasGennedDoor=false; - - static final long serialVersionUID = 45544342L; - - - public LinkData() - { - this.exists=false; - } - - public LinkData(int exitLinkDimID, int exitX, int exitY, int exitZ) - { - this.destDimID=exitLinkDimID; - this.destXCoord=exitX; - this.destYCoord=exitY; - this.destZCoord=exitZ; - } - - public LinkData(int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, boolean isPocket,int orientation) - { - this.exists = true; - this.locXCoord=locationXCoord; - this.locYCoord=locationYCoord; - this.locZCoord=locationZCoord; - - this.destXCoord=destinationXCoord; - this.destYCoord=destinationYCoord; - this.destZCoord=destinationZCoord; - - this.destDimID=destinationDimID; - this.locDimID=locationDimID; - this.isLocPocket=isPocket; - this.linkOrientation=orientation; - } - - public String printLinkData() - { - //TODO: Rewrite this to make it prettier. @_@ I'm afraid of changing it to ToString() on the off - //chance it'll cause explosions and sadness. Damn serialization! ~SenseiKiwi - - String linkInfo; - linkInfo = String.valueOf(this.locDimID) + "locDimID "+String.valueOf(this.locXCoord)+":locXCoord "+String.valueOf(this.locYCoord)+":locYCoord "+String.valueOf(this.locZCoord)+":locZCoord "; - linkInfo.concat("\n"+ String.valueOf(this.destDimID)+"DestDimID "+String.valueOf(this.destXCoord)+":destXCoord "+String.valueOf(this.destYCoord)+":destYCoord "+String.valueOf(this.destZCoord)+":destZCoord "); - return linkInfo; - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/PacketHandler.java b/StevenDimDoors/mod_pocketDim/PacketHandler.java index 38a2d50..a12ef35 100644 --- a/StevenDimDoors/mod_pocketDim/PacketHandler.java +++ b/StevenDimDoors/mod_pocketDim/PacketHandler.java @@ -14,6 +14,7 @@ import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import com.google.common.io.ByteArrayDataInput; @@ -105,7 +106,7 @@ public class PacketHandler implements IPacketHandler { DimData dimDataToAddLink= dimHelper.instance.getDimData(dimId); - LinkData linkToAdd = new LinkData(dimId, data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readBoolean(),data.readInt()); + NewLinkData linkToAdd = new NewLinkData(dimId, data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readBoolean(),data.readInt()); linkToAdd.hasGennedDoor=data.readBoolean(); dimHelper.instance.createLink(linkToAdd); @@ -130,7 +131,7 @@ public class PacketHandler implements IPacketHandler { DimData dimDataToRemoveFrom= dimHelper.instance.getDimData(dimId); - LinkData linkToAdd = new LinkData(dimId, data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readBoolean(),data.readInt()); + NewLinkData linkToAdd = new NewLinkData(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); } @@ -144,7 +145,7 @@ public class PacketHandler implements IPacketHandler } if(id==this.linkKeyPacketID) { - LinkData link = new LinkData(data.readInt(), data.readInt(), data.readInt(), data.readInt()); + NewLinkData link = new NewLinkData(data.readInt(), data.readInt(), data.readInt(), data.readInt()); dimHelper.instance.interDimLinkList.put(data.readInt(), link); } @@ -168,18 +169,18 @@ public class PacketHandler implements IPacketHandler manager.addToSendQueue(PacketHandler.onDimCreatedPacket(data)); - Collection >> linkList = data.linksInThisDim.values(); + Collection >> linkList = data.linksInThisDim.values(); for(HashMap map : linkList ) { - Collection > linkList2 = map.values(); + Collection > linkList2 = map.values(); for(HashMap map2 : linkList2) { - Collection linkList3 = map2.values(); + Collection linkList3 = map2.values(); - for(LinkData link : linkList3) + for(NewLinkData link : linkList3) { packetsToSend.add(( PacketHandler.onLinkCreatedPacket(link))); @@ -206,7 +207,7 @@ public class PacketHandler implements IPacketHandler } - public static Packet250CustomPayload onLinkCreatedPacket(LinkData link) + public static Packet250CustomPayload onLinkCreatedPacket(NewLinkData link) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(bos); @@ -247,7 +248,7 @@ public class PacketHandler implements IPacketHandler } - public static Packet250CustomPayload linkKeyPacket(LinkData link, int key) + public static Packet250CustomPayload linkKeyPacket(NewLinkData link, int key) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(bos); @@ -283,7 +284,7 @@ public class PacketHandler implements IPacketHandler } - public static void onLinkRemovedPacket(LinkData link) + public static void onLinkRemovedPacket(NewLinkData link) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(bos); diff --git a/StevenDimDoors/mod_pocketDim/RiftGenerator.java b/StevenDimDoors/mod_pocketDim/RiftGenerator.java index 1009b31..5b02031 100644 --- a/StevenDimDoors/mod_pocketDim/RiftGenerator.java +++ b/StevenDimDoors/mod_pocketDim/RiftGenerator.java @@ -7,6 +7,7 @@ import net.minecraft.block.material.Material; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraftforge.common.DimensionManager; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.items.itemDimDoor; import StevenDimDoors.mod_pocketDim.world.LimboProvider; @@ -55,7 +56,7 @@ public class RiftGenerator implements IWorldGenerator int attempts; int correction; boolean valid; - LinkData link; + NewLinkData link; //Check if we're generating things in the Nether if (world.provider.dimensionId == NETHER_DIMENSION_ID) @@ -93,7 +94,7 @@ public class RiftGenerator implements IWorldGenerator //Otherwise, create a one-way link and connect to the destination of the first link. if (link == null) { - link = new LinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 0); + link = new NewLinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 0); link = dimHelper.instance.createPocket(link, true, true); } else @@ -129,7 +130,7 @@ public class RiftGenerator implements IWorldGenerator { //Create a two-way link between the upper block of the gateway and a pocket dimension //That pocket dimension is where we'll start a dungeon! - link = new LinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 0); + link = new NewLinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 0); link = dimHelper.instance.createPocket(link, true, true); //If the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java index 630b21f..62e357e 100644 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ b/StevenDimDoors/mod_pocketDim/SchematicLoader.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Random; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -15,7 +16,7 @@ public class SchematicLoader { private SchematicLoader() { } - public static boolean generateDungeonPocket(LinkData link, DDProperties properties) + public static boolean generateDungeonPocket(NewLinkData link, DDProperties properties) { if (link == null || properties == null) { @@ -155,7 +156,7 @@ public class SchematicLoader return dungeon; } - private static long computeDestinationHash(LinkData link) + private static long computeDestinationHash(NewLinkData link) { //Time for some witchcraft. //The code here is inspired by a discussion on Stack Overflow regarding hash codes for 3D. diff --git a/StevenDimDoors/mod_pocketDim/TileEntityRift.java b/StevenDimDoors/mod_pocketDim/TileEntityRift.java index e15ba5c..cfff50f 100644 --- a/StevenDimDoors/mod_pocketDim/TileEntityRift.java +++ b/StevenDimDoors/mod_pocketDim/TileEntityRift.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Random; import StevenDimDoors.mod_pocketDim.blocks.BlockRift; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; @@ -41,7 +42,7 @@ public class TileEntityRift extends TileEntity public int age = 0; public HashMap renderingCenters = new HashMap(); - public LinkData nearestRiftData; + public NewLinkData nearestRiftData; public int spawnedEndermenID=0; Random rand; DataWatcher watcher = new DataWatcher(); @@ -243,7 +244,7 @@ public class TileEntityRift extends TileEntity if (growCount<100) { - LinkData link = dimHelper.instance.getLinkDataFromCoords(this.xCoord, this.yCoord, this.zCoord, worldObj); + NewLinkData link = dimHelper.instance.getLinkDataFromCoords(this.xCoord, this.yCoord, this.zCoord, worldObj); if(link!=null) { if(!this.hasGrownRifts&&rand.nextInt(3)==0) diff --git a/StevenDimDoors/mod_pocketDim/TransientDoor.java b/StevenDimDoors/mod_pocketDim/TransientDoor.java index 3df173b..47a0445 100644 --- a/StevenDimDoors/mod_pocketDim/TransientDoor.java +++ b/StevenDimDoors/mod_pocketDim/TransientDoor.java @@ -3,6 +3,7 @@ package StevenDimDoors.mod_pocketDim; import java.util.Random; import StevenDimDoors.mod_pocketDim.blocks.ExitDoor; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import net.minecraft.block.Block; @@ -86,7 +87,7 @@ public class TransientDoor extends ExitDoor - LinkData linkData= dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World); + NewLinkData linkData= dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World); if(linkData!=null) { if(dimHelper.dimList.containsKey(linkData.destDimID)) diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java index 95289a9..0e047e5 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java @@ -12,8 +12,8 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import StevenDimDoors.mod_pocketDim.BlankTeleporter; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import cpw.mods.fml.common.FMLCommonHandler; @@ -51,10 +51,10 @@ public class BlockDimWallPerm extends Block { Random rand = new Random(); - LinkData link=dimHelper.instance.getRandomLinkData(false); + NewLinkData link=dimHelper.instance.getRandomLinkData(false); if(link==null) { - link =new LinkData(0,0,0,0); + link =new NewLinkData(0,0,0,0); } link.destDimID = 0; link.locDimID = par1World.provider.dimensionId; diff --git a/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java b/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java index 82447ee..bf621ee 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java @@ -3,8 +3,8 @@ package StevenDimDoors.mod_pocketDim.blocks; import java.util.Random; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import net.minecraft.block.Block; @@ -76,7 +76,7 @@ public class ChaosDoor extends dimDoor if(newDim) { - LinkData link = new LinkData(par1World.provider.dimensionId, properties.LimboDimensionID, par2, par3, par4, par2, par3+500, par4, false,0); + NewLinkData link = new NewLinkData(par1World.provider.dimensionId, properties.LimboDimensionID, par2, par3, par4, par2, par3+500, par4, false,0); link.linkOrientation= par1World.getBlockMetadata(par2, par3-1, par4); dimHelper.instance.createLink(link); // System.out.println(link.linkOrientation); @@ -118,7 +118,7 @@ public class ChaosDoor extends dimDoor { i++; - LinkData link = (LinkData) dimHelper.instance.getRandomLinkData(false); + NewLinkData link = (NewLinkData) dimHelper.instance.getRandomLinkData(false); if(link!=null) { @@ -127,7 +127,7 @@ public class ChaosDoor extends dimDoor { foundRandomDest=true; - dimHelper.instance.traverseDimDoor(par1World, new LinkData(link.destDimID,link.locDimID,link.destXCoord,link.destYCoord,link.destZCoord,link.locXCoord,link.locYCoord,link.locZCoord,link.isLocPocket,0), par5Entity); + dimHelper.instance.traverseDimDoor(par1World, new NewLinkData(link.destDimID,link.locDimID,link.destXCoord,link.destYCoord,link.destZCoord,link.locXCoord,link.locYCoord,link.locZCoord,link.isLocPocket,0), par5Entity); if(dimHelper.getWorld(link.locDimID)!=null) { diff --git a/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java b/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java index 1d48443..346b5cd 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java @@ -3,8 +3,8 @@ package StevenDimDoors.mod_pocketDim.blocks; import java.util.Random; import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; diff --git a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java b/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java index 5e94326..86dc8c9 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java @@ -3,9 +3,9 @@ package StevenDimDoors.mod_pocketDim.blocks; import java.util.Random; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; @@ -59,19 +59,19 @@ public class dimDoor extends BlockContainer { if(dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)!=null) { - LinkData link= dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World); + NewLinkData link= dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World); par1World.setBlock(par2, par3, par4, properties.RiftBlockID); } if(dimHelper.instance.getLinkDataFromCoords(par2, par3-1, par4, par1World)!=null) { - LinkData link= dimHelper.instance.getLinkDataFromCoords(par2, par3-1, par4, par1World); + NewLinkData link= dimHelper.instance.getLinkDataFromCoords(par2, par3-1, par4, par1World); par1World.setBlock(par2, par3-1, par4, properties.RiftBlockID); } if(dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World)!=null) { - LinkData link= dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World); + NewLinkData link= dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World); par1World.setBlock(par2, par3+1, par4, properties.RiftBlockID); } @@ -89,7 +89,7 @@ public class dimDoor extends BlockContainer int var12 = (int) (MathHelper.floor_double((double)((par5Entity.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); int num=0; - LinkData linkData=null; + NewLinkData linkData=null; if(par1World.getBlockId(par2, par3-1, par4)==this.blockID) { @@ -264,7 +264,7 @@ public class dimDoor extends BlockContainer - LinkData link = new LinkData(par1World.provider.dimensionId, 0, par2, par3, par4, par2, par3, par4, true,par1World.getBlockMetadata(par2, par3-1, par4)); + NewLinkData link = new NewLinkData(par1World.provider.dimensionId, 0, par2, par3, par4, par2, par3, par4, true,par1World.getBlockMetadata(par2, par3-1, par4)); dimHelper.instance.createPocket(link,true, false); // System.out.println(link.linkOrientation); diff --git a/StevenDimDoors/mod_pocketDim/blocks/dimHatch.java b/StevenDimDoors/mod_pocketDim/blocks/dimHatch.java index cb27839..a7ad487 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/dimHatch.java +++ b/StevenDimDoors/mod_pocketDim/blocks/dimHatch.java @@ -1,8 +1,8 @@ package StevenDimDoors.mod_pocketDim.blocks; import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.world.PocketProvider; import net.minecraft.block.BlockTrapDoor; @@ -55,7 +55,7 @@ public class dimHatch extends BlockTrapDoor DimData dimData = (DimData) dimHelper.instance.dimList.get(par1World.provider.dimensionId); - LinkData exitLink=dimData.exitDimLink; + NewLinkData exitLink=dimData.exitDimLink; exitLink.locDimID=par1World.provider.dimensionId; diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index 81c50f7..f444170 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -6,7 +6,7 @@ import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.MathHelper; import StevenDimDoors.mod_pocketDim.DungeonGenerator; -import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; @@ -60,7 +60,7 @@ public class CommandCreateDungeonRift extends DDCommandBase int x = MathHelper.floor_double(sender.posX); int y = MathHelper.floor_double(sender.posY); int z = MathHelper.floor_double (sender.posZ); - LinkData link = new LinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); + NewLinkData link = new NewLinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); if (command[0].equals("random")) { diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java b/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java index 27a0d5f..7b685f3 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java @@ -1,7 +1,7 @@ package StevenDimDoors.mod_pocketDim.commands; import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; public class CommandCreatePocket extends DDCommandBase @@ -39,7 +39,7 @@ public class CommandCreatePocket extends DDCommandBase int x = (int) sender.posX; int y = (int) sender.posY; int z = (int) sender.posZ; - LinkData link = DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); + NewLinkData link = DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); //Notify the player sender.sendChatToPlayer("Created a door to a pocket dimension (Dimension ID = " + link.destDimID + "). Please build your dungeon there."); diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java index f48b352..1133cb1 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java @@ -5,7 +5,7 @@ import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; public class CommandDeleteAllLinks extends DDCommandBase @@ -57,9 +57,9 @@ public class CommandDeleteAllLinks extends DDCommandBase if(dimHelper.dimList.containsKey(targetDim)) { DimData dim = dimHelper.instance.getDimData(targetDim); - ArrayList linksInDim = dim.getLinksInDim(); + ArrayList linksInDim = dim.getLinksInDim(); - for (LinkData link : linksInDim) + for (NewLinkData link : linksInDim) { World targetWorld = dimHelper.getWorld(targetDim); diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java index 4c2242f..75b6513 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java @@ -5,7 +5,7 @@ import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; public class CommandDeleteDimensionData extends DDCommandBase @@ -60,10 +60,10 @@ public class CommandDeleteDimensionData extends DDCommandBase { for(DimData dimData :dimHelper.dimList.values()) { - Collection links= new ArrayList(); + Collection links= new ArrayList(); links.addAll( dimData.getLinksInDim()); - for(LinkData link : links) + for(NewLinkData link : links) { if(link.destDimID==targetDim) { diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java index 1e22fea..d3c925d 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -5,8 +5,8 @@ import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; public class CommandDeleteRifts extends DDCommandBase @@ -58,9 +58,9 @@ public class CommandDeleteRifts extends DDCommandBase if(dimHelper.dimList.containsKey(targetDim)) { DimData dim = dimHelper.instance.getDimData(targetDim); - ArrayList linksInDim = dim.getLinksInDim(); + ArrayList linksInDim = dim.getLinksInDim(); - for(LinkData link : linksInDim) + for(NewLinkData link : linksInDim) { World targetWorld = dimHelper.getWorld(targetDim); diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java b/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java index 427a8bf..14105d5 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; public class CommandPrintDimensionData extends DDCommandBase @@ -56,11 +56,11 @@ public class CommandPrintDimensionData extends DDCommandBase return DDCommandResult.UNREGISTERED_DIMENSION; } - ArrayList links = dimData.getLinksInDim(); + ArrayList links = dimData.getLinksInDim(); sender.sendChatToPlayer("Dimension ID = " + dimData.dimID); sender.sendChatToPlayer("Dimension Depth = " + dimData.depth); - for (LinkData link : links) + for (NewLinkData link : links) { sender.sendChatToPlayer(link.printLinkData()); } diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java b/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java index dacb16e..5145b9a 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java @@ -7,7 +7,7 @@ import java.util.Set; import net.minecraft.entity.player.EntityPlayer; import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; public class CommandPruneDimensions extends DDCommandBase @@ -47,12 +47,12 @@ public class CommandPruneDimensions extends DDCommandBase for (DimData data : allDims) { - for (LinkData link : data.getLinksInDim()) + for (NewLinkData link : data.getLinksInDim()) { linkedDimensions.add(link.destDimID); } } - for (LinkData link : dimHelper.instance.interDimLinkList.values()) + for (NewLinkData link : dimHelper.instance.interDimLinkList.values()) { linkedDimensions.add(link.destDimID); } diff --git a/StevenDimDoors/mod_pocketDim/core/NewLinkData.java b/StevenDimDoors/mod_pocketDim/core/NewLinkData.java new file mode 100644 index 0000000..c2deee1 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/core/NewLinkData.java @@ -0,0 +1,36 @@ +package StevenDimDoors.mod_pocketDim.core; + +import java.io.Serializable; + +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public class NewLinkData implements Serializable +{ + private static final long serialVersionUID = 1462177151401498444L; + + private Point4D source; + private Point4D destination; + + public NewLinkData(int srcX, int srcY, int srcZ, int srcDimension) + { + source = new Point4D(srcX, srcY, srcZ, srcDimension); + destination = null; + } + + public NewLinkData(int srcX, int srcY, int srcZ, int srcDimension, int dstX, int dstY, int dstZ, int dstDimension) + { + source = new Point4D(srcX, srcY, srcZ, srcDimension); + destination = new Point4D(dstX, dstY, dstZ, dstDimension); + } + + public NewLinkData(Point4D source, Point 4D destination) + { + + } + + @Override + public String toString() + { + return source + " -> " + destination; + } +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index 23f0156..60b0073 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -17,8 +17,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.Point3D; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; @@ -295,7 +295,7 @@ public class DungeonSchematic extends Schematic { //Set the orientation of the rift exit Point3D entranceRiftLocation = entrance.clone(); BlockRotator.transformPoint(entranceRiftLocation, entrance, rotation, pocketCenter); - LinkData sideLink = dimHelper.instance.getLinkDataFromCoords( + NewLinkData sideLink = dimHelper.instance.getLinkDataFromCoords( entranceRiftLocation.getX(), entranceRiftLocation.getY(), entranceRiftLocation.getZ(), @@ -319,8 +319,8 @@ public class DungeonSchematic extends Schematic { int blockDirection = world.getBlockMetadata(location.getX(), location.getY() - 1, location.getZ()); Point3D linkDestination = location.clone(); - LinkData randomLink = dimHelper.instance.getRandomLinkData(false); - LinkData sideLink = new LinkData(destDimID, + NewLinkData randomLink = dimHelper.instance.getRandomLinkData(false); + NewLinkData sideLink = new NewLinkData(destDimID, dimHelper.instance.getDimData(originDimID).exitDimLink.destDimID, location.getX(), location.getY(), @@ -405,7 +405,7 @@ public class DungeonSchematic extends Schematic { BlockRotator.transformPoint(linkDestination, zeroPoint, blockDirection - BlockRotator.EAST_DOOR_METADATA, location); //Create the link between our current door and its intended exit in destination pocket - LinkData sideLink = new LinkData(destDimID, 0, + NewLinkData sideLink = new NewLinkData(destDimID, 0, location.getX(), location.getY(), location.getZ(), diff --git a/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java b/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java index 3e82c28..c2388bb 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java @@ -8,7 +8,7 @@ import java.util.Random; import net.minecraft.util.WeightedRandom; import StevenDimDoors.mod_pocketDim.DungeonGenerator; -import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.util.WeightedContainer; @@ -123,7 +123,7 @@ public class DungeonPack } } - public DungeonGenerator getNextDungeon(LinkData inbound, Random random) + public DungeonGenerator getNextDungeon(NewLinkData inbound, Random random) { if (allDungeons.isEmpty()) { diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index ac2fcfd..fa44b8f 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -22,8 +22,8 @@ import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.DimData; import StevenDimDoors.mod_pocketDim.DungeonGenerator; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; @@ -290,10 +290,10 @@ public class DungeonHelper return pack; } - public LinkData createCustomDungeonDoor(World world, int x, int y, int z) + public NewLinkData createCustomDungeonDoor(World world, int x, int y, int z) { //Create a link above the specified position. Link to a new pocket dimension. - LinkData link = new LinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); + NewLinkData link = new NewLinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); link = dimHelper.instance.createPocket(link, true, false); //Place a Warp Door linked to that pocket @@ -530,7 +530,7 @@ public class DungeonHelper } } - public void generateDungeonLink(LinkData inbound, DungeonPack pack, Random random) + public void generateDungeonLink(NewLinkData inbound, DungeonPack pack, Random random) { DungeonGenerator selection; DungeonPackConfig config; @@ -658,7 +658,7 @@ public class DungeonHelper for (int count = 1; count < maxSize && found; count++) { found = false; - for (LinkData link : tailDim.getLinksInDim()) + for (NewLinkData link : tailDim.getLinksInDim()) { DimData neighbor = dimHelper.instance.getDimData(link.destDimID); if (neighbor.depth == tailDim.depth - 1 && neighbor.dungeonGenerator != null && @@ -674,7 +674,7 @@ public class DungeonHelper return history; } - private static int getPackDepth(LinkData inbound, DungeonPack pack) + private static int getPackDepth(NewLinkData inbound, DungeonPack pack) { //TODO: I've improved this code for the time being. However, searching across links is a flawed approach. A player could //manipulate the output of this function by setting up links to mislead our algorithm or by removing links. @@ -688,7 +688,7 @@ public class DungeonHelper do { found = false; - for (LinkData link : tailDim.getLinksInDim()) + for (NewLinkData link : tailDim.getLinksInDim()) { DimData neighbor = dimHelper.instance.getDimData(link.destDimID); if (neighbor.depth == tailDim.depth - 1 && neighbor.dungeonGenerator != null && @@ -728,7 +728,7 @@ public class DungeonHelper while (dungeons.size() < maxSize && !pendingDimensions.isEmpty()) { DimData current = pendingDimensions.remove(); - for (LinkData link : current.getLinksInDim()) + for (NewLinkData link : current.getLinksInDim()) { DimData child = helper.getDimData(link.destDimID); if (child.depth == current.depth + 1 && child.dungeonGenerator != null && checked.add(child)) diff --git a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java index 0324072..c07f9f5 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java @@ -35,13 +35,13 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream; import StevenDimDoors.mod_pocketDim.PacketHandler; import StevenDimDoors.mod_pocketDim.Point3D; import StevenDimDoors.mod_pocketDim.SchematicLoader; import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; @@ -79,7 +79,7 @@ public class dimHelper extends DimensionManager * HashMap for temporary storage of Link Signature damage hash values. See itemLinkSignature for more details * @Return */ - public HashMap interDimLinkList= new HashMap(); + public HashMap interDimLinkList= new HashMap(); /** * ArrayList containing all link data not sorted for easy random access, used for random doors and for recreating rifts if they have a block placed over them. @@ -103,7 +103,7 @@ public class dimHelper extends DimensionManager } // GreyMaria: My god, what a mess. Here, let me clean it up a bit. - public Entity teleportEntity(World world, Entity entity, LinkData link) //this beautiful teleport method is based off of xCompWiz's teleport function. + public Entity teleportEntity(World world, Entity entity, NewLinkData link) //this beautiful teleport method is based off of xCompWiz's teleport function. { WorldServer oldWorld = (WorldServer)world; WorldServer newWorld; @@ -260,7 +260,7 @@ public class dimHelper extends DimensionManager * @param orientation- the orientation of the door used to teleport, determines player orientation and door placement on arrival * @Return */ - public void traverseDimDoor(World world,LinkData linkData, Entity entity) + public void traverseDimDoor(World world,NewLinkData linkData, Entity entity) { DDProperties properties = DDProperties.instance(); @@ -355,7 +355,7 @@ public class dimHelper extends DimensionManager * @return */ - public LinkData createLink( int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord) + public NewLinkData createLink( int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord) { if(this.getLinkDataFromCoords(locationXCoord, locationYCoord, locationZCoord, locationDimID)!=null) { @@ -381,13 +381,13 @@ public class dimHelper extends DimensionManager * @param linkOrientation * @return */ - public LinkData createLink( int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord,int linkOrientation) + public NewLinkData createLink( int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord,int linkOrientation) { - LinkData linkData =new LinkData( locationDimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord ,destinationZCoord,false,linkOrientation); + NewLinkData linkData =new NewLinkData( locationDimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord ,destinationZCoord,false,linkOrientation); return this.createLink(linkData); } - public LinkData createLink(LinkData link) + public NewLinkData createLink(NewLinkData link) { DDProperties properties = DDProperties.instance(); @@ -421,11 +421,11 @@ public class dimHelper extends DimensionManager return link; } - public int getDestOrientation(LinkData link) + public int getDestOrientation(NewLinkData link) { if(link !=null) { - LinkData destLink = this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); + NewLinkData destLink = this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); if(destLink!=null) { return destLink.linkOrientation; @@ -443,7 +443,7 @@ public class dimHelper extends DimensionManager } } - public void removeLink(LinkData link) + public void removeLink(NewLinkData link) { this.removeLink(link.locDimID, link.locXCoord, link.locYCoord, link.locZCoord); } @@ -462,7 +462,7 @@ public class dimHelper extends DimensionManager DimData locationDimData= new DimData(locationDimID, false, 0, locationDimID,locationXCoord,locationYCoord,locationZCoord); dimHelper.dimList.put(locationDimID, locationDimData); } - LinkData link = this.getLinkDataFromCoords(locationXCoord, locationYCoord, locationZCoord, locationDimID); + NewLinkData link = this.getLinkDataFromCoords(locationXCoord, locationYCoord, locationZCoord, locationDimID); dimHelper.instance.getDimData(locationDimID).removeLinkAtCoords(link); //updates clients that a rift has been removed if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER) @@ -471,7 +471,7 @@ public class dimHelper extends DimensionManager this.save(); } } - public LinkData findNearestRift(World world, int x, int y, int z, int range) + public NewLinkData findNearestRift(World world, int x, int y, int z, int range) { return dimHelper.instance.getDimData(world).findNearestRift(world, range, x, y, z); } @@ -480,7 +480,7 @@ public class dimHelper extends DimensionManager * @param world- door * @param incLink */ - public void generateDoor(World world, LinkData incLink) + public void generateDoor(World world, NewLinkData incLink) { int locX = incLink.locXCoord; int locY = incLink.locYCoord; @@ -504,7 +504,7 @@ public class dimHelper extends DimensionManager { DimensionManager.initDimension(destinationID); } - LinkData destLink = this.getLinkDataFromCoords(destX, destY, destZ, destinationID); + NewLinkData destLink = this.getLinkDataFromCoords(destX, destY, destZ, destinationID); int destOrientation = 0; if(destLink!=null) { @@ -536,7 +536,7 @@ public class dimHelper extends DimensionManager * @param orientation * @return */ - public void generatePocket(LinkData incomingLink) + public void generatePocket(NewLinkData incomingLink) { DDProperties properties = DDProperties.instance(); try @@ -697,10 +697,10 @@ public class dimHelper extends DimensionManager DeleteFolder.deleteFolder(save); dimData.hasBeenFilled = false; dimData.hasDoor = false; - for(LinkData link : dimData.getLinksInDim()) + for(NewLinkData link : dimData.getLinksInDim()) { link.hasGennedDoor = false; - LinkData linkOut = this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); + NewLinkData linkOut = this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); if (linkOut != null) { linkOut.hasGennedDoor = false; @@ -788,7 +788,7 @@ public class dimHelper extends DimensionManager * @param orientation- determines the orientation of the entrance link to this dim. Should be the metaData of the door occupying the rift. -1 if no door. * @return */ - public LinkData createPocket(LinkData link , boolean isGoingDown, boolean isRandomRift) + public NewLinkData createPocket(NewLinkData link , boolean isGoingDown, boolean isRandomRift) { DDProperties properties = DDProperties.instance(); if(dimHelper.getWorld(0)==null) @@ -821,7 +821,7 @@ public class dimHelper extends DimensionManager } if(rand.nextInt(13-depth)==0) { - LinkData link1=getRandomLinkData(false); + NewLinkData link1=getRandomLinkData(false); } } if(locationDimData.isPocket) //determines the qualites of the pocket dim being created, based on parent dim. @@ -969,7 +969,7 @@ public class dimHelper extends DimensionManager try { - this.interDimLinkList = (HashMap) comboSave.get("interDimLinkList"); + this.interDimLinkList = (HashMap) comboSave.get("interDimLinkList"); } catch(Exception e) { @@ -1020,7 +1020,7 @@ public class dimHelper extends DimensionManager try { - this.interDimLinkList=(HashMap) comboSave.get("interDimLinkList"); + this.interDimLinkList=(HashMap) comboSave.get("interDimLinkList"); } catch(Exception e) { @@ -1073,7 +1073,7 @@ public class dimHelper extends DimensionManager - public LinkData getRandomLinkData(boolean allowInPocket) + public NewLinkData getRandomLinkData(boolean allowInPocket) { boolean foundRandomDest=false; int i=0; @@ -1083,7 +1083,7 @@ public class dimHelper extends DimensionManager { i++; DimData dimData; - ArrayList linksInDim = new ArrayList(); + ArrayList linksInDim = new ArrayList(); for(size--;size>0;) { dimData = dimHelper.instance.getDimData((Integer)dimList.keySet().toArray()[rand.nextInt(dimList.keySet().size())]); @@ -1103,7 +1103,7 @@ public class dimHelper extends DimensionManager break; } - LinkData link1 = (LinkData) linksInDim.get(rand.nextInt(linksInDim.size())); + NewLinkData link1 = (NewLinkData) linksInDim.get(rand.nextInt(linksInDim.size())); if(link1!=null) { @@ -1125,7 +1125,7 @@ public class dimHelper extends DimensionManager * @param link * @return */ - public LinkData getLinkDataAtDestination(LinkData link) + public NewLinkData getLinkDataAtDestination(NewLinkData link) { return this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); } @@ -1144,9 +1144,9 @@ public class dimHelper extends DimensionManager * @param updateLinksPointingHere * @return */ - public boolean moveLinkDataLocation(LinkData link, int x,int y, int z, int dimID, boolean updateLinksPointingHere) + public boolean moveLinkDataLocation(NewLinkData link, int x,int y, int z, int dimID, boolean updateLinksPointingHere) { - LinkData linkToMove = this.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID); + NewLinkData linkToMove = this.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID); if(linkToMove!=null) { int oldX = linkToMove.locXCoord; @@ -1156,10 +1156,10 @@ public class dimHelper extends DimensionManager if(updateLinksPointingHere) { - ArrayList incomingLinks = new ArrayList(); + ArrayList incomingLinks = new ArrayList(); for(DimData dimData : dimHelper.dimList.values()) { - for(LinkData allLink : dimData.getLinksInDim()) + for(NewLinkData allLink : dimData.getLinksInDim()) { if(this.getLinkDataAtDestination(allLink)==linkToMove) { @@ -1168,7 +1168,7 @@ public class dimHelper extends DimensionManager } } } - this.createLink(new LinkData(dimID,linkToMove.destDimID,x,y,z,linkToMove.destXCoord,linkToMove.destYCoord,linkToMove.destZCoord,linkToMove.isLocPocket,linkToMove.linkOrientation)); + this.createLink(new NewLinkData(dimID,linkToMove.destDimID,x,y,z,linkToMove.destXCoord,linkToMove.destYCoord,linkToMove.destZCoord,linkToMove.isLocPocket,linkToMove.linkOrientation)); if(this.getLinkDataFromCoords(oldX,oldY,oldZ,oldDimID)!=null) { @@ -1189,14 +1189,14 @@ public class dimHelper extends DimensionManager * @param updateLinksAtDestination * @return */ - public boolean moveLinkDataDestination(LinkData link, int x, int y, int z, int dimID, boolean updateLinksAtDestination) + public boolean moveLinkDataDestination(NewLinkData link, int x, int y, int z, int dimID, boolean updateLinksAtDestination) { - LinkData linkToMove = this.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID); + NewLinkData linkToMove = this.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID); if(linkToMove!=null) { if(updateLinksAtDestination) { - LinkData linkAtDestination = this.getLinkDataAtDestination(linkToMove); + NewLinkData linkAtDestination = this.getLinkDataAtDestination(linkToMove); if(linkAtDestination!=null) { this.moveLinkDataLocation(linkAtDestination, x, y, z, dimID, false); @@ -1207,7 +1207,7 @@ public class dimHelper extends DimensionManager linkToMove.destYCoord=y; linkToMove.destZCoord=z; this.createLink(linkToMove); - LinkData testLink = this.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID); + NewLinkData testLink = this.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID); return true; } @@ -1222,7 +1222,7 @@ public class dimHelper extends DimensionManager * @param par1World * @return */ - public LinkData getLinkDataFromCoords(int x, int y, int z, World par1World) + public NewLinkData getLinkDataFromCoords(int x, int y, int z, World par1World) { return this.getLinkDataFromCoords(x, y, z, par1World.provider.dimensionId); } @@ -1234,7 +1234,7 @@ public class dimHelper extends DimensionManager * @param worldID * @return */ - public LinkData getLinkDataFromCoords(int x, int y, int z, int worldID) + public NewLinkData getLinkDataFromCoords(int x, int y, int z, int worldID) { if(dimHelper.dimList.containsKey(worldID)) { @@ -1261,7 +1261,7 @@ public class dimHelper extends DimensionManager { DDProperties properties = DDProperties.instance(); - LinkData nearest=null; + NewLinkData nearest=null; float distance=range+1; int i=-range; int j=-range; diff --git a/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java b/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java index dd14838..3f9a4f5 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java @@ -1,6 +1,6 @@ package StevenDimDoors.mod_pocketDim.helpers; -import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.world.World; @@ -11,7 +11,7 @@ public class yCoordHelper { private static final int MAXIMUM_UNCOVERED_Y = 245; - public static int getFirstUncovered(LinkData pointerLink) + public static int getFirstUncovered(NewLinkData pointerLink) { return yCoordHelper.getFirstUncovered( pointerLink.destDimID, diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java index 7737df4..2ca96a7 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java @@ -21,8 +21,8 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -183,7 +183,7 @@ public class ItemRiftBlade extends ItemSword int z = MathHelper.floor_double(var9); int rotation = (int) (MathHelper.floor_double((double)((par3EntityPlayer.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); - LinkData link = new LinkData(par2World.provider.dimensionId, 0, x, y, z, x, y, z, true,rotation); + NewLinkData link = new NewLinkData(par2World.provider.dimensionId, 0, x, y, z, x, y, z, true,rotation); if(this.getMaxItemUseDuration(par1ItemStack)-par4>12&&!par2World.isRemote&&itemDimDoor.canPlace(par2World, x, y, z, rotation)) { @@ -212,7 +212,7 @@ public class ItemRiftBlade extends ItemSword { if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ)==properties.RiftBlockID) { - LinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); + NewLinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); if(link!=null) { diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index 3da5016..504f66c 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -3,8 +3,8 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.List; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import net.minecraft.block.Block; @@ -58,7 +58,7 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { int key; - LinkData linkData; + NewLinkData linkData; int thisWorldID=par3World.provider.dimensionId; Integer[] linkCoords =this.readFromNBT(par1ItemStack); diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java b/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java index a84d2d9..b5a741b 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java @@ -2,10 +2,10 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.List; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.SchematicLoader; import StevenDimDoors.mod_pocketDim.Spells; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; import StevenDimDoors.mod_pocketDimClient.ClientTickHandler; @@ -117,7 +117,7 @@ public class ItemStableFabric extends Item { //if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ)==properties.RiftBlockID) { - LinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); + NewLinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); if(link!=null) { Block var11; diff --git a/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java b/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java index c8f3c6c..c877d69 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java +++ b/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java @@ -14,8 +14,8 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; public class itemDimDoor extends ItemDoor @@ -138,7 +138,7 @@ public class itemDimDoor extends ItemDoor { if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID) { - LinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); + NewLinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); if(link!=null) { Block var11; diff --git a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java index 9de5a38..6136038 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java @@ -4,8 +4,8 @@ import java.util.List; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import net.minecraft.block.Block; @@ -69,7 +69,7 @@ public class itemLinkSignature extends Item public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { int key; - LinkData linkData; + NewLinkData linkData; int thisWorldID=par3World.provider.dimensionId; diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index b2ca95a..c8400b5 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -33,6 +33,7 @@ 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.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.items.ItemBlockDimWall; @@ -426,7 +427,7 @@ public class mod_pocketDim if(!dimHelper.dimList.containsKey(properties.LimboDimensionID)) { - dimHelper.dimList.put(properties.LimboDimensionID, new DimData( properties.LimboDimensionID, false, 0, new LinkData())); + dimHelper.dimList.put(properties.LimboDimensionID, new DimData( properties.LimboDimensionID, false, 0, new NewLinkData())); } } diff --git a/StevenDimDoors/mod_pocketDim/pocketTeleporter.java b/StevenDimDoors/mod_pocketDim/pocketTeleporter.java index 5513386..1f3e92f 100644 --- a/StevenDimDoors/mod_pocketDim/pocketTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/pocketTeleporter.java @@ -1,5 +1,6 @@ package StevenDimDoors.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityMinecart; @@ -12,7 +13,7 @@ public class pocketTeleporter { int x,y,z; - LinkData sendingLink; + NewLinkData sendingLink; public pocketTeleporter() @@ -28,7 +29,7 @@ public class pocketTeleporter * Create a new portal near an entity. */ - public void placeInPortal(Entity par1Entity, WorldServer world, LinkData link) + public void placeInPortal(Entity par1Entity, WorldServer world, NewLinkData link) { diff --git a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java index 0297638..536c0b7 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java +++ b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java @@ -13,7 +13,7 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.LinkData; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; @@ -171,7 +171,7 @@ public class MobMonolith extends EntityFlying implements IMob - LinkData link = new LinkData(this.worldObj.provider.dimensionId, properties.LimboDimensionID, (int)this.posX, (int)this.posY, (int)this.posZ, (int)this.posX+rand.nextInt(500)-250, (int)this.posY+500, (int)this.posZ+rand.nextInt(500)-250, false,0); + NewLinkData link = new NewLinkData(this.worldObj.provider.dimensionId, properties.LimboDimensionID, (int)this.posX, (int)this.posY, (int)this.posZ, (int)this.posX+rand.nextInt(500)-250, (int)this.posY+500, (int)this.posZ+rand.nextInt(500)-250, false,0); dimHelper.instance.traverseDimDoor(worldObj, link, entityPlayer); this.aggro=0; diff --git a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index 386c73b..b840e48 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -2,9 +2,9 @@ package StevenDimDoors.mod_pocketDim.ticking; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.LinkData; import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; @@ -38,10 +38,10 @@ public class RiftRegenerator implements IRegularTickReceiver { while (i < 15 && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { i++; - LinkData link; + NewLinkData link; //actually gets the random rift based on the size of the list - link = (LinkData) dimHelper.instance.getRandomLinkData(true); + link = (NewLinkData) dimHelper.instance.getRandomLinkData(true); if (link != null) { diff --git a/StevenDimDoors/mod_pocketDim/util/Point4D.java b/StevenDimDoors/mod_pocketDim/util/Point4D.java new file mode 100644 index 0000000..8d8c963 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/util/Point4D.java @@ -0,0 +1,131 @@ +package StevenDimDoors.mod_pocketDim.util; + +public final class Point4D +{ + private final int x; + private final int y; + private final int z; + private final int dimension; + + public Point4D(int x, int y, int z, int dimension) + { + this.x = x; + this.y = y; + this.z = z; + this.dimension = dimension; + } + + public int getX() + { + return x; + } + + public int getY() + { + return y; + } + + public int getZ() + { + return z; + } + + public int getDimension() + { + return dimension; + } + + @Override + public int hashCode() + { + //Time for some witchcraft. + //The code here is inspired by a discussion on Stack Overflow regarding hash codes for 3D. + //Source: http://stackoverflow.com/questions/9858376/hashcode-for-3d-integer-coordinates-with-high-spatial-coherence + + //I believe that most of the time, any points we might be hashing will be in close proximity to each other. + //For instance, points that are within the same chunk or within a few neighboring chunks. Only the low-order + //bits of each component would differ. I'll use 8 bits from Y and the 12 bits from X and Z. ~SenseiKiwi + + int bit; + int hash; + int index; + + hash = 0; + index = 0; + for (bit = 0; bit < 8; bit++) + { + hash |= ((y >> bit) & 1) << index; + index++; + hash |= ((x >> bit) & 1) << index; + index++; + hash |= ((z >> bit) & 1) << index; + index++; + } + for (; bit < 12; bit++) + { + hash |= ((x >> bit) & 1) << index; + index++; + hash |= ((z >> bit) & 1) << index; + index++; + } + return hash; + } + + public long longHashCode() + { + //Time for some witchcraft. + //The code here is inspired by a discussion on Stack Overflow regarding hash codes for 3D. + //Source: http://stackoverflow.com/questions/9858376/hashcode-for-3d-integer-coordinates-with-high-spatial-coherence + + //Use 8 bits from Y and 24 bits from X and Z. Mix in 8 bits from the destination dim ID too - that means + //even if you aligned two doors perfectly between two pockets, it's unlikely they would lead to the same dungeon. + + int bit; + int index; + long hash; + + hash = 0; + index = 0; + for (bit = 0; bit < 8; bit++) + { + hash |= ((dimension >> bit) & 1) << index; + index++; + hash |= ((x >> bit) & 1) << index; + index++; + hash |= ((y >> bit) & 1) << index; + index++; + hash |= ((z >> bit) & 1) << index; + index++; + } + for (; bit < 24; bit++) + { + hash |= ((x >> bit) & 1) << index; + index++; + hash |= ((z >> bit) & 1) << index; + index++; + } + return hash; + } + + @Override + public boolean equals(Object obj) + { + return equals((Point4D) obj); + } + + public boolean equals(Point4D other) + { + if (this == other) + return true; + if (other == null) + return false; + + return (x == other.x && y == other.y && z == other.z && dimension == other.dimension); + } + + @Override + public String toString() + { + return "(" + x + ", " + y + ", " + z + ", " + dimension + ")"; + } +} -- 2.39.5 From 934dcfde3dc8d46ded755b4676329dd7707e1139 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 29 Aug 2013 02:14:24 -0400 Subject: [PATCH 02/24] Flipped a Table Replaced several core classes from DD with new classes to enforce integrity checks. Rewriting everything that depended on those classes is a massive undertaking but it should simplify our code and prevent the many bugs we've seen lately. The rewrite isn't done yet, just committing my progress so far. --- .../mod_pocketDim/BlankTeleporter.java | 2 +- .../mod_pocketDim/ConnectionHandler.java | 39 +- .../mod_pocketDim/DDProperties.java | 5 +- .../mod_pocketDim/DDTeleporter.java | 376 +++++ StevenDimDoors/mod_pocketDim/DimData.java | 259 ---- .../mod_pocketDim/DungeonGenerator.java | 85 - .../mod_pocketDim/EventHookContainer.java | 43 +- .../mod_pocketDim/PacketHandler.java | 292 ++-- .../mod_pocketDim/SchematicLoader.java | 205 --- .../mod_pocketDim/TileEntityRift.java | 554 ++++--- .../mod_pocketDim/TransientDoor.java | 188 +-- .../blocks/BlockDimWallPerm.java | 73 +- .../mod_pocketDim/blocks/BlockLimbo.java | 2 +- .../mod_pocketDim/blocks/BlockRift.java | 9 +- .../mod_pocketDim/blocks/ChaosDoor.java | 147 +- .../mod_pocketDim/blocks/ExitDoor.java | 194 +-- .../mod_pocketDim/blocks/dimDoor.java | 986 +++++------- .../mod_pocketDim/blocks/dimHatch.java | 100 +- .../commands/CommandCreateDungeonRift.java | 41 +- .../commands/CommandCreatePocket.java | 5 +- .../commands/CommandDeleteAllLinks.java | 24 +- .../commands/CommandDeleteDimensionData.java | 24 +- .../commands/CommandDeleteRifts.java | 24 +- .../commands/CommandPrintDimensionData.java | 20 +- .../commands/CommandPruneDimensions.java | 22 +- .../commands/CommandResetDungeons.java | 8 +- .../commands/CommandTeleportPlayer.java | 10 +- .../mod_pocketDim/core/IDimLink.java | 31 + .../mod_pocketDim/core/LinkTail.java | 31 + .../mod_pocketDim/core/NewDimData.java | 496 ++++++ .../mod_pocketDim/core/NewLinkData.java | 36 - .../mod_pocketDim/core/PocketManager.java | 623 ++++++++ .../mod_pocketDim/dungeon/DungeonData.java | 76 + .../dungeon/DungeonSchematic.java | 14 +- .../dungeon/pack/DungeonPack.java | 64 +- .../mod_pocketDim/helpers/DungeonHelper.java | 182 +-- .../mod_pocketDim/helpers/dimHelper.java | 1364 ----------------- .../mod_pocketDim/helpers/yCoordHelper.java | 62 +- .../mod_pocketDim/items/ItemRiftBlade.java | 16 +- .../items/ItemStabilizedRiftSignature.java | 12 +- .../mod_pocketDim/items/ItemStableFabric.java | 12 +- .../mod_pocketDim/items/itemDimDoor.java | 6 +- .../items/itemLinkSignature.java | 20 +- .../mod_pocketDim/items/itemRiftRemover.java | 4 +- .../mod_pocketDim/mod_pocketDim.java | 31 +- .../mod_pocketDim/pocketTeleporter.java | 226 --- .../{ => ticking}/LimboDecay.java | 9 +- .../ticking/LimboGatewayGenerator.java | 4 +- .../mod_pocketDim/ticking/MobMonolith.java | 4 +- .../ticking/MonolithSpawner.java | 32 +- .../ticking/RiftRegenerator.java | 76 +- .../mod_pocketDim/util/Point4D.java | 17 +- .../GatewayGenerator.java} | 39 +- .../mod_pocketDim/world/PocketBuilder.java | 422 +++++ .../mod_pocketDim/world/PocketGenerator.java | 16 +- .../mod_pocketDim/world/PocketProvider.java | 9 +- .../mod_pocketDimClient/ClosingRiftFX.java | 4 +- .../mod_pocketDimClient/GoggleRiftFX.java | 4 +- .../mod_pocketDimClient/RiftFX.java | 4 +- schematics/core/simpleStairsDown.schematic | Bin 1239 -> 0 bytes schematics/core/simpleStairsUp.schematic | Bin 1112 -> 0 bytes 61 files changed, 3450 insertions(+), 4233 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/DDTeleporter.java delete mode 100644 StevenDimDoors/mod_pocketDim/DimData.java delete mode 100644 StevenDimDoors/mod_pocketDim/DungeonGenerator.java delete mode 100644 StevenDimDoors/mod_pocketDim/SchematicLoader.java create mode 100644 StevenDimDoors/mod_pocketDim/core/IDimLink.java create mode 100644 StevenDimDoors/mod_pocketDim/core/LinkTail.java create mode 100644 StevenDimDoors/mod_pocketDim/core/NewDimData.java delete mode 100644 StevenDimDoors/mod_pocketDim/core/NewLinkData.java create mode 100644 StevenDimDoors/mod_pocketDim/core/PocketManager.java create mode 100644 StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java delete mode 100644 StevenDimDoors/mod_pocketDim/helpers/dimHelper.java delete mode 100644 StevenDimDoors/mod_pocketDim/pocketTeleporter.java rename StevenDimDoors/mod_pocketDim/{ => ticking}/LimboDecay.java (94%) rename StevenDimDoors/mod_pocketDim/{RiftGenerator.java => world/GatewayGenerator.java} (86%) create mode 100644 StevenDimDoors/mod_pocketDim/world/PocketBuilder.java delete mode 100644 schematics/core/simpleStairsDown.schematic delete mode 100644 schematics/core/simpleStairsUp.schematic diff --git a/StevenDimDoors/mod_pocketDim/BlankTeleporter.java b/StevenDimDoors/mod_pocketDim/BlankTeleporter.java index 259ff0e..99aea03 100644 --- a/StevenDimDoors/mod_pocketDim/BlankTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/BlankTeleporter.java @@ -1,6 +1,6 @@ package StevenDimDoors.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityMinecart; import net.minecraft.entity.player.EntityPlayer; diff --git a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java index 6de4ad7..0d0c9fd 100644 --- a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java +++ b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java @@ -3,7 +3,8 @@ package StevenDimDoors.mod_pocketDim; import java.util.ArrayList; import java.util.Collection; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.network.INetworkManager; import net.minecraft.network.NetLoginHandler; @@ -25,10 +26,8 @@ public class ConnectionHandler implements IConnectionHandler if (properties == null) properties = DDProperties.instance(); - Collection set = new ArrayList(); - set.addAll(dimHelper.dimList.keySet()); - PacketHandler.onClientJoinPacket(manager, dimHelper.dimList); - PacketHandler.onDimCreatedPacket(new DimData(properties.LimboDimensionID, false, 0, 0, 0, 0, 0)); + PacketHandler.onClientJoinPacket(manager, PocketManager.dimList); + PacketHandler.onDimCreatedPacket(new NewDimData(properties.LimboDimensionID, false, 0, 0, 0, 0, 0)); return null; } @@ -39,10 +38,7 @@ public class ConnectionHandler implements IConnectionHandler } @Override - public void connectionOpened(NetHandler netClientHandler,MinecraftServer server, INetworkManager manager) - { - - } + public void connectionOpened(NetHandler netClientHandler,MinecraftServer server, INetworkManager manager) { } @Override public void connectionClosed(INetworkManager manager) @@ -50,32 +46,17 @@ public class ConnectionHandler implements IConnectionHandler if (connected) { System.out.println("Clearing dim cache"); - dimHelper.instance.save(); - dimHelper.instance.unregsisterDims(); - dimHelper.dimList.clear(); + PocketManager.instance.save(); + PocketManager.instance.unregsisterDims(); + PocketManager.dimList.clear(); } connected = false; - } @Override - public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, - Packet1Login login) - { - - - - } + public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) { } @Override - public void playerLoggedIn(Player player, NetHandler netHandler, - INetworkManager manager) - { - - - - - - } + public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) { } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/DDProperties.java b/StevenDimDoors/mod_pocketDim/DDProperties.java index a10cb31..2d21924 100644 --- a/StevenDimDoors/mod_pocketDim/DDProperties.java +++ b/StevenDimDoors/mod_pocketDim/DDProperties.java @@ -4,6 +4,7 @@ import java.io.File; import net.minecraftforge.common.Configuration; import StevenDimDoors.mod_pocketDim.ticking.MonolithSpawner; +import StevenDimDoors.mod_pocketDim.world.GatewayGenerator; public class DDProperties { @@ -211,11 +212,11 @@ public class DDProperties "spawn in a given Limbo chunk. The default chance is 28.").getInt(); ClusterGenerationChance = config.get(Configuration.CATEGORY_GENERAL, "Cluster Generation Chance", 3, - "Sets the chance (out of " + RiftGenerator.MAX_CLUSTER_GENERATION_CHANCE + ") that a cluster of rifts will " + + "Sets the chance (out of " + GatewayGenerator.MAX_CLUSTER_GENERATION_CHANCE + ") that a cluster of rifts will " + "generate in a given chunk. The default chance is 3.").getInt(); GatewayGenerationChance = config.get(Configuration.CATEGORY_GENERAL, "Gateway Generation Chance", 10, - "Sets the chance (out of " + RiftGenerator.MAX_GATEWAY_GENERATION_CHANCE + ") that a Rift Gateway will " + + "Sets the chance (out of " + GatewayGenerator.MAX_GATEWAY_GENERATION_CHANCE + ") that a Rift Gateway will " + "generate in a given chunk. The default chance is 10.").getInt(); RiftSpreadModifier = config.get(Configuration.CATEGORY_GENERAL, "Rift Spread Modifier", 3, diff --git a/StevenDimDoors/mod_pocketDim/DDTeleporter.java b/StevenDimDoors/mod_pocketDim/DDTeleporter.java new file mode 100644 index 0000000..1203cd5 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/DDTeleporter.java @@ -0,0 +1,376 @@ +package StevenDimDoors.mod_pocketDim; + +import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.item.EntityMinecart; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.packet.Packet41EntityEffect; +import net.minecraft.network.packet.Packet43Experience; +import net.minecraft.network.packet.Packet9Respawn; +import net.minecraft.potion.PotionEffect; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.DimensionManager; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public class DDTeleporter +{ + private DDTeleporter() { } + + /** + * Create a new portal near an entity. + */ + public static void placeInPortal(Entity par1Entity, WorldServer world, IDimLink link) + { + 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; + } + } + + if (par1Entity instanceof EntityPlayer) + { + EntityPlayer player = (EntityPlayer) par1Entity; + player.rotationYaw=(orientation*90)+90; + if(orientation==2||orientation==6) + { + player.setPositionAndUpdate( x+1.5, y-1, z+.5 ); + } + else if(orientation==3||orientation==7) + { + player.setPositionAndUpdate( x+.5, y-1, z+1.5 ); + } + else if(orientation==0||orientation==4) + { + player.setPositionAndUpdate(x-.5, y-1, z+.5); + } + else if(orientation==1||orientation==5) + { + player.setPositionAndUpdate(x+.5, y-1, z-.5); + } + else + { + player.setPositionAndUpdate(x, y-1, z); + } + } + else if (par1Entity instanceof EntityMinecart) + { + par1Entity.motionX=0; + par1Entity.motionZ=0; + par1Entity.motionY=0; + par1Entity.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); + } + else if(orientation==3||orientation==7) + { + DDTeleporter.setEntityPosition(par1Entity, x+.5, y, z+1.5 ); + par1Entity.motionZ =.39; + par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false); + } + else if(orientation==0||orientation==4) + { + DDTeleporter.setEntityPosition(par1Entity,x-.5, y, z+.5); + par1Entity.motionX =-.39; + par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false); + } + else if(orientation==1||orientation==5) + { + DDTeleporter.setEntityPosition(par1Entity,x+.5, y, z-.5); + par1Entity.motionZ =-.39; + par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false); + } + else + { + DDTeleporter.setEntityPosition(par1Entity,x, y, z); + } + } + else if (par1Entity instanceof Entity) + { + par1Entity.rotationYaw=(orientation*90)+90; + if(orientation==2||orientation==6) + { + DDTeleporter.setEntityPosition(par1Entity, x+1.5, y, z+.5 ); + } + else if(orientation==3||orientation==7) + { + + DDTeleporter.setEntityPosition(par1Entity, x+.5, y, z+1.5 ); + } + else if(orientation==0||orientation==4) + { + DDTeleporter.setEntityPosition(par1Entity,x-.5, y, z+.5); + } + else if(orientation==1||orientation==5) + { + DDTeleporter.setEntityPosition(par1Entity,x+.5, y, z-.5); + } + else + { + DDTeleporter.setEntityPosition(par1Entity,x, y, z); + } + } + } + + private static void setEntityPosition(Entity entity, double x, double y, double z) + { + entity.lastTickPosX = entity.prevPosX = entity.posX = x; + entity.lastTickPosY = entity.prevPosY = entity.posY = y + (double)entity.yOffset; + entity.lastTickPosZ = entity.prevPosZ = entity.posZ = z; + entity.setPosition(x, y, z); + } + + public static Entity teleportEntity(World world, Entity entity, IDimLink link) + { + //This beautiful teleport method is based off of xCompWiz's teleport function. + + WorldServer oldWorld = (WorldServer)world; + WorldServer newWorld; + EntityPlayerMP player = (entity instanceof EntityPlayerMP) ? (EntityPlayerMP)entity : null; + + // Is something riding? Handle it first. + if(entity.riddenByEntity != null) + { + return teleportEntity(oldWorld, entity.riddenByEntity, link); + } + + // Are we riding something? Dismount and tell the mount to go first. + Entity cart = entity.ridingEntity; + if (cart != null) + { + entity.mountEntity(null); + cart = teleportEntity(oldWorld, cart, link); + // 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(); + if (difDest) + { + newWorld = DimensionManager.getWorld(link.destination().getDimension()); + } + else + { + newWorld = (WorldServer) oldWorld; + } + + // 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); + + if (difDest) // Are we moving our target to a new dimension? + { + if(player != null) // Are we working with a player? + { + // 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.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. + // This should fix an apparently unreported bug where + // the last non-sleeping player leaves the Overworld + // for a pocket dimension, causing all sleeping players + // to remain asleep instead of progressing to day. + oldWorld.removePlayerEntityDangerously(player); + 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); + newWorld.getPlayerManager().addPlayer(player); + + player.theItemInWorldManager.setWorld((WorldServer)newWorld); + + // Synchronize with the server so the client knows what time it is and what it's holding. + player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer)newWorld); + player.mcServer.getConfigurationManager().syncPlayerInventory(player); + for(Object potionEffect : player.getActivePotionEffects()) + { + PotionEffect effect = (PotionEffect)potionEffect; + player.playerNetServerHandler.sendPacketToPlayer(new Packet41EntityEffect(player.entityId, effect)); + } + + player.playerNetServerHandler.sendPacketToPlayer(new Packet43Experience(player.experience, player.experienceTotal, player.experienceLevel)); + } + + // Creates sanity by removing the entity from its old location's chunk entity list, if applicable. + int entX = entity.chunkCoordX; + int entZ = entity.chunkCoordZ; + if ((entity.addedToChunk) && (oldWorld.getChunkProvider().chunkExists(entX, entZ))) + { + oldWorld.getChunkFromChunkCoords(entX, entZ).removeEntity(entity); + oldWorld.getChunkFromChunkCoords(entX, entZ).isModified = true; + } + // Memory concerns. + oldWorld.releaseEntitySkin(entity); + + if (player == null) // Are we NOT working with a player? + { + NBTTagCompound entityNBT = new NBTTagCompound(); + entity.isDead = false; + entity.addEntityID(entityNBT); + entity.isDead = true; + entity = EntityList.createEntityFromNBT(entityNBT, newWorld); + + if (entity == null) + { // 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 + */ + } + + } + + // Finally, respawn the entity in its new home. + newWorld.spawnEntityInWorld(entity); + entity.setWorld(newWorld); + } + entity.worldObj.updateEntityWithOptionalForce(entity, false); + + // Hey, remember me? It's time to remount. + if (cart != null) + { + // Was there a player teleported? If there was, it's important that we update shit. + if (player != null) + { + entity.worldObj.updateEntityWithOptionalForce(entity, true); + } + entity.mountEntity(cart); + } + + // Did we teleport a player? Load the chunk for them. + if(player != null) + { + WorldServer.class.cast(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); + 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 + */ + public static void traverseDimDoor(World world, IDimLink linkData, Entity entity) + { + DDProperties properties = DDProperties.instance(); + + if (world.isRemote) + { + return; + } + if (linkData != null) + { + 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); + } + } + } + } + return; + } +} diff --git a/StevenDimDoors/mod_pocketDim/DimData.java b/StevenDimDoors/mod_pocketDim/DimData.java deleted file mode 100644 index bd56b84..0000000 --- a/StevenDimDoors/mod_pocketDim/DimData.java +++ /dev/null @@ -1,259 +0,0 @@ -package StevenDimDoors.mod_pocketDim; -/**Class that contains all the information about a specific dim that is pertienent to Dim Doors. Holds all the rifts present in the dim sorted by x,y,z and - * wether or not the dim is a pocket or not, along with its depth. - * @Return - */ -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; - -import StevenDimDoors.mod_pocketDim.core.NewLinkData; - -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; - -public class DimData implements Serializable -{ - public int dimID; - public int depth; - public int dimOrientation; - - public World world; - - public NewLinkData exitDimLink; - - public boolean isPocket; - public boolean hasBeenFilled=false; - public boolean hasDoor=false; - public boolean isDimRandomRift=false; - public DungeonGenerator dungeonGenerator = null; - //public boolean isPrivatePocket = false; - public HashMap>> linksInThisDim = new HashMap(); - HashMap dimX; - HashMap> dimY ; - - static final long serialVersionUID = 454342L; - - public DimData(int dimID, boolean isPocket, int depth, NewLinkData exitLinkData) - { - this.dimID=dimID; - this.depth=depth; - this.isPocket=isPocket; - - this.exitDimLink= exitLinkData; - } - - public DimData(int dimID, boolean isPocket, int depth, int exitLinkDimID, int exitX, int exitY, int exitZ) - { - this(dimID, isPocket, depth, new NewLinkData(exitLinkDimID, exitX, exitY, exitZ)); - } - - public NewLinkData findNearestRift(World world, int range, int x, int y, int z) - { - NewLinkData nearest=null; - float distance=range+1; - int i=-range; - int j=-range; - int k=-range; - DDProperties properties = DDProperties.instance(); - - while (i(); - } - } - else - { - this.dimX=new HashMap(); - this.dimY=new HashMap>(); - } - - this.dimX.put(link.locXCoord, link); - this.dimY.put(link.locYCoord, dimX); - this.linksInThisDim.put(link.locZCoord, dimY); - - //System.out.println("added link to dim "+this.dimID); - return link; - - } - - public NewLinkData addLinkToDim( int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord, int linkOrientation) - { - NewLinkData linkData= new NewLinkData(this.dimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord,destinationZCoord,this.isPocket,linkOrientation); - - return this.addLinkToDim(linkData); - } - - public boolean isLimbo() - { - return (this.dimID == DDProperties.instance().LimboDimensionID); - } - - public void removeLinkAtCoords(NewLinkData link) - { - this.removeLinkAtCoords(link.locDimID, link.locXCoord, link.locYCoord, link.locZCoord); - } - - public void removeLinkAtCoords(int locationID, int locationXCoord, int locationYCoord, int locationZCoord) - { - if (this.linksInThisDim.containsKey(locationZCoord)) - { - this.dimY=this.linksInThisDim.get(locationZCoord); - - if(this.dimY.containsKey(locationYCoord)) - { - this.dimX=this.dimY.get(locationYCoord); - } - else - { - this.dimX=new HashMap(); - } - } - else - { - this.dimX=new HashMap(); - this.dimY=new HashMap>(); - } - - this.dimX.remove(locationXCoord); - this.dimY.put(locationYCoord, dimX); - this.linksInThisDim.put(locationZCoord, dimY); - } - - public NewLinkData findLinkAtCoords(int locationXCoord, int locationYCoord, int locationZCoord) - { - try - { - if(this.linksInThisDim.containsKey(locationZCoord)) - { - this.dimY=this.linksInThisDim.get(locationZCoord); - - if(this.dimY.containsKey(locationYCoord)) - { - this.dimX=this.dimY.get(locationYCoord); - - if(this.dimX.containsKey(locationXCoord)) - { - return this.dimX.get(locationXCoord); - } - - } - } - } - catch(Exception E) - { - return null; - } - return null; - } - - public ArrayList getLinksInDim() - { - //TODO: We might want to modify this function, but I'm afraid of breaking something right now. - //To begin with, the name is wrong. This doesn't print anything! >_o ~SenseiKiwi - - ArrayList links = new ArrayList(); - if (this.linksInThisDim == null) - { - return links; - } - for (HashMap> first : this.linksInThisDim.values()) - { - for (HashMap second : first.values()) - { - for (NewLinkData linkData : second.values()) - { - links.add(linkData); - } - } - } - return links; - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/DungeonGenerator.java b/StevenDimDoors/mod_pocketDim/DungeonGenerator.java deleted file mode 100644 index 861bed7..0000000 --- a/StevenDimDoors/mod_pocketDim/DungeonGenerator.java +++ /dev/null @@ -1,85 +0,0 @@ -package StevenDimDoors.mod_pocketDim; - -import java.io.File; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; - -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; -import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType; -import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; - -public class DungeonGenerator implements Serializable -{ - //This static field is hax so that I don't have to add an instance field to DungeonGenerator to support DungeonType. - //Otherwise it would have to be serializable and all sorts of problems would arise. - private static final HashMap dungeonTypes = new HashMap(); - - public int weight; - public String schematicPath; - public ArrayList sideRifts = new ArrayList(); - public NewLinkData exitLink; - public boolean isOpen; - - public int sideDoorsSoFar=0; - public int exitDoorsSoFar=0; - public int deadEndsSoFar=0; - - public DungeonGenerator(int weight, String schematicPath, boolean isOpen, DungeonType dungeonType) - { - this.weight = weight; - this.schematicPath = schematicPath; - this.isOpen = isOpen; - - dungeonTypes.put(this, dungeonType); //Hax... - } - - public DungeonType getDungeonType() - { - DungeonType type = dungeonTypes.get(this); - if (type == null) - { - //Infer the dungeon's type from its file name - //There is minimal risk of us applying this to untagged dungeons and this'll be phased out - //when we get the new save format. - try - { - File file = new File(schematicPath); - String typeName = file.getName().split("_")[0]; - String packName = file.getParentFile().getName(); - DungeonPack pack = DungeonHelper.instance().getDungeonPack(packName); - if (pack == null) - { - pack = DungeonHelper.instance().getDungeonPack("ruins"); - } - type = pack.getType(typeName); - } - catch (Exception e) { } - if (type == null) - { - type = DungeonType.UNKNOWN_TYPE; - } - dungeonTypes.put(this, type); - } - return type; - } - - @Override - public int hashCode() - { - return (schematicPath != null) ? schematicPath.hashCode() : 0; - } - - @Override - public boolean equals(Object other) - { - return equals((DungeonGenerator) other); - } - - public boolean equals(DungeonGenerator other) - { - return ((this.schematicPath != null && this.schematicPath.equals(other.schematicPath)) || - (this.schematicPath == other.schematicPath)); - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 24f67b5..4ed540e 100644 --- a/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -1,13 +1,12 @@ package StevenDimDoors.mod_pocketDim; -import net.minecraft.world.World; import net.minecraftforge.client.event.sound.SoundLoadEvent; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.player.PlayerDropsEvent; import net.minecraftforge.event.world.WorldEvent; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.ticking.RiftRegenerator; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -38,38 +37,7 @@ public class EventHookContainer @ForgeSubscribe public void onWorldLoad(WorldEvent.Load event) { - if (!mod_pocketDim.hasInitDims && event.world.provider.dimensionId == 0 && !event.world.isRemote) - { - System.out.println("Registering Pocket Dims"); - mod_pocketDim.hasInitDims = true; - dimHelper.instance.unregsisterDims(); - dimHelper.dimList.clear(); - dimHelper.instance.interDimLinkList.clear(); - dimHelper.instance.initPockets(); - } - - //TODO: In the future, we should iterate over DimHelper's dimension list. We ignore other dimensions anyway. - for (int dimensionID : dimHelper.getIDs()) - { - World world = dimHelper.getWorld(dimensionID); - int linkCount = 0; - - if (dimHelper.dimList.containsKey(dimensionID)) - { - for (NewLinkData link : dimHelper.instance.getDimData(dimensionID).getLinksInDim()) - { - if (!mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord)) - { - world.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); - } - linkCount++; - if (linkCount >= 100) - { - break; - } - } - } - } + RiftRegenerator.regenerateRiftsInAllWorlds(); } @ForgeSubscribe @@ -88,10 +56,9 @@ public class EventHookContainer @ForgeSubscribe public void onWorldsave(WorldEvent.Save event) { - - if (mod_pocketDim.hasInitDims && event.world.provider.dimensionId == 0) + if (PocketManager.isInitialized() && event.world.provider.dimensionId == 0) { - dimHelper.instance.save(); + PocketManager.save(); } } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/PacketHandler.java b/StevenDimDoors/mod_pocketDim/PacketHandler.java index a12ef35..2c5c18b 100644 --- a/StevenDimDoors/mod_pocketDim/PacketHandler.java +++ b/StevenDimDoors/mod_pocketDim/PacketHandler.java @@ -8,213 +8,164 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; -import net.minecraft.world.World; - -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; -import cpw.mods.fml.client.FMLClientHandler; -import cpw.mods.fml.common.network.FMLNetworkHandler; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.Player; public class PacketHandler implements IPacketHandler { - public static int regsiterDimPacketID = 3; - public static int registerLinkPacketID = 4; - public static int removeLinkPacketID = 5; - public static int linkKeyPacketID = 7; - public static int dimPacketID = 6; - public static int dimUpdatePacketID = 1; - private static DDProperties properties = null; + 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; @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { - if (packet.channel.equals("DimDoorPackets")) { - handleRandom(packet,player); + processPacket(packet, player); } - - } - private void handleRandom(Packet250CustomPayload packet, Player player) + private void processPacket(Packet250CustomPayload packet, Player player) { - ByteArrayDataInput data = ByteStreams.newDataInput(packet.data); - - int id=data.readByte(); - - - - - - if(id==regsiterDimPacketID) + ByteArrayDataInput data = ByteStreams.newDataInput(packet.data); + int id = data.readByte(); + if (id == REGISTER_DIM_PACKET_ID) { - - - - int dimId = data.readInt(); - // System.out.println("regsitered dim ID" + dimId); - try - { - DimData dimDataToAdd = new DimData(dimId, data.readBoolean(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt()); - - if(!dimHelper.dimList.containsKey(dimId)) - { - dimHelper.dimList.put(dimId, dimDataToAdd); - } - if(dimDataToAdd.isPocket) - { - if (properties == null) - properties = DDProperties.instance(); - - dimHelper.registerDimension(dimId, properties.PocketProviderID); - //System.out.println("regsitered dim ID" + dimId); - } - - } - catch (Exception e) - { - // e.printStackTrace(); - if(dimId!=0) - { - // System.out.println(String.valueOf(dimId)+"dimID already registered"); - } - } - - - } - - if(id==registerLinkPacketID) - { - - - - int dimId = data.readInt(); try { - DimData dimDataToAddLink= dimHelper.instance.getDimData(dimId); - - NewLinkData linkToAdd = new NewLinkData(dimId, data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readBoolean(),data.readInt()); - linkToAdd.hasGennedDoor=data.readBoolean(); - - dimHelper.instance.createLink(linkToAdd); + NewDimData dimDataToAdd = new NewDimData(dimId, data.readBoolean(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt()); + if(!PocketManager.dimList.containsKey(dimId)) + { + PocketManager.dimList.put(dimId, dimDataToAdd); + } + if (dimDataToAdd.isPocket) + { + DDProperties properties = DDProperties.instance(); + PocketManager.registerDimension(dimId, properties.PocketProviderID); + } } catch (Exception e) { e.printStackTrace(); - System.out.println("Tried to update client link data & failed!"); } - - } - if(id==removeLinkPacketID) + else if (id == REGISTER_LINK_PACKET_ID) { - - - - int dimId = data.readInt(); try { - DimData dimDataToRemoveFrom= dimHelper.instance.getDimData(dimId); + NewDimData dimDataToAddLink= PocketManager.instance.getDimData(dimId); - NewLinkData linkToAdd = new NewLinkData(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); + ILinkData linkToAdd = new ILinkData(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); } catch (Exception e) { - //e.printStackTrace(); - System.out.println("Tried to update client link data & failed!"); + System.err.println("Tried to update client link data and failed!"); + e.printStackTrace(); } - - } - if(id==this.linkKeyPacketID) + else if (id == REMOVE_LINK_PACKET_ID) { - NewLinkData link = new NewLinkData(data.readInt(), data.readInt(), data.readInt(), data.readInt()); - dimHelper.instance.interDimLinkList.put(data.readInt(), link); + int dimId = data.readInt(); + try + { + 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()); + dimDataToRemoveFrom.removeLinkAtCoords(linkToAdd.locDimID, linkToAdd.locXCoord,linkToAdd.locYCoord, linkToAdd.locZCoord); + } + catch (Exception e) + { + System.out.println("Tried to update client link data & failed!"); + 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); } - - - - - } - - public static void onClientJoinPacket(INetworkManager manager, HashMap dimList) + + private static void processRegisterDimPacket() + { + + } + + private static void processUpdateDimPacket() + { + + } + + private static void processRegisterLinkPacket() + { + + } + + private static void processRemoveLinkPacket() + { + + } + + public static void onClientJoinPacket(INetworkManager manager, HashMap dimList) { - Collection dimIDs= dimList.keySet(); - Collection dimDataSet= dimList.values(); + Collection dimDataSet= dimList.values(); Collection packetsToSend = new HashSet(); - - - for(DimData data : dimDataSet) + for(NewDimData data : dimDataSet) { - manager.addToSendQueue(PacketHandler.onDimCreatedPacket(data)); - Collection >> linkList = data.linksInThisDim.values(); + Collection >> linkList = data.linksInThisDim.values(); for(HashMap map : linkList ) { - - Collection > linkList2 = map.values(); - + Collection > linkList2 = map.values(); for(HashMap map2 : linkList2) { - Collection linkList3 = map2.values(); + Collection linkList3 = map2.values(); - for(NewLinkData link : linkList3) + for(ILinkData link : linkList3) { - packetsToSend.add(( PacketHandler.onLinkCreatedPacket(link))); - - } - - - } - } - - - - - } + for (Packet250CustomPayload packet : packetsToSend) { manager.addToSendQueue(packet); } - } - - public static Packet250CustomPayload onLinkCreatedPacket(NewLinkData link) + public static void sendLinkCreatedPacket(ILinkData link) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(bos); try { - dataOut.writeByte(PacketHandler.registerLinkPacketID); dataOut.writeInt(link.locDimID); dataOut.writeInt(link.destDimID); @@ -228,19 +179,14 @@ public class PacketHandler implements IPacketHandler dataOut.writeInt(link.linkOrientation); dataOut.writeBoolean(link.hasGennedDoor); - - } - - - catch (IOException e) { e.printStackTrace(); } Packet250CustomPayload packet= new Packet250CustomPayload(); - packet.channel="DimDoorPackets"; + packet.channel = "DimDoorPackets"; packet.data = bos.toByteArray(); packet.length = bos.size();; PacketDispatcher.sendPacketToAllPlayers(packet); @@ -248,14 +194,13 @@ public class PacketHandler implements IPacketHandler } - public static Packet250CustomPayload linkKeyPacket(NewLinkData link, int key) + 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); @@ -263,36 +208,27 @@ public class PacketHandler implements IPacketHandler dataOut.writeInt(link.destYCoord); dataOut.writeInt(link.destZCoord); dataOut.writeInt(key); - - - } - - - catch (IOException e) { e.printStackTrace(); } - Packet250CustomPayload packet= new Packet250CustomPayload(); + Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel="DimDoorPackets"; packet.data = bos.toByteArray(); packet.length = bos.size();; PacketDispatcher.sendPacketToAllPlayers(packet); - return packet; } - public static void onLinkRemovedPacket(NewLinkData link) + public static void sendLinkRemovedPacket(ILinkData link) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(bos); - try { - dataOut.writeByte(PacketHandler.removeLinkPacketID); dataOut.writeInt(link.locDimID); dataOut.writeInt(link.destDimID); @@ -303,13 +239,7 @@ public class PacketHandler implements IPacketHandler dataOut.writeInt(link.destYCoord); dataOut.writeInt(link.destZCoord); dataOut.writeBoolean(link.isLocPocket); - - - } - - - catch (IOException e) { e.printStackTrace(); @@ -323,17 +253,13 @@ public class PacketHandler implements IPacketHandler } - public static Packet250CustomPayload onDimCreatedPacket(DimData data) + public static void sendDimCreatedPacket(NewDimData data) { - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(bos); - try { - dataOut.writeByte(PacketHandler.regsiterDimPacketID); dataOut.writeInt(data.dimID); dataOut.writeBoolean(data.isPocket); @@ -343,14 +269,7 @@ public class PacketHandler implements IPacketHandler dataOut.writeInt(data.exitDimLink.destXCoord); dataOut.writeInt(data.exitDimLink.destYCoord); dataOut.writeInt(data.exitDimLink.destZCoord); - - - - } - - - catch (IOException e) { e.printStackTrace(); @@ -363,40 +282,9 @@ public class PacketHandler implements IPacketHandler PacketDispatcher.sendPacketToAllPlayers(packet); return packet; - - } - /** - private void handleObjectPacket(Packet250CustomPayload packet, Player player) - { - ObjectInputStream data = new ObjectInputStream; - int length = data.readInt(); - int id=data.readByte(); - System.out.println(id); - if(id==dimPacketID) - { - - - - - try - { - DimData dimData = data.read - - dimHelper.dimList.put(key, value) - - } - catch (Exception e) - { - e.printStackTrace(); - } - - - } - } - **/ - public static void sendDimObject(DimData dim) + public static void sendDimObject(NewDimData dim) { try { @@ -410,15 +298,9 @@ public class PacketHandler implements IPacketHandler packet.length = bos.size();; PacketDispatcher.sendPacketToAllPlayers(packet); } - catch (IOException e) - - + catch (IOException e) { e.printStackTrace(); } } - - - - } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/SchematicLoader.java b/StevenDimDoors/mod_pocketDim/SchematicLoader.java deleted file mode 100644 index 7e76b94..0000000 --- a/StevenDimDoors/mod_pocketDim/SchematicLoader.java +++ /dev/null @@ -1,205 +0,0 @@ -package StevenDimDoors.mod_pocketDim; -import java.io.File; -import java.io.FileNotFoundException; -import java.util.HashMap; -import java.util.Random; - -import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic; -import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; -import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; -import StevenDimDoors.mod_pocketDim.schematic.InvalidSchematicException; - -public class SchematicLoader -{ - private SchematicLoader() { } - - public static boolean generateDungeonPocket(NewLinkData link, DDProperties properties) - { - if (link == null || properties == null) - { - return false; - } - try - { - String schematicPath; - int originDimID = link.locDimID; - int destDimID = link.destDimID; - HashMap dimList = dimHelper.dimList; - DungeonHelper dungeonHelper = DungeonHelper.instance(); - World world; - - if (dimList.containsKey(destDimID)) - { - dimList.get(destDimID).hasBeenFilled = true; - if (dimHelper.getWorld(destDimID) == null) - { - dimHelper.initDimension(destDimID); - } - world = dimHelper.getWorld(destDimID); - - if (dimList.get(destDimID).dungeonGenerator == null) - { - //TODO: We should centralize RNG initialization and world-seed modifiers for each specific application. - final long localSeed = world.getSeed() ^ 0x2F50DB9B4A8057E4L ^ calculateDestinationSeed(link); - final Random random = new Random(localSeed); - - dungeonHelper.generateDungeonLink(link, dungeonHelper.getDimDungeonPack(originDimID), random); - } - schematicPath = dimList.get(destDimID).dungeonGenerator.schematicPath; - } - else - { - return false; - } - - DungeonSchematic dungeon = checkSourceAndLoad(schematicPath); - boolean valid; - - //Validate the dungeon's dimensions - if (hasValidDimensions(dungeon)) - { - dungeon.applyImportFilters(properties); - - //Check that the dungeon has an entrance or we'll have a crash - if (dungeon.getEntranceDoorLocation() != null) - { - valid = true; - } - else - { - System.err.println("The following schematic file does not have an entrance: " + schematicPath); - valid = false; - } - } - else - { - System.err.println("The following schematic file has dimensions that exceed the maximum permitted dimensions for dungeons: " + schematicPath); - valid = false; - } - - if (!valid) - { - //TODO: In the future, remove this dungeon from the generation lists altogether. - //That will have to wait until our code is updated to support that more easily. - System.err.println("The dungeon will not be loaded."); - DungeonGenerator defaultError = dungeonHelper.getDefaultErrorDungeon(); - dimList.get(destDimID).dungeonGenerator = defaultError; - dungeon = checkSourceAndLoad(defaultError.schematicPath); - dungeon.applyImportFilters(properties); - } - - //Adjust the height at which the dungeon is placed to prevent vertical clipping - int fixedY = adjustDestinationY(world, link.destYCoord, dungeon); - if (fixedY != link.destYCoord) - { - dimHelper helperInstance = dimHelper.instance; - helperInstance.moveLinkDataDestination(link, link.destXCoord, fixedY, link.destZCoord, link.destDimID, true); - } - DungeonPackConfig packConfig = dungeonHelper.getDimDungeonPack(destDimID).getConfig(); - - dungeon.copyToWorld(world, new Point3D(link.destXCoord, link.destYCoord, link.destZCoord), - link.linkOrientation, originDimID, destDimID, packConfig.doDistortDoorCoordinates()); - return true; - } - catch (Exception e) - { - e.printStackTrace(); - return false; - } - } - - private static int adjustDestinationY(World world, int y, DungeonSchematic dungeon) - { - //The goal here is to guarantee that the dungeon fits within the vertical bounds - //of the world while shifting it as little as possible. - int destY = y; - - //Is the top of the dungeon going to be at Y < worldHeight? - int entranceY = dungeon.getEntranceDoorLocation().getY(); - int pocketTop = (dungeon.getHeight() - 1) + destY - entranceY; - int worldHeight = world.getHeight(); - if (pocketTop >= worldHeight) - { - destY = (worldHeight - 1) - (dungeon.getHeight() - 1) + entranceY; - } - - //Is the bottom of the dungeon at Y >= 0? - if (destY < entranceY) - { - destY = entranceY; - } - return destY; - } - - private static boolean hasValidDimensions(DungeonSchematic dungeon) - { - return (dungeon.getWidth() <= DungeonHelper.MAX_DUNGEON_WIDTH && - dungeon.getHeight() <= DungeonHelper.MAX_DUNGEON_HEIGHT && - dungeon.getLength() <= DungeonHelper.MAX_DUNGEON_LENGTH); - } - - private static DungeonSchematic checkSourceAndLoad(String schematicPath) throws FileNotFoundException, InvalidSchematicException - { - //FIXME: Change this code once we introduce an isInternal flag in dungeon data - DungeonSchematic dungeon; - if ((new File(schematicPath)).exists()) - { - dungeon = DungeonSchematic.readFromFile(schematicPath); - } - else - { - dungeon = DungeonSchematic.readFromResource(schematicPath); - } - return dungeon; - } - - private static long calculateDestinationSeed(LinkData link) - { - //Time for some witchcraft. - //The code here is inspired by a discussion on Stack Overflow regarding hash codes for 3D. - //Source: http://stackoverflow.com/questions/9858376/hashcode-for-3d-integer-coordinates-with-high-spatial-coherence - - //Use 8 bits from Y and 16 bits from X and Z. Mix in 8 bits from the destination dim ID too - that means - //even if you aligned two doors perfectly between two pockets, it's unlikely they would lead to the same dungeon. - //We map bits in reverse order to produce more varied RNG output for nearly-identical points. The reason is - //that Java's Random outputs the 32 MSBs of its internal state to produce its output. If the differences - //between two seeds are small (i.e. in the LSBs), then they will tend to produce similar random outputs anyway! - - //Only bother to assign the 48 least-significant bits since Random only takes those bits from its seed. - //NOTE: The casts to long are necessary to get the right results from the bit shifts!!! - - int bit; - int index; - long hash; - final int w = link.destDimID; - final int x = link.destXCoord; - final int y = link.destYCoord; - final int z = link.destZCoord; - - hash = 0; - index = 48; - for (bit = 0; bit < 8; bit++) - { - hash |= (long) ((w >> bit) & 1) << index; - index--; - hash |= (long) ((x >> bit) & 1) << index; - index--; - hash |= (long) ((y >> bit) & 1) << index; - index--; - hash |= (long) ((z >> bit) & 1) << index; - index--; - } - for (; bit < 16; bit++) - { - hash |= (long) ((x >> bit) & 1) << index; - index--; - hash |= (long) ((z >> bit) & 1) << index; - index--; - } - - return hash; - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/TileEntityRift.java b/StevenDimDoors/mod_pocketDim/TileEntityRift.java index cfff50f..72565c4 100644 --- a/StevenDimDoors/mod_pocketDim/TileEntityRift.java +++ b/StevenDimDoors/mod_pocketDim/TileEntityRift.java @@ -2,80 +2,68 @@ package StevenDimDoors.mod_pocketDim; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Random; -import StevenDimDoors.mod_pocketDim.blocks.BlockRift; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; -import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; -import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; - import net.minecraft.entity.DataWatcher; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; import net.minecraft.entity.monster.EntityEnderman; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.Packet130UpdateSign; import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.util.Point4D; public class TileEntityRift extends TileEntity - { + private static Random random = new Random(); + 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 isClosing=false; public boolean isNearRift=false; private int count=200; private int count2 = 0; public int age = 0; public HashMap renderingCenters = new HashMap(); - public NewLinkData nearestRiftData; + public IDimLink nearestRiftData; public int spawnedEndermenID=0; - Random rand; DataWatcher watcher = new DataWatcher(); - - - - + public void updateEntity() - { - if(rand == null) - { - rand = new Random(); - rand.setSeed(this.xCoord+this.yCoord+this.zCoord); - } - if(dimHelper.instance.getLinkDataFromCoords(xCoord, yCoord, zCoord, this.worldObj.provider.dimensionId)==null)//ensures that only rifts with TEs are active - { - this.invalidate(); - if(this.worldObj.getBlockId(xCoord, yCoord, zCoord)==mod_pocketDim.blockRift.blockID)//deletes rift TE if its behind something thats not a rift block - { - this.worldObj.setBlockToAir(xCoord, yCoord, zCoord); - this.invalidate(); - return; - } - } - if(this.worldObj.getBlockId(xCoord, yCoord, zCoord)!=mod_pocketDim.blockRift.blockID)//deletes rift TE if its behind something thats not a rift block - { - 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. - /** + { + //Invalidate this tile entity if it shouldn't exist + if (PocketManager.getLink(xCoord, yCoord, zCoord, worldObj.provider.dimensionId) == null) + { + this.invalidate(); + if (worldObj.getBlockId(xCoord, yCoord, zCoord) == mod_pocketDim.blockRift.blockID) + { + worldObj.setBlockToAir(xCoord, yCoord, zCoord); + this.invalidate(); + return; + } + } + + if (worldObj.getBlockId(xCoord, yCoord, zCoord) != mod_pocketDim.blockRift.blockID) + { + 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. + /** if(rand.nextInt(15) == 1) { age = age + 1; @@ -83,213 +71,219 @@ public class TileEntityRift extends TileEntity } this.clearBlocksOnRift(); **/ - - //This code should execute once every 10 seconds - count++; - if(count>200) - { - this.spawnEndermen(); - this.calculateOldParticleOffset(); //this also calculates the distance for the particle stuff. - if(distance>1)//only grow if rifts are nearby - { - this.grow(distance); - } - count=0; - } - - if(this.shouldClose)//Determines if rift should render white closing particles and spread closing effect to other rifts nearby - { - closeRift(); - } - } - public boolean canUpdate() - { - return true; - } - public void clearBlocksOnRift()//clears blocks for the new rending effect - { - - 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(!BlockRift.isBlockImmune(worldObj,this.xCoord+x, this.yCoord+y, this.zCoord+z))//right side - { - this.worldObj.setBlockToAir(this.xCoord+x, this.yCoord+y, this.zCoord+z); - } - - if(!BlockRift.isBlockImmune(worldObj,this.xCoord-x, this.yCoord-y, this.zCoord-z))//left side - { - this.worldObj.setBlockToAir(this.xCoord-x, this.yCoord-y, this.zCoord-z); - } - } - } - public void spawnEndermen() - { - if(this.worldObj.isRemote) - { - return; - } - if(dimHelper.instance.getDimData(this.worldObj.provider.dimensionId)!=null)//ensures that this rift is only spawning one enderman at a time, to prevent hordes of endermen - { - if(this.worldObj.getEntityByID(this.spawnedEndermenID)!=null) + //This code should execute once every 10 seconds + count++; + if (count > 200) + { + this.spawnEndermen(); + this.calculateOldParticleOffset(); //this also calculates the distance for the particle stuff. + if (distance > 1) //only grow if rifts are nearby { - if(this.worldObj.getEntityByID(this.spawnedEndermenID) instanceof EntityEnderman) + this.grow(distance); + } + count = 0; + } + + if (this.shouldClose) //Determines if rift should render white closing particles and spread closing effect to other rifts nearby + { + closeRift(); + } + } + + public boolean canUpdate() + { + return true; + } + + public void clearBlocksOnRift() + { + //clears blocks for the new rending effect + + 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 + { + 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 + { + worldObj.setBlockToAir(this.xCoord-x, this.yCoord-y, this.zCoord-z); + } + + } + } + + public void spawnEndermen() + { + if (worldObj.isRemote) + { + return; + } + + NewDimData dimension = PocketManager.getDimensionData(worldObj); + + //Ensure that this rift is only spawning one enderman at a time, to prevent hordes of endermen + Entity entity = worldObj.getEntityByID(this.spawnedEndermenID); + if (entity != null && entity instanceof EntityEnderman) + { + return; + } + + //enderman will only spawn in groups of rifts + nearestRiftData = dimension.findNearestRift(worldObj, 5, xCoord, yCoord, zCoord); + if (nearestRiftData != null) + { + if (random.nextInt(30) == 0) + { + @SuppressWarnings("unchecked") + List list = (List) worldObj.getEntitiesWithinAABB(EntityEnderman.class, + AxisAlignedBB.getBoundingBox(xCoord - 9, yCoord - 3, zCoord - 9, xCoord + 9, yCoord + 3, zCoord + 9)); + + if (list.isEmpty()) { - return; + EntityEnderman enderman = new EntityEnderman(worldObj); + enderman.setLocationAndAngles(xCoord + 0.5, yCoord - 1, zCoord + 0.5, 5, 6); + worldObj.spawnEntityInWorld(enderman); + } + } + } + else + { + this.isNearRift = false; + } + } + + public void closeRift() + { + NewDimData dimension = PocketManager.getDimensionData(worldObj); + if (count2 > 20 && count2 < 22) + { + nearestRiftData = dimension.findNearestRift(worldObj, 10, xCoord, yCoord, zCoord); + if (this.nearestRiftData != null) + { + Point4D location = nearestRiftData.source(); + TileEntityRift rift = (TileEntityRift) worldObj.getBlockTileEntity(location.getX(), location.getY(), location.getZ()); + if (rift != null) + { + rift.shouldClose = true; } } - - nearestRiftData = dimHelper.instance.getDimData(this.worldObj.provider.dimensionId).findNearestRift(worldObj, 5, xCoord, yCoord, zCoord);//enderman will only spawn in groups of rifts - if(nearestRiftData!=null) - { - if(rand.nextInt(30)==0&&!this.worldObj.isRemote) - { - - List list = worldObj.getEntitiesWithinAABB(EntityEnderman.class, AxisAlignedBB.getBoundingBox( this.xCoord-9, this.yCoord-3, this.zCoord-9, this.xCoord+9, this.yCoord+3, this.zCoord+9)); - - if(list.size()<1) - { - - - EntityEnderman creeper = new EntityEnderman(worldObj); - creeper.setLocationAndAngles(this.xCoord+.5, this.yCoord-1, this.zCoord+.5, 5, 6); - worldObj.spawnEntityInWorld(creeper); - } - } - } - else - { - this.isNearRift=false; - } - - } - } - public void closeRift() - { - if(count2>20&&count2<22) - { - nearestRiftData = dimHelper.instance.getDimData(this.worldObj.provider.dimensionId).findNearestRift(worldObj, 10, xCoord, yCoord, zCoord); - if(this.nearestRiftData!=null) - { - TileEntityRift rift = (TileEntityRift) this.worldObj.getBlockTileEntity(nearestRiftData.locXCoord, nearestRiftData.locYCoord, nearestRiftData.locZCoord); - if(rift!=null) - { - rift.shouldClose=true; - } - } - } - if(count2>40) - { - this.invalidate(); - this.worldObj.setBlock(this.xCoord, this.yCoord, this.zCoord,0); - if(dimHelper.instance.getLinkDataFromCoords(this.xCoord, this.yCoord, this.zCoord, this.worldObj.provider.dimensionId)!=null) - { - dimHelper.instance.removeLink(this.worldObj.provider.dimensionId, this.xCoord, this.yCoord, this.zCoord); - this.worldObj.playSound(xCoord, yCoord, zCoord, "mods.DimDoors.sfx.riftClose", (float) .7, 1,true); + } + if (count2 > 40) + { + this.invalidate(); + worldObj.setBlockToAir(xCoord, yCoord, zCoord); + if (dimension.getLink(xCoord, yCoord, zCoord) != null) + { + dimension.deleteLink(xCoord, yCoord, zCoord); + worldObj.playSound(xCoord, yCoord, zCoord, "mods.DimDoors.sfx.riftClose", (float) .7, 1, true); + } + } + count2++; + } - } - } - count2++; - } - public void calculateOldParticleOffset() - { - nearestRiftData = dimHelper.instance.getDimData(this.worldObj.provider.dimensionId).findNearestRift(worldObj, 5, xCoord, yCoord, zCoord); - if(nearestRiftData!=null) - { - this.xOffset=this.xCoord-nearestRiftData.locXCoord; - this.yOffset=this.yCoord-nearestRiftData.locYCoord; - this.zOffset=this.zCoord-nearestRiftData.locZCoord; - this.distance=(int) (MathHelper.abs(xOffset)+MathHelper.abs(yOffset)+MathHelper.abs(zOffset)); - this.isNearRift=true; - - if(!this.worldObj.isRemote&&distance>1) - { - try - { - grow(distance); - } - catch(Exception e) - { - - } - } - } - } - public void grow(int distance) - { - if(this.worldObj.isRemote) - { - return; - } - int growCount=0; - if(rand.nextInt(distance*2)==0) - { + public void calculateOldParticleOffset() + { + nearestRiftData = PocketManager.getDimensionData(worldObj).findNearestRift(worldObj, 5, xCoord, yCoord, zCoord); + if (nearestRiftData != null) + { + Point4D location = nearestRiftData.source(); + 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; + + if (!worldObj.isRemote && distance > 1) + { + try + { + grow(distance); + } + catch(Exception e) + { + + } + } + } + } + + 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-(rand.nextInt(2)*2)*rand.nextInt(6)); - y=this.yCoord+(1-(rand.nextInt(2)*2)*rand.nextInt(4)); - z=this.zCoord+(1-(rand.nextInt(2)*2)*rand.nextInt(6)); - if(this.worldObj.isAirBlock(x, y, z)) + 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) + if (growCount < 100) { - - NewLinkData link = dimHelper.instance.getLinkDataFromCoords(this.xCoord, this.yCoord, this.zCoord, worldObj); - if(link!=null) + NewDimData dimension = PocketManager.getDimensionData(worldObj); + IDimLink link = dimension.getLink(xCoord, yCoord, zCoord); + if (link != null) { - if(!this.hasGrownRifts&&rand.nextInt(3)==0) + if (!this.hasGrownRifts && random.nextInt(3) == 0) { - // System.out.println(link.numberofChildren); - link.numberofChildren++; - dimHelper.instance.createLink(this.worldObj.provider.dimensionId, link.destDimID, x, y, z, link.destXCoord, link.destYCoord, link.destZCoord).numberofChildren=link.numberofChildren+1; - this.hasGrownRifts=true; + 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)))); - int iteration=0; - while(iteration< maxSize) - { - iteration++; - double fl =Math.log(iteration+1)/(iteration); - double[] coords= new double[4]; - double noise = ((rand.nextGaussian())/(2+iteration/3+1)); - - if(!this.renderingCenters.containsKey(iteration-1)) - { - if(rand.nextBoolean()) - { + } + } + + public void calculateNextRenderQuad(float age, Random rand) + { + int maxSize = MathHelper.floor_double((Math.log(Math.pow(age+1,2)))); + int iteration=0; + while(iteration< maxSize) + { + iteration++; + double fl =Math.log(iteration+1)/(iteration); + double[] coords= new double[4]; + double noise = ((rand.nextGaussian())/(2+iteration/3+1)); + + if(!this.renderingCenters.containsKey(iteration-1)) + { + if (rand.nextBoolean()) + { coords[0] = fl*1.5; coords[1] = rand.nextGaussian()/5; coords[2] = 0; coords[3] = 1; - } - else - { + } + else + { coords[0] = 0; coords[1] = rand.nextGaussian()/5; coords[2] = fl*1.5; coords[3] = 0; - } - this.renderingCenters.put(iteration-1,coords); - iteration--; - } - else if(!this.renderingCenters.containsKey(iteration)) - { + } + this.renderingCenters.put(iteration-1,coords); + iteration--; + } + else if(!this.renderingCenters.containsKey(iteration)) + { if(this.renderingCenters.get(iteration-1)[3]==0) { coords[0]=noise/2+this.renderingCenters.get(iteration-1)[0]; @@ -305,66 +299,66 @@ public class TileEntityRift extends TileEntity coords[3] = 1; } this.renderingCenters.put(iteration,coords); - } - } - } - - @Override - public boolean shouldRenderInPass(int pass) - { - return pass == 1; - } - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - this.renderingCenters= new HashMap(); - 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.spawnedEndermenID = nbt.getInteger("spawnedEndermenID"); - } - - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - nbt.setInteger("hashMapSize", this.renderingCenters.size()); - nbt.setInteger("age", this.age); - nbt.setInteger("count", this.count); - nbt.setInteger("count2", this.count2); - nbt.setBoolean("grownRifts",this.hasGrownRifts); - nbt.setInteger("xOffset", this.xOffset); - nbt.setInteger("yOffset", this.yOffset); - nbt.setInteger("zOffset", this.zOffset); - nbt.setBoolean("shouldClose", this.shouldClose); - nbt.setInteger("spawnedEndermenID", this.spawnedEndermenID); - } - - @Override - public Packet getDescriptionPacket() - { - Packet132TileEntityData packet = new Packet132TileEntityData(); - packet.actionType = 0; - packet.xPosition = xCoord; - packet.yPosition = yCoord; - packet.zPosition = zCoord; - - NBTTagCompound nbt = new NBTTagCompound(); - writeToNBT(nbt); - packet.customParam1 = nbt; - return packet; + } } + } - @Override - public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) - { - readFromNBT(pkt.customParam1); - } - + @Override + public boolean shouldRenderInPass(int pass) + { + return pass == 1; + } + + @Override + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + this.renderingCenters= new HashMap(); + 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.spawnedEndermenID = nbt.getInteger("spawnedEndermenID"); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + nbt.setInteger("hashMapSize", this.renderingCenters.size()); + nbt.setInteger("age", this.age); + nbt.setInteger("count", this.count); + nbt.setInteger("count2", this.count2); + nbt.setBoolean("grownRifts",this.hasGrownRifts); + nbt.setInteger("xOffset", this.xOffset); + nbt.setInteger("yOffset", this.yOffset); + nbt.setInteger("zOffset", this.zOffset); + nbt.setBoolean("shouldClose", this.shouldClose); + nbt.setInteger("spawnedEndermenID", this.spawnedEndermenID); + } + + @Override + public Packet getDescriptionPacket() + { + Packet132TileEntityData packet = new Packet132TileEntityData(); + packet.actionType = 0; + packet.xPosition = xCoord; + packet.yPosition = yCoord; + packet.zPosition = zCoord; + + NBTTagCompound nbt = new NBTTagCompound(); + writeToNBT(nbt); + packet.customParam1 = nbt; + return packet; + } + + @Override + public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) + { + readFromNBT(pkt.customParam1); + } } diff --git a/StevenDimDoors/mod_pocketDim/TransientDoor.java b/StevenDimDoors/mod_pocketDim/TransientDoor.java index 47a0445..a0a8fcd 100644 --- a/StevenDimDoors/mod_pocketDim/TransientDoor.java +++ b/StevenDimDoors/mod_pocketDim/TransientDoor.java @@ -2,152 +2,102 @@ package StevenDimDoors.mod_pocketDim; import java.util.Random; -import StevenDimDoors.mod_pocketDim.blocks.ExitDoor; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.Item; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.blocks.ExitDoor; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class TransientDoor extends ExitDoor { - + protected TransientDoor(int par1, Material material) { super(par1, Material.grass); - // this.blockIndexInTexture = 18; + // this.blockIndexInTexture = 18; if (properties == null) properties = DDProperties.instance(); } - - private static DDProperties properties = null; - - public void registerIcons(IconRegister par1IconRegister) - { - this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); - } + private static DDProperties properties = null; + + public void registerIcons(IconRegister par1IconRegister) + { + this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); + + } @SideOnly(Side.CLIENT) - /** - * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side - */ - public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) - { - - return this.blockIcon; - - - } - public boolean isCollidable() - { - return false; - } - - public void onBlockAdded(World par1World, int par2, int par3, int par4) - { - super.onBlockAdded(par1World, par2, par3, par4); - this.updateAttatchedTile(par1World, par2, par3, par4); - } - - public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) - { - return null; - } + /** + * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side + */ + public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) + { + + return this.blockIcon; + + + } + public boolean isCollidable() + { + return false; + } + + public void onBlockAdded(World par1World, int par2, int par3, int par4) + { + super.onBlockAdded(par1World, par2, par3, par4); + this.updateAttachedTile(par1World, par2, par3, par4); + } + + public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) + { + return null; + } @Override - public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) - { - - int var12 = (int) (MathHelper.floor_double((double)((par5Entity.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); - int num = par1World.getBlockMetadata(par2, par3, par4); - // System.out.println("metadata "+num+" orientation "+var12); - - if(!par1World.isRemote&&(num)==var12||!par1World.isRemote&&!(par5Entity instanceof EntityPlayer)) + public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) + { + //TODO: Would it kill us to use REASONABLE variable names? <_< ~SenseiKiwi + int var12 = (int) (MathHelper.floor_double((double) ((entity.rotationYaw + 90) * 4.0F / 360.0F) + 0.5D) & 3); + + int orientation = world.getBlockMetadata(x, y - 1, z); + if (!world.isRemote && (orientation >= 4 && orientation <= 7) && (orientation - 4) == var12 && + world.getBlockId(x, y - 1, z) == this.blockID) + { + this.onPoweredBlockChange(world, x, y, z, false); + + IDimLink link = PocketManager.getLink(x, y, z, world.provider.dimensionId); + if (link != null) { - - - - - NewLinkData linkData= dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World); - if(linkData!=null) - { - if(dimHelper.dimList.containsKey(linkData.destDimID)) - { - par1World.setBlock(par2, par3-1, par4, 0); - par1World.setBlock(par2, par3, par4, properties.RiftBlockID); - dimHelper.instance.traverseDimDoor(par1World, linkData, par5Entity); - - - } - } - - else - { - linkData= dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World); - if(linkData!=null) - { - if(dimHelper.dimList.containsKey(linkData.destDimID)) - { - par1World.setBlock(par2, par3, par4, 0); - par1World.setBlock(par2, par3+1, par4, properties.RiftBlockID); - dimHelper.instance.traverseDimDoor(par1World, linkData, par5Entity); - - - } - } - } - - } - - - } - - - - + //Turn the transient door into a rift before teleporting the entity + world.setBlock(x, y, z, properties.RiftBlockID); + world.setBlockToAir(x, y - 1, z); + PocketManager.traverseDimDoor(world, link, entity); + } + } + } + public int idPicked(World par1World, int par2, int par3, int par4) + { + return 0; + } - - public int idPicked(World par1World, int par2, int par3, int par4) - { - return 0; - } - - public int idDropped(int par1, Random par2Random, int par3) - { - return 0; - } - - - - - /** - * A function to open a door. - */ - - public int getRenderType() - { - return 8; - } - + public int idDropped(int par1, Random par2Random, int par3) + { + return 0; + } + public int getRenderType() + { + return 8; + } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java index 0e047e5..da81b74 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java @@ -9,14 +9,12 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import StevenDimDoors.mod_pocketDim.BlankTeleporter; +import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; -import cpw.mods.fml.common.FMLCommonHandler; public class BlockDimWallPerm extends Block { @@ -45,32 +43,33 @@ public class BlockDimWallPerm extends Block /** * Only matters if the player is in limbo, acts to teleport the player from limbo back to dim 0 */ - public void onEntityWalking(World par1World, int par2, int par3, int par4, Entity par5Entity) + public void onEntityWalking(World par1World, int par2, int par3, int par4, Entity entity) { - if(!par1World.isRemote&&par1World.provider.dimensionId==properties.LimboDimensionID) + if (!par1World.isRemote && par1World.provider.dimensionId == properties.LimboDimensionID) { Random rand = new Random(); - NewLinkData link=dimHelper.instance.getRandomLinkData(false); - if(link==null) + IDimLink link = PocketManager.getRandomLinkData(false); + if (link == null) { link =new NewLinkData(0,0,0,0); } link.destDimID = 0; link.locDimID = par1World.provider.dimensionId; + World overworld = DimensionManager.getWorld(0); - - if(dimHelper.getWorld(0)==null) + if (overworld == null) { - dimHelper.initDimension(0); + DimensionManager.initDimension(0); + overworld = DimensionManager.getWorld(0); } - - - if(dimHelper.getWorld(0)!=null&&par5Entity instanceof EntityPlayerMP) + + if (overworld != null && entity instanceof EntityPlayerMP) { - par5Entity.fallDistance=0; - int x = (link.destXCoord + rand.nextInt(properties.LimboReturnRange)-properties.LimboReturnRange/2); - int z = (link.destZCoord + rand.nextInt(properties.LimboReturnRange)-properties.LimboReturnRange/2); + EntityPlayer player = (EntityPlayer) entity; + player.fallDistance = 0; + int x = (link.destXCoord + rand.nextInt(properties.LimboReturnRange) - properties.LimboReturnRange/2); + int z = (link.destZCoord + rand.nextInt(properties.LimboReturnRange) - properties.LimboReturnRange/2); //make sure I am in the middle of a chunk, and not on a boundary, so it doesn't load the chunk next to me x = x + (x >> 4); @@ -78,46 +77,39 @@ public class BlockDimWallPerm extends Block int y = yCoordHelper.getFirstUncovered(0, x, 63, z, true); - EntityPlayer.class.cast(par5Entity).setPositionAndUpdate( x, y, z ); + player.setPositionAndUpdate( x, y, z ); //this complicated chunk teleports the player back to the overworld at some random location. Looks funky becaue it has to load the chunk link.destXCoord = x; link.destYCoord = y; link.destZCoord = z; - dimHelper.instance.teleportEntity(par1World, par5Entity, link); - //FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().transferPlayerToDimension((EntityPlayerMP) par5Entity, 0,new BlankTeleporter((WorldServer)par5Entity.worldObj)); - //dimHelper.instance.teleportToPocket(par1World, new LinkData(par1World.provider.dimensionId,0,x,y,z,link.locXCoord,link.locYCoord,link.locZCoord,link.isLocPocket,0), - // EntityPlayer.class.cast(par5Entity)); - - - EntityPlayer.class.cast(par5Entity).setPositionAndUpdate( x, y, z ); + PocketManager.teleportEntity(par1World, player, link); + + player.setPositionAndUpdate( x, y, z ); // Make absolutely sure the player doesn't spawn inside blocks, though to be honest this shouldn't ever have to be a problem... - dimHelper.getWorld(0).setBlock(x, y, z, 0); - dimHelper.getWorld(0).setBlock(x, y+1, z, 0); + overworld.setBlockToAir(x, y, z); + overworld.setBlockToAir(x, y + 1, z); int i=x; int j=y; int k=z; - for(int xc=-3;xc<4;xc++) { for(int zc=-3;zc<4;zc++) { for(int yc=0;yc<200;yc++) { - if(yc==0) + if (yc==0) { - if(Math.abs(xc)+Math.abs(zc) blocksImmuneToRift; + private final ArrayList blocksImmuneToRift; public BlockRift(int i, int j, Material par2Material, DDProperties properties) { @@ -154,7 +154,7 @@ public class BlockRift extends BlockContainer public void updateTick(World world, int x, int y, int z, Random random) { if (properties.RiftGriefingEnabled && !world.isRemote && - dimHelper.instance.getLinkDataFromCoords(x, y, z, world.provider.dimensionId) != null) + PocketManager.getLink(x, y, z, world.provider.dimensionId) != null) { //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. @@ -335,7 +335,8 @@ public class BlockRift extends BlockContainer } } } - public static boolean isBlockImmune(World world, int x, int y, int z) + + public boolean isBlockImmune(World world, int x, int y, int z) { Block block = Block.blocksList[world.getBlockId(x, y, z)]; if (block != null) diff --git a/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java b/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java index bf621ee..f4c01e5 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java @@ -2,27 +2,18 @@ package StevenDimDoors.mod_pocketDim.blocks; import java.util.Random; -import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -30,117 +21,45 @@ public class ChaosDoor extends dimDoor { private Icon blockIconBottom; private static DDProperties properties = null; - + public ChaosDoor(int par1, Material material) { - super(par1, Material.iron); + super(par1, material); if (properties == null) properties = DDProperties.instance(); } - - public void registerIcons(IconRegister par1IconRegister) - { - this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); - this.blockIconBottom = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_bottom"); - } + public void registerIcons(IconRegister par1IconRegister) + { + this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); + this.blockIconBottom = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_bottom"); + + } @SideOnly(Side.CLIENT) - /** - * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side - */ - public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) - { - if(par1IBlockAccess.getBlockId(par2, par3-1, par4)==this.blockID) - { - return this.blockIcon; - } - else - { - return this.blockIconBottom; - } - } - - @Override - public void onBlockAdded(World par1World, int par2, int par3, int par4) + /** + * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side + */ + public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { - if(!par1World.isRemote&&par1World.getBlockId(par2, par3-1, par4)==this.blockID) - { - boolean newDim=false; - - if(dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)==null) - { - newDim=true; - } - - if(newDim) - { - NewLinkData link = new NewLinkData(par1World.provider.dimensionId, properties.LimboDimensionID, par2, par3, par4, par2, par3+500, par4, false,0); - link.linkOrientation= par1World.getBlockMetadata(par2, par3-1, par4); - dimHelper.instance.createLink(link); - // System.out.println(link.linkOrientation); - - - } - - - if(dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)!=null) - { - dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World).linkOrientation=par1World.getBlockMetadata(par2, par3-1, par4); - - - } + if (par1IBlockAccess.getBlockId(par2, par3 - 1, par4) == this.blockID) + { + return this.blockIcon; + } + else + { + return this.blockIconBottom; } - } - - - //uses the rift rendering list to find a random destination for the player - public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) - { - - int var12 = (int) (MathHelper.floor_double((double)((par5Entity.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); - - int num = par1World.getBlockMetadata(par2, par3-1, par4); - if(!par1World.isRemote&&(num==5||num==4||num==6||num==7)&&(num-4)==var12&&par1World.getBlockId(par2, par3-1, par4)==properties.UnstableDoorID) - { - this.onPoweredBlockChange(par1World, par2, par3, par4, false); - - boolean foundRandomDest=false; - - int i=0; - - - Random rand= new Random(); - - while (!foundRandomDest&&i<100) - { - i++; - - NewLinkData link = (NewLinkData) dimHelper.instance.getRandomLinkData(false); - - if(link!=null) - { - - if(!link.isLocPocket&&link.linkOrientation!=-10&&link.destDimID!=properties.LimboDimensionID) - { - foundRandomDest=true; - - dimHelper.instance.traverseDimDoor(par1World, new NewLinkData(link.destDimID,link.locDimID,link.destXCoord,link.destYCoord,link.destZCoord,link.locXCoord,link.locYCoord,link.locZCoord,link.isLocPocket,0), par5Entity); - - if(dimHelper.getWorld(link.locDimID)!=null) - { - if(dimHelper.getWorld(link.locDimID).isAirBlock(link.locXCoord,link.locYCoord,link.locZCoord)) - { - dimHelper.getWorld(link.locDimID).setBlock(link.locXCoord,link.locYCoord,link.locZCoord, properties.RiftBlockID); - } - } - } - } - } - } - } - + @Override + public void onBlockAdded(World world, int x, int y, int z) + { + if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) + { + NewDimData dimension = PocketManager.getDimensionData(world); + dimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_RANDOM); + } + } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java b/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java index 346b5cd..1e4feb9 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java @@ -2,160 +2,74 @@ package StevenDimDoors.mod_pocketDim.blocks; import java.util.Random; -import StevenDimDoors.mod_pocketDim.DimData; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.item.Item; +import net.minecraft.util.Icon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; -import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; -import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; - +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; - - -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.Item; -import net.minecraft.util.Icon; -import net.minecraft.util.MathHelper; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - public class ExitDoor extends dimDoor { - private Icon blockIconBottom; - public ExitDoor(int par1, Material par2Material) - { - - super(par1, Material.wood); - - // TODO Auto-generated constructor stub + public ExitDoor(int blockID, Material material) + { + super(blockID, material); } - public void registerIcons(IconRegister par1IconRegister) - { - this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); - this.blockIconBottom = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_bottom"); - - } - - @Override - public void onBlockAdded(World par1World, int par2, int par3, int par4) { - - - if(!par1World.isRemote&&par1World.getBlockId(par2, par3-1, par4)==this.blockID) - { - - - int locDimID=par1World.provider.dimensionId; - - if(dimHelper.instance.dimList.containsKey(locDimID)&&dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)==null) - { - DimData dimData = dimHelper.instance.getDimData(locDimID); - int ExitDimID = dimData.exitDimLink.destDimID; - if(dimHelper.instance.getDimData(par1World.provider.dimensionId).isPocket) - { - int yCoord=yCoordHelper.getFirstUncovered(ExitDimID, par2, par3, par4)-1; - - - dimHelper.instance.createLink(locDimID, ExitDimID, par2, par3, par4, par2, yCoord, par4,par1World.getBlockMetadata(par2, par3-1, par4)); - dimHelper.instance.createLink(ExitDimID, locDimID, par2, yCoord, par4, par2, par3, par4, - BlockRotator.transformMetadata(par1World.getBlockMetadata(par2, par3 - 1, par4), 2, Block.doorWood.blockID)); - } - - - - /** - - if(dimHelper.instance.getDimDepth(locDimID)==1) - { - //System.out.println("exitToOverowrld from "+String.valueOf(locDimID)); - - int yCoord=yCoordHelper.getFirstUncovered(ExitDimID, par2, par3, par4); - - - dimHelper.instance.createLink(locDimID, ExitDimID, par2, par3, par4, par2, yCoord, par4,par1World.getBlockMetadata(par2, par3-1, par4)); - dimHelper.instance.createLink(ExitDimID, locDimID, par2, yCoord, par4, par2, par3, par4,dimHelper.instance.flipDoorMetadata(par1World.getBlockMetadata(par2, par3-1, par4))); - - - - - } - else if(dimHelper.instance.getDimData(par1World.provider.dimensionId).isPocket) - { - //System.out.println("Created new dim from "+String.valueOf(par1World.provider.dimensionId)); - - LinkData link = new LinkData(par1World.provider.dimensionId, 0, par2, par3, par4, par2, par3, par4, true, par1World.getBlockMetadata(par2, par3-1, par4)); - dimHelper.instance.createPocket(link,false, false); - - - - // dimHelper.instance.generatePocket(dimHelper.getWorld(destDimID), par2, par3, par4,par1World.getBlockMetadata(par2, par3-1, par4)); - - - } - **/ - - } - else if (dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)!=null) - { - - //System.out.println("RiftPresent at "+String.valueOf(par1World.provider.dimensionId)); - dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World).linkOrientation=par1World.getBlockMetadata(par2, par3-1, par4); - dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World).hasGennedDoor=false; - - - - - - - } - - - - } - - par1World.setBlockTileEntity(par2, par3, par4, this.createNewTileEntity(par1World)); - + this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); + this.blockIconBottom = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_bottom"); } + + @Override + public void onBlockAdded(World world, int x, int y, int z) + { + //FIXME: We need to set door generation flags on the tile entities. Ignoring that for now. ~SenseiKiwi + + if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) + { + NewDimData dimension = PocketManager.getDimensionData(world); + IDimLink link = dimension.getLink(x, y, z); + if (link == null) + { + dimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_SAFE_EXIT); + } + } + world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); + } + @SideOnly(Side.CLIENT) + /** + * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side + */ + public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) + { + if(par1IBlockAccess.getBlockId(par2, par3-1, par4)==this.blockID) + { + return this.blockIcon; + } + else + { + return this.blockIconBottom; + } + } - /** - * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side - */ - public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) - { - if(par1IBlockAccess.getBlockId(par2, par3-1, par4)==this.blockID) - { - return this.blockIcon; - } - else - { - return this.blockIconBottom; - } - } - - public int idPicked(World par1World, int par2, int par3, int par4) - { - return Item.doorWood.itemID; - } - - public int idDropped(int par1, Random par2Random, int par3) - { - return (par1 & 8) != 0 ? 0 : (Item.doorWood.itemID); - } - - - + public int idPicked(World par1World, int par2, int par3, int par4) + { + return Item.doorWood.itemID; + } + public int idDropped(int par1, Random par2Random, int par3) + { + return (par1 & 8) != 0 ? 0 : (Item.doorWood.itemID); + } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java b/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java index 86dc8c9..24dc5e0 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java @@ -2,19 +2,11 @@ package StevenDimDoors.mod_pocketDim.blocks; import java.util.Random; -import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.TileEntityDimDoor; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; -import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; - import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; @@ -25,517 +17,386 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.TileEntityDimDoor; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class dimDoor extends BlockContainer { - private static Icon blockIconBottom; + private static DDProperties properties = null; + private Icon blockIconBottom; + public dimDoor(int par1, Material material) { - super(par1, Material.iron); - // this.blockIndexInTexture = 18; + super(par1, material); if (properties == null) properties = DDProperties.instance(); } - - private static DDProperties properties = null; - public void registerIcons(IconRegister par1IconRegister) - { - this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); - this.blockIconBottom = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_bottom"); + { + this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); + this.blockIconBottom = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_bottom"); + } - } - - - //spawns the rift attatched to the block. Doesnt work in creative mode for some reason - //TODO make work in creative - public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) - { - if(!par1World.isRemote) - { - if(dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)!=null) - { - NewLinkData link= dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World); - par1World.setBlock(par2, par3, par4, properties.RiftBlockID); - - } - if(dimHelper.instance.getLinkDataFromCoords(par2, par3-1, par4, par1World)!=null) - { - NewLinkData link= dimHelper.instance.getLinkDataFromCoords(par2, par3-1, par4, par1World); - par1World.setBlock(par2, par3-1, par4, properties.RiftBlockID); - - } - if(dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World)!=null) - { - NewLinkData link= dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World); - par1World.setBlock(par2, par3+1, par4, properties.RiftBlockID); - - } - - } - - } + @Override + public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) + { + //TODO: Would it kill us to use REASONABLE variable names? <_< ~SenseiKiwi + int var12 = (int) (MathHelper.floor_double((double) ((entity.rotationYaw + 90) * 4.0F / 360.0F) + 0.5D) & 3); - //finds the rift data and teleports the player to it. - public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) - { - - if(!par1World.isRemote) - { - int var12 = (int) (MathHelper.floor_double((double)((par5Entity.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); - - int num=0; - NewLinkData linkData=null; - - if(par1World.getBlockId(par2, par3-1, par4)==this.blockID) - { - num=par1World.getBlockMetadata(par2, par3-1, par4); - linkData= dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World); - } - - if(par1World.getBlockId(par2, par3+1, par4)==this.blockID) - { - num=par1World.getBlockMetadata(par2, par3, par4); - linkData= dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World); - } - - if(!(par5Entity instanceof EntityPlayer)&&num>3) - { - this.onPoweredBlockChange(par1World, par2, par3, par4, false); - dimHelper.instance.traverseDimDoor(par1World, linkData, par5Entity); - } - - else if(!par1World.isRemote&&(num==5||num==4||num==6||num==7)&&(num-4)==var12) - { - - //int destinationID= dimHelper.instance.getDestIDFromCoords(par2, par3, par4, par1World); - - - this.onPoweredBlockChange(par1World, par2, par3, par4, false); - - dimHelper.instance.traverseDimDoor(par1World, linkData, par5Entity); + int orientation = world.getBlockMetadata(x, y - 1, z); + if (!world.isRemote && (orientation >= 4 && orientation <= 7) && (orientation - 4) == var12 && + world.getBlockId(x, y - 1, z) == this.blockID) + { + this.onPoweredBlockChange(world, x, y, z, false); - - - - - - - - - - - - } - } - } + IDimLink link = PocketManager.getLink(x, y, z, world.provider.dimensionId); + if (link != null) + { + PocketManager.traverseDimDoor(world, link, entity); + } + } + } public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) - { - - boolean shouldOpen=true; - - //System.out.println(String.valueOf(par1World.getBlockMetadata(par2, par3, par4))); + { + + boolean shouldOpen=true; + + //System.out.println(String.valueOf(par1World.getBlockMetadata(par2, par3, par4))); if(par5EntityPlayer.inventory.getCurrentItem()!=null) { if(par5EntityPlayer.inventory.getCurrentItem().getItem() == mod_pocketDim.itemRiftBlade) { - shouldOpen=false; - if(!par1World.isRemote&&par1World.getBlockId(par2, par3-1, par4)==this.blockID) + shouldOpen = false; + if (!par1World.isRemote && par1World.getBlockId(par2, par3-1, par4) == this.blockID) { int var12 = (int) (MathHelper.floor_double((double)((par5EntityPlayer.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); - - if(par1World.getBlockMetadata(par2, par3-1, par4)==var12) + + if (par1World.getBlockMetadata(par2, par3-1, par4) == var12) { - var12 = BlockRotator.transformMetadata(var12, 2, Block.doorWood.blockID); - } - par1World.setBlockMetadataWithNotify(par2, par3-1, par4, var12,2); - - if( dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)!=null) - { - dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World).linkOrientation= par1World.getBlockMetadata(par2, par3-1, par4); - + var12 = BlockRotator.transformMetadata(var12, 1, this.blockID); } + par1World.setBlockMetadataWithNotify(par2, par3-1, par4, var12, 2); } - if(!par1World.isRemote&&par1World.getBlockId(par2, par3+1, par4)==this.blockID) + if (!par1World.isRemote && par1World.getBlockId(par2, par3+1, par4) == this.blockID) { int var12 = (int) (MathHelper.floor_double((double)((par5EntityPlayer.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); if(par1World.getBlockMetadata(par2, par3, par4)==var12) { - var12 = BlockRotator.transformMetadata(var12, 2, Block.doorWood.blockID); + var12 = BlockRotator.transformMetadata(var12, 1, this.blockID); } - par1World.setBlockMetadataWithNotify(par2, par3, par4, var12,2); - - if( dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World)!=null) - { - dimHelper.instance.getLinkDataFromCoords(par2, par3+1, par4, par1World).linkOrientation= par1World.getBlockMetadata(par2, par3, par4); - } - + par1World.setBlockMetadataWithNotify(par2, par3, par4, var12, 2); } - par1World.playAuxSFXAtEntity(par5EntityPlayer, 1001, par2, par3, par4, 0); - - if(!shouldOpen&&!par1World.isRemote) - { - - par5EntityPlayer.inventory.getCurrentItem().damageItem(5, par5EntityPlayer); - - // par5EntityPlayer.sendChatToPlayer("You wedge the stick into a cranny in the door attempt to rotate the it"); - // par5EntityPlayer.sendChatToPlayer("The door rotates, but the stick breaks in half and is lost"); - } - - - - } - } - - if(shouldOpen) - { - - int var10 = this.getFullMetadata(par1World, par2, par3, par4); - int var11 = var10 & 7; - var11 ^= 4; - - if ((var10 & 8) == 0) - { - par1World.setBlockMetadataWithNotify(par2, par3, par4, var11,2); - par1World.markBlockRangeForRenderUpdate(par2, par3, par4, par2, par3, par4); - } - else - { - par1World.setBlockMetadataWithNotify(par2, par3 - 1, par4, var11,2); - par1World.markBlockRangeForRenderUpdate(par2, par3 - 1, par4, par2, par3, par4); - } - - par1World.playAuxSFXAtEntity(par5EntityPlayer, 1003, par2, par3, par4, 0); - if(dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)!=null) - { - // System.out.println("Link orient is- " +dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World).linkOrientation); - } - return true; - } - else - { - return false; - } - - } - - /** - * A function to open a door. - */ - public void onPoweredBlockChange(World par1World, int par2, int par3, int par4, boolean par5) - { - int var6 = this.getFullMetadata(par1World, par2, par3, par4); - boolean var7 = (var6 & 4) != 0; - - if (var7 != par5) - { - int var8 = var6 & 7; - var8 ^= 4; - - if ((var6 & 8) == 0) - { - par1World.setBlockMetadataWithNotify(par2, par3, par4, var8,2); - par1World.markBlockRangeForRenderUpdate(par2, par3, par4, par2, par3, par4); - } - else - { - par1World.setBlockMetadataWithNotify(par2, par3 - 1, par4, var8,2); - par1World.markBlockRangeForRenderUpdate(par2, par3 - 1, par4, par2, par3, par4); - } - - par1World.playAuxSFXAtEntity((EntityPlayer)null, 1003, par2, par3, par4, 0); - } - } -//TODO simplify this - @Override - public void onBlockAdded(World par1World, int par2, int par3, int par4) - { - if(!par1World.isRemote&&par1World.getBlockId(par2, par3-1, par4)==this.blockID) - { - - - if(dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)==null) - { - - - - NewLinkData link = new NewLinkData(par1World.provider.dimensionId, 0, par2, par3, par4, par2, par3, par4, true,par1World.getBlockMetadata(par2, par3-1, par4)); - dimHelper.instance.createPocket(link,true, false); - // System.out.println(link.linkOrientation); - - - - } - - - - if(dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World)!=null) - { - dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World).linkOrientation=par1World.getBlockMetadata(par2, par3-1, par4); - dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, par1World).hasGennedDoor=false; + par1World.playAuxSFXAtEntity(par5EntityPlayer, 1001, par2, par3, par4, 0); + if (!shouldOpen && !par1World.isRemote) + { + par5EntityPlayer.inventory.getCurrentItem().damageItem(5, par5EntityPlayer); + } } } - par1World.setBlockTileEntity(par2, par3, par4, this.createNewTileEntity(par1World)); - - } - - @SideOnly(Side.CLIENT) - - /** - * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side - */ - public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) - { - if(par1IBlockAccess.getBlockId(par2, par3-1, par4)==this.blockID) - { - return this.blockIcon; - } - else - { - return this.blockIconBottom; - } - } - - //Called to update the render information on the tile entity. Could probably implement a data watcher, but this works fine and is more versatile I think. - public dimDoor updateAttatchedTile(IBlockAccess par1World, int par2, int par3, int par4) - { - TileEntity tile = (TileEntity) par1World.getBlockTileEntity(par2, par3, par4); - if(tile instanceof TileEntityDimDoor ) + if(shouldOpen) { - TileEntityDimDoor dimTile=(TileEntityDimDoor)tile; - - if(par1World.getBlockId( par2, par3+1, par4 )==par1World.getBlockId( par2, par3, par4 )) + int var10 = this.getFullMetadata(par1World, par2, par3, par4); + int var11 = var10 & 7; + var11 ^= 4; + + if ((var10 & 8) == 0) { - //dimTile.openOrClosed=false; - } - if(dimHelper.instance.getLinkDataFromCoords(par2, par3, par4, (World)par1World)==null) - { - dimTile.openOrClosed=false; + par1World.setBlockMetadataWithNotify(par2, par3, par4, var11,2); + par1World.markBlockRangeForRenderUpdate(par2, par3, par4, par2, par3, par4); } else { - dimTile.openOrClosed=true; + par1World.setBlockMetadataWithNotify(par2, par3 - 1, par4, var11,2); + par1World.markBlockRangeForRenderUpdate(par2, par3 - 1, par4, par2, par3, par4); } - - int metaData = this.getFullMetadata(par1World, par2, par3, par4)%8; - dimTile.orientation=metaData; + + par1World.playAuxSFXAtEntity(par5EntityPlayer, 1003, par2, par3, par4, 0); + return true; + } + else + { + return false; + } + + } + + /** + * A function to open a door. + */ + public void onPoweredBlockChange(World par1World, int par2, int par3, int par4, boolean par5) + { + int var6 = this.getFullMetadata(par1World, par2, par3, par4); + boolean var7 = (var6 & 4) != 0; + + if (var7 != par5) + { + int var8 = var6 & 7; + var8 ^= 4; + + if ((var6 & 8) == 0) + { + par1World.setBlockMetadataWithNotify(par2, par3, par4, var8,2); + par1World.markBlockRangeForRenderUpdate(par2, par3, par4, par2, par3, par4); + } + else + { + par1World.setBlockMetadataWithNotify(par2, par3 - 1, par4, var8,2); + par1World.markBlockRangeForRenderUpdate(par2, par3 - 1, par4, par2, par3, par4); + } + + par1World.playAuxSFXAtEntity((EntityPlayer)null, 1003, par2, par3, par4, 0); } - return this; - } - /** - * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two - * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. - */ - public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) - { - - TileEntityDimDoor tile = (TileEntityDimDoor) par1World.getBlockTileEntity(par2, par3, par4); - tile.openOrClosed=this.isDoorOpen( par1World, par2, par3, par4); - int metaData = this.getFullMetadata(par1World, par2, par3, par4); - tile.orientation=metaData%8 ; - - + @Override + public void onBlockAdded(World world, int x, int y, int z) + { + //FIXME: We need to set door generation flags on the tile entities. Ignoring that for now. ~SenseiKiwi + + if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) + { + NewDimData dimension = PocketManager.getDimensionData(world); + IDimLink link = dimension.getLink(x, y, z); + if (link == null) + { + dimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_POCKET); + } + } + world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); + } - - - - } - public boolean isOpaqueCube() - { - return false; - } + @SideOnly(Side.CLIENT) - public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) - { - int var5 = this.getFullMetadata(par1IBlockAccess, par2, par3, par4); - return (var5 & 4) != 0; - } + /** + * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side + */ + public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) + { + if(par1IBlockAccess.getBlockId(par2, par3-1, par4) == this.blockID) + { + return this.blockIcon; + } + else + { + return blockIconBottom; + } + } - /** - * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) - */ - public boolean renderAsNormalBlock() - { - return false; - } + //Called to update the render information on the tile entity. Could probably implement a data watcher, + //but this works fine and is more versatile I think. + public dimDoor updateAttachedTile(World world, int x, int y, int z) + { + TileEntity tile = world.getBlockTileEntity(x, y, z); + if (tile instanceof TileEntityDimDoor ) + { + TileEntityDimDoor dimTile = (TileEntityDimDoor) tile; + dimTile.openOrClosed = PocketManager.getLink(x, y, z, world.provider.dimensionId) != null; + dimTile.orientation = this.getFullMetadata(world, x, y, z) & 7; + } + return this; + } - /** - * The type of render function that is called for this block - */ - public int getRenderType() - { - return 7; - } + /** + * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two + * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. + */ + public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) + { + TileEntityDimDoor tile = (TileEntityDimDoor) par1World.getBlockTileEntity(par2, par3, par4); + tile.openOrClosed = this.isDoorOpen( par1World, par2, par3, par4); + tile.orientation = this.getFullMetadata(par1World, par2, par3, par4) & 7; + } + + public boolean isOpaqueCube() + { + return false; + } - @SideOnly(Side.CLIENT) + public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) + { + int var5 = this.getFullMetadata(par1IBlockAccess, par2, par3, par4); + return (var5 & 4) != 0; + } - /** - * Returns the bounding box of the wired rectangular prism to render. - */ - public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) - { - this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); - return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4); - } + /** + * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) + */ + public boolean renderAsNormalBlock() + { + return false; + } - /** - * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been - * cleared to be reused) - */ - public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) - { - this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); - return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4); - } + /** + * The type of render function that is called for this block + */ + public int getRenderType() + { + return 7; + } - /** - * Updates the blocks bounds based on its current state. Args: world, x, y, z - */ - public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) - { - this.setDoorRotation(this.getFullMetadata(par1IBlockAccess, par2, par3, par4)); - } + @SideOnly(Side.CLIENT) - /** - * Returns 0, 1, 2 or 3 depending on where the hinge is. - */ - public int getDoorOrientation(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) - { - return this.getFullMetadata(par1IBlockAccess, par2, par3, par4) & 3; - } + /** + * Returns the bounding box of the wired rectangular prism to render. + */ + public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) + { + this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); + return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4); + } - public boolean isDoorOpen(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) - { - return (this.getFullMetadata(par1IBlockAccess, par2, par3, par4) & 4) != 0; - } + /** + * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been + * cleared to be reused) + */ + public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) + { + this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); + return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4); + } - private void setDoorRotation(int par1) - { - float var2 = 0.1875F; - this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F); - int var3 = par1 & 3; - boolean var4 = (par1 & 4) != 0; - boolean var5 = (par1 & 16) != 0; + /** + * Updates the blocks bounds based on its current state. Args: world, x, y, z + */ + public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) + { + this.setDoorRotation(this.getFullMetadata(par1IBlockAccess, par2, par3, par4)); + } - if (var3 == 0) - { - if (var4) - { - if (!var5) - { - this.setBlockBounds(0.001F, 0.0F, 0.0F, 1.0F, 1.0F, var2); - } - else - { - this.setBlockBounds(0.001F, 0.0F, 1.0F - var2, 1.0F, 1.0F, 1.0F); - } - } - else - { - this.setBlockBounds(0.0F, 0.0F, 0.0F, var2, 1.0F, 1.0F); - } - } - else if (var3 == 1) - { - if (var4) - { - if (!var5) - { - this.setBlockBounds(1.0F - var2, 0.0F, 0.001F, 1.0F, 1.0F, 1.0F); - } - else - { - this.setBlockBounds(0.0F, 0.0F, 0.001F, var2, 1.0F, 1.0F); - } - } - else - { - this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, var2); - } - } - else if (var3 == 2) - { - if (var4) - { - if (!var5) - { - this.setBlockBounds(0.0F, 0.0F, 1.0F - var2, .99F, 1.0F, 1.0F); - } - else - { - this.setBlockBounds(0.0F, 0.0F, 0.0F, .99F, 1.0F, var2); - } - } - else - { - this.setBlockBounds(1.0F - var2, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); - } - } - else if (var3 == 3) - { - if (var4) - { - if (!var5) - { - this.setBlockBounds(0.0F, 0.0F, 0.0F, var2, 1.0F, 0.99F); - } - else - { - this.setBlockBounds(1.0F - var2, 0.0F, 0.0F, 1.0F, 1.0F, 0.99F); - } - } - else - { - this.setBlockBounds(0.0F, 0.0F, 1.0F - var2, 1.0F, 1.0F, 1.0F); - } - } - } + /** + * Returns 0, 1, 2 or 3 depending on where the hinge is. + */ + public int getDoorOrientation(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) + { + return this.getFullMetadata(par1IBlockAccess, par2, par3, par4) & 3; + } - /** - * Called when the block is clicked by a player. Args: x, y, z, entityPlayer - */ - public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) - { - // System.out.println(this.getFullMetadata(par1World, par2, par3, par4)%4); - } + public boolean isDoorOpen(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) + { + return (this.getFullMetadata(par1IBlockAccess, par2, par3, par4) & 4) != 0; + } - /** - * Called upon block activation (right click on the block.) - */ - + private void setDoorRotation(int par1) + { + float var2 = 0.1875F; + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F); + int var3 = par1 & 3; + boolean var4 = (par1 & 4) != 0; + boolean var5 = (par1 & 16) != 0; - /** - * A function to open a door. - */ - - /** - * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are - * their own) Args: x, y, z, neighbor blockID - */ - public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) - { - int var6 = par1World.getBlockMetadata(par2, par3, par4); + if (var3 == 0) + { + if (var4) + { + if (!var5) + { + this.setBlockBounds(0.001F, 0.0F, 0.0F, 1.0F, 1.0F, var2); + } + else + { + this.setBlockBounds(0.001F, 0.0F, 1.0F - var2, 1.0F, 1.0F, 1.0F); + } + } + else + { + this.setBlockBounds(0.0F, 0.0F, 0.0F, var2, 1.0F, 1.0F); + } + } + else if (var3 == 1) + { + if (var4) + { + if (!var5) + { + this.setBlockBounds(1.0F - var2, 0.0F, 0.001F, 1.0F, 1.0F, 1.0F); + } + else + { + this.setBlockBounds(0.0F, 0.0F, 0.001F, var2, 1.0F, 1.0F); + } + } + else + { + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, var2); + } + } + else if (var3 == 2) + { + if (var4) + { + if (!var5) + { + this.setBlockBounds(0.0F, 0.0F, 1.0F - var2, .99F, 1.0F, 1.0F); + } + else + { + this.setBlockBounds(0.0F, 0.0F, 0.0F, .99F, 1.0F, var2); + } + } + else + { + this.setBlockBounds(1.0F - var2, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + } + else if (var3 == 3) + { + if (var4) + { + if (!var5) + { + this.setBlockBounds(0.0F, 0.0F, 0.0F, var2, 1.0F, 0.99F); + } + else + { + this.setBlockBounds(1.0F - var2, 0.0F, 0.0F, 1.0F, 1.0F, 0.99F); + } + } + else + { + this.setBlockBounds(0.0F, 0.0F, 1.0F - var2, 1.0F, 1.0F, 1.0F); + } + } + } - if ((var6 & 8) == 0) - { - boolean var7 = false; + /** + * Called when the block is clicked by a player. Args: x, y, z, entityPlayer + */ + public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) + { + // System.out.println(this.getFullMetadata(par1World, par2, par3, par4)%4); + } - if (par1World.getBlockId(par2, par3 + 1, par4) != this.blockID) - { - par1World.setBlock(par2, par3, par4, 0); - var7 = true; - } + /** + * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are + * their own) Args: x, y, z, neighbor blockID + */ + public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) + { + int var6 = par1World.getBlockMetadata(par2, par3, par4); - /** + if ((var6 & 8) == 0) + { + boolean var7 = false; + + if (par1World.getBlockId(par2, par3 + 1, par4) != this.blockID) + { + par1World.setBlock(par2, par3, par4, 0); + var7 = true; + } + + /** if (!par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4)) { par1World.setBlockWithNotify(par2, par3, par4, 0); @@ -546,129 +407,120 @@ public class dimDoor extends BlockContainer par1World.setBlockWithNotify(par2, par3 + 1, par4, 0); } } - **/ + **/ - if (var7) - { - if (!par1World.isRemote) - { - this.dropBlockAsItem(par1World, par2, par3, par4, properties.DimensionalDoorID, 0); - } - } - else - { - boolean var8 = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4) || par1World.isBlockIndirectlyGettingPowered(par2, par3 + 1, par4); + if (var7) + { + if (!par1World.isRemote) + { + this.dropBlockAsItem(par1World, par2, par3, par4, properties.DimensionalDoorID, 0); + } + } + else + { + boolean var8 = par1World.isBlockIndirectlyGettingPowered(par2, par3, par4) || par1World.isBlockIndirectlyGettingPowered(par2, par3 + 1, par4); - if ((var8 || par5 > 0 && Block.blocksList[par5].canProvidePower()) && par5 != this.blockID) - { - this.onPoweredBlockChange(par1World, par2, par3, par4, var8); - } - } - } - else - { - if (par1World.getBlockId(par2, par3 - 1, par4) != this.blockID) - { - par1World.setBlock(par2, par3, par4, 0); - } + if ((var8 || par5 > 0 && Block.blocksList[par5].canProvidePower()) && par5 != this.blockID) + { + this.onPoweredBlockChange(par1World, par2, par3, par4, var8); + } + } + } + else + { + if (par1World.getBlockId(par2, par3 - 1, par4) != this.blockID) + { + par1World.setBlock(par2, par3, par4, 0); + } - if (par5 > 0 && par5 != this.blockID) - { - this.onNeighborBlockChange(par1World, par2, par3 - 1, par4, par5); - } - } - } + if (par5 > 0 && par5 != this.blockID) + { + this.onNeighborBlockChange(par1World, par2, par3 - 1, par4, par5); + } + } + } - /** - * Returns the ID of the items to drop on destruction. - */ - + /** + * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world, + * x, y, z, startVec, endVec + */ + public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3) + { + this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); + return super.collisionRayTrace(par1World, par2, par3, par4, par5Vec3, par6Vec3); + } - /** - * Ray traces through the blocks collision from start vector to end vector returning a ray trace hit. Args: world, - * x, y, z, startVec, endVec - */ - public MovingObjectPosition collisionRayTrace(World par1World, int par2, int par3, int par4, Vec3 par5Vec3, Vec3 par6Vec3) - { - this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); - return super.collisionRayTrace(par1World, par2, par3, par4, par5Vec3, par6Vec3); - } + /** + * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z + */ + public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) + { + return par3 >= 255 ? false : par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) && super.canPlaceBlockAt(par1World, par2, par3, par4) && super.canPlaceBlockAt(par1World, par2, par3 + 1, par4); + } - /** - * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z - */ - public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) - { - return par3 >= 255 ? false : par1World.doesBlockHaveSolidTopSurface(par2, par3 - 1, par4) && super.canPlaceBlockAt(par1World, par2, par3, par4) && super.canPlaceBlockAt(par1World, par2, par3 + 1, par4); - } + /** + * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility + * and stop pistons + */ + public int getMobilityFlag() + { + return 2; + } - /** - * Returns the mobility information of the block, 0 = free, 1 = can't push but can move over, 2 = total immobility - * and stop pistons - */ - public int getMobilityFlag() - { - return 2; - } + /** + * Returns the full metadata value created by combining the metadata of both blocks the door takes up. + */ + public int getFullMetadata(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) + { + int var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4); + boolean var6 = (var5 & 8) != 0; + int var7; + int var8; - /** - * Returns the full metadata value created by combining the metadata of both blocks the door takes up. - */ - public int getFullMetadata(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) - { - int var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4); - boolean var6 = (var5 & 8) != 0; - int var7; - int var8; + if (var6) + { + var7 = par1IBlockAccess.getBlockMetadata(par2, par3 - 1, par4); + var8 = var5; + } + else + { + var7 = var5; + var8 = par1IBlockAccess.getBlockMetadata(par2, par3 + 1, par4); + } - if (var6) - { - var7 = par1IBlockAccess.getBlockMetadata(par2, par3 - 1, par4); - var8 = var5; - } - else - { - var7 = var5; - var8 = par1IBlockAccess.getBlockMetadata(par2, par3 + 1, par4); - } + boolean var9 = (var8 & 1) != 0; + return var7 & 7 | (var6 ? 8 : 0) | (var9 ? 16 : 0); + } - boolean var9 = (var8 & 1) != 0; - return var7 & 7 | (var6 ? 8 : 0) | (var9 ? 16 : 0); - } + @SideOnly(Side.CLIENT) + /** + * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) + */ + public int idPicked(World par1World, int par2, int par3, int par4) + { + return Item.doorIron.itemID; + } - @SideOnly(Side.CLIENT) + public int idDropped(int par1, Random par2Random, int par3) + { + return (par1 & 8) != 0 ? 0 : (Item.doorIron.itemID); + } - /** - * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) - */ - public int idPicked(World par1World, int par2, int par3, int par4) - { - return Item.doorIron.itemID; - } - - public int idDropped(int par1, Random par2Random, int par3) - { - return (par1 & 8) != 0 ? 0 : (Item.doorIron.itemID); - } + /** + * Called when the block is attempted to be harvested + */ + public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) + { + if (par6EntityPlayer.capabilities.isCreativeMode && (par5 & 8) != 0 && par1World.getBlockId(par2, par3 - 1, par4) == this.blockID) + { + par1World.setBlock(par2, par3 - 1, par4, 0); + } + } - /** - * Called when the block is attempted to be harvested - */ - public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) - { - if (par6EntityPlayer.capabilities.isCreativeMode && (par5 & 8) != 0 && par1World.getBlockId(par2, par3 - 1, par4) == this.blockID) - { - par1World.setBlock(par2, par3 - 1, par4, 0); - } - } - - - - public TileEntity createNewTileEntity(World par1World) - { - - TileEntity tile= new TileEntityDimDoor(); - - return tile; - } + @Override + public TileEntity createNewTileEntity(World world) + { + TileEntity tile = new TileEntityDimDoor(); + return tile; + } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/dimHatch.java b/StevenDimDoors/mod_pocketDim/blocks/dimHatch.java index a7ad487..c4b528b 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/dimHatch.java +++ b/StevenDimDoors/mod_pocketDim/blocks/dimHatch.java @@ -1,19 +1,13 @@ package StevenDimDoors.mod_pocketDim.blocks; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; -import StevenDimDoors.mod_pocketDim.world.PocketProvider; import net.minecraft.block.BlockTrapDoor; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.MathHelper; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.world.PocketProvider; public class dimHatch extends BlockTrapDoor { @@ -21,59 +15,55 @@ public class dimHatch extends BlockTrapDoor public dimHatch(int par1,int par2, Material par2Material) { super(par1, Material.iron); - this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - // this.setTextureFile("/PocketBlockTextures.png"); - // this.blockIndexInTexture = 16; + this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); + // this.setTextureFile("/PocketBlockTextures.png"); + // this.blockIndexInTexture = 16; } public void registerIcons(IconRegister par1IconRegister) - { - this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()); + { + this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()); + + } + + public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) + { - } - - public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) - { - - { - int var10 = par1World.getBlockMetadata(par2, par3, par4); - par1World.setBlockMetadataWithNotify(par2, par3, par4, var10 ^ 4,2); - par1World.playAuxSFXAtEntity(par5EntityPlayer, 1003, par2, par3, par4, 0); - return true; - } - } - //Teleports the player to the exit link of that dimension, assuming it is a pocket - public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) - { - - int num = par1World.getBlockMetadata(par2, par3, par4); - - if(!par1World.isRemote&&(num>3&&num<8||num>11)&&par1World.provider instanceof PocketProvider) { - - this.onPoweredBlockChange(par1World, par2, par3, par4, false); - - DimData dimData = (DimData) dimHelper.instance.dimList.get(par1World.provider.dimensionId); - - NewLinkData exitLink=dimData.exitDimLink; - exitLink.locDimID=par1World.provider.dimensionId; - - - dimHelper.instance.traverseDimDoor(par1World, exitLink, par5Entity); - - + int var10 = par1World.getBlockMetadata(par2, par3, par4); + par1World.setBlockMetadataWithNotify(par2, par3, par4, var10 ^ 4,2); + par1World.playAuxSFXAtEntity(par5EntityPlayer, 1003, par2, par3, par4, 0); + return true; } - } + } - public void onPoweredBlockChange(World par1World, int par2, int par3, int par4, boolean par5) - { - int var6 = par1World.getBlockMetadata(par2, par3, par4); - boolean var7 = (var6 & 4) > 0; + //Teleports the player to the exit link of that dimension, assuming it is a pocket + public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) + { + int num = par1World.getBlockMetadata(par2, par3, par4); - if (var7 != par5) - { - par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 ^ 4,2); - par1World.playAuxSFXAtEntity((EntityPlayer)null, 1003, par2, par3, par4, 0); - } - } + if (!par1World.isRemote&&(num>3&&num<8||num>11)&&par1World.provider instanceof PocketProvider) + { + this.onPoweredBlockChange(par1World, par2, par3, par4, false); + + /* FIXME: No point in fixing the following code when it's going to be rewritten later anyway. ~SenseiKiwi + + NewDimData newDimData = (NewDimData) dimHelper.PocketManager.dimList.get(par1World.provider.dimensionId); + ILinkData exitLink=newDimData.exitDimLink; + exitLink.locDimID=par1World.provider.dimensionId; + PocketManager.instance.traverseDimDoor(par1World, exitLink, par5Entity);*/ + } + } + + public void onPoweredBlockChange(World par1World, int par2, int par3, int par4, boolean par5) + { + int var6 = par1World.getBlockMetadata(par2, par3, par4); + boolean var7 = (var6 & 4) > 0; + + if (var7 != par5) + { + par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 ^ 4,2); + par1World.playAuxSFXAtEntity((EntityPlayer)null, 1003, par2, par3, par4, 0); + } + } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index f444170..8a055f8 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -1,14 +1,13 @@ package StevenDimDoors.mod_pocketDim.commands; -import java.io.File; import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.MathHelper; -import StevenDimDoors.mod_pocketDim.DungeonGenerator; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; public class CommandCreateDungeonRift extends DDCommandBase { @@ -56,16 +55,17 @@ public class CommandCreateDungeonRift extends DDCommandBase } else { - DungeonGenerator result; + IDimLink link; + DungeonData result; int x = MathHelper.floor_double(sender.posX); int y = MathHelper.floor_double(sender.posY); int z = MathHelper.floor_double (sender.posZ); - NewLinkData link = new NewLinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); if (command[0].equals("random")) { - dimHelper.instance.createLink(link); - link = dimHelper.instance.createPocket(link, true, true); + link = new NewLinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); + PocketManager.createLink(link); + link = PocketManager.createPocket(link, true, true); sender.sendChatToPlayer("Created a rift to a random dungeon (Dimension ID = " + link.destDimID + ")."); } else @@ -79,9 +79,10 @@ public class CommandCreateDungeonRift extends DDCommandBase if (result != null) { //Create a rift to our selected dungeon and notify the player - link = dimHelper.instance.createPocket(link, true, true); - dimHelper.instance.getDimData(link.destDimID).dungeonGenerator = result; - sender.sendChatToPlayer("Created a rift to \"" + getSchematicName(result) + "\" dungeon (Dimension ID = " + link.destDimID + ")."); + link = new NewLinkData(sender.worldObj.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); + link = PocketManager.instance.createPocket(link, true, true); + PocketManager.instance.getDimData(link.destDimID).dungeonGenerator = result; + sender.sendChatToPlayer("Created a rift to \"" + result.schematicName() + "\" dungeon (Dimension ID = " + link.destination.getDimensionID() + ")."); } else { @@ -93,20 +94,20 @@ public class CommandCreateDungeonRift extends DDCommandBase return DDCommandResult.SUCCESS; } - private DungeonGenerator findDungeonByPartialName(String query, Collection dungeons) + private DungeonData findDungeonByPartialName(String query, Collection dungeons) { //Search for the shortest dungeon name that contains the lowercase query string. String dungeonName; String normalQuery = query.toLowerCase(); - DungeonGenerator bestMatch = null; + DungeonData bestMatch = null; int matchLength = Integer.MAX_VALUE; - for (DungeonGenerator dungeon : dungeons) + 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 = getSchematicName(dungeon).toLowerCase(); + dungeonName = dungeon.schematicName().toLowerCase(); if (dungeonName.length() < matchLength && dungeonName.contains(normalQuery)) { matchLength = dungeonName.length(); @@ -115,14 +116,4 @@ public class CommandCreateDungeonRift extends DDCommandBase } return bestMatch; } - - private static String getSchematicName(DungeonGenerator dungeon) - { - //TODO: Move this to DungeonHelper and use it for all schematic name parsing. - //In the future, we really should include the schematic's name as part of DungeonGenerator - //to avoid redoing this work constantly. - File schematic = new File(dungeon.schematicPath); - String fileName = schematic.getName(); - return fileName.substring(0, fileName.length() - DungeonHelper.SCHEMATIC_FILE_EXTENSION.length()); - } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java b/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java index 7b685f3..6365d74 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java @@ -1,7 +1,6 @@ package StevenDimDoors.mod_pocketDim.commands; import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; public class CommandCreatePocket extends DDCommandBase @@ -39,10 +38,10 @@ public class CommandCreatePocket extends DDCommandBase int x = (int) sender.posX; int y = (int) sender.posY; int z = (int) sender.posZ; - NewLinkData link = DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); + DungeonHelper.instance().createCustomDungeonDoor(sender.worldObj, x, y, z); //Notify the player - sender.sendChatToPlayer("Created a door to a pocket dimension (Dimension ID = " + link.destDimID + "). Please build your dungeon there."); + sender.sendChatToPlayer("Created a door to a pocket dimension. Please build your dungeon there."); } return DDCommandResult.SUCCESS; } diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java index 1133cb1..55b307b 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteAllLinks.java @@ -4,9 +4,9 @@ import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.ILinkData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; public class CommandDeleteAllLinks extends DDCommandBase { @@ -39,7 +39,7 @@ public class CommandDeleteAllLinks extends DDCommandBase else if(command.length==1) { targetDim = parseInt(sender, command[0]); - if(!dimHelper.dimList.containsKey(targetDim)) + if (!PocketManager.dimList.containsKey(targetDim)) { sender.sendChatToPlayer("Error- dim "+targetDim+" not registered"); shouldGo=false; @@ -54,24 +54,24 @@ public class CommandDeleteAllLinks extends DDCommandBase if(shouldGo) { - if(dimHelper.dimList.containsKey(targetDim)) + if(PocketManager.dimList.containsKey(targetDim)) { - DimData dim = dimHelper.instance.getDimData(targetDim); - ArrayList linksInDim = dim.getLinksInDim(); + NewDimData dim = PocketManager.instance.getDimData(targetDim); + ArrayList linksInDim = dim.getLinksInDim(); - for (NewLinkData link : linksInDim) + for (ILinkData link : linksInDim) { - World targetWorld = dimHelper.getWorld(targetDim); + World targetWorld = PocketManager.getWorld(targetDim); if(targetWorld==null) { - dimHelper.initDimension(targetDim); + PocketManager.initDimension(targetDim); } else if(targetWorld.provider==null) { - dimHelper.initDimension(targetDim); + PocketManager.initDimension(targetDim); } - targetWorld = dimHelper.getWorld(targetDim); + targetWorld = PocketManager.getWorld(targetDim); dim.removeLinkAtCoords(link); targetWorld.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, 0); linksRemoved++; diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java index 75b6513..7d65435 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteDimensionData.java @@ -4,9 +4,9 @@ import java.util.ArrayList; import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.ILinkData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; public class CommandDeleteDimensionData extends DDCommandBase { @@ -39,7 +39,7 @@ public class CommandDeleteDimensionData extends DDCommandBase else if (command.length==1) { targetDim = parseInt(sender, command[0]); - if(!dimHelper.dimList.containsKey(targetDim)) + if(!PocketManager.dimList.containsKey(targetDim)) { sender.sendChatToPlayer("Error- dim "+targetDim+" not registered"); shouldGo=false; @@ -54,23 +54,23 @@ public class CommandDeleteDimensionData extends DDCommandBase if(shouldGo) { - if(dimHelper.dimList.containsKey(targetDim)) + if(PocketManager.dimList.containsKey(targetDim)) { try { - for(DimData dimData :dimHelper.dimList.values()) + for(NewDimData newDimData :PocketManager.dimList.values()) { - Collection links= new ArrayList(); - links.addAll( dimData.getLinksInDim()); + Collection links= new ArrayList(); + links.addAll( newDimData.getLinksInDim()); - for(NewLinkData link : links) + for(ILinkData link : links) { if(link.destDimID==targetDim) { - dimHelper.instance.getDimData(link.locDimID).removeLinkAtCoords(link); + PocketManager.instance.getDimData(link.locDimID).removeLinkAtCoords(link); linksRemoved++; } - if(dimData.dimID==targetDim) + if(newDimData.dimID==targetDim) { linksRemoved++; } @@ -82,7 +82,7 @@ public class CommandDeleteDimensionData extends DDCommandBase e.printStackTrace(); } - dimHelper.dimList.remove(targetDim); + PocketManager.dimList.remove(targetDim); sender.sendChatToPlayer("Removed dimension " + targetDim + " from DimDoors and deleted " + linksRemoved + " links"); } else diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java index d3c925d..529cf20 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandDeleteRifts.java @@ -4,10 +4,10 @@ import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.DimData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.ILinkData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; public class CommandDeleteRifts extends DDCommandBase { @@ -40,7 +40,7 @@ public class CommandDeleteRifts extends DDCommandBase else if(command.length==1) { targetDim = parseInt(sender, command[0]); - if(!dimHelper.dimList.containsKey(targetDim)) + if(!PocketManager.dimList.containsKey(targetDim)) { sender.sendChatToPlayer("Error- dim "+targetDim+" not registered"); shouldGo=false; @@ -55,24 +55,24 @@ public class CommandDeleteRifts extends DDCommandBase if(shouldGo) { - if(dimHelper.dimList.containsKey(targetDim)) + if(PocketManager.dimList.containsKey(targetDim)) { - DimData dim = dimHelper.instance.getDimData(targetDim); - ArrayList linksInDim = dim.getLinksInDim(); + NewDimData dim = PocketManager.instance.getDimData(targetDim); + ArrayList linksInDim = dim.getLinksInDim(); - for(NewLinkData link : linksInDim) + for(ILinkData link : linksInDim) { - World targetWorld = dimHelper.getWorld(targetDim); + World targetWorld = PocketManager.getWorld(targetDim); if(targetWorld==null) { - dimHelper.initDimension(targetDim); + PocketManager.initDimension(targetDim); } else if(targetWorld.provider==null) { - dimHelper.initDimension(targetDim); + PocketManager.initDimension(targetDim); } - targetWorld = dimHelper.getWorld(targetDim); + targetWorld = PocketManager.getWorld(targetDim); if (targetWorld.getBlockId(link.locXCoord, link.locYCoord, link.locZCoord) == mod_pocketDim.blockRift.blockID) { diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java b/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java index 14105d5..e4a99c6 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandPrintDimensionData.java @@ -3,9 +3,9 @@ package StevenDimDoors.mod_pocketDim.commands; import java.util.ArrayList; import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.ILinkData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; public class CommandPrintDimensionData extends DDCommandBase { @@ -28,7 +28,7 @@ public class CommandPrintDimensionData extends DDCommandBase protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { int targetDim; - DimData dimData; + NewDimData newDimData; if (command.length == 0) { @@ -50,17 +50,17 @@ public class CommandPrintDimensionData extends DDCommandBase return DDCommandResult.TOO_MANY_ARGUMENTS; } - dimData = dimHelper.instance.getDimData(targetDim); - if (dimData == null) + newDimData = PocketManager.instance.getDimData(targetDim); + if (newDimData == null) { return DDCommandResult.UNREGISTERED_DIMENSION; } - ArrayList links = dimData.getLinksInDim(); + ArrayList links = newDimData.getLinksInDim(); - sender.sendChatToPlayer("Dimension ID = " + dimData.dimID); - sender.sendChatToPlayer("Dimension Depth = " + dimData.depth); - for (NewLinkData link : links) + sender.sendChatToPlayer("Dimension ID = " + newDimData.dimID); + sender.sendChatToPlayer("Dimension Depth = " + newDimData.depth); + for (ILinkData link : links) { sender.sendChatToPlayer(link.printLinkData()); } diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java b/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java index 5145b9a..faee05f 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandPruneDimensions.java @@ -6,9 +6,9 @@ import java.util.HashSet; import java.util.Set; import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.ILinkData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; public class CommandPruneDimensions extends DDCommandBase { @@ -42,31 +42,31 @@ public class CommandPruneDimensions extends DDCommandBase int removedCount = 0; boolean deleteFolders = (command.length == 1); Set linkedDimensions = new HashSet(); - Collection allDims = new ArrayList(); - allDims.addAll(dimHelper.dimList.values()); + Collection allDims = new ArrayList(); + allDims.addAll(PocketManager.dimList.values()); - for (DimData data : allDims) + for (NewDimData data : allDims) { - for (NewLinkData link : data.getLinksInDim()) + for (ILinkData link : data.getLinksInDim()) { linkedDimensions.add(link.destDimID); } } - for (NewLinkData link : dimHelper.instance.interDimLinkList.values()) + for (ILinkData link : dimHelper.PocketManager.interDimLinkList.values()) { linkedDimensions.add(link.destDimID); } - for (DimData data : allDims) + for (NewDimData data : allDims) { if (!linkedDimensions.contains(data.dimID)) { - if (dimHelper.instance.pruneDimension(data, deleteFolders)) + if (PocketManager.instance.pruneDimension(data, deleteFolders)) { removedCount++; } } } - dimHelper.instance.save(); + PocketManager.instance.save(); sender.sendChatToPlayer("Removed " + removedCount + " unreachable pocket dims."); return DDCommandResult.SUCCESS; } diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java b/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java index 11c875a..73e808e 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandResetDungeons.java @@ -1,8 +1,8 @@ package StevenDimDoors.mod_pocketDim.commands; import net.minecraft.entity.player.EntityPlayer; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; public class CommandResetDungeons extends DDCommandBase { @@ -32,12 +32,12 @@ public class CommandResetDungeons extends DDCommandBase int dungeonCount = 0; int resetCount = 0; - for (DimData data : dimHelper.dimList.values()) + for (NewDimData data : PocketManager.dimList.values()) { if (data.isDimRandomRift) { dungeonCount++; - if (dimHelper.instance.resetPocket(data)) + if (PocketManager.instance.resetPocket(data)) { resetCount++; } diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java b/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java index 27c08f6..1892b22 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandTeleportPlayer.java @@ -6,7 +6,7 @@ import java.util.List; import cpw.mods.fml.common.FMLCommonHandler; import StevenDimDoors.mod_pocketDim.BlankTeleporter; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import net.minecraft.entity.player.EntityPlayer; @@ -39,7 +39,7 @@ public class CommandTeleportPlayer extends DDCommandBase @Override protected DDCommandResult processCommand(EntityPlayer sender, String[] command) { - List dimensionIDs = Arrays.asList(dimHelper.getStaticDimensionIDs()); //Gets list of all registered dimensions, regardless if loaded or not + List dimensionIDs = Arrays.asList(PocketManager.getStaticDimensionIDs()); //Gets list of all registered dimensions, regardless if loaded or not EntityPlayer targetPlayer = sender; int dimDestinationID = sender.worldObj.provider.dimensionId; @@ -66,12 +66,12 @@ public class CommandTeleportPlayer extends DDCommandBase { return DDCommandResult.INVALID_DIMENSION_ID; } - if(dimHelper.getWorld(dimDestinationID)==null) + if(PocketManager.getWorld(dimDestinationID)==null) { - dimHelper.initDimension(dimDestinationID); + PocketManager.initDimension(dimDestinationID); } - FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().transferPlayerToDimension((EntityPlayerMP) targetPlayer, dimDestinationID, new BlankTeleporter(dimHelper.getWorld(dimDestinationID))); + FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().transferPlayerToDimension((EntityPlayerMP) targetPlayer, dimDestinationID, new BlankTeleporter(PocketManager.getWorld(dimDestinationID))); targetPlayer.setPositionAndUpdate(Integer.parseInt(command[2]),Integer.parseInt(command[3]),Integer.parseInt(command[4])); } else diff --git a/StevenDimDoors/mod_pocketDim/core/IDimLink.java b/StevenDimDoors/mod_pocketDim/core/IDimLink.java new file mode 100644 index 0000000..34d2f9b --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/core/IDimLink.java @@ -0,0 +1,31 @@ +package StevenDimDoors.mod_pocketDim.core; + +import java.io.Serializable; + +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public interface IDimLink extends Serializable +{ + public final int TYPE_ENUM_MIN = 0; + public final int TYPE_ENUM_MAX = 8; + + public final int TYPE_NORMAL = 0; + public final int TYPE_LIMBO = 1; + public final int TYPE_POCKET = 2; + public final int TYPE_DUNGEON = 3; + public final int TYPE_RANDOM = 4; + public final int TYPE_DUNGEON_EXIT = 5; + public final int TYPE_SAFE_EXIT = 6; + public final int TYPE_UNSAFE_EXIT = 7; + public final int TYPE_RANDOM_DUNGEON = 8; + + public Point4D source(); + public Point4D destination(); + public boolean hasDestination(); + public Iterable children(); + public int childCount(); + public IDimLink parent(); + public int linkType(); + public IDimLink setDestination(int x, int y, int z, NewDimData dimension); + public IDimLink setLinkType(int linkType); +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/core/LinkTail.java b/StevenDimDoors/mod_pocketDim/core/LinkTail.java new file mode 100644 index 0000000..5513600 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/core/LinkTail.java @@ -0,0 +1,31 @@ +package StevenDimDoors.mod_pocketDim.core; + +import StevenDimDoors.mod_pocketDim.util.Point4D; + +class LinkTail +{ + private Point4D destination; + private int linkType; + + public LinkTail(int linkType, Point4D destination) + { + this.linkType = linkType; + this.destination = destination; + } + + public Point4D getDestination() { + return destination; + } + + public void setDestination(Point4D destination) { + this.destination = destination; + } + + public int getLinkType() { + return linkType; + } + + public void setLinkType(int linkType) { + this.linkType = linkType; + } +} diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java new file mode 100644 index 0000000..543ffba --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -0,0 +1,496 @@ +package StevenDimDoors.mod_pocketDim.core; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.TreeMap; + +import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public abstract class NewDimData implements Serializable +{ + private static class DimLink implements IDimLink + { + //DimLink is an inner class here to make it immutable to code outside NewDimData + + private static final long serialVersionUID = 1462177151401498444L; + private static final int EXPECTED_CHILDREN = 2; + + private Point4D source; + private DimLink parent; + private LinkTail tail; + private ArrayList children; + + public DimLink(Point4D source, DimLink parent) + { + this.parent = parent; + this.source = source; + this.tail = parent.tail; + this.children = new ArrayList(EXPECTED_CHILDREN); + parent.children.add(this); + } + + public DimLink(Point4D source) + { + this.parent = null; + this.source = source; + this.tail = new LinkTail(0, null); + this.children = new ArrayList(EXPECTED_CHILDREN); + } + + @Override + public Point4D source() + { + return source; + } + + @Override + public Point4D destination() + { + return tail.getDestination(); + } + + @Override + public boolean hasDestination() + { + return (tail.getDestination() != null); + } + + @Override + public IDimLink setDestination(int x, int y, int z, NewDimData dimension) + { + if (dimension == null) + { + throw new IllegalArgumentException("dimension cannot be null."); + } + + tail.setDestination(new Point4D(x, y, z, dimension.id())); + return this; + } + + @Override + public IDimLink setLinkType(int linkType) + { + if (linkType < IDimLink.TYPE_ENUM_MIN || linkType > IDimLink.TYPE_ENUM_MAX) + { + throw new IllegalArgumentException("The specified link type is invalid."); + } + + tail.setLinkType(linkType); + return this; + } + + @Override + public Iterable children() + { + return children; + } + + @Override + public int childCount() + { + return children.size(); + } + + @Override + public IDimLink parent() + { + return parent; + } + + @Override + public int linkType() + { + return tail.getLinkType(); + } + + public void clear() + { + //Release children + for (IDimLink child : children) + { + ((DimLink) child).parent = null; + } + children.clear(); + + //Release parent + if (parent != null) + { + parent.children.remove(this); + } + + parent = null; + source = null; + tail = new LinkTail(0, null); + } + + public void overwrite(DimLink nextParent) + { + if (this == nextParent) + { + //Ignore this request silently + return; + } + + //Release children + for (IDimLink child : children) + { + ((DimLink) child).parent = null; + } + children.clear(); + + //Release parent + if (parent != null) + { + parent.children.remove(this); + } + + //Attach to new parent + parent = nextParent; + if (parent != null) + { + tail = parent.tail; + parent.children.add(this); + } + else + { + tail = new LinkTail(0, null); + } + } + + @Override + public String toString() + { + return source + " -> " + (hasDestination() ? destination() : ""); + } + } + + private static final long serialVersionUID = 89361974746997260L; + private static Random random = new Random(); + + private final int id; + private final Map linkMapping; + private final List linkList; + private final boolean isDungeon; + private boolean isFilled; + private final int depth; + private int packDepth; + private final NewDimData parent; + private final NewDimData root; + private final List children; + private Point4D origin; + private int orientation; + private DungeonData dungeon; + + protected NewDimData(int id, NewDimData parent, boolean isPocket, boolean isDungeon) + { + //The isPocket flag is redundant. It's meant as an integrity safeguard. + if (isPocket == (parent != null)) + { + throw new NullPointerException("Dimensions can be pocket dimensions if and only if they have a parent dimension."); + } + if (isDungeon && !isPocket) + { + throw new IllegalArgumentException("A dimensional dungeon must also be a pocket dimension."); + } + + this.id = id; + this.linkMapping = new TreeMap(); //Should be stored in oct tree -- temporary solution + this.linkList = new ArrayList(); //Should be stored in oct tree -- temporary solution + this.children = new ArrayList(); + this.parent = parent; + this.root = (parent != null ? parent.root : this); + this.depth = (parent != null ? parent.depth + 1 : 0); + this.packDepth = 0; + this.isDungeon = isDungeon; + this.isFilled = false; + this.orientation = 0; + this.origin = null; + this.dungeon = null; + + //Register with parent + addChildDimension(this); + } + + private void addChildDimension(NewDimData child) + { + children.add(child); + } + + public IDimLink findNearestRift(World world, int range, int x, int y, int z) + { + //TODO: Rewrite this later to use an octtree, remove World parameter + + //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. + + IDimLink nearest = null; + IDimLink link; + + int distance; + int minDistance = Integer.MAX_VALUE; + 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 > 1 && distance < minDistance && world.getBlockId(x + i, y + j, z + k) == properties.RiftBlockID) + { + link = getLink(x+i, y+j, z+k); + if (link != null) + { + nearest = link; + minDistance = distance; + } + } + } + } + } + + return nearest; + } + + private static int getAbsoluteSum(int i, int j, int k) + { + return Math.abs(i) + Math.abs(j) + Math.abs(k); + } + + public IDimLink createLink(int x, int y, int z) + { + return createLink(new Point4D(x, y, z, id)); + } + + private IDimLink createLink(Point4D source) + { + //Return an existing link if there is one to avoid creating multiple links starting at the same point. + DimLink link = linkMapping.get(source); + if (link == null) + { + link = new DimLink(source); + linkMapping.put(source, link); + linkList.add(link); + } + else + { + link.overwrite(null); + } + return link; + } + + public IDimLink createChildLink(int x, int y, int z, IDimLink parent) + { + if (parent == null) + { + throw new IllegalArgumentException("parent cannot be null."); + } + + return createChildLink(new Point4D(x, y, z, id), (DimLink) parent); + } + + private IDimLink createChildLink(Point4D source, DimLink parent) + { + //To avoid having multiple links at a single point, if we find an existing link then we overwrite + //its destination data instead of creating a new instance. + + DimLink link = linkMapping.get(source); + if (link == null) + { + link = new DimLink(source, parent); + linkMapping.put(source, link); + linkList.add(link); + } + else + { + link.overwrite(parent); + } + + return link; + } + + public boolean deleteLink(IDimLink link) + { + if (link.source().getDimension() != id) + { + throw new IllegalArgumentException("Attempted to delete a link from another dimension."); + } + DimLink target = linkMapping.remove(link.source()); + if (target != null) + { + linkList.remove(target); + target.clear(); + } + return (target != null); + } + + public boolean deleteLink(int x, int y, int z) + { + Point4D location = new Point4D(x, y, z, id); + DimLink target = linkMapping.remove(location); + if (target != null) + { + linkList.remove(target); + target.clear(); + } + return (target != null); + } + + public IDimLink getLink(int x, int y, int z) + { + Point4D location = new Point4D(x, y, z, id); + return linkMapping.get(location); + } + + public IDimLink getLink(Point4D location) + { + if (location.getDimension() != id) + return null; + + return linkMapping.get(location); + } + + public ArrayList getAllLinks() + { + ArrayList results = new ArrayList(linkMapping.size()); + results.addAll(linkMapping.values()); + return results; + } + + public boolean isPocketDimension() + { + return (parent != null); + } + + public boolean isDungeon() + { + return isDungeon; + } + + public boolean isFilled() + { + return isFilled; + } + + public void setFilled(boolean isFilled) + { + this.isFilled = isFilled; + } + + public int id() + { + return id; + } + + public int depth() + { + return depth; + } + + public int packDepth() + { + return packDepth; + } + + public Point4D origin() + { + return origin; + } + + public NewDimData parent() + { + return parent; + } + + public NewDimData root() + { + return root; + } + + public int orientation() + { + return orientation; + } + + public DungeonData dungeon() + { + return dungeon; + } + + public boolean isInitialized() + { + return (origin != null); + } + + public int linkCount() + { + return linkMapping.size(); + } + + public Iterable children() + { + return children; + } + + public void initializeDungeon(int originX, int originY, int originZ, int orientation, IDimLink link, DungeonData dungeon) + { + if (!isDungeon) + { + throw new IllegalStateException("Cannot invoke initializeDungeon() on a non-dungeon dimension."); + } + if (isInitialized()) + { + throw new IllegalStateException("The dimension has already been initialized."); + } + + link.setDestination(originX, originY, originZ, this); + this.origin = link.destination(); + this.orientation = orientation; + this.dungeon = dungeon; + } + + public void initializePocket(int originX, int originY, int originZ, int orientation, IDimLink link) + { + if (!isPocketDimension()) + { + throw new IllegalStateException("Cannot invoke initializePocket() on a non-pocket dimension."); + } + if (isInitialized()) + { + throw new IllegalStateException("The dimension has already been initialized."); + } + + link.setDestination(originX, originY, originZ, this); + this.origin = link.destination(); + this.orientation = orientation; + } + + public IDimLink getRandomLink() + { + if (linkMapping.isEmpty()) + { + throw new IllegalStateException("There are no links to select from in this dimension."); + } + if (linkList.size() > 1) + { + return linkList.get(random.nextInt(linkList.size())); + } + else + { + return linkList.get(0); + } + } +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/core/NewLinkData.java b/StevenDimDoors/mod_pocketDim/core/NewLinkData.java deleted file mode 100644 index c2deee1..0000000 --- a/StevenDimDoors/mod_pocketDim/core/NewLinkData.java +++ /dev/null @@ -1,36 +0,0 @@ -package StevenDimDoors.mod_pocketDim.core; - -import java.io.Serializable; - -import StevenDimDoors.mod_pocketDim.util.Point4D; - -public class NewLinkData implements Serializable -{ - private static final long serialVersionUID = 1462177151401498444L; - - private Point4D source; - private Point4D destination; - - public NewLinkData(int srcX, int srcY, int srcZ, int srcDimension) - { - source = new Point4D(srcX, srcY, srcZ, srcDimension); - destination = null; - } - - public NewLinkData(int srcX, int srcY, int srcZ, int srcDimension, int dstX, int dstY, int dstZ, int dstDimension) - { - source = new Point4D(srcX, srcY, srcZ, srcDimension); - destination = new Point4D(dstX, dstY, dstZ, dstDimension); - } - - public NewLinkData(Point4D source, Point 4D destination) - { - - } - - @Override - public String toString() - { - return source + " -> " + destination; - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java new file mode 100644 index 0000000..e373107 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -0,0 +1,623 @@ +package StevenDimDoors.mod_pocketDim.core; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectOutputStream; +import java.util.HashMap; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.packet.Packet41EntityEffect; +import net.minecraft.network.packet.Packet43Experience; +import net.minecraft.network.packet.Packet9Respawn; +import net.minecraft.potion.PotionEffect; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.DimensionManager; +import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.DDTeleporter; +import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream; +import StevenDimDoors.mod_pocketDim.PacketHandler; +import StevenDimDoors.mod_pocketDim.TileEntityRift; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder; +import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; +import StevenDimDoors.mod_pocketDim.util.Point4D; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; + +/** + * This class regulates all the operations involving the storage and manipulation of dimensions. It handles saving dim data, teleporting the player, and + * creating/registering new dimensions as well as loading old dimensions on startup + */ +public class PocketManager +{ + private static class InnerDimData extends NewDimData + { + //This inner class allows us to instantiate NewDimData indirectly without exposing + //a public constructor from NewDimData. It's meant to stop us from constructing instances + //of NewDimData without using PocketManager's functions. In turn, that enforces that any + //link destinations must be real dimensions controlled by PocketManager. + + private static final long serialVersionUID = -3497038894870586232L; + + public InnerDimData(int id, NewDimData parent, boolean isPocket, boolean isDungeon) + { + super(id, parent, isPocket, isDungeon); + } + } + + private static int OVERWORLD_DIMENSION_ID = 0; + + private static boolean isInitialized = false; + private static boolean isSaving = false; + private static Random random = new Random(); + + //HashMap containing all the dims registered with DimDoors, sorted by dim ID. loaded on startup + private static HashMap dimensionData = new HashMap(); + + //HashMap for temporary storage of Link Signature damage hash values. See itemLinkSignature for more details + private static HashMap keyLinkMapping = new HashMap(); + + public static boolean isInitialized() + { + return isInitialized; + } + + public ILinkData createLink(ILinkData link) + { + DDProperties properties = DDProperties.instance(); + + if(!PocketManager.dimList.containsKey(link.locDimID)) + { + NewDimData locationDimData= new NewDimData(link.locDimID, false, 0, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); + PocketManager.dimList.put(link.locDimID, locationDimData); + link.isLocPocket=false; + } + if(!dimList.containsKey(link.destDimID)) + { + PocketManager.dimList.put(link.destDimID, new NewDimData(link.destDimID, false, 0, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord)); + } + NewDimData locationDimData= PocketManager.instance.getDimData(link.locDimID); + link.isLocPocket=locationDimData.isPocket; + locationDimData.addLinkToDim(link); + + World world = PocketManager.getWorld(link.locDimID); + if (world != null) + { + if (!mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord)) + { + world.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); + } + } + //Notifies other players that a link has been created. + //TODO: Couldn't we use the serverside/clientside annotations to achieve this instead? Seems safer. ~SenseiKiwi + if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER) + { + PacketHandler.onLinkCreatedPacket(link); + } + return link; + } + + /** + * properly deletes a link at the given coordinates. used by the rift remover. Also notifies clients of change. + * @param locationDimID + * @param locationXCoord + * @param locationYCoord + * @param locationZCoord + */ + public void removeLink( int locationDimID, int locationXCoord, int locationYCoord, int locationZCoord) + { + if(!PocketManager.dimList.containsKey(locationDimID)) + { + NewDimData locationDimData= new NewDimData(locationDimID, false, 0, locationDimID,locationXCoord,locationYCoord,locationZCoord); + PocketManager.dimList.put(locationDimID, locationDimData); + } + ILinkData link = this.getLinkDataFromCoords(locationXCoord, locationYCoord, locationZCoord, locationDimID); + PocketManager.instance.getDimData(locationDimID).removeLinkAtCoords(link); + //updates clients that a rift has been removed + if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER) + { + PacketHandler.onLinkRemovedPacket(link); + this.save(); + } + } + + /** + * generates a door based on what door was used to teleport. Only functions once per linking. + * @param world- door + * @param incLink + */ + public void generateDoor(World world, ILinkData incLink) + { + int locX = incLink.locXCoord; + int locY = incLink.locYCoord; + int locZ = incLink.locZCoord; + + int destX = incLink.destXCoord; + int destY = incLink.destYCoord; + int destZ = incLink.destZCoord; + + DDProperties properties = DDProperties.instance(); + + if(!incLink.hasGennedDoor) + { + int destinationID = incLink.destDimID; + + int id =world.getBlockId(locX, locY, locZ); + if(id==properties.WarpDoorID||id==properties.DimensionalDoorID||id==properties.TransientDoorID) + { + int doorTypeToPlace=id; + if(DimensionManager.getWorld(destinationID)==null) + { + DimensionManager.initDimension(destinationID); + } + ILinkData destLink = this.getLinkDataFromCoords(destX, destY, destZ, destinationID); + int destOrientation = 0; + if(destLink!=null) + { + destOrientation = destLink.linkOrientation; + destLink.hasGennedDoor=true; + } + int blockToReplace= DimensionManager.getWorld(destinationID).getBlockId(destX, destY, destZ); + if(blockToReplace!=properties.DimensionalDoorID&&blockToReplace!=properties.WarpDoorID&&blockToReplace != properties.TransientDoorID) + { + DimensionManager.getWorld(destinationID).setBlock(destX, destY-1, destZ, doorTypeToPlace,destOrientation,2); + DimensionManager.getWorld(destinationID).setBlock(destX, destY, destZ, doorTypeToPlace,8,2); + } + incLink.hasGennedDoor=true; + } + } + } + + /** + * 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() + { + if (isInitialized) + { + throw new IllegalStateException("Pocket dimensions have already been initialized!"); + } + + DDProperties properties = DDProperties.instance(); + + 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(); + } + } + } + } + + public boolean resetPocket(NewDimData dimension) + { + if (!dimension.isPocketDimension() || DimensionManager.getWorld(dimension.id()) != null) + { + return false; + } + + File save = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimension.id()); + DeleteFolder.deleteFolder(save); + dimension.setFilled(false); + //FIXME: Reset door information? + return true; + } + + public static boolean pruneDimension(NewDimData dimension, boolean deleteFolder) + { + //FIXME: Shouldn't the links in and out of this dimension be altered somehow? Otherwise we have links pointing + //into a deleted dimension! + + //Checks to see if the pocket is loaded or isn't actually a pocket. + if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null) + { + dimensionData.remove(dimension.id()); + //FIXME: I added the following line. Seems like a good idea. Is it? + DimensionManager.unregisterDimension(dimension.id()); + if (deleteFolder) + { + File save = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimension.id()); + DeleteFolder.deleteFolder(save); + } + return true; + } + else + { + return false; + } + } + + private static void unregisterDimensions() + { + for (NewDimData dimension : dimensionData.values()) + { + if (dimension.isPocketDimension()) + { + try + { + DimensionManager.unregisterDimension(dimension.id()); + } + catch (Exception e) + { + System.err.println("An unexpected error occurred while unregistering pocket dimension #" + dimension.id() + ":"); + e.printStackTrace(); + } + } + } + } + + /** + * Used to associate a damage value on a Rift Signature with a link pair. See LinkSignature for details. + * @return + */ + public static int createUniqueLinkKey() + { + int linkKey; + do + { + linkKey = random.nextInt(30000); + } + while (keyLinkMapping.containsKey(linkKey)); + return linkKey; + } + + /** + * Method used to create and register a new pocket dimension. Creates a reverse link if necessary. + * Populates the destination as well. + */ + private NewDimData createDestinationPocket(IDimLink link) + { + //First check the destination type + if (link.linkType() != IDimLink.TYPE_DUNGEON && link.linkType() != IDimLink.TYPE_POCKET) + { + throw new IllegalArgumentException("The link must lead to a dimensional dungeon or a pocket dimension."); + } + + DDProperties properties = DDProperties.instance(); + + //FIXME: This code had a check for whether dimension 0 was null. Why? Removed it for the time being. ~SenseiKiwi + + + if (PocketManager.getWorld(link.locDimID) == null) + { + PocketManager.initDimension(link.locDimID); + } + + int dimensionID; + int depth = this.getDimDepth(link.locDimID); + dimensionID = getNextFreeDimId(); + registerDimension(dimensionID, properties.PocketProviderID); + NewDimData locationDimData; + NewDimData destDimData; + + + + if(PocketManager.dimList.containsKey(link.locDimID)&&!DimensionManager.getWorld(link.locDimID).isRemote) //checks to see if dim is already registered. If not, it creates a DimData entry for it later + { + //randomizes exit if deep enough + locationDimData= dimList.get(DimensionManager.getWorld(link.locDimID).provider.dimensionId); + + if(depth>5) + { + if(depth>=12) + { + depth=11; + } + if(rand.nextInt(13-depth)==0) + { + ILinkData link1=getRandomLinkData(false); + } + } + if(locationDimData.isPocket) //determines the qualites of the pocket dim being created, based on parent dim. + { + if(isGoingDown) + { + destDimData= new NewDimData(dimensionID, true, locationDimData.depth+1, locationDimData.exitDimLink); + } + else + { + destDimData= new NewDimData(dimensionID, true, locationDimData.depth-1, locationDimData.exitDimLink); + } + } + else + { + destDimData= new NewDimData(dimensionID, true, 1, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); + } + + } + else + { + locationDimData= new NewDimData(link.locDimID, false, 0, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); + destDimData= new NewDimData(dimensionID, true, 1, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); + } + destDimData.isDimRandomRift=isRandomRift; + PocketManager.dimList.put(DimensionManager.getWorld(link.locDimID).provider.dimensionId, locationDimData); + PocketManager.dimList.put(dimensionID, destDimData); + + if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER)//sends packet to clients notifying them that a new dim has been created. + { + PacketHandler.onDimCreatedPacket(destDimData); + } + link = this.createLink(DimensionManager.getWorld(link.locDimID).provider.dimensionId,dimensionID,link.locXCoord,link.locYCoord,link.locZCoord, link.destXCoord,constrainPocketY(link.destYCoord),link.destZCoord,link.linkOrientation); //creates and registers the two rifts that link the parent and pocket dim. + this.createLink(dimensionID,DimensionManager.getWorld(link.locDimID).provider.dimensionId, link.destXCoord,constrainPocketY(link.destYCoord),link.destZCoord, link.locXCoord,link.locYCoord,link.locZCoord, BlockRotator.transformMetadata(link.linkOrientation, 2, Block.doorWood.blockID)); + return link; + } + + /** + * Function that saves all dim data in a hashMap. Calling too often can cause Concurrent modification exceptions, so be careful. + * @return + */ + public static void save() + { + //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 (isSaving) + { + return; + } + World world = DimensionManager.getWorld(OVERWORLD_DIMENSION_ID); + if (world == null || world.isRemote) + { + return; + } + if (DimensionManager.getCurrentSaveRootDirectory() != null) + { + isSaving = true; + HashMap comboSave = new HashMap(); + comboSave.put("dimensionData", dimensionData); + comboSave.put("keyLinkMapping", keyLinkMapping); + + FileOutputStream saveFile = null; + try + { + String saveFileName=DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataTEMP"; + saveFile = new FileOutputStream(saveFileName); + + ObjectOutputStream save = new ObjectOutputStream(saveFile); + save.writeObject(comboSave); + save.close(); + saveFile.close(); + + if (new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD").exists()) + { + new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD").delete(); + } + new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsData").renameTo(new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD")); + + new File(saveFileName).renameTo( new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsData")); + } + catch(Exception e) + { + e.printStackTrace(); + System.err.println("Could not save data-- SEVERE"); + } + isSaving = false; + } + } + + /** + * loads the dim data from the saved hashMap. Also handles compatibility with old saves, see OldSaveHandler + * @return + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static void load() + { + //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 + //be a function so that you can apply it to the save file first, then the "backup", instead of duplicating + //so much code. >_< + + boolean firstRun = false; + System.out.println("Loading DimDoors data"); + FileInputStream saveFile = null; + + if (!DimensionManager.getWorld(OVERWORLD_DIMENSION_ID).isRemote && DimensionManager.getCurrentSaveRootDirectory()!=null) + { + try + { + File dataStore = new File( DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsData"); + if (!dataStore.exists()) + { + if (!new File( DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD").exists()) + { + firstRun=true; + } + } + saveFile = new FileInputStream(dataStore); + ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); + HashMap comboSave = ((HashMap) save.readObject()); + + try + { + keyLinkMapping = (HashMap) comboSave.get("keyLinkMapping"); + } + catch (Exception e) + { + System.out.println("Could not load Link Signature list. Link Sig items will lose their stored locations."); + } + + try + { + dimensionData = (HashMap) comboSave.get("dimensionData"); + } + catch(Exception e) + { + System.out.println("Could not load pocket dimension list. Saves are probably lost, but repairable. Move the files from individual pocket dim files to active ones. See MC thread for details."); + } + + save.close(); + saveFile.close(); + } + catch (Exception e) + { + try + { + if (!firstRun) + { + System.out.println("Save data damaged, trying backup..."); + } + World world=FMLCommonHandler.instance().getMinecraftServerInstance().worldServers[0]; + File dataStore =new File( world.getSaveHandler().getMapFileFromName("idcounts").getParentFile().getParent()+"/DimensionalDoorsDataOLD"); + + + saveFile = new FileInputStream(dataStore); + ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); + HashMap comboSave =((HashMap)save.readObject()); + + try + { + keyLinkMapping = (HashMap) comboSave.get("keyLinkMapping"); + } + catch (Exception e2) + { + System.out.println("Could not load Link Signature list. Link Sig items will loose restored locations."); + } + + try + { + dimensionData = (HashMap) comboSave.get("dimensionData"); + } + catch (Exception e2) + { + System.out.println("Could not load pocket dim list. Saves probably lost, but repairable. Move the files from indivual pocket dim files to active ones. See MC thread for details."); + } + + save.close(); + saveFile.close(); + } + catch (Exception e2) + { + if (!firstRun) + { + System.err.println("Could not read data-- SEVERE"); + e2.printStackTrace(); + } + } + } + } + } + + public static boolean removeRift(World world, int x, int y, int z, int range, EntityPlayer player, ItemStack item) + { + //Function called by rift tile entities and the rift remover to find and spread between rifts. + //Does not actually unregister the rift data, see deleteRift for that. + + NewDimData dimension = getDimensionData(world); + IDimLink nearest = dimension.findNearestRift(world, range, x, y, z); + + if (nearest != null) + { + Point4D location = nearest.source(); + TileEntity tileEntity = world.getBlockTileEntity(location.getX(), location.getY(), location.getZ()); + if (tileEntity != null) + { + TileEntityRift riftEntity = (TileEntityRift) tileEntity; + riftEntity.shouldClose = true; + item.damageItem(1, player); + return true; + } + } + return false; + } + + public static NewDimData registerDimension(World world) + { + return registerDimension(world.provider.dimensionId, null, false, false); + } + + public static NewDimData registerPocket(NewDimData parent, boolean isDungeon) + { + if (parent == null) + { + throw new IllegalArgumentException("parent cannot be null. A pocket dimension must always have a parent dimension."); + } + + DDProperties properties = DDProperties.instance(); + int dimensionID = DimensionManager.getNextFreeDimId(); + DimensionManager.registerDimension(dimensionID, properties.PocketProviderID); + return registerDimension(dimensionID, parent, true, isDungeon); + } + + private static NewDimData registerDimension(int dimensionID, NewDimData parent, boolean isPocket, boolean isDungeon) + { + if (dimensionData.containsKey(dimensionID)) + { + throw new IllegalArgumentException("Cannot register a dimension with ID = " + dimensionID + " because it has already been registered."); + } + + NewDimData dimension = new InnerDimData(dimensionID, parent, isPocket, isDungeon); + dimensionData.put(dimensionID, dimension); + return dimension; + } + + public static NewDimData getDimensionData(World world) + { + return getDimensionData(world.provider.dimensionId); + } + + public static NewDimData getDimensionData(int dimensionID) + { + //Retrieve the data for a dimension. If we don't have a record for that dimension, + //assume it's a non-pocket dimension that hasn't been initialized with us before + //and create a NewDimData instance for it. + //Any pocket dimension must be listed with PocketManager to have a dimension ID + //assigned, so it's safe to assume that any unknown dimensions don't belong to us. + + NewDimData dimension = PocketManager.dimensionData.get(dimensionID); + if (dimension == null) + { + dimension = registerDimension(dimensionID, null, false, false); + } + return dimension; + } + + public static void unload() + { + save(); + unregisterDimensions(); + dimensionData.clear(); + keyLinkMapping.clear(); + } + + public static Iterable getDimensions() + { + return dimensionData.values(); + } + + public static IDimLink getLink(int x, int y, int z, int dimensionID) + { + NewDimData dimension = dimensionData.get(dimensionID); + if (dimension != null) + { + return dimension.getLink(x, y, z); + } + else + { + return null; + } + } +} diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java new file mode 100644 index 0000000..6d57e7d --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java @@ -0,0 +1,76 @@ +package StevenDimDoors.mod_pocketDim.dungeon; + +import java.io.FileNotFoundException; +import java.io.Serializable; + +import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType; +import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; +import StevenDimDoors.mod_pocketDim.schematic.InvalidSchematicException; + +public class DungeonData implements Serializable +{ + private static final long serialVersionUID = -5624866366474710161L; + + private final int weight; + private final boolean isOpen; + private final boolean isInternal; + private final String schematicPath; + private final String schematicName; + private final DungeonType dungeonType; + + public DungeonData(String schematicPath, boolean isInternal, DungeonType dungeonType, boolean isOpen, int weight) + { + this.schematicPath = schematicPath; + this.schematicName = getSchematicName(schematicPath); + this.dungeonType = dungeonType; + this.isInternal = isInternal; + this.isOpen = isOpen; + this.weight = weight; + } + + private static String getSchematicName(String schematicPath) + { + int indexA = schematicPath.lastIndexOf('\\'); + int indexB = schematicPath.lastIndexOf('/'); + indexA = Math.max(indexA, indexB) + 1; + + return schematicPath.substring(indexA, schematicPath.length() - DungeonHelper.SCHEMATIC_FILE_EXTENSION.length() - indexA); + } + + public int weight() + { + return weight; + } + + public boolean isOpen() + { + return isOpen; + } + + public String schematicPath() + { + return schematicPath; + } + + public DungeonType dungeonType() + { + return dungeonType; + } + + public String schematicName() + { + return schematicName; + } + + public DungeonSchematic loadSchematic() throws InvalidSchematicException, FileNotFoundException + { + if (isInternal) + { + return DungeonSchematic.readFromResource(schematicPath); + } + else + { + return DungeonSchematic.readFromFile(schematicPath); + } + } +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index 60b0073..4c0eb59 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -19,7 +19,7 @@ import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.Point3D; import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.schematic.CompoundFilter; @@ -295,7 +295,7 @@ public class DungeonSchematic extends Schematic { //Set the orientation of the rift exit Point3D entranceRiftLocation = entrance.clone(); BlockRotator.transformPoint(entranceRiftLocation, entrance, rotation, pocketCenter); - NewLinkData sideLink = dimHelper.instance.getLinkDataFromCoords( + NewLinkData sideLink = PocketManager.instance.getLinkDataFromCoords( entranceRiftLocation.getX(), entranceRiftLocation.getY(), entranceRiftLocation.getZ(), @@ -319,9 +319,9 @@ public class DungeonSchematic extends Schematic { int blockDirection = world.getBlockMetadata(location.getX(), location.getY() - 1, location.getZ()); Point3D linkDestination = location.clone(); - NewLinkData randomLink = dimHelper.instance.getRandomLinkData(false); + NewLinkData randomLink = PocketManager.instance.getRandomLinkData(false); NewLinkData sideLink = new NewLinkData(destDimID, - dimHelper.instance.getDimData(originDimID).exitDimLink.destDimID, + PocketManager.instance.getDimData(originDimID).exitDimLink.destDimID, location.getX(), location.getY(), location.getZ(), @@ -346,7 +346,7 @@ public class DungeonSchematic extends Schematic { } sideLink.linkOrientation = world.getBlockMetadata(linkDestination.getX(), linkDestination.getY() - 1, linkDestination.getZ()); - dimHelper.instance.createLink(sideLink); + PocketManager.instance.createLink(sideLink); /**dimHelper.instance.createLink(sideLink.destDimID , sideLink.locDimID, sideLink.destXCoord, @@ -377,7 +377,7 @@ public class DungeonSchematic extends Schematic { private static void setUpDimensionalDoorLink(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter, int originDimID, int destDimID, boolean applyNoise, Random random) { - int depth = dimHelper.instance.getDimDepth(originDimID) + 1; + int depth = PocketManager.instance.getDimDepth(originDimID) + 1; int forwardNoise; int sidewaysNoise; @@ -413,7 +413,7 @@ public class DungeonSchematic extends Schematic { linkDestination.getY() + 1, linkDestination.getZ(), true, blockDirection); - dimHelper.instance.createPocket(sideLink, true, true); + PocketManager.instance.createPocket(sideLink, true, true); } private static void spawnMonolith(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) diff --git a/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java b/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java index c2388bb..61f182c 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java @@ -7,10 +7,9 @@ import java.util.HashSet; import java.util.Random; import net.minecraft.util.WeightedRandom; -import StevenDimDoors.mod_pocketDim.DungeonGenerator; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.util.WeightedContainer; public class DungeonPack @@ -21,12 +20,12 @@ public class DungeonPack //The ID numbers would be a problem since it couldn't have a valid number, since it wasn't initialized by the pack instance. //FIXME: Do not release this code as an update without dealing with disowned types! - private static final int MAX_HISTORY_LENGTH = 1337; + private static final int MAX_HISTORY_LENGTH = 30; private final String name; private final HashMap nameToTypeMapping; - private final ArrayList> groupedDungeons; - private final ArrayList allDungeons; + private final ArrayList> groupedDungeons; + private final ArrayList allDungeons; private final DungeonPackConfig config; private final int maxRuleLength; private final ArrayList rules; @@ -40,9 +39,9 @@ public class DungeonPack int index; int maxLength = 0; int typeCount = config.getTypeNames().size(); - this.allDungeons = new ArrayList(); + this.allDungeons = new ArrayList(); this.nameToTypeMapping = new HashMap(typeCount); - this.groupedDungeons = new ArrayList>(typeCount); + this.groupedDungeons = new ArrayList>(typeCount); this.groupedDungeons.add(allDungeons); //Make sure the list of all dungeons is placed at index 0 this.nameToTypeMapping.put(DungeonType.WILDCARD_TYPE.Name, DungeonType.WILDCARD_TYPE); @@ -52,7 +51,7 @@ public class DungeonPack { String standardName = typeName.toUpperCase(); this.nameToTypeMapping.put(standardName, new DungeonType(this, standardName, index)); - this.groupedDungeons.add(new ArrayList()); + this.groupedDungeons.add(new ArrayList()); index++; } @@ -108,14 +107,14 @@ public class DungeonPack return (this.getType(typeName) != null); } - public void addDungeon(DungeonGenerator generator) + public void addDungeon(DungeonData dungeon) { //Make sure this dungeon really belongs in this pack - DungeonType type = generator.getDungeonType(); + DungeonType type = dungeon.dungeonType(); if (type.Owner == this) { - allDungeons.add(generator); - groupedDungeons.get(type.ID).add(generator); + allDungeons.add(dungeon); + groupedDungeons.get(type.ID).add(dungeon); } else { @@ -123,7 +122,7 @@ public class DungeonPack } } - public DungeonGenerator getNextDungeon(NewLinkData inbound, Random random) + public DungeonData getNextDungeon(NewDimData dimension, Random random) { if (allDungeons.isEmpty()) { @@ -136,27 +135,26 @@ public class DungeonPack //for dungeon packs that can extend arbitrarily deep. We should probably set a reasonable limit anyway. int maxSearchLength = config.allowDuplicatesInChain() ? maxRuleLength : MAX_HISTORY_LENGTH; - ArrayList history = DungeonHelper.getDungeonChainHistory( - dimHelper.instance.getDimData(inbound.locDimID), this, maxSearchLength); + ArrayList history = DungeonHelper.getDungeonChainHistory(dimension.parent(), this, maxSearchLength); return getNextDungeon(history, random); } - private DungeonGenerator getNextDungeon(ArrayList history, Random random) + private DungeonData getNextDungeon(ArrayList history, Random random) { //Extract the dungeon types that have been used from history and convert them into an array of IDs int index; int[] typeHistory = new int[history.size()]; - HashSet excludedDungeons = null; + HashSet excludedDungeons = null; for (index = 0; index < typeHistory.length; index++) { - typeHistory[index] = history.get(index).getDungeonType().ID; + typeHistory[index] = history.get(index).dungeonType().ID; } for (DungeonChainRule rule : rules) { if (rule.evaluate(typeHistory)) { - //Pick a random dungeon type to be generated next based on the rule's products + //Pick a random dungeon type to be generated next based on the rule's products ArrayList> products = rule.products(); DungeonType nextType; do @@ -167,16 +165,16 @@ public class DungeonPack //Initialize the set of excluded dungeons if needed if (excludedDungeons == null && !config.allowDuplicatesInChain()) { - excludedDungeons = new HashSet(history); + excludedDungeons = new HashSet(history); } //List which dungeons are allowed - ArrayList candidates; - ArrayList group = groupedDungeons.get(nextType.ID); + ArrayList candidates; + ArrayList group = groupedDungeons.get(nextType.ID); if (excludedDungeons != null && !excludedDungeons.isEmpty()) { - candidates = new ArrayList(group.size()); - for (DungeonGenerator dungeon : group) + candidates = new ArrayList(group.size()); + for (DungeonData dungeon : group) { if (!excludedDungeons.contains(dungeon)) { @@ -204,7 +202,7 @@ public class DungeonPack return getRandomDungeon(random); } - public DungeonGenerator getRandomDungeon(Random random) + public DungeonData getRandomDungeon(Random random) { if (!allDungeons.isEmpty()) { @@ -217,7 +215,7 @@ public class DungeonPack } private static DungeonType getRandomDungeonType(Random random, Collection> types, - ArrayList> groupedDungeons) + ArrayList> groupedDungeons) { //TODO: Make this faster? This algorithm runs in quadratic time in the worst case because of the random-selection //process and the removal search. Might be okay for normal use, though. ~SenseiKiwi @@ -248,18 +246,18 @@ public class DungeonPack return null; } - private static DungeonGenerator getRandomDungeon(Random random, Collection dungeons) + private static DungeonData getRandomDungeon(Random random, Collection dungeons) { //Use Minecraft's WeightedRandom to select our dungeon. =D - ArrayList> weights = - new ArrayList>(dungeons.size()); - for (DungeonGenerator dungeon : dungeons) + ArrayList> weights = + new ArrayList>(dungeons.size()); + for (DungeonData dungeon : dungeons) { - weights.add(new WeightedContainer(dungeon, dungeon.weight)); + weights.add(new WeightedContainer(dungeon, dungeon.weight())); } @SuppressWarnings("unchecked") - WeightedContainer resultContainer = (WeightedContainer) WeightedRandom.getRandomItem(random, weights); + WeightedContainer resultContainer = (WeightedContainer) WeightedRandom.getRandomItem(random, weights); return (resultContainer != null) ? resultContainer.getData() : null; } } diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index fa44b8f..ba65103 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -20,10 +20,11 @@ import java.util.regex.Pattern; import net.minecraft.util.WeightedRandom; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.DungeonGenerator; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; @@ -62,8 +63,6 @@ public class DungeonHelper public static final String SCHEMATIC_FILE_EXTENSION = ".schematic"; - private static final String DEFAULT_UP_SCHEMATIC_PATH = "/schematics/core/simpleStairsUp.schematic"; - private static final String DEFAULT_DOWN_SCHEMATIC_PATH = "/schematics/core/simpleStairsDown.schematic"; private static final String DEFAULT_ERROR_SCHEMATIC_PATH = "/schematics/core/somethingBroke.schematic"; private static final String DUNGEON_CREATION_GUIDE_SOURCE_PATH = "/mods/DimDoors/text/How_to_add_dungeons.txt"; private static final String RUINS_PACK_PATH = "/schematics/ruins"; @@ -86,16 +85,14 @@ public class DungeonHelper public static final short MAX_DUNGEON_HEIGHT = MAX_DUNGEON_WIDTH; public static final short MAX_DUNGEON_LENGTH = MAX_DUNGEON_WIDTH; - private ArrayList untaggedDungeons = new ArrayList(); - private ArrayList registeredDungeons = new ArrayList(); + private ArrayList untaggedDungeons = new ArrayList(); + private ArrayList registeredDungeons = new ArrayList(); private DungeonPack RuinsPack; private HashMap dungeonPackMapping = new HashMap(); private ArrayList dungeonPackList = new ArrayList(); - private DungeonGenerator defaultUp; - private DungeonGenerator defaultDown; - private DungeonGenerator defaultError; + private DungeonData defaultError; private DungeonHelper() { @@ -227,47 +224,34 @@ public class DungeonHelper } } - public List getRegisteredDungeons() + public List getRegisteredDungeons() { return Collections.unmodifiableList(this.registeredDungeons); } - public List getUntaggedDungeons() + public List getUntaggedDungeons() { return Collections.unmodifiableList(this.untaggedDungeons); } - public DungeonGenerator getDefaultErrorDungeon() + public DungeonData getDefaultErrorDungeon() { return defaultError; } - public DungeonGenerator getDefaultUpDungeon() - { - return defaultUp; - } - - public DungeonGenerator getDefaultDownDungeon() - { - return defaultDown; - } - public DungeonPack getDungeonPack(String name) { //TODO: This function might be obsolete after the new save format is implemented. return dungeonPackMapping.get(name.toUpperCase()); } - public DungeonPack getDimDungeonPack(int dimensionID) + private DungeonPack getDimDungeonPack(NewDimData data) { - //FIXME: This function is a workaround to our current dungeon data limitations. Modify later. - //The upcoming save format change and code overhaul will make this obsolete. - DungeonPack pack; - DungeonGenerator generator = dimHelper.dimList.get(dimensionID).dungeonGenerator; - if (generator != null) + DungeonData dungeon = data.dungeon(); + if (dungeon != null) { - pack = generator.getDungeonType().Owner; + pack = dungeon.dungeonType().Owner; //Make sure the pack isn't null. This can happen for dungeons with the special UNKNOWN type. if (pack == null) @@ -277,7 +261,7 @@ public class DungeonHelper } else { - if (dimensionID == NETHER_DIMENSION_ID) + if (data.id() == NETHER_DIMENSION_ID) { //TODO: Change this to the nether-side pack later ^_^ pack = RuinsPack; @@ -290,11 +274,11 @@ public class DungeonHelper return pack; } - public NewLinkData createCustomDungeonDoor(World world, int x, int y, int z) + public IDimLink createCustomDungeonDoor(World world, int x, int y, int z) { //Create a link above the specified position. Link to a new pocket dimension. - NewLinkData link = new NewLinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 3); - link = dimHelper.instance.createPocket(link, true, false); + NewDimData dimension = PocketManager.getDimensionData(world); + IDimLink link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); //Place a Warp Door linked to that pocket itemDimDoor.placeDoorBlock(world, x, y, z, 3, mod_pocketDim.ExitDoor); @@ -304,7 +288,6 @@ public class DungeonHelper public boolean validateDungeonType(String type, DungeonPack pack) { - //Check if the dungeon type is valid return pack.isKnownType(type); } @@ -370,10 +353,10 @@ public class DungeonHelper int weight = (dungeonData.length == 4) ? Integer.parseInt(dungeonData[3]) : DEFAULT_DUNGEON_WEIGHT; //Add this custom dungeon to the list corresponding to its type - DungeonGenerator generator = new DungeonGenerator(weight, path, isOpen, dungeonType); + DungeonData dungeon = new DungeonData(path, isInternal, dungeonType, isOpen, weight); - pack.addDungeon(generator); - registeredDungeons.add(generator); + pack.addDungeon(dungeon); + registeredDungeons.add(dungeon); if (verbose) { System.out.println("Registered dungeon: " + name); @@ -385,7 +368,7 @@ public class DungeonHelper { System.out.println("The following dungeon name is invalid for its given pack. It will not be generated naturally: " + schematicPath); } - untaggedDungeons.add(new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, path, true, DungeonType.UNKNOWN_TYPE)); + untaggedDungeons.add(new DungeonData(path, isInternal, DungeonType.UNKNOWN_TYPE, true, DEFAULT_DUNGEON_WEIGHT)); System.out.println("Registered untagged dungeon: " + name); } } @@ -462,9 +445,7 @@ public class DungeonHelper { //Register the core schematics //These are used for debugging and in case of unusual errors while loading dungeons - defaultUp = new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, DEFAULT_UP_SCHEMATIC_PATH, true, DungeonType.UNKNOWN_TYPE); - defaultDown = new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, DEFAULT_DOWN_SCHEMATIC_PATH, true, DungeonType.UNKNOWN_TYPE); - defaultError = new DungeonGenerator(DEFAULT_DUNGEON_WEIGHT, DEFAULT_ERROR_SCHEMATIC_PATH, true, DungeonType.UNKNOWN_TYPE); + defaultError = new DungeonData(DEFAULT_ERROR_SCHEMATIC_PATH, true, DungeonType.UNKNOWN_TYPE, true, DEFAULT_DUNGEON_WEIGHT); //Open the list of dungeons packaged with our mod and register their schematics registerBundledPack(BUNDLED_RUINS_LIST_PATH, RUINS_PACK_PATH, "Ruins", reader); @@ -530,9 +511,10 @@ public class DungeonHelper } } - public void generateDungeonLink(NewLinkData inbound, DungeonPack pack, Random random) + public DungeonData selectDungeon(NewDimData dimension, Random random) { - DungeonGenerator selection; + DungeonPack pack = getDimDungeonPack(dimension); + DungeonData selection; DungeonPackConfig config; DungeonPack selectedPack; @@ -546,13 +528,13 @@ public class DungeonHelper { //Calculate the chance of switching to a different pack type int packSwitchChance; - if (dimHelper.dimList.get(inbound.locDimID).depth == 0) + if (dimension.depth() == 1) { packSwitchChance = START_PACK_SWITCH_CHANCE; } else { - packSwitchChance = MIN_PACK_SWITCH_CHANCE + (getPackDepth(inbound, pack) - 1) * PACK_SWITCH_CHANCE_PER_LEVEL; + packSwitchChance = MIN_PACK_SWITCH_CHANCE + dimension.parent().packDepth() * PACK_SWITCH_CHANCE_PER_LEVEL; } //Decide randomly whether to switch packs or not @@ -564,7 +546,7 @@ public class DungeonHelper } //Pick the next dungeon - selection = selectedPack.getNextDungeon(inbound, random); + selection = selectedPack.getNextDungeon(dimension, random); } catch (Exception e) { @@ -580,7 +562,7 @@ public class DungeonHelper selection = defaultError; } } - dimHelper.instance.getDimData(inbound.destDimID).dungeonGenerator = selection; + return selection; } @SuppressWarnings("unchecked") @@ -621,16 +603,16 @@ public class DungeonHelper return sortedNames; } - private static ArrayList parseDungeonNames(ArrayList dungeons) + private static ArrayList parseDungeonNames(ArrayList dungeons) { String name; File schematic; ArrayList names = new ArrayList(dungeons.size()); - for (DungeonGenerator dungeon : dungeons) + for (DungeonData dungeon : dungeons) { //Retrieve the file name and strip off the file extension - schematic = new File(dungeon.schematicPath); + schematic = new File(dungeon.schematicPath()); name = schematic.getName(); name = name.substring(0, name.length() - SCHEMATIC_FILE_EXTENSION.length()); names.add(name); @@ -638,102 +620,48 @@ public class DungeonHelper return names; } - public static ArrayList getDungeonChainHistory(DimData dimData, DungeonPack pack, int maxSize) + public static ArrayList getDungeonChainHistory(NewDimData dimension, DungeonPack pack, int maxSize) { - //TODO: I've improved this code for the time being. However, searching across links is a flawed approach. A player could - //manipulate the output of this function by setting up links to mislead our algorithm or by removing links. - //Dimensions MUST have built-in records of their parent dimensions in the future. ~SenseiKiwi - - ArrayList history = new ArrayList(); - DimData tailDim = dimData; - boolean found = true; - - if (dimData.dungeonGenerator == null || dimData.dungeonGenerator.getDungeonType().Owner != pack || maxSize < 1) + if (dimension == null) { - //The initial dimension is already outside our pack. Return an empty list. - return history; + throw new IllegalArgumentException("dimension cannot be null."); } - history.add(dimData.dungeonGenerator); - for (int count = 1; count < maxSize && found; count++) + int count = 0; + NewDimData tail = dimension; + DungeonData dungeon = tail.dungeon(); + ArrayList history = new ArrayList(); + + while (count < maxSize && dungeon != null && dungeon.dungeonType().Owner == pack) { - found = false; - for (NewLinkData link : tailDim.getLinksInDim()) - { - DimData neighbor = dimHelper.instance.getDimData(link.destDimID); - if (neighbor.depth == tailDim.depth - 1 && neighbor.dungeonGenerator != null && - neighbor.dungeonGenerator.getDungeonType().Owner == pack) - { - tailDim = neighbor; - history.add(tailDim.dungeonGenerator); - found = true; - break; - } - } + history.add(dungeon); + tail = tail.parent(); + dungeon = tail.dungeon(); + count++; } return history; } - private static int getPackDepth(NewLinkData inbound, DungeonPack pack) + public static ArrayList getFlatDungeonTree(NewDimData dimension, int maxSize) { - //TODO: I've improved this code for the time being. However, searching across links is a flawed approach. A player could - //manipulate the output of this function by setting up links to mislead our algorithm or by removing links. - //Dimensions MUST have built-in records of their parent dimensions in the future. ~SenseiKiwi - //Dimensions should also just keep track of pack depth internally. + NewDimData root = dimension; + ArrayList dungeons = new ArrayList(); + Queue pendingDimensions = new LinkedList(); - int packDepth = 1; - DimData tailDim = dimHelper.dimList.get(inbound.destDimID); - boolean found; - - do - { - found = false; - for (NewLinkData link : tailDim.getLinksInDim()) - { - DimData neighbor = dimHelper.instance.getDimData(link.destDimID); - if (neighbor.depth == tailDim.depth - 1 && neighbor.dungeonGenerator != null && - neighbor.dungeonGenerator.getDungeonType().Owner == pack) - { - tailDim = neighbor; - found = true; - packDepth++; - break; - } - } - } - while (found); - - return packDepth; - } - - public static ArrayList getFlatDungeonTree(DimData dimData, int maxSize) - { - //TODO: I've improved this code for the time being. However, searching across links is a flawed approach. A player could - //manipulate the output of this function by setting up links to mislead our algorithm or by removing links. - //Dimensions MUST have built-in records of their parent dimensions in the future. ~SenseiKiwi - - dimHelper helper = dimHelper.instance; - ArrayList dungeons = new ArrayList(); - DimData root = helper.getDimData(helper.getLinkDataFromCoords(dimData.exitDimLink.destXCoord, dimData.exitDimLink.destYCoord, dimData.exitDimLink.destZCoord, dimData.exitDimLink.destDimID).destDimID); - HashSet checked = new HashSet(); - Queue pendingDimensions = new LinkedList(); - - if (root.dungeonGenerator == null) + if (root.dungeon() == null) { return dungeons; } pendingDimensions.add(root); - checked.add(root); while (dungeons.size() < maxSize && !pendingDimensions.isEmpty()) { - DimData current = pendingDimensions.remove(); - for (NewLinkData link : current.getLinksInDim()) + NewDimData current = pendingDimensions.remove(); + for (NewDimData child : current.children()) { - DimData child = helper.getDimData(link.destDimID); - if (child.depth == current.depth + 1 && child.dungeonGenerator != null && checked.add(child)) + if (child.dungeon() != null) { - dungeons.add(child.dungeonGenerator); + dungeons.add(child.dungeon()); pendingDimensions.add(child); } if (dungeons.size() == maxSize) diff --git a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java b/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java deleted file mode 100644 index c07f9f5..0000000 --- a/StevenDimDoors/mod_pocketDim/helpers/dimHelper.java +++ /dev/null @@ -1,1364 +0,0 @@ -package StevenDimDoors.mod_pocketDim.helpers; -/** - * This class regulates all the operations involving the storage and manipulation of dimensions. It handles saving dim data, teleporting the player, and - * creating/registering new dimensions as well as loading old dimensions on startup - * @Return - */ - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Random; -import java.util.Set; - -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.packet.Packet41EntityEffect; -import net.minecraft.network.packet.Packet43Experience; -import net.minecraft.network.packet.Packet9Respawn; -import net.minecraft.potion.PotionEffect; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.storage.ExtendedBlockStorage; -import net.minecraftforge.common.DimensionManager; -import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream; -import StevenDimDoors.mod_pocketDim.PacketHandler; -import StevenDimDoors.mod_pocketDim.Point3D; -import StevenDimDoors.mod_pocketDim.SchematicLoader; -import StevenDimDoors.mod_pocketDim.TileEntityRift; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; -import StevenDimDoors.mod_pocketDim.world.LimboProvider; -import StevenDimDoors.mod_pocketDim.world.PocketProvider; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; - -public class dimHelper extends DimensionManager -{ - /** - * hashMap for the private pocket dimensions - */ - - public static HashMap privatePockets = new HashMap(); - /** - * HashMap containing all the dims registered with DimDoors, sorted by dim ID. loaded on startup - * @Return - */ - public static HashMap dimList=new HashMap(); - public static boolean isSaving=false; - - /** - * ArrayList containing any blocks in limbo that have been placed by the player. Cycled through in the common tick manager - * @Return - */ - public static ArrayList blocksToDecay = new ArrayList(); - - /** - * instance of the dimHelper - * @Return - */ - public static dimHelper instance = new dimHelper(); - - /** - * HashMap for temporary storage of Link Signature damage hash values. See itemLinkSignature for more details - * @Return - */ - public HashMap interDimLinkList= new HashMap(); - - /** - * ArrayList containing all link data not sorted for easy random access, used for random doors and for recreating rifts if they have a block placed over them. - * See the common tick manager and the Chaos door for details on usage - * @Return - */ - //public ArrayList linksForRendering =new ArrayList(); - Random rand= new Random(); - - public static final int DEFAULT_POCKET_SIZE = 39; - public static final int DEFAULT_POCKET_WALL_THICKNESS = 5; - public static final int MAX_WORLD_HEIGHT = 254; - - public int getDimDepth(int DimID) - { - if (dimList.containsKey(DimID)) - { - return dimList.get(DimID).depth; - } - else return 1; - } - - // GreyMaria: My god, what a mess. Here, let me clean it up a bit. - public Entity teleportEntity(World world, Entity entity, NewLinkData link) //this beautiful teleport method is based off of xCompWiz's teleport function. - { - WorldServer oldWorld = (WorldServer)world; - WorldServer newWorld; - EntityPlayerMP player = (entity instanceof EntityPlayerMP) ? (EntityPlayerMP)entity : null; - - /*// SPECIAL CASE: Is our link null? If so, we've likely come from Limbo. Ensure this is the case. - if(link == null) - { - if(world.provider.dimensionId == DDProperties.instance().LimboDimensionID) - { - link = new LinkData(0, 0, 0, 0); - // Find destination point. - } - }*/ - - - // Is something riding? Handle it first. - if(entity.riddenByEntity != null) - { - return this.teleportEntity(oldWorld,entity.riddenByEntity, link); - } - // Are we riding something? Dismount and tell the mount to go first. - Entity cart = entity.ridingEntity; - if (cart != null) - { - entity.mountEntity(null); - cart = teleportEntity(oldWorld, cart, link); - // 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.destDimID)==null) - { - DimensionManager.initDimension(link.destDimID); - } - - // Determine if our destination's in another realm. - boolean difDest = link.destDimID != link.locDimID; - if(difDest) - { - newWorld = DimensionManager.getWorld(link.destDimID); - } - else - { - newWorld=(WorldServer)oldWorld; - } - - // 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. - mod_pocketDim.teleporter.placeInPortal(entity, newWorld, link); - - if (difDest) // Are we moving our target to a new dimension? - { - if(player != null) // Are we working with a player? - { - // 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.destDimID; - 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. - // This should fix an apparently unreported bug where - // the last non-sleeping player leaves the Overworld - // for a pocket dimension, causing all sleeping players - // to remain asleep instead of progressing to day. - oldWorld.removePlayerEntityDangerously(player); - 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); - newWorld.getPlayerManager().addPlayer(player); - - player.theItemInWorldManager.setWorld((WorldServer)newWorld); - - // Synchronize with the server so the client knows what time it is and what it's holding. - player.mcServer.getConfigurationManager().updateTimeAndWeatherForPlayer(player, (WorldServer)newWorld); - player.mcServer.getConfigurationManager().syncPlayerInventory(player); - for(Object potionEffect : player.getActivePotionEffects()) - { - PotionEffect effect = (PotionEffect)potionEffect; - player.playerNetServerHandler.sendPacketToPlayer(new Packet41EntityEffect(player.entityId, effect)); - } - - player.playerNetServerHandler.sendPacketToPlayer(new Packet43Experience(player.experience, player.experienceTotal, player.experienceLevel)); - } - - // Creates sanity by removing the entity from its old location's chunk entity list, if applicable. - int entX = entity.chunkCoordX; - int entZ = entity.chunkCoordZ; - if ((entity.addedToChunk) && (oldWorld.getChunkProvider().chunkExists(entX, entZ))) - { - oldWorld.getChunkFromChunkCoords(entX, entZ).removeEntity(entity); - oldWorld.getChunkFromChunkCoords(entX, entZ).isModified = true; - } - // Memory concerns. - oldWorld.releaseEntitySkin(entity); - - if (player == null) // Are we NOT working with a player? - { - NBTTagCompound entityNBT = new NBTTagCompound(); - entity.isDead = false; - entity.addEntityID(entityNBT); - entity.isDead = true; - entity = EntityList.createEntityFromNBT(entityNBT, newWorld); - - if (entity == null) - { // 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 - */ - } - - } - - // Finally, respawn the entity in its new home. - newWorld.spawnEntityInWorld(entity); - entity.setWorld(newWorld); - } - entity.worldObj.updateEntityWithOptionalForce(entity, false); - - // Hey, remember me? It's time to remount. - if (cart != null) - { - // Was there a player teleported? If there was, it's important that we update shit. - if (player != null) - { - entity.worldObj.updateEntityWithOptionalForce(entity, true); - } - entity.mountEntity(cart); - } - - // Did we teleport a player? Load the chunk for them. - if(player != null) - { - WorldServer.class.cast(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); - - } - mod_pocketDim.teleporter.placeInPortal(entity, newWorld, link); - 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 the pocketTeleporter. - * @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 - */ - public void traverseDimDoor(World world,NewLinkData linkData, Entity entity) - { - DDProperties properties = DDProperties.instance(); - - if (world.isRemote) - { - return; - } - if (linkData != null) - { - int destinationID=linkData.destDimID; - - if(dimHelper.dimList.containsKey(destinationID) && dimHelper.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 )&&dimHelper.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); - } - } - } - } - return; - } - - /** - * Creates a link at the location, pointing to the destination. Does NOT create a pair, so must be called twice. - * @param locationDimID - * @param destinationDimID - * @param locationXCoord - * @param locationYCoord - * @param locationZCoord - * @param destinationXCoord - * @param destinationYCoord - * @param destinationZCoord - - * @return - */ - public NewLinkData createLink( int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord) - { - if(this.getLinkDataFromCoords(locationXCoord, locationYCoord, locationZCoord, locationDimID)!=null) - { - return this.createLink(locationDimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord, destinationZCoord, this.getLinkDataFromCoords(locationXCoord, locationYCoord, locationZCoord, locationDimID).linkOrientation); - } - else - { - return this.createLink(locationDimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord, destinationZCoord, -10); - } - } - - - /** - * Creates a link at the location, pointing to the destination. Does NOT create a pair, so must be called twice. - * @param locationDimID - * @param destinationDimID - * @param locationXCoord - * @param locationYCoord - * @param locationZCoord - * @param destinationXCoord - * @param destinationYCoord - * @param destinationZCoord - * @param linkOrientation - * @return - */ - public NewLinkData createLink( int locationDimID, int destinationDimID, int locationXCoord, int locationYCoord, int locationZCoord, int destinationXCoord, int destinationYCoord, int destinationZCoord,int linkOrientation) - { - NewLinkData linkData =new NewLinkData( locationDimID, destinationDimID, locationXCoord, locationYCoord, locationZCoord, destinationXCoord, destinationYCoord ,destinationZCoord,false,linkOrientation); - return this.createLink(linkData); - } - - public NewLinkData createLink(NewLinkData link) - { - DDProperties properties = DDProperties.instance(); - - if(!dimHelper.dimList.containsKey(link.locDimID)) - { - DimData locationDimData= new DimData(link.locDimID, false, 0, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); - dimHelper.dimList.put(link.locDimID, locationDimData); - link.isLocPocket=false; - } - if(!dimList.containsKey(link.destDimID)) - { - dimHelper.dimList.put(link.destDimID, new DimData(link.destDimID, false, 0, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord)); - } - DimData locationDimData= dimHelper.instance.getDimData(link.locDimID); - link.isLocPocket=locationDimData.isPocket; - locationDimData.addLinkToDim(link); - - World world = dimHelper.getWorld(link.locDimID); - if (world != null) - { - if (!mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord)) - { - world.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); - } - } - //Notifies other players that a link has been created. - if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER) - { - PacketHandler.onLinkCreatedPacket(link); - } - return link; - } - - public int getDestOrientation(NewLinkData link) - { - if(link !=null) - { - NewLinkData destLink = this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); - if(destLink!=null) - { - return destLink.linkOrientation; - } - else - { - //System.out.println("Cant find destination link"); - return 0; - } - } - else - { - // System.out.println("sending link is null"); - return 0; - } - } - - public void removeLink(NewLinkData link) - { - this.removeLink(link.locDimID, link.locXCoord, link.locYCoord, link.locZCoord); - } - - /** - * properly deletes a link at the given coordinates. used by the rift remover. Also notifies clients of change. - * @param locationDimID - * @param locationXCoord - * @param locationYCoord - * @param locationZCoord - */ - public void removeLink( int locationDimID, int locationXCoord, int locationYCoord, int locationZCoord) - { - if(!dimHelper.dimList.containsKey(locationDimID)) - { - DimData locationDimData= new DimData(locationDimID, false, 0, locationDimID,locationXCoord,locationYCoord,locationZCoord); - dimHelper.dimList.put(locationDimID, locationDimData); - } - NewLinkData link = this.getLinkDataFromCoords(locationXCoord, locationYCoord, locationZCoord, locationDimID); - dimHelper.instance.getDimData(locationDimID).removeLinkAtCoords(link); - //updates clients that a rift has been removed - if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER) - { - PacketHandler.onLinkRemovedPacket(link); - this.save(); - } - } - public NewLinkData findNearestRift(World world, int x, int y, int z, int range) - { - return dimHelper.instance.getDimData(world).findNearestRift(world, range, x, y, z); - } - /** - * generates a door based on what door was used to teleport. Only funtions once per linking. - * @param world- door - * @param incLink - */ - public void generateDoor(World world, NewLinkData incLink) - { - int locX = incLink.locXCoord; - int locY = incLink.locYCoord; - int locZ = incLink.locZCoord; - - int destX = incLink.destXCoord; - int destY = incLink.destYCoord; - int destZ = incLink.destZCoord; - - DDProperties properties = DDProperties.instance(); - - if(!incLink.hasGennedDoor) - { - int destinationID = incLink.destDimID; - - int id =world.getBlockId(locX, locY, locZ); - if(id==properties.WarpDoorID||id==properties.DimensionalDoorID||id==properties.TransientDoorID) - { - int doorTypeToPlace=id; - if(DimensionManager.getWorld(destinationID)==null) - { - DimensionManager.initDimension(destinationID); - } - NewLinkData destLink = this.getLinkDataFromCoords(destX, destY, destZ, destinationID); - int destOrientation = 0; - if(destLink!=null) - { - destOrientation = destLink.linkOrientation; - destLink.hasGennedDoor=true; - } - int blockToReplace= DimensionManager.getWorld(destinationID).getBlockId(destX, destY, destZ); - if(blockToReplace!=properties.DimensionalDoorID&&blockToReplace!=properties.WarpDoorID&&blockToReplace != properties.TransientDoorID) - { - DimensionManager.getWorld(destinationID).setBlock(destX, destY-1, destZ, doorTypeToPlace,destOrientation,2); - DimensionManager.getWorld(destinationID).setBlock(destX, destY, destZ, doorTypeToPlace,8,2); - } - incLink.hasGennedDoor=true; - } - } - } - - - - - /** - * Generates the black pocket out of fabric of reality blocks. Placement of the pocket is based off of the orignial doors orientation. Kind of a clunky method, - * but is necessary to maintain a one to one relationship with the overworld. Is called every teleport, but checks if the dim has been filled first and is a pocket . - * Also responsible for generation the random dungeons. - * @param world- id of the world TO BE FILLED - * @param x - * @param y - * @param z - * @param orientation - * @return - */ - public void generatePocket(NewLinkData incomingLink) - { - DDProperties properties = DDProperties.instance(); - try - { - if (DimensionManager.getWorld(incomingLink.destDimID) == null) - { - DimensionManager.initDimension(incomingLink.destDimID); - } - if (DimensionManager.getWorld(incomingLink.destDimID).provider == null) - { - DimensionManager.initDimension(incomingLink.destDimID); - } - } - catch(Exception E) - { - E.printStackTrace(); - return; - } - // World world = this.getWorld(incomingLink.destDimID); - DimData data = dimHelper.instance.getDimData(incomingLink.destDimID); - - if(!data.hasBeenFilled&&data.isPocket&&!data.isDimRandomRift) - { - data.hasBeenFilled=true; - //System.out.println("genning pocket"); - int x = incomingLink.destXCoord; - int y = incomingLink.destYCoord; - int z = incomingLink.destZCoord; - int orientation= (incomingLink.linkOrientation); - - int depth= this.getDimDepth(incomingLink.locDimID); - //x=x*depth; - //y=y*depth; - //z=z*depth; - y=y+13; - - - if(orientation==0) - { - x=x+15; - //this.getWorld(incomingLink.destDimID).provider.setSpawnPoint(x-1, y, z); - - } - else if(orientation==1) - { - z=z+15; - //this.getWorld(incomingLink.destDimID).provider.setSpawnPoint(x, y, z-1); - - } - else if(orientation==2) - { - x=x-15; - //this.getWorld(incomingLink.destDimID).provider.setSpawnPoint(x+1, y, z); - - } - else if(orientation==3) - { - z=z-15; - //this.getWorld(incomingLink.destDimID).provider.setSpawnPoint(x, y, z+1); - - } - int searchRadius=19; - - if(!DimensionManager.getWorld(incomingLink.destDimID).isRemote) - { - int xCount=-searchRadius; - int yCount=-searchRadius; - int zCount=-searchRadius; - - while (xCount<=searchRadius) - { - while(yCount<=searchRadius) - { - while(zCount<=searchRadius) - { - if((Math.abs(xCount)>=15||Math.abs(yCount)>=15||Math.abs(zCount)>=15)&&DimensionManager.getWorld(incomingLink.destDimID).isAirBlock( x+xCount, y+yCount, z+zCount)&&((yCount+y)>0)) - { - if(Math.abs(xCount)>=19||Math.abs(yCount)>=19||Math.abs(zCount)>=19) - { - dimHelper.setBlockDirectly(DimensionManager.getWorld(incomingLink.destDimID), x+xCount, y+yCount, z+zCount,properties.PermaFabricBlockID,0); - } - else - { - dimHelper.setBlockDirectly(DimensionManager.getWorld(incomingLink.destDimID), x+xCount, y+yCount, z+zCount,properties.FabricBlockID,0); - if(properties.TNFREAKINGT_Enabled) - { - if((Math.abs(xCount)>=16||Math.abs(yCount)>=16||Math.abs(zCount)>=16) && rand.nextInt(properties.NonTntWeight + 1) == 0) - { - DimensionManager.getWorld(incomingLink.destDimID).setBlock( x+xCount, y+yCount, z+zCount,Block.tnt.blockID); - } - } - } - } - zCount++; - } - zCount=-searchRadius; - yCount++; - } - yCount=-searchRadius; - xCount++; - } - } - } - else if (!data.hasBeenFilled && data.isPocket && data.isDimRandomRift) - { - SchematicLoader.generateDungeonPocket(incomingLink, properties); - data.hasBeenFilled=true; - } - } - - /** - * 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 void initPockets() - { - DDProperties properties = DDProperties.instance(); - mod_pocketDim.hasInitDims=true; - this.load(); - if(!dimHelper.dimList.isEmpty()) - { - Set allDimIds=dimList.keySet(); - //FIXME: ...Wat. Why aren't we using a foreach loop here instead of manipulating an explicit iterator? ;-; ~SenseiKiwi - Iterator itr = allDimIds.iterator(); - while(itr.hasNext()) - { - DimData dimData = (DimData) dimList.get(itr.next()); - if(dimData.isPocket) - { - try - { - DimensionManager.getNextFreeDimId(); - registerDimension(dimData.dimID,properties.PocketProviderID); - } - catch (Exception e) - { - if(dimData.isPocket) - { - System.out.println("Warning- could not register dim "+dimData.depth+" . Probably caused by a version update/save data corruption/other mods. "); - } - else - { - e.printStackTrace(); - } - } - } - } - } - } - - public boolean resetPocket(DimData dimData) - { - if (!dimData.isPocket || getWorld(dimData.dimID) != null) - { - return false; - } - File save = new File(getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimData.dimID); - DeleteFolder.deleteFolder(save); - dimData.hasBeenFilled = false; - dimData.hasDoor = false; - for(NewLinkData link : dimData.getLinksInDim()) - { - link.hasGennedDoor = false; - NewLinkData linkOut = this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); - if (linkOut != null) - { - linkOut.hasGennedDoor = false; - } - } - return true; - } - - public boolean pruneDimension(DimData dimData, boolean deleteFolder) - { - - //TODO: All the logic for checking that this is an isolated pocket should be moved in here. - if (!dimData.isPocket || getWorld(dimData.dimID) != null)//Checks to see if the pocket is loaded or isnt actually a pocket. - { - return false; - } - dimList.remove(dimData.dimID); - if (deleteFolder) - { - File save = new File(getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimData.dimID); - DeleteFolder.deleteFolder(save); - } - return true; - } - - /** - * method called when the client disconnects/server stops to unregister dims. - * @Return - */ - public void unregsisterDims() - { - - if(!dimHelper.dimList.isEmpty()) - { - Set allDimIds=dimList.keySet(); - Iterator itr =allDimIds.iterator(); - while(itr.hasNext()) - { - DimData dimData = (DimData) dimList.get(itr.next()); - if(dimData.isPocket) - { - try - { - DimensionManager.unregisterDimension(dimData.dimID); - } - catch(Exception e) - { - System.out.println("Dim-"+String.valueOf(dimData.dimID)+"is already unregistered, ok? Enough with it already."); - } - // initDimension(dimData.dimID); - } - } - } - } - - /** - * Used to associate a damage value on a Rift Signature with a link pair. See LinkSignature for details. - * @return - */ - public int createUniqueInterDimLinkKey() - { - int linkKey; - Random rand= new Random(); - do - { - linkKey=rand.nextInt(30000); - } - while(this.interDimLinkList.containsKey(linkKey)); - return linkKey; - } - - /** - * Method used to create and register a new pocket dimension. Called on door placement and rift generation. It does NOT actually generate the structure of the dim, just - * registers it with the dimension manager and adds the necessary links and dim info to the dimlist/linklists. - * Also registers existing dims with the dimList, so link data can be stored for them. - * - * Handles the randomization associated with depth as well, going far enough causes the next dims exit link to be randomized. - * - * @param world- World currently occupied, the parent of the pocket dim to be created. - * @param x - * @param y - * @param z - * @param isGoingDown - * @param isRandomRift - * @param orientation- determines the orientation of the entrance link to this dim. Should be the metaData of the door occupying the rift. -1 if no door. - * @return - */ - public NewLinkData createPocket(NewLinkData link , boolean isGoingDown, boolean isRandomRift) - { - DDProperties properties = DDProperties.instance(); - if(dimHelper.getWorld(0)==null) - { - return link; - } - if (dimHelper.getWorld(link.locDimID) == null) - { - dimHelper.initDimension(link.locDimID); - } - int dimensionID; - int depth = this.getDimDepth(link.locDimID); - dimensionID = getNextFreeDimId(); - registerDimension(dimensionID, properties.PocketProviderID); - DimData locationDimData; - DimData destDimData; - - - - if(dimHelper.dimList.containsKey(link.locDimID)&&!DimensionManager.getWorld(link.locDimID).isRemote) //checks to see if dim is already registered. If not, it creates a DimData entry for it later - { - //randomizes exit if deep enough - locationDimData= dimList.get(DimensionManager.getWorld(link.locDimID).provider.dimensionId); - - if(depth>5) - { - if(depth>=12) - { - depth=11; - } - if(rand.nextInt(13-depth)==0) - { - NewLinkData link1=getRandomLinkData(false); - } - } - if(locationDimData.isPocket) //determines the qualites of the pocket dim being created, based on parent dim. - { - if(isGoingDown) - { - destDimData= new DimData(dimensionID, true, locationDimData.depth+1, locationDimData.exitDimLink); - } - else - { - destDimData= new DimData(dimensionID, true, locationDimData.depth-1, locationDimData.exitDimLink); - } - } - else - { - destDimData= new DimData(dimensionID, true, 1, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); - } - - } - else - { - locationDimData= new DimData(link.locDimID, false, 0, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); - destDimData= new DimData(dimensionID, true, 1, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); - } - destDimData.isDimRandomRift=isRandomRift; - dimHelper.dimList.put(DimensionManager.getWorld(link.locDimID).provider.dimensionId, locationDimData); - dimHelper.dimList.put(dimensionID, destDimData); - - if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER)//sends packet to clients notifying them that a new dim has been created. - { - PacketHandler.onDimCreatedPacket(destDimData); - } - link = this.createLink(DimensionManager.getWorld(link.locDimID).provider.dimensionId,dimensionID,link.locXCoord,link.locYCoord,link.locZCoord, link.destXCoord,constrainPocketY(link.destYCoord),link.destZCoord,link.linkOrientation); //creates and registers the two rifts that link the parent and pocket dim. - this.createLink(dimensionID,DimensionManager.getWorld(link.locDimID).provider.dimensionId, link.destXCoord,constrainPocketY(link.destYCoord),link.destZCoord, link.locXCoord,link.locYCoord,link.locZCoord, BlockRotator.transformMetadata(link.linkOrientation, 2, Block.doorWood.blockID)); - return link; - } - - public static int constrainPocketY(int entranceDoorYPos) - { - - if(entranceDoorYPos+DEFAULT_POCKET_SIZE-DEFAULT_POCKET_WALL_THICKNESS>= MAX_WORLD_HEIGHT) - { - return entranceDoorYPos-DEFAULT_POCKET_SIZE+DEFAULT_POCKET_WALL_THICKNESS; - } - if(entranceDoorYPos-1-DEFAULT_POCKET_WALL_THICKNESS<=0) - { - return entranceDoorYPos+DEFAULT_POCKET_WALL_THICKNESS; - - } - else return entranceDoorYPos; - - } - /** - * function that saves all dim data in a hashMap. Calling too often can cause Concurrent modification exceptions, so be careful. - * @return - */ - //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 - public void save() - { - if(dimHelper.isSaving) return; - World world = DimensionManager.getWorld(0); - if(world==null || world.isRemote) return; - if(DimensionManager.getCurrentSaveRootDirectory()!=null) - { - //System.out.println("saving"); - - dimHelper.isSaving=true; - HashMap comboSave=new HashMap(); - comboSave.put("dimList", dimHelper.dimList); - comboSave.put("interDimLinkList", this.interDimLinkList); - comboSave.put("blocksToDecay", dimHelper.blocksToDecay); - - - - FileOutputStream saveFile = null; - try - { - //World world=FMLCommonHandler.instance().getMinecraftServerInstance().worldServers[0]; - String saveFileName=DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataTEMP"; - saveFile = new FileOutputStream(saveFileName); - - ObjectOutputStream save = new ObjectOutputStream(saveFile); - save.writeObject(comboSave); - save.close(); - saveFile.close(); - - if(new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD").exists()) - { - new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD").delete(); - } - new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsData").renameTo(new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD")); - - new File(saveFileName).renameTo( new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsData")); - } - catch(Exception e) - { - e.printStackTrace(); - System.out.println("Could not save data-- SEVERE"); - } - - - - - dimHelper.isSaving=false; - } - } - - /** - * loads the dim data from the saved hashMap. Also handles compatabilty with old saves, see OldSaveHandler - * @return - */ - //TODO change to loading vars instead of objects - @SuppressWarnings("unchecked") - public void load() - { - boolean firstRun=false; - System.out.println("Loading DimDoors data"); - FileInputStream saveFile = null; - - if(!DimensionManager.getWorld(0).isRemote&&DimensionManager.getCurrentSaveRootDirectory()!=null) - { - - try - { - File dataStore = new File( DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsData"); - - if(!dataStore.exists()) - { - - - if(!new File( DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD").exists()) - { - firstRun=true; - } - } - - - - - - saveFile = new FileInputStream(dataStore); - ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); - HashMap comboSave =((HashMap) save.readObject()); - - try - { - this.interDimLinkList = (HashMap) comboSave.get("interDimLinkList"); - } - catch(Exception e) - { - System.out.println("Could not load Link Signature list. Link Sig items will loose restored locations."); - } - - try - { - dimHelper.dimList = (HashMap) comboSave.get("dimList"); - } - catch(Exception e) - { - System.out.println("Could not load pocket dim list. Saves probably lost, but repairable. Move the files from indivual pocket dim files to active ones. See MC thread for details."); - } - - - - try - { - dimHelper.blocksToDecay= (ArrayList) comboSave.get("blocksToDecay"); - } - catch(Exception e) - { - System.out.println("Could not load list of blocks to decay in Limbo. Probably because you updated versions, in which case this is normal. "); - - } - save.close(); - saveFile.close(); - - - - } - catch(Exception e4) - { - try - { - if(!firstRun) - { - System.out.println("Save data damaged, trying backup..."); - } - World world=FMLCommonHandler.instance().getMinecraftServerInstance().worldServers[0]; - File dataStore =new File( world.getSaveHandler().getMapFileFromName("idcounts").getParentFile().getParent()+"/DimensionalDoorsDataOLD"); - - - saveFile = new FileInputStream(dataStore); - ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); - HashMap comboSave =((HashMap)save.readObject()); - - try - { - this.interDimLinkList=(HashMap) comboSave.get("interDimLinkList"); - } - catch(Exception e) - { - System.out.println("Could not load Link Signature list. Link Sig items will loose restored locations."); - } - - try - { - dimHelper.dimList=(HashMap) comboSave.get("dimList"); - } - catch(Exception e) - { - System.out.println("Could not load pocket dim list. Saves probably lost, but repairable. Move the files from indivual pocket dim files to active ones. See MC thread for details."); - } - - - - try - { - dimHelper.blocksToDecay=(ArrayList) comboSave.get("blocksToDecay"); - } - catch(Exception e) - { - System.out.println("Could not load list of blocks to decay in Limbo. Probably because you updated versions, in which case this is normal. "); - - } - save.close(); - saveFile.close(); - - } - catch(Exception e2) - { - if(!firstRun) - { - e2.printStackTrace(); - System.out.println("Could not read data-- SEVERE"); - } - - - - - } - - - - } - } - - } - - - - public NewLinkData getRandomLinkData(boolean allowInPocket) - { - boolean foundRandomDest=false; - int i=0; - int size = dimHelper.dimList.size(); - - while (!foundRandomDest&&size>0&&i<100) - { - i++; - DimData dimData; - ArrayList linksInDim = new ArrayList(); - for(size--;size>0;) - { - dimData = dimHelper.instance.getDimData((Integer)dimList.keySet().toArray()[rand.nextInt(dimList.keySet().size())]); - if(dimData==null) - { - break; - } - linksInDim = dimData.getLinksInDim(); - if(!linksInDim.isEmpty()) - { - break; - } - } - - if(linksInDim.isEmpty()) - { - break; - } - - NewLinkData link1 = (NewLinkData) linksInDim.get(rand.nextInt(linksInDim.size())); - - if(link1!=null) - { - - if(!link1.isLocPocket||allowInPocket) - { - foundRandomDest=true; - return link1; - } - } - } - - return null; - - } - - /** - * Gets a link at the destination of the link provided. Returns null if none exists. - * @param link - * @return - */ - public NewLinkData getLinkDataAtDestination(NewLinkData link) - { - return this.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, link.destDimID); - } - /** - * Moves the location of the link passed in to the provided coords. Does not change the links destination coords. - * The boolean flag determines whether or not to update other links that point to this link- true causes all links that pointed to this link to be updated - * to point to the new link location. - * - * Return true if there was an actual link to be moved. - * - * @param link - * @param x - * @param y - * @param z - * @param dimID - * @param updateLinksPointingHere - * @return - */ - public boolean moveLinkDataLocation(NewLinkData link, int x,int y, int z, int dimID, boolean updateLinksPointingHere) - { - NewLinkData linkToMove = this.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID); - if(linkToMove!=null) - { - int oldX = linkToMove.locXCoord; - int oldY = linkToMove.locYCoord; - int oldZ = linkToMove.locZCoord; - int oldDimID = linkToMove.locDimID; - - if(updateLinksPointingHere) - { - ArrayList incomingLinks = new ArrayList(); - for(DimData dimData : dimHelper.dimList.values()) - { - for(NewLinkData allLink : dimData.getLinksInDim()) - { - if(this.getLinkDataAtDestination(allLink)==linkToMove) - { - this.moveLinkDataDestination(allLink, x, y, z, dimID, false); - } - } - } - } - this.createLink(new NewLinkData(dimID,linkToMove.destDimID,x,y,z,linkToMove.destXCoord,linkToMove.destYCoord,linkToMove.destZCoord,linkToMove.isLocPocket,linkToMove.linkOrientation)); - - if(this.getLinkDataFromCoords(oldX,oldY,oldZ,oldDimID)!=null) - { - this.removeLink(this.getLinkDataFromCoords(oldX,oldY,oldZ,oldDimID)); - } - - return true; - } - return false; - } - /** - * Changes the destination coords of the link passed in if it exists to the provided coords. - * @param link - * @param x - * @param y - * @param z - * @param dimID - * @param updateLinksAtDestination - * @return - */ - public boolean moveLinkDataDestination(NewLinkData link, int x, int y, int z, int dimID, boolean updateLinksAtDestination) - { - NewLinkData linkToMove = this.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID); - if(linkToMove!=null) - { - if(updateLinksAtDestination) - { - NewLinkData linkAtDestination = this.getLinkDataAtDestination(linkToMove); - if(linkAtDestination!=null) - { - this.moveLinkDataLocation(linkAtDestination, x, y, z, dimID, false); - } - } - linkToMove.destDimID=dimID; - linkToMove.destXCoord=x; - linkToMove.destYCoord=y; - linkToMove.destZCoord=z; - this.createLink(linkToMove); - NewLinkData testLink = this.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID); - - return true; - } - return false; - } - - /** - * gets a link based on coords and a world object - * @param x - * @param y - * @param z - * @param par1World - * @return - */ - public NewLinkData getLinkDataFromCoords(int x, int y, int z, World par1World) - { - return this.getLinkDataFromCoords(x, y, z, par1World.provider.dimensionId); - } - /** - * gets a link based on coords and a world ID - * @param x - * @param y - * @param z - * @param worldID - * @return - */ - public NewLinkData getLinkDataFromCoords(int x, int y, int z, int worldID) - { - if(dimHelper.dimList.containsKey(worldID)) - { - DimData dimData=dimHelper.instance.getDimData(worldID); - - return dimData.findLinkAtCoords(x, y, z); - - } - - return null; - } - /** - * function called by rift tile entities and the rift remover to find and spread between rifts. Does not actually de-register the rift data, see deleteRift for that. - * @param world - * @param x - * @param y - * @param z - * @param range - * @param player - * @param item - * @return - */ - public static boolean removeRift(World world, int x, int y, int z, int range, EntityPlayer player, ItemStack item) - { - DDProperties properties = DDProperties.instance(); - - NewLinkData nearest=null; - float distance=range+1; - int i=-range; - int j=-range; - int k=-range; - - while (i>4; - int cZ=z >>4; - int cY=y >>4; - Chunk chunk; - int chunkX=(x % 16)< 0 ? ((x) % 16)+16 : ((x) % 16); - int chunkY=y; - int chunkZ=((z) % 16)< 0 ? ((z) % 16)+16 : ((z) % 16); - - - // this.chunk=new EmptyChunk(world,cX, cZ); - try - { - chunk=world.getChunkFromChunkCoords(cX, cZ); - if (chunk.getBlockStorageArray()[cY] == null) { - chunk.getBlockStorageArray()[cY] = new ExtendedBlockStorage(cY << 4, !world.provider.hasNoSky); - } - - - chunk.getBlockStorageArray()[cY].setExtBlockID(chunkX, (y) & 15, chunkZ, id); - chunk.getBlockStorageArray()[cY].setExtBlockMetadata(chunkX, (y) & 15, chunkZ, metadata); - } - catch(Exception e) - { - e.printStackTrace(); - } - - } - - public void addDimData(DimData dimData) - { - dimHelper.dimList.put(dimData.dimID, dimData); - } - - public void createDimData(World world) - { - dimHelper.dimList.put(world.provider.dimensionId, new DimData(world.provider.dimensionId, false, 0,0,world.provider.getSpawnPoint().posX,world.provider.getSpawnPoint().posY,world.provider.getSpawnPoint().posZ)); - } - - public DimData getDimData(World world) - { - return dimHelper.instance.getDimData(world.provider.dimensionId); - } - - public DimData getDimData(int dimID) - { - return dimHelper.dimList.get(dimID); - } -} diff --git a/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java b/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java index 3f9a4f5..a083c03 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java @@ -1,41 +1,20 @@ package StevenDimDoors.mod_pocketDim.helpers; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; - public class yCoordHelper { private static final int MAXIMUM_UNCOVERED_Y = 245; - public static int getFirstUncovered(NewLinkData pointerLink) - { - return yCoordHelper.getFirstUncovered( - pointerLink.destDimID, - pointerLink.destXCoord, - pointerLink.destYCoord, - pointerLink.destZCoord); - } - - public static int getFirstUncovered(int worldID, int x, int yStart, int z) - { return getFirstUncovered(worldID, x, yStart, z, false); } - - public static int getFirstUncovered(int worldID, int x, int yStart, int z, boolean fromTop) - { - if (dimHelper.getWorld(worldID) == null || - dimHelper.getWorld(worldID).provider == null) - { - dimHelper.initDimension(worldID); - } - - return yCoordHelper.getFirstUncovered(dimHelper.getWorld(worldID), x, yStart, z, fromTop); - } + private yCoordHelper() { } public static int getFirstUncovered(World world, int x, int yStart, int z) - { return getFirstUncovered(world, x, yStart, z, false); } + { + return getFirstUncovered(world, x, yStart, z, false); + } public static int getFirstUncovered(World world, int x, int yStart, int z, boolean fromTop) { @@ -46,18 +25,20 @@ public class yCoordHelper int height = MAXIMUM_UNCOVERED_Y; //world.getHeight(); int y; - if(!fromTop) + if (!fromTop) { boolean covered = true; for (y = yStart; y < height && covered; y++) { - covered = IsCoveredBlock(chunk, localX, y - 1, localZ) || IsCoveredBlock(chunk, localX, y, localZ); + covered = isCoveredBlock(chunk, localX, y - 1, localZ) || isCoveredBlock(chunk, localX, y, localZ); } - } else { + } + else + { boolean covered = false; for (y = MAXIMUM_UNCOVERED_Y; y > 1 && !covered; y--) { - covered = IsCoveredBlock(chunk, localX, y - 1, localZ); + covered = isCoveredBlock(chunk, localX, y - 1, localZ); } if (!covered) y = 63; y++; @@ -66,7 +47,7 @@ public class yCoordHelper return y; } - public static boolean IsCoveredBlock(Chunk chunk, int localX, int y, int localZ) + public static boolean isCoveredBlock(Chunk chunk, int localX, int y, int localZ) { int blockID; Block block; @@ -86,4 +67,25 @@ public class yCoordHelper material = block.blockMaterial; return (material.isLiquid() || !material.isReplaceable()); } + + public static int adjustDestinationY(int y, int worldHeight, int entranceY, int dungeonHeight) + { + //The goal here is to guarantee that the dungeon fits within the vertical bounds + //of the world while shifting it as little as possible. + int destY = y; + + //Is the top of the dungeon going to be at Y < worldHeight? + int pocketTop = (dungeonHeight - 1) + destY - entranceY; + if (pocketTop >= worldHeight) + { + destY = (worldHeight - 1) - (dungeonHeight - 1) + entranceY; + } + + //Is the bottom of the dungeon at Y >= 0? + if (destY < entranceY) + { + destY = entranceY; + } + return destY; + } } diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java index 2ca96a7..f8340f5 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java @@ -23,7 +23,7 @@ import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -188,16 +188,16 @@ public class ItemRiftBlade extends ItemSword if(this.getMaxItemUseDuration(par1ItemStack)-par4>12&&!par2World.isRemote&&itemDimDoor.canPlace(par2World, x, y, z, rotation)) { - if(dimHelper.instance.getDimData(par2World.provider.dimensionId)!=null) + if(PocketManager.instance.getDimData(par2World.provider.dimensionId)!=null) { - if(dimHelper.instance.getDimData(par2World.provider.dimensionId).depth==0) + if(PocketManager.instance.getDimData(par2World.provider.dimensionId).depth==0) { - dimHelper.instance.createPocket(link,true, false); + PocketManager.instance.createPocket(link,true, false); } } else { - dimHelper.instance.createPocket(link,true, false); + PocketManager.instance.createPocket(link,true, false); } par3EntityPlayer.worldObj.playSoundAtEntity(par3EntityPlayer,"mods.DimDoors.sfx.riftDoor", (float) .6, 1); itemDimDoor.placeDoorBlock(par2World, x, y-1, z, rotation, mod_pocketDim.transientDoor); @@ -212,7 +212,7 @@ public class ItemRiftBlade extends ItemSword { if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ)==properties.RiftBlockID) { - NewLinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); + NewLinkData link = PocketManager.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); if(link!=null) { @@ -229,7 +229,7 @@ public class ItemRiftBlade extends ItemSword { int var12 = MathHelper.floor_double((double)((par3EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - if (!itemDimDoor.canPlace(par2World, par4, par5, par6, var12)||!itemDimDoor.canPlace(par2World, par4, par5-1, par6, var12)||dimHelper.instance.getLinkDataFromCoords(par4, par5, par6, par2World)==null) + if (!itemDimDoor.canPlace(par2World, par4, par5, par6, var12)||!itemDimDoor.canPlace(par2World, par4, par5-1, par6, var12)||PocketManager.instance.getLinkDataFromCoords(par4, par5, par6, par2World)==null) { return par1ItemStack; } @@ -342,7 +342,7 @@ public class ItemRiftBlade extends ItemSword { int var12 = MathHelper.floor_double((double)((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - if (!itemDimDoor.canPlace(par3World, par4, par5, par6, var12)||dimHelper.instance.getLinkDataFromCoords(par4, par5+1, par6, par3World)==null) + if (!itemDimDoor.canPlace(par3World, par4, par5, par6, var12)||PocketManager.instance.getLinkDataFromCoords(par4, par5+1, par6, par3World)==null) { return false; } diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index 504f66c..5933e56 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -5,7 +5,7 @@ import java.util.List; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -83,11 +83,11 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature } if(hasEnder&&!par3World.isRemote) { - if(dimHelper.instance.getLinkDataFromCoords(linkCoords[0], linkCoords[1], linkCoords[2], par3World)==null) + if(PocketManager.instance.getLinkDataFromCoords(linkCoords[0], linkCoords[1], linkCoords[2], par3World)==null) { - dimHelper.instance.createLink(linkCoords[3], par3World.provider.dimensionId, linkCoords[0], linkCoords[1], linkCoords[2],par4, par5+offset, par6); + PocketManager.instance.createLink(linkCoords[3], par3World.provider.dimensionId, linkCoords[0], linkCoords[1], linkCoords[2],par4, par5+offset, par6); } - dimHelper.instance.createLink(par3World.provider.dimensionId, linkCoords[3], par4, par5+offset, par6, linkCoords[0], linkCoords[1], linkCoords[2]); + PocketManager.instance.createLink(par3World.provider.dimensionId, linkCoords[3], par4, par5+offset, par6, linkCoords[0], linkCoords[1], linkCoords[2]); par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftEnd", (float) .6, 1); par2EntityPlayer.sendChatToPlayer("Rift Created"); @@ -105,7 +105,7 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature offset = 1; } //otherwise, it creates the first half of the link. Next click will complete it. - key= dimHelper.instance.createUniqueInterDimLinkKey(); + key= PocketManager.instance.createUniqueInterDimLinkKey(); this.writeToNBT(par1ItemStack, par4, par5+offset, par6,par3World.provider.dimensionId); par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftStart", (float) .6, 1); @@ -126,7 +126,7 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature if(par1ItemStack.stackTagCompound.getBoolean("isCreated")) { Integer[] coords = this.readFromNBT(par1ItemStack); - par3List.add(String.valueOf("Leads to dim "+coords[3] +" with depth "+dimHelper.instance.getDimDepth(dimHelper.instance.getDimDepth(coords[3])))); + par3List.add(String.valueOf("Leads to dim "+coords[3] +" with depth "+PocketManager.instance.getDimDepth(PocketManager.instance.getDimDepth(coords[3])))); par3List.add("at x="+coords[0]+" y="+coords[1]+" z="+coords[2]); } } diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java b/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java index b5a741b..3eb39d9 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java @@ -6,7 +6,7 @@ import StevenDimDoors.mod_pocketDim.SchematicLoader; import StevenDimDoors.mod_pocketDim.Spells; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; import StevenDimDoors.mod_pocketDimClient.ClientTickHandler; @@ -55,13 +55,13 @@ public class ItemStableFabric extends Item Block block = Block.blocksList[par3World.getBlockId(par4, par5, par6)]; - if(dimHelper.dimList.containsKey(par3World.provider.dimensionId)) + if(PocketManager.dimList.containsKey(par3World.provider.dimensionId)) { - if(dimHelper.instance.getDimData(par3World.provider.dimensionId).isPocket) + if(PocketManager.instance.getDimData(par3World.provider.dimensionId).isPocket) { - if(dimHelper.instance.getDimData(par3World.provider.dimensionId).dungeonGenerator!=null) + if(PocketManager.instance.getDimData(par3World.provider.dimensionId).dungeonGenerator!=null) { - System.out.println("Dungeon name "+dimHelper.instance.getDimData(par3World.provider.dimensionId).dungeonGenerator.schematicPath); + System.out.println("Dungeon name "+PocketManager.instance.getDimData(par3World.provider.dimensionId).dungeonGenerator.schematicPath); } } @@ -117,7 +117,7 @@ public class ItemStableFabric extends Item { //if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ)==properties.RiftBlockID) { - NewLinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); + NewLinkData link = PocketManager.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); if(link!=null) { Block var11; diff --git a/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java b/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java index c877d69..f5668e3 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java +++ b/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java @@ -16,7 +16,7 @@ import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; public class itemDimDoor extends ItemDoor { @@ -138,7 +138,7 @@ public class itemDimDoor extends ItemDoor { if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID) { - NewLinkData link = dimHelper.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); + NewLinkData link = PocketManager.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); if(link!=null) { Block var11; @@ -169,7 +169,7 @@ public class itemDimDoor extends ItemDoor int var12 = MathHelper.floor_double((double)((par3EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; if (!canPlace(par2World, par4, par5, par6, var12) || !canPlace(par2World, par4, par5-1, par6, var12) || - dimHelper.instance.getLinkDataFromCoords(par4, par5, par6, par2World) == null) + PocketManager.instance.getLinkDataFromCoords(par4, par5, par6, par2World) == null) { return par1ItemStack; } diff --git a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java index 6136038..0c19ba8 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java @@ -3,10 +3,10 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.List; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DimData; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.ILinkData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -69,7 +69,7 @@ public class itemLinkSignature extends Item public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { int key; - NewLinkData linkData; + ILinkData linkData; int thisWorldID=par3World.provider.dimensionId; @@ -118,13 +118,13 @@ public class itemLinkSignature extends Item for(int count = 0;count<3;count++) { - if(dimHelper.instance.getLinkDataFromCoords(par4, par5+count, par6,par3World)!=null) + if(PocketManager.instance.getLinkDataFromCoords(par4, par5+count, par6,par3World)!=null) { int id= (par3World.getBlockId(par4, par5+count, par6)); if(id == properties.DimensionalDoorID||id==properties.WarpDoorID||id== properties.UnstableDoorID) { - orientation = dimHelper.instance.getLinkDataFromCoords(par4, par5+count, par6,par3World).linkOrientation; + orientation = PocketManager.instance.getLinkDataFromCoords(par4, par5+count, par6,par3World).linkOrientation; } } @@ -139,8 +139,8 @@ public class itemLinkSignature extends Item - dimHelper.instance.createLink(par3World.provider.dimensionId, linkCoords[3], par4, par5+offset, par6, linkCoords[0], linkCoords[1], linkCoords[2],orientation); - dimHelper.instance.createLink(linkCoords[3], par3World.provider.dimensionId, linkCoords[0], linkCoords[1], linkCoords[2],par4, par5+offset, par6,linkCoords[4]); + PocketManager.instance.createLink(par3World.provider.dimensionId, linkCoords[3], par4, par5+offset, par6, linkCoords[0], linkCoords[1], linkCoords[2],orientation); + PocketManager.instance.createLink(linkCoords[3], par3World.provider.dimensionId, linkCoords[0], linkCoords[1], linkCoords[2],par4, par5+offset, par6,linkCoords[4]); @@ -155,7 +155,7 @@ public class itemLinkSignature extends Item //otherwise, it creates the first half of the link. Next click will complete it. - key= dimHelper.instance.createUniqueInterDimLinkKey(); + key= PocketManager.instance.createUniqueInterDimLinkKey(); this.writeToNBT(par1ItemStack, par4, par5+offset, par6,par3World.provider.dimensionId,orientation); par2EntityPlayer.sendChatToPlayer("Rift Signature Stored"); par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftStart", (float) .6, 1); @@ -183,7 +183,7 @@ public class itemLinkSignature extends Item { Integer[] coords = this.readFromNBT(par1ItemStack); - par3List.add(String.valueOf("Leads to dim "+coords[3] +" with depth "+(dimHelper.instance.getDimDepth(coords[3])))); + par3List.add(String.valueOf("Leads to dim "+coords[3] +" with depth "+(PocketManager.instance.getDimDepth(coords[3])))); par3List.add("at x="+coords[0]+" y="+coords[1]+" z="+coords[2]); } diff --git a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java index 8d15172..4058789 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java +++ b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java @@ -3,7 +3,7 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.List; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; @@ -83,7 +83,7 @@ public class itemRiftRemover extends Item if(hit!=null) { //System.out.println(hit.hitVec); - if(dimHelper.instance.removeRift(par2World, hit.blockX, hit.blockY, hit.blockZ, 1, par3EntityPlayer, par1ItemStack)) + if(PocketManager.instance.removeRift(par2World, hit.blockX, hit.blockY, hit.blockZ, 1, par3EntityPlayer, par1ItemStack)) { par3EntityPlayer.worldObj.playSoundAtEntity(par3EntityPlayer,"mods.DimDoors.sfx.riftClose", (float) .8, 1); diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index c8400b5..0ac2b10 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -33,9 +33,8 @@ 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.NewLinkData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; import StevenDimDoors.mod_pocketDim.items.ItemBlockDimWall; import StevenDimDoors.mod_pocketDim.items.ItemChaosDoor; import StevenDimDoors.mod_pocketDim.items.ItemRiftBlade; @@ -46,11 +45,13 @@ import StevenDimDoors.mod_pocketDim.items.itemExitDoor; import StevenDimDoors.mod_pocketDim.items.itemLinkSignature; import StevenDimDoors.mod_pocketDim.items.itemRiftRemover; import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; +import StevenDimDoors.mod_pocketDim.ticking.LimboDecay; import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; import StevenDimDoors.mod_pocketDim.ticking.MonolithSpawner; import StevenDimDoors.mod_pocketDim.ticking.RiftRegenerator; import StevenDimDoors.mod_pocketDim.world.BiomeGenLimbo; import StevenDimDoors.mod_pocketDim.world.BiomeGenPocket; +import StevenDimDoors.mod_pocketDim.world.GatewayGenerator; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; import StevenDimDoors.mod_pocketDimClient.ClientPacketHandler; @@ -99,8 +100,6 @@ public class mod_pocketDim @Instance("PocketDimensions") public static mod_pocketDim instance = new mod_pocketDim(); - public static pocketTeleporter teleporter; - public static Block transientDoor; public static Block ExitDoor; public static Block chaosDoor; @@ -127,12 +126,11 @@ public class mod_pocketDim public static HashMap> limboSpawnInventory = new HashMap>(); - public static boolean hasInitDims = false; public static boolean isPlayerWearingGoogles = false; public static DDProperties properties; public static MonolithSpawner spawner; //Added this field temporarily. Will be refactored out later. - public static RiftGenerator riftGen; + public static GatewayGenerator riftGen; public static long genTime; public static int teleTimer = 0; @@ -165,10 +163,8 @@ public class mod_pocketDim //These fields MUST be initialized after properties are loaded to prevent //instances from holding onto null references to the properties. - - teleporter = new pocketTeleporter(); tracker = new PlayerRespawnTracker(); - riftGen = new RiftGenerator(); + riftGen = new GatewayGenerator(); } @Init @@ -396,12 +392,7 @@ public class mod_pocketDim { try { - dimHelper.instance.save(); - dimHelper.instance.unregsisterDims(); - dimHelper.dimList.clear(); - dimHelper.blocksToDecay.clear(); - dimHelper.instance.interDimLinkList.clear(); - mod_pocketDim.hasInitDims=false; + PocketManager.unload(); } catch(Exception e) { @@ -409,7 +400,6 @@ public class mod_pocketDim } } - @ServerStarting public void serverStarting(FMLServerStartingEvent event) { @@ -423,13 +413,6 @@ public class mod_pocketDim CommandPruneDimensions.instance().register(event); CommandCreatePocket.instance().register(event); CommandTeleportPlayer.instance().register(event); - dimHelper.instance.load(); - - if(!dimHelper.dimList.containsKey(properties.LimboDimensionID)) - { - dimHelper.dimList.put(properties.LimboDimensionID, new DimData( properties.LimboDimensionID, false, 0, new NewLinkData())); - } + PocketManager.load(); } - - } diff --git a/StevenDimDoors/mod_pocketDim/pocketTeleporter.java b/StevenDimDoors/mod_pocketDim/pocketTeleporter.java deleted file mode 100644 index 1f3e92f..0000000 --- a/StevenDimDoors/mod_pocketDim/pocketTeleporter.java +++ /dev/null @@ -1,226 +0,0 @@ -package StevenDimDoors.mod_pocketDim; - -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; -import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EntityMinecart; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.Teleporter; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; - -public class pocketTeleporter -{ - int x,y,z; - - NewLinkData sendingLink; - - - public pocketTeleporter() - - { - - - - } - - - /** - * Create a new portal near an entity. - */ - - public void placeInPortal(Entity par1Entity, WorldServer world, NewLinkData link) - { - - - this.x=link.destXCoord; - this.y=link.destYCoord; - this.z=link.destZCoord; - - this.sendingLink=link; - - int id; - - //TODO Temporary workaround for mismatched door/rift metadata cases. Gives priority to the door. - id=dimHelper.instance.getDestOrientation(sendingLink); - int receivingDoorMeta=world.getBlockMetadata(link.destXCoord, link.destYCoord-1, link.destZCoord); - int recevingDoorID=world.getBlockId(link.destXCoord, link.destYCoord, link.destZCoord); - if(receivingDoorMeta!=id) - { - if(recevingDoorID==mod_pocketDim.dimDoor.blockID||recevingDoorID==mod_pocketDim.ExitDoor.blockID) - { - dimHelper.instance.getLinkDataFromCoords(link.destXCoord, link.destYCoord, link.destZCoord, world).linkOrientation=receivingDoorMeta; - id=receivingDoorMeta; - - } - } - - - - if(par1Entity instanceof EntityPlayer) - { - EntityPlayer player = (EntityPlayer) par1Entity; - - - - - //System.out.println("Teleporting with link oreintation "+id); - - - player.rotationYaw=(id*90)+90; - if(id==2||id==6) - { - player.setPositionAndUpdate( x+1.5, y-1, z+.5 ); - - - } - else if(id==3||id==7) - { - - player.setPositionAndUpdate( x+.5, y-1, z+1.5 ); - - - } - else if(id==0||id==4) - { - - player.setPositionAndUpdate(x-.5, y-1, z+.5); - - } - else if(id==1||id==5) - { - player.setPositionAndUpdate(x+.5, y-1, z-.5); - - - } - else - { - player.setPositionAndUpdate(x, y-1, z); - - } - - - - } - - else if(par1Entity instanceof EntityMinecart) - { - par1Entity.motionX=0; - par1Entity.motionZ=0; - par1Entity.motionY=0; - - - - par1Entity.rotationYaw=(id*90)+90; - - if(id==2||id==6) - { - - - this.setEntityPosition(par1Entity, x+1.5, y, z+.5 ); - par1Entity.motionX =.39; - par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false); - - } - else if(id==3||id==7) - { - - - this.setEntityPosition(par1Entity, x+.5, y, z+1.5 ); - par1Entity.motionZ =.39; - par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false); - - - - } - else if(id==0||id==4) - { - - - this.setEntityPosition(par1Entity,x-.5, y, z+.5); - par1Entity.motionX =-.39; - par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false); - - - } - else if(id==1||id==5) - { - - this.setEntityPosition(par1Entity,x+.5, y, z-.5); - par1Entity.motionZ =-.39; - par1Entity.worldObj.updateEntityWithOptionalForce(par1Entity, false); - - - } - else - { - this.setEntityPosition(par1Entity,x, y, z); - - } - - - - - } - - - else if(par1Entity instanceof Entity) - { - - //System.out.println("Teleporting with link oreintation "+id); - - - par1Entity.rotationYaw=(id*90)+90; - - // EntityMinecart.class.cast(par1Entity).isinreverse=false; - if(id==2||id==6) - { - this.setEntityPosition(par1Entity, x+1.5, y, z+.5 ); - - - } - else if(id==3||id==7) - { - - this.setEntityPosition(par1Entity, x+.5, y, z+1.5 ); - - - } - else if(id==0||id==4) - { - - this.setEntityPosition(par1Entity,x-.5, y, z+.5); - - } - else if(id==1||id==5) - { - this.setEntityPosition(par1Entity,x+.5, y, z-.5); - - - } - else - { - this.setEntityPosition(par1Entity,x, y, z); - - } - - - - - } - - } - - public void setEntityPosition(Entity entity, double x, double y, double z) - { - entity.lastTickPosX = entity.prevPosX = entity.posX = x; - entity.lastTickPosY = entity.prevPosY = entity.posY = y + (double)entity.yOffset; - entity.lastTickPosZ = entity.prevPosZ = entity.posZ = z; - entity.setPosition(x, y, z); - } - - - - - -} diff --git a/StevenDimDoors/mod_pocketDim/LimboDecay.java b/StevenDimDoors/mod_pocketDim/ticking/LimboDecay.java similarity index 94% rename from StevenDimDoors/mod_pocketDim/LimboDecay.java rename to StevenDimDoors/mod_pocketDim/ticking/LimboDecay.java index 8038541..999c813 100644 --- a/StevenDimDoors/mod_pocketDim/LimboDecay.java +++ b/StevenDimDoors/mod_pocketDim/ticking/LimboDecay.java @@ -1,4 +1,4 @@ -package StevenDimDoors.mod_pocketDim; +package StevenDimDoors.mod_pocketDim.ticking; import java.util.Random; @@ -6,9 +6,8 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; -import StevenDimDoors.mod_pocketDim.ticking.IRegularTickReceiver; -import StevenDimDoors.mod_pocketDim.ticking.IRegularTickSender; +import net.minecraftforge.common.DimensionManager; +import StevenDimDoors.mod_pocketDim.DDProperties; /** * Provides methods for applying Limbo decay. Limbo decay refers to the effect that most blocks placed in Limbo @@ -81,7 +80,7 @@ public class LimboDecay implements IRegularTickReceiver { int x, y, z; int sectionY; int limboHeight; - World limbo = dimHelper.getWorld(properties.LimboDimensionID); + World limbo = DimensionManager.getWorld(properties.LimboDimensionID); if (limbo != null) { diff --git a/StevenDimDoors/mod_pocketDim/ticking/LimboGatewayGenerator.java b/StevenDimDoors/mod_pocketDim/ticking/LimboGatewayGenerator.java index 34536d4..3908bc9 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/LimboGatewayGenerator.java +++ b/StevenDimDoors/mod_pocketDim/ticking/LimboGatewayGenerator.java @@ -8,8 +8,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.world.GameRules; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.util.ChunkLocation; diff --git a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java index 536c0b7..d102596 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java +++ b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java @@ -14,7 +14,7 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; @@ -173,7 +173,7 @@ public class MobMonolith extends EntityFlying implements IMob NewLinkData link = new NewLinkData(this.worldObj.provider.dimensionId, properties.LimboDimensionID, (int)this.posX, (int)this.posY, (int)this.posZ, (int)this.posX+rand.nextInt(500)-250, (int)this.posY+500, (int)this.posZ+rand.nextInt(500)-250, false,0); - dimHelper.instance.traverseDimDoor(worldObj, link, entityPlayer); + PocketManager.instance.traverseDimDoor(worldObj, link, entityPlayer); this.aggro=0; entityPlayer.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.crack",13, 1); diff --git a/StevenDimDoors/mod_pocketDim/ticking/MonolithSpawner.java b/StevenDimDoors/mod_pocketDim/ticking/MonolithSpawner.java index 49c6292..59f8fb5 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/MonolithSpawner.java +++ b/StevenDimDoors/mod_pocketDim/ticking/MonolithSpawner.java @@ -7,9 +7,10 @@ import net.minecraft.entity.Entity; import net.minecraft.server.MinecraftServer; import net.minecraft.world.GameRules; import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.util.ChunkLocation; @@ -69,23 +70,24 @@ public class MonolithSpawner implements IRegularTickReceiver { private void placeMonolithsInPocket(int dimensionID, int chunkX, int chunkZ) { - World pocket = dimHelper.getWorld(dimensionID); - DimData dimData = dimHelper.instance.getDimData(dimensionID); + NewDimData dimension = PocketManager.getDimensionData(dimensionID); + World pocket = DimensionManager.getWorld(dimensionID); + + if (pocket == null || + dimension == null || + dimension.dungeon() == null || + dimension.dungeon().isOpen()) + { + return; + } + int sanity = 0; int blockID = 0; boolean didSpawn = false; - if (pocket == null || - dimData == null || - dimData.dungeonGenerator == null || - dimData.dungeonGenerator.isOpen) - { - return; - } - //The following initialization code is based on code from ChunkProviderGenerate. //It makes our generation depend on the world seed. - Random random = new Random(pocket.getSeed()); + Random random = new Random(pocket.getSeed() ^ 0xA210FE65F20017D6L); long factorA = random.nextLong() / 2L * 2L + 1L; long factorB = random.nextLong() / 2L * 2L + 1L; random.setSeed(chunkX * factorA + chunkZ * factorB ^ pocket.getSeed()); @@ -139,7 +141,7 @@ public class MonolithSpawner implements IRegularTickReceiver { private void placeMonolithsInLimbo(int dimensionID, int chunkX, int chunkZ) { - World limbo = dimHelper.getWorld(dimensionID); + World limbo = DimensionManager.getWorld(dimensionID); if (limbo == null) { @@ -148,7 +150,7 @@ public class MonolithSpawner implements IRegularTickReceiver { //The following initialization code is based on code from ChunkProviderGenerate. //It makes our generation depend on the world seed. - Random random = new Random(limbo.getSeed()); + Random random = new Random(limbo.getSeed() ^ 0xB5130C4ACC71A822L); long factorA = random.nextLong() / 2L * 2L + 1L; long factorB = random.nextLong() / 2L * 2L + 1L; random.setSeed(chunkX * factorA + chunkZ * factorB ^ limbo.getSeed()); diff --git a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index b840e48..6fb2ff1 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -1,18 +1,22 @@ package StevenDimDoors.mod_pocketDim.ticking; import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.util.Point4D; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; public class RiftRegenerator implements IRegularTickReceiver { - private static final int RIFT_REGENERATION_INTERVAL = 100; //Regenerate random rifts every 100 ticks - + private static final int RIFT_REGENERATION_INTERVAL = 200; //Regenerate random rifts every 200 ticks + private static final int RIFTS_REGENERATED_PER_DIMENSION = 5; + private DDProperties properties; public RiftRegenerator(IRegularTickSender sender, DDProperties properties) @@ -24,49 +28,33 @@ public class RiftRegenerator implements IRegularTickReceiver { @Override public void notifyTick() { - regenerate(); + regenerateRiftsInAllWorlds(); } - - private void regenerate() + + public static void regenerateRiftsInAllWorlds() { - try - { - //Regenerate rifts that have been replaced (not permanently removed) by players - - int i = 0; - - while (i < 15 && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) + //Regenerate rifts that have been replaced (not permanently removed) by players + DDProperties properties = DDProperties.instance(); + + for (NewDimData dimension : PocketManager.getDimensions()) + { + if (dimension.linkCount() > 0) { - i++; - NewLinkData link; - - //actually gets the random rift based on the size of the list - link = (NewLinkData) dimHelper.instance.getRandomLinkData(true); - - if (link != null) - { - World world = dimHelper.getWorld(link.locDimID); - - if (world != null && !mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord)) - { - if (dimHelper.instance.getLinkDataFromCoords(link.locXCoord, link.locYCoord, link.locZCoord, link.locDimID) != null) - { - world.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); - TileEntityRift rift = (TileEntityRift) world.getBlockTileEntity(link.locXCoord, link.locYCoord, link.locZCoord); - if (rift == null) - { - dimHelper.getWorld(link.locDimID).setBlockTileEntity(link.locXCoord, link.locYCoord, link.locZCoord, new TileEntityRift()); - } - rift.hasGrownRifts = true; - } - } - } + World world = DimensionManager.getWorld(dimension.id()); + + if (world != null) + { + for (int count = 0; count < RIFTS_REGENERATED_PER_DIMENSION; count++) + { + IDimLink link = dimension.getRandomLink(); + Point4D source = link.source(); + if (!mod_pocketDim.blockRift.isBlockImmune(world, source.getX(), source.getY(), source.getZ())) + { + world.setBlock(source.getX(), source.getY(), source.getZ(), properties.RiftBlockID); + } + } + } } - } - catch (Exception e) - { - System.err.println("An exception occurred in RiftRegenerator.regenerate():"); - e.printStackTrace(); - } + } } } diff --git a/StevenDimDoors/mod_pocketDim/util/Point4D.java b/StevenDimDoors/mod_pocketDim/util/Point4D.java index ca4dd89..e8c6214 100644 --- a/StevenDimDoors/mod_pocketDim/util/Point4D.java +++ b/StevenDimDoors/mod_pocketDim/util/Point4D.java @@ -1,7 +1,7 @@ package StevenDimDoors.mod_pocketDim.util; -public final class Point4D +public final class Point4D implements Comparable { private final int x; private final int y; @@ -135,6 +135,21 @@ public final class Point4D return (x == other.x && y == other.y && z == other.z && dimension == other.dimension); } + @Override + public int compareTo(Point4D other) + { + int diff = x - other.x; + if (diff != 0) + return diff; + diff = y - other.y; + if (diff != 0) + return diff; + diff = z - other.z; + if (diff != 0) + return diff; + return dimension - other.dimension; + } + @Override public String toString() { diff --git a/StevenDimDoors/mod_pocketDim/RiftGenerator.java b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java similarity index 86% rename from StevenDimDoors/mod_pocketDim/RiftGenerator.java rename to StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java index 5b02031..db56e71 100644 --- a/StevenDimDoors/mod_pocketDim/RiftGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java @@ -1,4 +1,4 @@ -package StevenDimDoors.mod_pocketDim; +package StevenDimDoors.mod_pocketDim.world; import java.util.Random; @@ -7,14 +7,15 @@ import net.minecraft.block.material.Material; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; import net.minecraftforge.common.DimensionManager; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.items.itemDimDoor; -import StevenDimDoors.mod_pocketDim.world.LimboProvider; -import StevenDimDoors.mod_pocketDim.world.PocketProvider; import cpw.mods.fml.common.IWorldGenerator; -public class RiftGenerator implements IWorldGenerator +public class GatewayGenerator implements IWorldGenerator { public static final int MAX_GATEWAY_GENERATION_CHANCE = 10000; public static final int MAX_CLUSTER_GENERATION_CHANCE = 10000; @@ -30,7 +31,7 @@ public class RiftGenerator implements IWorldGenerator private static final int NETHER_DIMENSION_ID = -1; private static DDProperties properties = null; - public RiftGenerator() + public GatewayGenerator() { if (properties == null) properties = DDProperties.instance(); @@ -47,7 +48,7 @@ public class RiftGenerator implements IWorldGenerator return; } //This check prevents a crash related to superflat worlds not loading World 0 - if (dimHelper.getWorld(OVERWORLD_DIMENSION_ID) == null) + if (DimensionManager.getWorld(OVERWORLD_DIMENSION_ID) == null) { return; } @@ -56,7 +57,8 @@ public class RiftGenerator implements IWorldGenerator int attempts; int correction; boolean valid; - NewLinkData link; + IDimLink link; + NewDimData dimension; //Check if we're generating things in the Nether if (world.provider.dimensionId == NETHER_DIMENSION_ID) @@ -76,6 +78,7 @@ public class RiftGenerator implements IWorldGenerator if (random.nextInt(MAX_CLUSTER_GENERATION_CHANCE) < properties.ClusterGenerationChance) { link = null; + dimension = null; do { //Pick a random point on the surface of the chunk @@ -90,16 +93,15 @@ public class RiftGenerator implements IWorldGenerator world.getBlockId(x, y - 1, z) != Block.bedrock.blockID && world.getBlockId(x, y - 2, z) != Block.bedrock.blockID) { - //Create a link. If this is the first time, create a dungeon pocket and create a two-way link. - //Otherwise, create a one-way link and connect to the destination of the first link. + //Create a link. If this is not the first time, create a child link and connect it to the first link. if (link == null) { - link = new NewLinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 0); - link = dimHelper.instance.createPocket(link, true, true); + dimension = PocketManager.getDimensionData(world); + link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); } else { - link = dimHelper.instance.createLink(link.locDimID, link.destDimID, x, y + 1, z, link.destXCoord, link.destYCoord, link.destZCoord); + dimension.createChildLink(x, y + 1, z, link); } } } @@ -128,13 +130,12 @@ public class RiftGenerator implements IWorldGenerator //Build the gateway if we found a valid location if (valid) { - //Create a two-way link between the upper block of the gateway and a pocket dimension - //That pocket dimension is where we'll start a dungeon! - link = new NewLinkData(world.provider.dimensionId, 0, x, y + 1, z, x, y + 1, z, true, 0); - link = dimHelper.instance.createPocket(link, true, true); + //Create a partial link to a dungeon. + dimension = PocketManager.getDimensionData(world); + link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_DUNGEON); //If the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks - if (world.provider.dimensionId != properties.LimboDimensionID) + if (dimension.id() != properties.LimboDimensionID) { createStoneGateway(world, x, y, z, random); } diff --git a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java new file mode 100644 index 0000000..e880ce6 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -0,0 +1,422 @@ +package StevenDimDoors.mod_pocketDim.world; + +import java.util.HashMap; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import net.minecraftforge.common.DimensionManager; +import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.Point3D; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; +import StevenDimDoors.mod_pocketDim.dungeon.DungeonSchematic; +import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; +import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; +import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; +import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public class PocketBuilder +{ + public static final int MIN_POCKET_SIZE = 5; + public static final int MAX_POCKET_SIZE = 51; + public static final int DEFAULT_POCKET_SIZE = 39; + + public static final int MIN_POCKET_WALL_THICKNESS = 1; + public static final int MAX_POCKET_WALL_THICKNESS = 10; + public static final int DEFAULT_POCKET_WALL_THICKNESS = 5; + + private static final Random random = new Random(); + + private PocketBuilder() { } + + public static boolean initializeDestination(IDimLink link, DDProperties properties) + { + if (link.hasDestination()) + { + return true; + } + + //Check the destination type and respond accordingly + switch (link.linkType()) + { + case IDimLink.TYPE_DUNGEON: + return generateNewDungeonPocket(link, properties); + case IDimLink.TYPE_POCKET: + return generateNewPocket(link, properties); + default: + throw new IllegalArgumentException("link has an unrecognized link type."); + } + } + + public static boolean generateNewDungeonPocket(IDimLink link, DDProperties properties) + { + if (link == null) + { + throw new IllegalArgumentException("link cannot be null."); + } + if (properties == null) + { + throw new IllegalArgumentException("properties cannot be null."); + } + if (link.hasDestination()) + { + throw new IllegalArgumentException("link cannot have a destination assigned already."); + } + + try + { + //Register a new dimension + NewDimData parent = PocketManager.getDimensionData(link.source().getDimension()); + NewDimData dimension = PocketManager.registerPocket(parent, false); + + //Load a world + World world = DimensionManager.getWorld(dimension.id()); + + if (world == null) + { + DimensionManager.initDimension(dimension.id()); + world = DimensionManager.getWorld(dimension.id()); + } + if (world != null && world.provider == null) + { + DimensionManager.initDimension(dimension.id()); + } + if (world == null || world.provider == null) + { + System.err.println("Could not initialize dimension for a dungeon!"); + return false; + } + + /* This code is currently wrong. It's missing the following things: + * 1. Calculate the destination point for real. That includes adding door noise if needed. + * 2. Receive the DungeonData from selectDungeon() + * 3. The function signature for DungeonSchematic.copyToWorld() has to be rewritten. + */ + + //Choose a dungeon to generate + DungeonSchematic schematic = selectDungeon(dimension, random, properties); + + if (schematic == null) + { + System.err.println("Could not select a dungeon for generation!"); + return false; + } + + //Calculate the destination point + Point4D source = link.source(); + int destinationY = yCoordHelper.adjustDestinationY(destination, world.getHeight(), schematic.getEntranceDoorLocation().getY(), schematic.getHeight()); + int orientation = getDestinationOrientation(source); + destination.setY(destinationY); + + //Generate the dungeon + DungeonPackConfig packConfig = dungeon.dungeonType().Owner != null ? dungeon.dungeonType().Owner.getConfig() : null; + + schematic.copyToWorld(world, link, packConfig.doDistortDoorCoordinates()); + + //Finish up destination initialization + dimension.initializePocket(destination.getX(), destination.getY(), destination.getZ(), orientation, link); + dimension.setFilled(true); + return true; + } + catch (Exception e) + { + e.printStackTrace(); + return false; + } + } + + private static DungeonSchematic selectDungeon(NewDimData dimension, Random random, DDProperties properties) + { + //We assume the dimension doesn't have a dungeon assigned + if (dimension.dungeon() != null) + { + throw new IllegalArgumentException("dimension cannot have a dungeon assigned already."); + } + + DungeonData dungeon = null; + DungeonSchematic schematic = null; + + dungeon = DungeonHelper.instance().selectDungeon(dimension, random); + + if (dungeon != null) + { + schematic = loadAndValidateDungeon(dungeon, properties); + } + else + { + System.err.println("Could not select a dungeon at all!"); + } + + if (schematic == null) + { + //TODO: In the future, remove this dungeon from the generation lists altogether. + //That will have to wait until our code is updated to support that more easily. + + try + { + System.err.println("Loading the default error dungeon instead..."); + dungeon = DungeonHelper.instance().getDefaultErrorDungeon(); + schematic = loadAndValidateDungeon(dungeon, properties); + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + return schematic; + } + + private static DungeonSchematic loadAndValidateDungeon(DungeonData dungeon, DDProperties properties) + { + try + { + DungeonSchematic schematic = dungeon.loadSchematic(); + + //Validate the dungeon's dimensions + if (hasValidDimensions(schematic)) + { + schematic.applyImportFilters(properties); + + //Check that the dungeon has an entrance or we'll have a crash + if (schematic.getEntranceDoorLocation() == null) + { + System.err.println("The following schematic file does not have an entrance: " + dungeon.schematicPath()); + return null; + } + } + else + { + System.err.println("The following schematic file has dimensions that exceed the maximum permitted dimensions for dungeons: " + dungeon.schematicPath()); + return null; + } + return schematic; + } + catch (Exception e) + { + System.err.println("An error occurred while loading the following schematic: " + dungeon.schematicPath()); + System.err.println(e.getMessage()); + return null; + } + } + + private static boolean hasValidDimensions(DungeonSchematic schematic) + { + return (schematic.getWidth() <= DungeonHelper.MAX_DUNGEON_WIDTH && + schematic.getHeight() <= DungeonHelper.MAX_DUNGEON_HEIGHT && + schematic.getLength() <= DungeonHelper.MAX_DUNGEON_LENGTH); + } + + public static boolean generateNewPocket(IDimLink link, DDProperties properties) + { + return generateNewPocket(link, DEFAULT_POCKET_SIZE, DEFAULT_POCKET_WALL_THICKNESS, properties); + } + + private static int getDestinationOrientation(Point4D source) + { + // TODO Auto-generated method stub + return 0; + } + + public static boolean generateNewPocket(IDimLink link, int size, int wallThickness, DDProperties properties) + { + if (link == null) + { + throw new IllegalArgumentException(); + } + if (properties == null) + { + throw new IllegalArgumentException("properties cannot be null."); + } + if (link.hasDestination()) + { + throw new IllegalArgumentException("link cannot have a destination assigned already."); + } + + if (size < MIN_POCKET_SIZE || size > MAX_POCKET_SIZE) + { + throw new IllegalArgumentException("size must be between " + MIN_POCKET_SIZE + " and " + MAX_POCKET_SIZE + ", inclusive."); + } + if (wallThickness < MIN_POCKET_WALL_THICKNESS || wallThickness > MAX_POCKET_WALL_THICKNESS) + { + throw new IllegalArgumentException("wallThickness must be between " + MIN_POCKET_WALL_THICKNESS + " and " + MAX_POCKET_WALL_THICKNESS + ", inclusive."); + } + if (size % 2 == 0) + { + throw new IllegalArgumentException("size must be an odd number."); + } + if (size < 2 * wallThickness + 3) + { + throw new IllegalArgumentException("size must be large enough to fit the specified wall thickness and some air space."); + } + + try + { + //Register a new dimension + NewDimData parent = PocketManager.getDimensionData(link.source().getDimension()); + NewDimData dimension = PocketManager.registerPocket(parent, false); + + //Load a world + World world = DimensionManager.getWorld(dimension.id()); + + if (world == null) + { + DimensionManager.initDimension(dimension.id()); + world = DimensionManager.getWorld(dimension.id()); + } + if (world != null && world.provider == null) + { + DimensionManager.initDimension(dimension.id()); + } + if (world == null || world.provider == null) + { + System.err.println("Could not initialize dimension for a pocket!"); + return false; + } + + //Calculate the destination point + Point4D source = link.source(); + int destinationY = yCoordHelper.adjustDestinationY(source.getY(), world.getHeight(), wallThickness + 1, size); + int orientation = getDestinationOrientation(source); + + //Build the actual pocket area + buildPocket(world, source.getX(), destinationY, source.getZ(), orientation, size, wallThickness, properties); + + //Finish up destination initialization + dimension.initializePocket(source.getX(), destinationY, source.getZ(), orientation, link); + dimension.setFilled(true); + return true; + } + catch (Exception e) + { + e.printStackTrace(); + return false; + } + } + + private static void buildPocket(World world, int x, int y, int z, int orientation, int size, int wallThickness, DDProperties properties) + { + if (properties == null) + { + throw new IllegalArgumentException("properties cannot be null."); + } + if (size < MIN_POCKET_SIZE || size > MAX_POCKET_SIZE) + { + throw new IllegalArgumentException("size must be between " + MIN_POCKET_SIZE + " and " + MAX_POCKET_SIZE + ", inclusive."); + } + if (wallThickness < MIN_POCKET_WALL_THICKNESS || wallThickness > MAX_POCKET_WALL_THICKNESS) + { + throw new IllegalArgumentException("wallThickness must be between " + MIN_POCKET_WALL_THICKNESS + " and " + MAX_POCKET_WALL_THICKNESS + ", inclusive."); + } + if (size % 2 == 0) + { + throw new IllegalArgumentException("size must be an odd number."); + } + if (size < 2 * wallThickness + 3) + { + throw new IllegalArgumentException("size must be large enough to fit the specified wall thickness and some air space."); + } + + Point3D center = new Point3D(x - wallThickness + 1 + (size / 2), y - wallThickness - 1 + (size / 2), z); + Point3D door = new Point3D(x, y, z); + BlockRotator.transformPoint(center, door, orientation - BlockRotator.EAST_DOOR_METADATA, door); + + //Build the outer layer of Eternal Fabric + buildBox(world, center.getX(), center.getY(), center.getZ(), (size / 2), properties.PermaFabricBlockID, false, 0); + + //Build the (wallThickness - 1) layers of Fabric of Reality + for (int layer = 1; layer < wallThickness; layer++) + { + buildBox(world, center.getX(), center.getY(), center.getZ(), (size / 2) - layer, properties.FabricBlockID, + layer < (wallThickness - 1) && properties.TNFREAKINGT_Enabled, properties.NonTntWeight); + } + + //Build the door + int metadata = BlockRotator.transformMetadata(BlockRotator.EAST_DOOR_METADATA, orientation - BlockRotator.EAST_DOOR_METADATA, properties.DimensionalDoorID); + setBlockDirectly(world, x, y, z, properties.DimensionalDoorID, metadata); + setBlockDirectly(world, x, y - 1, z, properties.DimensionalDoorID, metadata); + } + + private static void buildBox(World world, int centerX, int centerY, int centerZ, int radius, int blockID, boolean placeTnt, int nonTntWeight) + { + int x, y, z; + + final int startX = centerX - radius; + final int startY = centerY - radius; + final int startZ = centerZ - radius; + + final int endX = centerX + radius; + final int endY = centerY + radius; + final int endZ = centerZ + radius; + + //Build faces of the box + for (x = startX; x <= endX; x++) + { + for (z = startZ; z <= endZ; z++) + { + setBlockDirectlySpecial(world, x, startY, z, blockID, 0, placeTnt, nonTntWeight); + setBlockDirectlySpecial(world, x, endY, z, blockID, 0, placeTnt, nonTntWeight); + } + + for (y = startY; y <= endY; y++) + { + setBlockDirectlySpecial(world, x, y, startZ, blockID, 0, placeTnt, nonTntWeight); + setBlockDirectlySpecial(world, x, y, endZ, blockID, 0, placeTnt, nonTntWeight); + } + } + + for (y = startY; y <= endY; y++) + { + for (z = startZ; z <= endZ; z++) + { + setBlockDirectlySpecial(world, startX, y, z, blockID, 0, placeTnt, nonTntWeight); + setBlockDirectlySpecial(world, endX, y, z, blockID, 0, placeTnt, nonTntWeight); + } + } + } + + private static void setBlockDirectlySpecial(World world, int x, int y, int z, int blockID, int metadata, boolean placeTnt, int nonTntWeight) + { + if (placeTnt && random.nextInt(nonTntWeight + 1) == 0) + { + setBlockDirectly(world, x, y, z, Block.tnt.blockID, 1); + } + else + { + setBlockDirectly(world, x, y, z, blockID, metadata); + } + } + + private static void setBlockDirectly(World world, int x, int y, int z, int blockID, int metadata) + { + if (blockID != 0 && Block.blocksList[blockID] == null) + { + return; + } + + int cX = x >> 4; + int cZ = z >> 4; + int cY = y >> 4; + Chunk chunk; + + int localX = (x % 16) < 0 ? (x % 16) + 16 : (x % 16); + int localZ = (z % 16) < 0 ? (z % 16) + 16 : (z % 16); + ExtendedBlockStorage extBlockStorage; + + chunk = world.getChunkFromChunkCoords(cX, cZ); + extBlockStorage = chunk.getBlockStorageArray()[cY]; + if (extBlockStorage == null) + { + extBlockStorage = new ExtendedBlockStorage(cY << 4, !world.provider.hasNoSky); + chunk.getBlockStorageArray()[cY] = extBlockStorage; + } + extBlockStorage.setExtBlockID(localX, y & 15, localZ, blockID); + extBlockStorage.setExtBlockMetadata(localX, y & 15, localZ, metadata); + } +} diff --git a/StevenDimDoors/mod_pocketDim/world/PocketGenerator.java b/StevenDimDoors/mod_pocketDim/world/PocketGenerator.java index bdf9b72..fd34184 100644 --- a/StevenDimDoors/mod_pocketDim/world/PocketGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/PocketGenerator.java @@ -8,8 +8,8 @@ import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.ChunkProviderGenerate; -import StevenDimDoors.mod_pocketDim.DimData; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.ticking.MonolithSpawner; public class PocketGenerator extends ChunkProviderGenerate implements IChunkProvider @@ -69,16 +69,10 @@ public class PocketGenerator extends ChunkProviderGenerate implements IChunkProv @Override public List getPossibleCreatures(EnumCreatureType var1, int var2, int var3, int var4) { - DimData data = dimHelper.instance.getDimData(this.worldObj.provider.dimensionId); - if (data != null) + NewDimData dimension = PocketManager.getDimensionData(this.worldObj); + if (dimension != null && dimension.dungeon() != null && !dimension.dungeon().isOpen()) { - if (data.dungeonGenerator != null) - { - if (data.isDimRandomRift && data.isPocket && !data.dungeonGenerator.isOpen) - { - return this.worldObj.getBiomeGenForCoords(var2, var3).getSpawnableList(var1); - } - } + return this.worldObj.getBiomeGenForCoords(var2, var3).getSpawnableList(var1); } return null; } diff --git a/StevenDimDoors/mod_pocketDim/world/PocketProvider.java b/StevenDimDoors/mod_pocketDim/world/PocketProvider.java index 3d82d09..fa2087c 100644 --- a/StevenDimDoors/mod_pocketDim/world/PocketProvider.java +++ b/StevenDimDoors/mod_pocketDim/world/PocketProvider.java @@ -6,10 +6,11 @@ import net.minecraft.util.Vec3; import net.minecraft.world.WorldProvider; import net.minecraft.world.biome.WorldChunkManagerHell; import net.minecraft.world.chunk.IChunkProvider; +import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.CloudRenderBlank; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.ticking.MonolithSpawner; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -113,12 +114,12 @@ public class PocketProvider extends WorldProvider } else { - respawnDim = dimHelper.instance.getDimData(this.dimensionId).exitDimLink.destDimID; + respawnDim = PocketManager.getDimensionData(this.dimensionId).root().id(); } - if (dimHelper.getWorld(respawnDim) == null) + if (DimensionManager.getWorld(respawnDim) == null) { - dimHelper.initDimension(respawnDim); + DimensionManager.initDimension(respawnDim); } return respawnDim; } diff --git a/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java b/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java index 93f535d..416b3fe 100644 --- a/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java +++ b/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java @@ -1,6 +1,6 @@ package StevenDimDoors.mod_pocketDimClient; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.client.particle.EffectRenderer; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.renderer.Tessellator; @@ -98,7 +98,7 @@ public class ClosingRiftFX extends EntityFX float var16 = .8F; try { - if(dimHelper.instance.getDimData(this.worldObj.provider.dimensionId).isPocket) + if(PocketManager.instance.getDimData(this.worldObj.provider.dimensionId).isPocket) { var16=.4F; } diff --git a/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java b/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java index b242abd..0a8eb72 100644 --- a/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java +++ b/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java @@ -1,6 +1,6 @@ package StevenDimDoors.mod_pocketDimClient; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.client.particle.EffectRenderer; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.particle.EntityFireworkSparkFX; @@ -55,7 +55,7 @@ public class GoggleRiftFX extends EntityFireworkSparkFX float var16 = .0F; try { - if(dimHelper.instance.getDimData(this.worldObj.provider.dimensionId).isPocket) + if(PocketManager.instance.getDimData(this.worldObj.provider.dimensionId).isPocket) { var16=.7F; } diff --git a/StevenDimDoors/mod_pocketDimClient/RiftFX.java b/StevenDimDoors/mod_pocketDimClient/RiftFX.java index ee3b97a..0157b91 100644 --- a/StevenDimDoors/mod_pocketDimClient/RiftFX.java +++ b/StevenDimDoors/mod_pocketDimClient/RiftFX.java @@ -1,6 +1,6 @@ package StevenDimDoors.mod_pocketDimClient; -import StevenDimDoors.mod_pocketDim.helpers.dimHelper; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.client.particle.EffectRenderer; import net.minecraft.client.particle.EntityFX; import net.minecraft.client.particle.EntityFireworkSparkFX; @@ -112,7 +112,7 @@ public class RiftFX extends EntityFX try { - if(dimHelper.instance.getDimData(this.worldObj.provider.dimensionId).isPocket) + if(PocketManager.instance.getDimData(this.worldObj.provider.dimensionId).isPocket) { f14=.7F; } diff --git a/schematics/core/simpleStairsDown.schematic b/schematics/core/simpleStairsDown.schematic deleted file mode 100644 index 5dd2153231f8d0d1cff881a211757470eaef7f5d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1239 zcmb2|=3sz;w|D*Xg2N?_J#^NvSm^UB|AOcSKCcN@3tlalYPC(cJ7(gIz&EQdq=q`> zEGym?$jrG(_;K7!??1nORH|j(l|N|pugES+^=os{huarVepq9l+gJ5;_2GY8;!oW+ zXJueWSbpd37vUc@)wAoE7@`yFFZ(~Zc7vPY%w}w?w9#!{o zc)YAxdi&##NAG_6`eTt~-?G1%#&Uaqx0HLmUt(YRYtzhg|32MLEBf*L#m@qps-jEz zZs%uR?7q2}|M>I67uSpX`yHSBuyAMeyFa$SOYP6u?VDBmC-K|Ir*9sYKmAsB{=NOb zdDTzY=5%xv;N$JZC|JLWbL$EwRFp= zs<%e*+;>)`D&NSes(#I1d3!zU3#XlyF?&_7Z}SQ3y!WWSt>XWUN6ycUZf;$}bn>`1 z_gSq8HG4K)A(Hdv(j@(+wUHcPonbeowSqOj$tue`H<>#=EWgau+C2Yz(6*FMll#M` z&5AvD?(BQN_fvBv|2%m-wKZ+}t=jUcXY+qSB%_Qjc<&Q4Qk8#yE_LsN=VtTQZg{iY zLm13|e(-#*;%bLaA5S@L=2DSguVYFvhZz{}VHMxE&9~>D{apR>r;PP?elNEC_knG} z_x1PwettXqI>Q0>=D8;s%5FcHA9nref-NV#cCUGwo;`Q&*4-c9vMvZ)8X9`I_5Ry9 z29J;bcK_dXnyuL}FU)M>+^wf})rzKU+SB8!xwLg+Hlo-d4RZHckIT%Kym|6)K&WjH(qMhEBLT0mRv+ zzFAx-jy1Bxt?3EpNgH>X3Z6?QMXtG2;l*EFDf^qDuUU-_1th)T;Yd|0jnR8tvwd+!Eq`|H;}@;6+c zqdOyY{ttETKb-rsQ$=UK@&4D{uy=#^&89N(f2aHpTAk7|iaZjRG1c`w>&-<6XMYpl zC%xYpsPIhOgwn~n8RZZ6|NEl8LvGt?jnyYoqNn60)t-n-@4mIS*`;uD`IIhHP1XC;!971u)xX0>ZM7OGY)+(X$}$pCp@9H2w@3JE{%1U} L|B2*27bXS(91v(y diff --git a/schematics/core/simpleStairsUp.schematic b/schematics/core/simpleStairsUp.schematic deleted file mode 100644 index 6c9ef12f0105c90974d0acac8a5ade06811bc8f7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1112 zcmb2|=3sz;w|D*XqC+K)J)GQf>goUjk>Wd#0A5MiPTivh~JEtJTUxq%UsLQMq!~ z;JsOa!^(oFGrlSD`@jFFRLi>?KkJ3H`}`>F`gv0p%ln@@KK*cIv5`i+4FB`PL3Vre zp;j>5Iel=OJ;SZrx4*G7q-;9*x_HN1euft_eEBYvn^`*CzxjlrHhnVlm$`%l)=XT= zwL!UNxi!pSEOgm{K+77_ndYCSDl4?y!qko$jUE|9=)om2$}cqN=#4w zX7%o@{~O+zFMqna|NMUIJiY$qmtQx3dirITr2n(SmBw@L{AsODEwG!jx9av8@%=T| z&h*vKoYT8}^7QA2(?0E*xhK-*cS)7$ygvnhKP6d7&!5)3>HFoAdWGF*v;EIko)!)YbRW zKj_booAu)M?+RQ#6@P5RhR$aj^7p>$vWw{HuqVr2|&TDu*N4JPdRPoQt1z$HY-%2 za?hp!TWlL@_I%6ZW3cGP>y&{^ecHr-?b8(@VB3S)(-h=9AT% z*DReiM|b0g?LhwRxjE%=v6VOjP*U_CPljctxBX6(g*>o~>lb*3q&ZigG|D^uN{#)fRJ4WrbiSj|V z{<<&KAA+_5<^7DUHYdH3w)rI+^}}qZ&o_HXPP2+Hx%->1g~eTp%r2YmqqckY#Dr$| z`tQ9~mCKE0>KK9a-#aw@WQvOCK1HLMYi5CLbWxieIvM1s6DgarjD%F~3(WKh^L1-_ zBCRy} GCI$fh`Wkrv -- 2.39.5 From 8e8346864ef7297235195379a1f891f22f773dc2 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 30 Aug 2013 10:57:08 -0400 Subject: [PATCH 03/24] Fixed DungeonSchematic Modified DungeonSchematic to use the new link and dimension classes. --- .../dungeon/DungeonSchematic.java | 154 +++--------------- 1 file changed, 26 insertions(+), 128 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index 4c0eb59..ecfb71a 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -14,19 +14,19 @@ import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MathHelper; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.Point3D; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.schematic.CompoundFilter; import StevenDimDoors.mod_pocketDim.schematic.InvalidSchematicException; import StevenDimDoors.mod_pocketDim.schematic.ReplacementFilter; import StevenDimDoors.mod_pocketDim.schematic.Schematic; import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; +import StevenDimDoors.mod_pocketDim.util.Point4D; public class DungeonSchematic extends Schematic { @@ -167,10 +167,10 @@ public class DungeonSchematic extends Schematic { return new DungeonSchematic(Schematic.copyFromWorld(world, x, y, z, width, height, length, doCompactBounds)); } - public void copyToWorld(World world, Point3D pocketCenter, int dungeonOrientation, int originDimID, int destDimID, boolean doDistortCoordinates) + public void copyToWorld(World world, Point3D pocketCenter, int dungeonOrientation, IDimLink entryLink) { //TODO: This function is an improvised solution so we can get the release moving. In the future, - //we should generalize block tranformations and implement support for them at the level of Schematic, + //we should generalize block transformations and implement support for them at the level of Schematic, //then just use that support from DungeonSchematic instead of making this local fix. //It might be easiest to support transformations using a WorldOperation @@ -222,10 +222,10 @@ public class DungeonSchematic extends Schematic { world.setBlockTileEntity(pocketPoint.getX(), pocketPoint.getY(), pocketPoint.getZ(), TileEntity.createAndLoadEntity(tileTag)); } - setUpDungeon(world, pocketCenter, turnAngle, originDimID, destDimID, doDistortCoordinates); + setUpDungeon(PocketManager.getDimensionData(world), world, pocketCenter, turnAngle, entryLink); } - private void setUpDungeon(World world, Point3D pocketCenter, int turnAngle, int originDimID, int destDimID, boolean doDistortCoordinates) + private void setUpDungeon(NewDimData dimension, World world, Point3D pocketCenter, int turnAngle, IDimLink entryLink) { //The following Random initialization code is based on code from ChunkProviderGenerate. //It makes our generation depend on the world seed. @@ -244,18 +244,18 @@ public class DungeonSchematic extends Schematic { filler.apply(world, minCorner, maxCorner); //Set up entrance door rift - setUpEntranceDoorLink(world, entranceDoorLocation, turnAngle, pocketCenter); + createEntranceReverseLink(dimension, pocketCenter, entryLink); //Set up link data for dimensional doors for (Point3D location : dimensionalDoorLocations) { - setUpDimensionalDoorLink(world, location, entranceDoorLocation, turnAngle, pocketCenter, originDimID, destDimID, doDistortCoordinates, random); + createDimensionalDoorLink(dimension, location, entranceDoorLocation, turnAngle, pocketCenter); } //Set up link data for exit door for (Point3D location : exitDoorLocations) { - setUpExitDoorLink(world, location, entranceDoorLocation, turnAngle, pocketCenter, originDimID, destDimID, random); + createExitDoorLink(dimension, location, entranceDoorLocation, turnAngle, pocketCenter); } //Remove end portal frames and spawn Monoliths @@ -290,130 +290,28 @@ public class DungeonSchematic extends Schematic { } } - private static void setUpEntranceDoorLink(World world, Point3D entrance, int rotation, Point3D pocketCenter) + private static void createEntranceReverseLink(NewDimData dimension, Point3D pocketCenter, IDimLink entryLink) { - //Set the orientation of the rift exit - Point3D entranceRiftLocation = entrance.clone(); - BlockRotator.transformPoint(entranceRiftLocation, entrance, rotation, pocketCenter); - NewLinkData sideLink = PocketManager.instance.getLinkDataFromCoords( - entranceRiftLocation.getX(), - entranceRiftLocation.getY(), - entranceRiftLocation.getZ(), - world); - sideLink.linkOrientation = world.getBlockMetadata( - entranceRiftLocation.getX(), - entranceRiftLocation.getY() - 1, - entranceRiftLocation.getZ()); + IDimLink link = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ()); + Point4D destination = link.source(); + link.setDestination(destination.getX(), destination.getY(), destination.getZ(), + PocketManager.getDimensionData(destination.getDimension())); } - private static void setUpExitDoorLink(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter, int originDimID, int destDimID, Random random) + private static void createExitDoorLink(NewDimData dimension, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) { - try - { - //TODO: Hax, remove this later - DDProperties properties = DDProperties.instance(); - - //Transform doorLocation to the pocket coordinate system. - Point3D location = point.clone(); - BlockRotator.transformPoint(location, entrance, rotation, pocketCenter); - int blockDirection = world.getBlockMetadata(location.getX(), location.getY() - 1, location.getZ()); - Point3D linkDestination = location.clone(); - - NewLinkData randomLink = PocketManager.instance.getRandomLinkData(false); - NewLinkData sideLink = new NewLinkData(destDimID, - PocketManager.instance.getDimData(originDimID).exitDimLink.destDimID, - location.getX(), - location.getY(), - location.getZ(), - linkDestination.getX(), - linkDestination.getY() + 1, - linkDestination.getZ(), - true, blockDirection); - - if (sideLink.destDimID == properties.LimboDimensionID) - { - sideLink.destDimID = 0; - } - else if ((random.nextBoolean() && randomLink != null)) - { - sideLink.destDimID = randomLink.locDimID; - } - sideLink.destYCoord = yCoordHelper.getFirstUncovered(sideLink.destDimID, linkDestination.getX(), linkDestination.getY(), linkDestination.getZ())-1; - - if (sideLink.destYCoord < 5) - { - sideLink.destYCoord = 70; - } - sideLink.linkOrientation = world.getBlockMetadata(linkDestination.getX(), linkDestination.getY() - 1, linkDestination.getZ()); - - PocketManager.instance.createLink(sideLink); - /**dimHelper.instance.createLink(sideLink.destDimID , - sideLink.locDimID, - sideLink.destXCoord, - sideLink.destYCoord, - sideLink.destZCoord, - sideLink.locXCoord, - sideLink.locYCoord, - sideLink.locZCoord, - BlockRotator.transformMetadata(sideLink.linkOrientation, 2, Block.doorWood.blockID)); - **/ - - if (world.getBlockId(linkDestination.getX(), linkDestination.getY() - 3, linkDestination.getZ()) == properties.FabricBlockID) - { - setBlockDirectly(world, linkDestination.getX(), linkDestination.getY() - 2, linkDestination.getZ(), Block.stoneBrick.blockID, 0); - } - else - { - setBlockDirectly(world,linkDestination.getX(), linkDestination.getY() - 2, linkDestination.getZ(), - world.getBlockId(linkDestination.getX(), linkDestination.getY() - 3, linkDestination.getZ()), - world.getBlockMetadata(linkDestination.getX(), linkDestination.getY() - 3, linkDestination.getZ())); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - private static void setUpDimensionalDoorLink(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter, int originDimID, int destDimID, boolean applyNoise, Random random) - { - int depth = PocketManager.instance.getDimDepth(originDimID) + 1; - int forwardNoise; - int sidewaysNoise; - - if (applyNoise) - { - forwardNoise = MathHelper.getRandomIntegerInRange(random, -50 * depth, 150 * depth); - sidewaysNoise = MathHelper.getRandomIntegerInRange(random, -10 * depth, 10 * depth); - } - else - { - forwardNoise = 0; - sidewaysNoise = 0; - } - - //Transform doorLocation to the pocket coordinate system + //Transform the door's location to the pocket coordinate system Point3D location = point.clone(); BlockRotator.transformPoint(location, entrance, rotation, pocketCenter); - int blockDirection = world.getBlockMetadata(location.getX(), location.getY() - 1, location.getZ()); - - //Rotate the link destination noise to point in the same direction as the door exit - //and add it to the door's location. Use EAST as the reference orientation since linkDestination - //is constructed as if pointing East. - Point3D linkDestination = new Point3D(forwardNoise, 0, sidewaysNoise); - Point3D zeroPoint = new Point3D(0, 0, 0); - BlockRotator.transformPoint(linkDestination, zeroPoint, blockDirection - BlockRotator.EAST_DOOR_METADATA, location); - - //Create the link between our current door and its intended exit in destination pocket - NewLinkData sideLink = new NewLinkData(destDimID, 0, - location.getX(), - location.getY(), - location.getZ(), - linkDestination.getX(), - linkDestination.getY() + 1, - linkDestination.getZ(), - true, blockDirection); - PocketManager.instance.createPocket(sideLink, true, true); + dimension.createLink(location.getX(), location.getY(), location.getZ()).setLinkType(IDimLink.TYPE_DUNGEON_EXIT); + } + + private static void createDimensionalDoorLink(NewDimData dimension, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) + { + //Transform the door's location to the pocket coordinate system + Point3D location = point.clone(); + BlockRotator.transformPoint(location, entrance, rotation, pocketCenter); + dimension.createLink(location.getX(), location.getY(), location.getZ()).setLinkType(IDimLink.TYPE_DUNGEON); } private static void spawnMonolith(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) -- 2.39.5 From 993006877554a20a6d7599486311c0eb4cf983f5 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 30 Aug 2013 16:27:27 -0400 Subject: [PATCH 04/24] Fixed PocketBuilder and More 1. Changed DungeonSchematic to use an external instance of Random rather than initializing its own. 2. Created the Pair class, a strongly-typed tuple that was needed in PocketBuilder. 3. Added a missing calculation in NewDimData for setting the packDepth field during dungeon initialization. 4. Finished code missing in PocketBuilder. Changes listed above were needed for this. --- .../mod_pocketDim/core/NewDimData.java | 34 ++++++ .../dungeon/DungeonSchematic.java | 16 +-- StevenDimDoors/mod_pocketDim/util/Pair.java | 26 +++++ .../mod_pocketDim/world/PocketBuilder.java | 100 ++++++++++-------- 4 files changed, 122 insertions(+), 54 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/util/Pair.java diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 543ffba..f8c9941 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -9,6 +9,7 @@ import java.util.TreeMap; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; +import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; import StevenDimDoors.mod_pocketDim.util.Point4D; public abstract class NewDimData implements Serializable @@ -460,6 +461,39 @@ public abstract class NewDimData implements Serializable this.origin = link.destination(); this.orientation = orientation; this.dungeon = dungeon; + this.packDepth = calculatePackDepth(parent, dungeon); + } + + private static int calculatePackDepth(NewDimData parent, DungeonData current) + { + DungeonData predecessor = parent.dungeon(); + if (current == null) + { + throw new IllegalArgumentException("current cannot be null."); + } + if (predecessor == null) + { + return 1; + } + + DungeonPack predOwner = predecessor.dungeonType().Owner; + DungeonPack currentOwner = current.dungeonType().Owner; + if (currentOwner == null) + { + return 1; + } + if (predOwner == null) + { + return 1; + } + if (predOwner == currentOwner) + { + return parent.packDepth + 1; + } + else + { + return 1; + } } public void initializePocket(int originX, int originY, int originZ, int orientation, IDimLink link) diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index ecfb71a..ab6013a 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -167,15 +167,14 @@ public class DungeonSchematic extends Schematic { return new DungeonSchematic(Schematic.copyFromWorld(world, x, y, z, width, height, length, doCompactBounds)); } - public void copyToWorld(World world, Point3D pocketCenter, int dungeonOrientation, IDimLink entryLink) + public void copyToWorld(World world, Point3D pocketCenter, int dungeonOrientation, IDimLink entryLink, Random random) { //TODO: This function is an improvised solution so we can get the release moving. In the future, //we should generalize block transformations and implement support for them at the level of Schematic, //then just use that support from DungeonSchematic instead of making this local fix. //It might be easiest to support transformations using a WorldOperation - final int turnAngle = dungeonOrientation - orientation; - + final int turnAngle = dungeonOrientation - orientation; int index; int count; @@ -222,18 +221,11 @@ public class DungeonSchematic extends Schematic { world.setBlockTileEntity(pocketPoint.getX(), pocketPoint.getY(), pocketPoint.getZ(), TileEntity.createAndLoadEntity(tileTag)); } - setUpDungeon(PocketManager.getDimensionData(world), world, pocketCenter, turnAngle, entryLink); + setUpDungeon(PocketManager.getDimensionData(world), world, pocketCenter, turnAngle, entryLink, random); } - private void setUpDungeon(NewDimData dimension, World world, Point3D pocketCenter, int turnAngle, IDimLink entryLink) + private void setUpDungeon(NewDimData dimension, World world, Point3D pocketCenter, int turnAngle, IDimLink entryLink, Random random) { - //The following Random initialization code is based on code from ChunkProviderGenerate. - //It makes our generation depend on the world seed. - Random random = new Random(world.getSeed()); - long factorA = random.nextLong() / 2L * 2L + 1L; - long factorB = random.nextLong() / 2L * 2L + 1L; - random.setSeed(pocketCenter.getX() * factorB + pocketCenter.getZ() * factorA ^ world.getSeed()); - //Transform dungeon corners Point3D minCorner = new Point3D(0, 0, 0); Point3D maxCorner = new Point3D(width - 1, height - 1, length - 1); diff --git a/StevenDimDoors/mod_pocketDim/util/Pair.java b/StevenDimDoors/mod_pocketDim/util/Pair.java new file mode 100644 index 0000000..7e5f341 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/util/Pair.java @@ -0,0 +1,26 @@ +package StevenDimDoors.mod_pocketDim.util; + +public class Pair +{ + //Pair is an implementation of a 2-tuple with generic parameters for strongly-typed elements. + //It's used instead of Minecraft's Tuple type because Tuple doesn't have strongly-typed elements. + + private P first; + private Q second; + + public Pair(P first, Q second) + { + this.first = first; + this.second = second; + } + + public P getFirst() + { + return first; + } + + public Q getSecond() + { + return second; + } +} diff --git a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index e880ce6..cc524fd 100644 --- a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -1,9 +1,9 @@ package StevenDimDoors.mod_pocketDim.world; -import java.util.HashMap; import java.util.Random; import net.minecraft.block.Block; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; @@ -19,6 +19,7 @@ import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; +import StevenDimDoors.mod_pocketDim.util.Pair; import StevenDimDoors.mod_pocketDim.util.Point4D; public class PocketBuilder @@ -35,25 +36,6 @@ public class PocketBuilder private PocketBuilder() { } - public static boolean initializeDestination(IDimLink link, DDProperties properties) - { - if (link.hasDestination()) - { - return true; - } - - //Check the destination type and respond accordingly - switch (link.linkType()) - { - case IDimLink.TYPE_DUNGEON: - return generateNewDungeonPocket(link, properties); - case IDimLink.TYPE_POCKET: - return generateNewPocket(link, properties); - default: - throw new IllegalArgumentException("link has an unrecognized link type."); - } - } - public static boolean generateNewDungeonPocket(IDimLink link, DDProperties properties) { if (link == null) @@ -93,31 +75,35 @@ public class PocketBuilder return false; } - /* This code is currently wrong. It's missing the following things: - * 1. Calculate the destination point for real. That includes adding door noise if needed. - * 2. Receive the DungeonData from selectDungeon() - * 3. The function signature for DungeonSchematic.copyToWorld() has to be rewritten. - */ - //Choose a dungeon to generate - DungeonSchematic schematic = selectDungeon(dimension, random, properties); - - if (schematic == null) + Pair pair = selectDungeon(dimension, random, properties); + if (pair == null) { System.err.println("Could not select a dungeon for generation!"); return false; } + DungeonData dungeon = pair.getFirst(); + DungeonSchematic schematic = pair.getSecond(); //Calculate the destination point + DungeonPackConfig packConfig = dungeon.dungeonType().Owner != null ? dungeon.dungeonType().Owner.getConfig() : null; Point4D source = link.source(); - int destinationY = yCoordHelper.adjustDestinationY(destination, world.getHeight(), schematic.getEntranceDoorLocation().getY(), schematic.getHeight()); - int orientation = getDestinationOrientation(source); - destination.setY(destinationY); + int orientation = getDoorOrientation(source, properties); + Point3D destination; + + if (packConfig != null && packConfig.doDistortDoorCoordinates()) + { + destination = calculateNoisyDestination(source, dimension, orientation); + } + else + { + destination = new Point3D(source.getX(), source.getY(), source.getZ()); + } + + destination.setY( yCoordHelper.adjustDestinationY(destination.getY(), world.getHeight(), schematic.getEntranceDoorLocation().getY(), schematic.getHeight()) ); //Generate the dungeon - DungeonPackConfig packConfig = dungeon.dungeonType().Owner != null ? dungeon.dungeonType().Owner.getConfig() : null; - - schematic.copyToWorld(world, link, packConfig.doDistortDoorCoordinates()); + schematic.copyToWorld(world, destination, orientation, link, random); //Finish up destination initialization dimension.initializePocket(destination.getX(), destination.getY(), destination.getZ(), orientation, link); @@ -131,7 +117,23 @@ public class PocketBuilder } } - private static DungeonSchematic selectDungeon(NewDimData dimension, Random random, DDProperties properties) + private static Point3D calculateNoisyDestination(Point4D source, NewDimData dimension, int orientation) + { + int depth = dimension.packDepth(); + int forwardNoise = MathHelper.getRandomIntegerInRange(random, -50 * depth, 150 * depth); + int sidewaysNoise = MathHelper.getRandomIntegerInRange(random, -10 * depth, 10 * depth); + + //Rotate the link destination noise to point in the same direction as the door exit + //and add it to the door's location. Use EAST as the reference orientation since linkDestination + //is constructed as if pointing East. + Point3D linkDestination = new Point3D(forwardNoise, 0, sidewaysNoise); + Point3D sourcePoint = new Point3D(source.getX(), source.getY(), source.getZ()); + Point3D zeroPoint = new Point3D(0, 0, 0); + BlockRotator.transformPoint(linkDestination, zeroPoint, orientation - BlockRotator.EAST_DOOR_METADATA, sourcePoint); + return linkDestination; + } + + private static Pair selectDungeon(NewDimData dimension, Random random, DDProperties properties) { //We assume the dimension doesn't have a dungeon assigned if (dimension.dungeon() != null) @@ -157,7 +159,6 @@ public class PocketBuilder { //TODO: In the future, remove this dungeon from the generation lists altogether. //That will have to wait until our code is updated to support that more easily. - try { System.err.println("Loading the default error dungeon instead..."); @@ -170,7 +171,7 @@ public class PocketBuilder return null; } } - return schematic; + return new Pair(dungeon, schematic); } private static DungeonSchematic loadAndValidateDungeon(DungeonData dungeon, DDProperties properties) @@ -218,10 +219,25 @@ public class PocketBuilder return generateNewPocket(link, DEFAULT_POCKET_SIZE, DEFAULT_POCKET_WALL_THICKNESS, properties); } - private static int getDestinationOrientation(Point4D source) + private static int getDoorOrientation(Point4D source, DDProperties properties) { - // TODO Auto-generated method stub - return 0; + World world = DimensionManager.getWorld(source.getDimension()); + if (world == null) + { + throw new IllegalStateException("The link's source world should be loaded!"); + } + + //Check if the block at that point is actually a door + int blockID = world.getBlockId(source.getX(), source.getY(), source.getZ()); + if (blockID != properties.DimensionalDoorID && blockID != properties.WarpDoorID && + blockID != properties.TransientDoorID) + { + throw new IllegalStateException("The link's source is not a door block. It should be impossible to traverse a rift without a door!"); + } + + //Return the orientation portion of its metadata + int orientation = world.getBlockMetadata(source.getX(), source.getY(), source.getZ()) & 3; + return orientation; } public static boolean generateNewPocket(IDimLink link, int size, int wallThickness, DDProperties properties) @@ -283,7 +299,7 @@ public class PocketBuilder //Calculate the destination point Point4D source = link.source(); int destinationY = yCoordHelper.adjustDestinationY(source.getY(), world.getHeight(), wallThickness + 1, size); - int orientation = getDestinationOrientation(source); + int orientation = getDoorOrientation(source, properties); //Build the actual pocket area buildPocket(world, source.getX(), destinationY, source.getZ(), orientation, size, wallThickness, properties); -- 2.39.5 From 5cabd3762eb0e9da191b4dee010c9045d8384704 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 07:39:52 -0400 Subject: [PATCH 05/24] More Progress on Rewrite Continued fixing things across various classes to make them work with our new core classes. --- .../mod_pocketDim/BlankTeleporter.java | 4 - .../mod_pocketDim/TransientDoor.java | 5 +- .../blocks/BlockDimWallPerm.java | 81 ++-- .../mod_pocketDim/blocks/dimDoor.java | 3 +- .../mod_pocketDim/core/PocketManager.java | 10 +- .../mod_pocketDim/helpers/DungeonHelper.java | 2 +- .../mod_pocketDim/helpers/yCoordHelper.java | 2 +- .../mod_pocketDim/items/ItemStableFabric.java | 173 +-------- .../mod_pocketDim/items/itemDimDoor.java | 347 +++++++++--------- .../mod_pocketDim/mod_pocketDim.java | 24 +- .../mod_pocketDim/schematic/BlockRotator.java | 4 +- .../mod_pocketDim/ticking/MobMonolith.java | 156 +++----- 12 files changed, 274 insertions(+), 537 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/BlankTeleporter.java b/StevenDimDoors/mod_pocketDim/BlankTeleporter.java index 99aea03..a066837 100644 --- a/StevenDimDoors/mod_pocketDim/BlankTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/BlankTeleporter.java @@ -1,11 +1,7 @@ package StevenDimDoors.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.entity.Entity; -import net.minecraft.entity.item.EntityMinecart; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.Teleporter; -import net.minecraft.world.World; import net.minecraft.world.WorldServer; public class BlankTeleporter extends Teleporter diff --git a/StevenDimDoors/mod_pocketDim/TransientDoor.java b/StevenDimDoors/mod_pocketDim/TransientDoor.java index a0a8fcd..7e02a31 100644 --- a/StevenDimDoors/mod_pocketDim/TransientDoor.java +++ b/StevenDimDoors/mod_pocketDim/TransientDoor.java @@ -78,10 +78,11 @@ public class TransientDoor extends ExitDoor IDimLink link = PocketManager.getLink(x, y, z, world.provider.dimensionId); if (link != null) { - //Turn the transient door into a rift before teleporting the entity + DDTeleporter.traverseDimDoor(world, link, entity); + //Turn the transient door into a rift AFTER teleporting the entity. + //The door's orientation may be needed for generating a room at the link's destination. world.setBlock(x, y, z, properties.RiftBlockID); world.setBlockToAir(x, y - 1, z); - PocketManager.traverseDimDoor(world, link, entity); } } } diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java index da81b74..bdf14a9 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java @@ -8,16 +8,18 @@ import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.DDTeleporter; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; -import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; +import StevenDimDoors.mod_pocketDim.util.Point4D; public class BlockDimWallPerm extends Block { + private static final Random random = new Random(); private static DDProperties properties = null; public BlockDimWallPerm(int i, int j, Material par2Material) @@ -43,83 +45,50 @@ public class BlockDimWallPerm extends Block /** * Only matters if the player is in limbo, acts to teleport the player from limbo back to dim 0 */ - public void onEntityWalking(World par1World, int par2, int par3, int par4, Entity entity) + public void onEntityWalking(World world, int x, int y, int z, Entity entity) { - if (!par1World.isRemote && par1World.provider.dimensionId == properties.LimboDimensionID) + if (!world.isRemote && world.provider.dimensionId == properties.LimboDimensionID) { - Random rand = new Random(); - - IDimLink link = PocketManager.getRandomLinkData(false); - if (link == null) - { - link =new NewLinkData(0,0,0,0); - } - link.destDimID = 0; - link.locDimID = par1World.provider.dimensionId; World overworld = DimensionManager.getWorld(0); - - if (overworld == null) - { - DimensionManager.initDimension(0); - overworld = DimensionManager.getWorld(0); - } - if (overworld != null && entity instanceof EntityPlayerMP) { EntityPlayer player = (EntityPlayer) entity; player.fallDistance = 0; - int x = (link.destXCoord + rand.nextInt(properties.LimboReturnRange) - properties.LimboReturnRange/2); - int z = (link.destZCoord + rand.nextInt(properties.LimboReturnRange) - properties.LimboReturnRange/2); + int rangeLimit = properties.LimboReturnRange / 2; + int destinationX = x + MathHelper.getRandomIntegerInRange(random, -rangeLimit, rangeLimit); + int destinationZ = z + MathHelper.getRandomIntegerInRange(random, -rangeLimit, rangeLimit); //make sure I am in the middle of a chunk, and not on a boundary, so it doesn't load the chunk next to me - x = x + (x >> 4); - z = z + (z >> 4); + destinationX = destinationX + (destinationX >> 4); + destinationZ = destinationZ + (destinationZ >> 4); - int y = yCoordHelper.getFirstUncovered(0, x, 63, z, true); + int destinationY = yCoordHelper.getFirstUncovered(overworld, destinationX, 63, destinationZ, true); - player.setPositionAndUpdate( x, y, z ); - //this complicated chunk teleports the player back to the overworld at some random location. Looks funky becaue it has to load the chunk - link.destXCoord = x; - link.destYCoord = y; - link.destZCoord = z; - PocketManager.teleportEntity(par1World, player, link); + //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); - player.setPositionAndUpdate( x, y, z ); + //player.setPositionAndUpdate( x, y, z ); // Make absolutely sure the player doesn't spawn inside blocks, though to be honest this shouldn't ever have to be a problem... - overworld.setBlockToAir(x, y, z); - overworld.setBlockToAir(x, y + 1, z); + overworld.setBlockToAir(destinationX, destinationY, destinationZ); + overworld.setBlockToAir(destinationX, destinationY + 1, destinationZ); - int i=x; - int j=y; - int k=z; - - for(int xc=-3;xc<4;xc++) + for (int xc = -3; xc < 4; xc++) { - for(int zc=-3;zc<4;zc++) + for (int zc = -3; zc < 4; zc++) { - for(int yc=0;yc<200;yc++) + if (Math.abs(xc) + Math.abs(zc) < random.nextInt(3) + 2 || + Math.abs(xc) + Math.abs(zc) < random.nextInt(3) + 3) { - if (yc==0) - { - if(Math.abs(xc)+Math.abs(zc) comboSave = new HashMap(); comboSave.put("dimensionData", dimensionData); comboSave.put("keyLinkMapping", keyLinkMapping); @@ -423,7 +421,7 @@ public class PocketManager * loads the dim data from the saved hashMap. Also handles compatibility with old saves, see OldSaveHandler * @return */ - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings("unchecked") public static void load() { //FIXME: There are a lot of things to fix here... First, we shouldn't be created so many File instances @@ -449,7 +447,7 @@ public class PocketManager } saveFile = new FileInputStream(dataStore); ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); - HashMap comboSave = ((HashMap) save.readObject()); + HashMap comboSave = (HashMap) save.readObject(); try { @@ -486,7 +484,7 @@ public class PocketManager saveFile = new FileInputStream(dataStore); ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); - HashMap comboSave =((HashMap)save.readObject()); + HashMap comboSave = (HashMap) save.readObject(); try { diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index ba65103..f7741ab 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -281,7 +281,7 @@ public class DungeonHelper IDimLink link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); //Place a Warp Door linked to that pocket - itemDimDoor.placeDoorBlock(world, x, y, z, 3, mod_pocketDim.ExitDoor); + itemDimDoor.placeDoorBlock(world, x, y, z, 3, mod_pocketDim.exitDoor); return link; } diff --git a/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java b/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java index a083c03..1574634 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/yCoordHelper.java @@ -22,7 +22,7 @@ public class yCoordHelper int localX = x < 0 ? (x % 16) + 16 : (x % 16); int localZ = z < 0 ? (z % 16) + 16 : (z % 16); - int height = MAXIMUM_UNCOVERED_Y; //world.getHeight(); + int height = MAXIMUM_UNCOVERED_Y; int y; if (!fromTop) diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java b/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java index 3eb39d9..b12d8df 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStableFabric.java @@ -1,184 +1,19 @@ package StevenDimDoors.mod_pocketDim.items; -import java.util.List; - -import StevenDimDoors.mod_pocketDim.SchematicLoader; -import StevenDimDoors.mod_pocketDim.Spells; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; -import StevenDimDoors.mod_pocketDimClient.ClientTickHandler; - -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.MathHelper; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; -import net.minecraftforge.common.ForgeDirection; -import net.minecraftforge.common.RotationHelper; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; public class ItemStableFabric extends Item { - private Material doorMaterial; - - public ItemStableFabric(int par1, int par2) + public ItemStableFabric(int itemID, int par2) { - super(par1); - // this.setitemIcon(Item.doorWood.getIconFromDamage(0)); + super(itemID); this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - } + public void registerIcons(IconRegister par1IconRegister) { this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); - - } - - public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) - { - - if(!par3World.isRemote) - { - System.out.println("Block metadata is "+par3World.getBlockMetadata(par4, par5, par6)); - System.out.println(par3World.getBiomeGenForCoords(par4, par6).biomeName); - - - this.onItemRightClick(par1ItemStack, par3World, par2EntityPlayer); - - Block block = Block.blocksList[par3World.getBlockId(par4, par5, par6)]; - - if(PocketManager.dimList.containsKey(par3World.provider.dimensionId)) - { - if(PocketManager.instance.getDimData(par3World.provider.dimensionId).isPocket) - { - if(PocketManager.instance.getDimData(par3World.provider.dimensionId).dungeonGenerator!=null) - { - System.out.println("Dungeon name "+PocketManager.instance.getDimData(par3World.provider.dimensionId).dungeonGenerator.schematicPath); - - } - } - - } - - - - - } - //System.out.println("Block texture data is "+Block.blocksList[par3World.getBlockId(par4, par5, par6)].getBlockTexture(par3World,par4, par5, par6,par7).getIconName()); - //System.out.println("Block name is is "+Block.blocksList[par3World.getBlockId(par4, par5, par6)].getUnlocalizedName2()); - - return true; - } - - - public MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) - { - float var4 = 1.0F; - float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; - float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; - double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4; - double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset; - double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4; - Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); - float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI); - float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI); - float var16 = -MathHelper.cos(-var5 * 0.017453292F); - float var17 = MathHelper.sin(-var5 * 0.017453292F); - float var18 = var15 * var16; - float var20 = var14 * var16; - double var21 = 5.0D; - if (par2EntityPlayer instanceof EntityPlayerMP) - { - var21 = 4; - } - Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21); - return par1World.rayTraceBlocks_do_do(var13, var23, true, false); - } - - public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - if (this.isSteven(par3EntityPlayer)) - { - new Spells(par3EntityPlayer, par1ItemStack.stackSize).cast(); - //mod_pocketDim.proxy.startCasting(par3EntityPlayer, par1ItemStack.stackSize); - } - - Boolean didFindThing=false; - MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(par3EntityPlayer.worldObj, par3EntityPlayer, false ); - if(hit!=null&&!par2World.isRemote) - { - //if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ)==properties.RiftBlockID) - { - NewLinkData link = PocketManager.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); - if(link!=null) - { - Block var11; - if(par1ItemStack.getItem() instanceof itemExitDoor ) - { - var11 = mod_pocketDim.ExitDoor; - } - - else if(par1ItemStack.getItem() instanceof ItemChaosDoor ) - { - var11 = mod_pocketDim.chaosDoor; - } - else - { - var11 = mod_pocketDim.dimDoor; - } - - int par4 = hit.blockX; - int par5 = hit.blockY-1; - int par6 = hit.blockZ; - int par7 = 0 ; - - - - - if (par3EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par3EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)&&!par2World.isRemote) - { - int var12 = MathHelper.floor_double((double)((par3EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - String cardinal= "default"; - - switch(link.linkOrientation) - { - case 0: - cardinal = "East"; - break; - case 1: - cardinal = "South"; - break; - case 2: - cardinal = "West"; - break; - case 3: - cardinal = "North"; - break; - } - System.out.println("Link orientation is " + link.linkOrientation + " - " + cardinal); - } - } - } - } - return par1ItemStack; - } - - - public boolean isSteven(EntityPlayer player) - { - return (player.username.equalsIgnoreCase("stevenrs11")); - } - - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) - { - } } diff --git a/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java b/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java index f5668e3..6b9edce 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java +++ b/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java @@ -15,194 +15,193 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; +import StevenDimDoors.mod_pocketDim.core.IDimLink; import StevenDimDoors.mod_pocketDim.core.PocketManager; public class itemDimDoor extends ItemDoor { private static DDProperties properties = null; - - public itemDimDoor(int par1, Material par2Material) - { - super(par1, par2Material); - this.setMaxStackSize(64); - this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - if (properties == null) - properties = DDProperties.instance(); - } - - public void registerIcons(IconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) + + public itemDimDoor(int par1, Material par2Material) + { + super(par1, par2Material); + this.setMaxStackSize(64); + this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); + if (properties == null) + properties = DDProperties.instance(); + } + + public void registerIcons(IconRegister par1IconRegister) + { + this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) - { - par3List.add("Place on the block under a rift"); - par3List.add("to activate that rift or place"); - par3List.add("anywhere else to create a"); - par3List.add("pocket dimension."); - } - - @Override - public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) - { - if (par7 != 1) - { - return false; - } - else - { - ++par5; - Block var11; + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { + par3List.add("Place on the block under a rift"); + par3List.add("to activate that rift or place"); + par3List.add("anywhere else to create a"); + par3List.add("pocket dimension."); + } - - if(par1ItemStack.getItem() instanceof itemExitDoor ) - { - var11 = mod_pocketDim.ExitDoor; - } - - else if(par1ItemStack.getItem() instanceof ItemChaosDoor ) - { - var11 = mod_pocketDim.chaosDoor; - } - else - { - var11 = mod_pocketDim.dimDoor; - } - - if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)&&!par3World.isRemote) - { - int var12 = MathHelper.floor_double((double)((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - - if (!canPlace(par3World, par4, par5, par6, var12) || !canPlace(par3World, par4, par5+1, par6, var12)) - { - return false; - } - else - { - int offset = 0; - int idBlock = par3World.getBlockId(par4, par5-1, par6); - - if(Block.blocksList.length>idBlock&&idBlock!=0) - { - if(Block.blocksList[idBlock].isBlockReplaceable(par3World, par4, par5-1, par6)) - { - offset = 1; - } - } - - placeDoorBlock(par3World, par4, par5-offset, par6, var12, var11); - - --par1ItemStack.stackSize; - return true; - } - } - else - { - return false; - } - } - } - - public MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) - { - float var4 = 1.0F; - float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; - float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; - double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4; - double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset; - double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4; - Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); - float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI); - float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI); - float var16 = -MathHelper.cos(-var5 * 0.017453292F); - float var17 = MathHelper.sin(-var5 * 0.017453292F); - float var18 = var15 * var16; - float var20 = var14 * var16; - double var21 = 5.0D; - if (par2EntityPlayer instanceof EntityPlayerMP) - { - var21 = 4; - } - Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21); - return par1World.rayTraceBlocks_do_do(var13, var23, true, false); - } - - public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(par3EntityPlayer.worldObj, par3EntityPlayer, false ); - if(hit!=null&&!par2World.isRemote) + @Override + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) + { + if (par7 != 1) { - if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID) + return false; + } + else + { + ++par5; + Block var11; + + + if(par1ItemStack.getItem() instanceof itemExitDoor) { - NewLinkData link = PocketManager.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); - if(link!=null) + var11 = mod_pocketDim.exitDoor; + } + + else if (par1ItemStack.getItem() instanceof ItemChaosDoor) + { + var11 = mod_pocketDim.unstableDoor; + } + else if (par1ItemStack.getItem() instanceof itemDimDoor) + { + var11 = mod_pocketDim.dimensionalDoor; + } + else + { + //Do nothing + return false; + } + + if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)&&!par3World.isRemote) + { + int var12 = MathHelper.floor_double((double)((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + + if (!canPlace(par3World, par4, par5, par6) || !canPlace(par3World, par4, par5+1, par6)) { - Block var11; - if(par1ItemStack.getItem() instanceof itemExitDoor ) - { - var11 = mod_pocketDim.ExitDoor; - } - - else if(par1ItemStack.getItem() instanceof ItemChaosDoor ) - { - var11 = mod_pocketDim.chaosDoor; - } - else - { - var11 = mod_pocketDim.dimDoor; - } - - int par4 = hit.blockX; - int par5 = hit.blockY; - int par6 = hit.blockZ; - int par7 = 0 ; - - - + return false; + } + else + { + int offset = 0; + int idBlock = par3World.getBlockId(par4, par5-1, par6); - if (par3EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par3EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)&&!par2World.isRemote) - { - int var12 = MathHelper.floor_double((double)((par3EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + if(Block.blocksList.length>idBlock&&idBlock!=0) + { + if(Block.blocksList[idBlock].isBlockReplaceable(par3World, par4, par5-1, par6)) + { + offset = 1; + } + } - if (!canPlace(par2World, par4, par5, par6, var12) || !canPlace(par2World, par4, par5-1, par6, var12) || - PocketManager.instance.getLinkDataFromCoords(par4, par5, par6, par2World) == null) - { - return par1ItemStack; - } - else - { - placeDoorBlock(par2World, par4, par5-1, par6, var12, var11); - - --par1ItemStack.stackSize; - - } - } + placeDoorBlock(par3World, par4, par5-offset, par6, var12, var11); + + --par1ItemStack.stackSize; + return true; + } + } + else + { + return false; + } + } + } + + public MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) + { + float var4 = 1.0F; + float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; + float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; + double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4; + double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset; + double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4; + Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); + float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI); + float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI); + float var16 = -MathHelper.cos(-var5 * 0.017453292F); + float var17 = MathHelper.sin(-var5 * 0.017453292F); + float var18 = var15 * var16; + float var20 = var14 * var16; + double var21 = 5.0D; + if (par2EntityPlayer instanceof EntityPlayerMP) + { + var21 = 4; + } + Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21); + return par1World.rayTraceBlocks_do_do(var13, var23, true, false); + } + + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) + { + if (world.isRemote) + { + return stack; + } + + MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(player.worldObj, player, false ); + if (hit != null) + { + if (world.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID) + { + IDimLink link = PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world.provider.dimensionId); + if (link != null) + { + Block block; + if (stack.getItem() instanceof itemExitDoor) + { + block = mod_pocketDim.exitDoor; + } + else if (stack.getItem() instanceof ItemChaosDoor) + { + block = mod_pocketDim.unstableDoor; + } + else if (stack.getItem() instanceof itemDimDoor) + { + block = mod_pocketDim.dimensionalDoor; + } + else + { + //Do nothing + return stack; + } + + int x = hit.blockX; + int y = hit.blockY; + int z = hit.blockZ; + int par7 = 0; + + if (player.canPlayerEdit(x, y, z, par7, stack) && player.canPlayerEdit(x, y - 1, z, par7, stack)) + { + int orientation = MathHelper.floor_double((double) ((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + + if (!canPlace(world, x, y, z) || !canPlace(world, x, y - 1, z)) + { + return stack; + } + else + { + placeDoorBlock(world, x, y - 1, z, orientation, block); + if (!player.capabilities.isCreativeMode) + { + stack.stackSize--; + } + } + } } } } - - return par1ItemStack; - - } - - public static boolean canPlace(World world,int i, int j, int k, int p) - { - int id = world.getBlockId(i, j, k); - - boolean flag = true; - if (id==properties.FabricBlockID || id==properties.RiftBlockID || id==properties.PermaFabricBlockID || id == 0) - { - return true; - } + return stack; + } - if (id != 0 && !Block.blocksList[id].blockMaterial.isReplaceable()) - { - flag = false; - } - return flag; - } + private static boolean canPlace(World world, int x, int y, int z) + { + int id = world.getBlockId(x, y, z); + + return (id == properties.RiftBlockID || id == 0 || Block.blocksList[id].blockMaterial.isReplaceable()); + } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 0ac2b10..7ef8f78 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -101,10 +101,10 @@ public class mod_pocketDim public static mod_pocketDim instance = new mod_pocketDim(); public static Block transientDoor; - public static Block ExitDoor; - public static Block chaosDoor; + public static Block exitDoor; + public static Block unstableDoor; public static Block blockLimbo; - public static Block dimDoor; + public static Block dimensionalDoor; public static Block blockDimWall; public static Block dimHatch; public static Block blockDimWallPerm; @@ -184,11 +184,11 @@ public class mod_pocketDim blockDimWall = (new BlockDimWall(properties.FabricBlockID, 0, Material.iron)).setLightValue(1.0F).setHardness(0.1F).setUnlocalizedName("blockDimWall"); blockDimWallPerm = (new BlockDimWallPerm(properties.PermaFabricBlockID, 0, Material.iron)).setLightValue(1.0F).setBlockUnbreakable().setResistance(6000000.0F).setUnlocalizedName("blockDimWallPerm"); - ExitDoor = (new ExitDoor(properties.WarpDoorID, Material.wood)).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); + exitDoor = (new ExitDoor(properties.WarpDoorID, Material.wood)).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); blockRift = (BlockRift) (new BlockRift(properties.RiftBlockID, 0, Material.air, properties).setHardness(1.0F) .setUnlocalizedName("rift")); blockLimbo = (new BlockLimbo(properties.LimboBlockID, 15, Material.iron, properties.LimboDimensionID, decay).setHardness(.2F).setUnlocalizedName("BlockLimbo").setLightValue(.0F)); - chaosDoor = (new ChaosDoor(properties.UnstableDoorID, Material.iron).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); - dimDoor = (new dimDoor(properties.DimensionalDoorID, Material.iron)).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor"); + unstableDoor = (new ChaosDoor(properties.UnstableDoorID, Material.iron).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); + dimensionalDoor = (new dimDoor(properties.DimensionalDoorID, Material.iron)).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor"); dimHatch = (new dimHatch(properties.TransTrapdoorID, 84, Material.iron)).setHardness(1.0F) .setUnlocalizedName("dimHatch"); // dimRail = (new DimRail(dimRailID, 88, false)).setHardness(.5F) .setUnlocalizedName("dimRail"); @@ -206,11 +206,11 @@ public class mod_pocketDim GameRegistry.registerWorldGenerator(mod_pocketDim.riftGen); - GameRegistry.registerBlock(chaosDoor, "Unstable Door"); - GameRegistry.registerBlock(ExitDoor, "Warp Door"); + GameRegistry.registerBlock(unstableDoor, "Unstable Door"); + GameRegistry.registerBlock(exitDoor, "Warp Door"); GameRegistry.registerBlock(blockRift, "Rift"); GameRegistry.registerBlock(blockLimbo, "Unraveled Fabric"); - GameRegistry.registerBlock(dimDoor, "Dimensional Door"); + GameRegistry.registerBlock(dimensionalDoor, "Dimensional Door"); GameRegistry.registerBlock(dimHatch,"Transdimensional Trapdoor"); GameRegistry.registerBlock(blockDimWallPerm, "Fabric of RealityPerm"); GameRegistry.registerBlock(transientDoor, "transientDoor"); @@ -226,11 +226,11 @@ public class mod_pocketDim LanguageRegistry.addName(transientDoor , "transientDoor"); LanguageRegistry.addName(blockRift , "Rift"); LanguageRegistry.addName(blockLimbo , "Unraveled Fabric"); - LanguageRegistry.addName(ExitDoor , "Warp Door"); - LanguageRegistry.addName(chaosDoor , "Unstable Door"); + LanguageRegistry.addName(exitDoor , "Warp Door"); + LanguageRegistry.addName(unstableDoor , "Unstable Door"); LanguageRegistry.addName(blockDimWall , "Fabric of Reality"); LanguageRegistry.addName(blockDimWallPerm , "Eternal Fabric"); - LanguageRegistry.addName(dimDoor, "Dimensional Door"); + LanguageRegistry.addName(dimensionalDoor, "Dimensional Door"); LanguageRegistry.addName(dimHatch, "Transdimensional Trapdoor"); LanguageRegistry.addName(itemExitDoor, "Warp Door"); diff --git a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java index d086d2d..dfc4a21 100644 --- a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java +++ b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java @@ -64,8 +64,8 @@ public class BlockRotator hasOrientations[Block.railActivator.blockID] = true; hasOrientations[Block.rail.blockID] = true; - hasOrientations[mod_pocketDim.dimDoor.blockID] = true; - hasOrientations[mod_pocketDim.ExitDoor.blockID] = true; + hasOrientations[mod_pocketDim.dimensionalDoor.blockID] = true; + hasOrientations[mod_pocketDim.exitDoor.blockID] = true; } diff --git a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java index d102596..f2e8ab3 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java +++ b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java @@ -13,8 +13,8 @@ import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.DDTeleporter; +import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.world.LimboProvider; import StevenDimDoors.mod_pocketDim.world.PocketProvider; @@ -24,7 +24,7 @@ public class MobMonolith extends EntityFlying implements IMob float soundTime = 0; int aggro = 0; byte textureState = 0; - + float scaleFactor = 0; int aggroMax; int destX=0; @@ -86,16 +86,14 @@ public class MobMonolith extends EntityFlying implements IMob @Override public void onEntityUpdate() { - if(!(this.worldObj.provider instanceof LimboProvider ||this.worldObj.provider instanceof PocketProvider)) + if (!(this.worldObj.provider instanceof LimboProvider || this.worldObj.provider instanceof PocketProvider)) { this.setDead(); } - + byte b0 = this.dataWatcher.getWatchableObjectByte(16); this.texture="/mods/DimDoors/textures/mobs/Monolith"+b0+".png"; - - super.onEntityUpdate(); if (this.isEntityAlive() && this.isEntityInsideOpaqueBlock()) @@ -103,12 +101,9 @@ public class MobMonolith extends EntityFlying implements IMob this.setDead(); } - - - EntityPlayer entityPlayer = this.worldObj.getClosestPlayerToEntity(this, 30); - if(entityPlayer != null) + if (entityPlayer != null) { if(this.soundTime<=0) { @@ -116,83 +111,57 @@ public class MobMonolith extends EntityFlying implements IMob this.soundTime=100; } - - this.faceEntity(entityPlayer, 1, 1); - if(shouldAttackPlayer(entityPlayer)) + if (shouldAttackPlayer(entityPlayer)) { - { - - } - if(aggro<470) + if (aggro<470) { - if(rand.nextInt(11)>this.textureState||this.aggro>=300||rand.nextInt(13)>this.textureState&&this.aggroMax>this.aggro) + if (rand.nextInt(11)>this.textureState||this.aggro>=300||rand.nextInt(13)>this.textureState&&this.aggroMax>this.aggro) { aggro++; } - - - if(this.worldObj.provider instanceof PocketProvider||this.worldObj.getClosestPlayerToEntity(this, 5)!=null) + if (this.worldObj.provider instanceof PocketProvider||this.worldObj.getClosestPlayerToEntity(this, 5)!=null) { - aggro++; aggro++; - if(rand.nextBoolean()) + if (rand.nextBoolean()) { aggro++; } } - if(aggro>430&&this.soundTime<100) + if (aggro>430&&this.soundTime<100) { - //this.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.tearing",2, 1); this.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ,"mods.DimDoors.sfx.tearing",2F, 1F); - this.soundTime=100; - } - if(aggro>445&&this.soundTime<200) + if (aggro>445&&this.soundTime<200) { - //this.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.tearing",5, 1); this.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ,"mods.DimDoors.sfx.tearing",5F, 1F); - this.soundTime=200; } - - - } - else if(!this.worldObj.isRemote&&!entityPlayer.capabilities.isCreativeMode) + else if (!this.worldObj.isRemote && !entityPlayer.capabilities.isCreativeMode) { - - - - - - NewLinkData link = new NewLinkData(this.worldObj.provider.dimensionId, properties.LimboDimensionID, (int)this.posX, (int)this.posY, (int)this.posZ, (int)this.posX+rand.nextInt(500)-250, (int)this.posY+500, (int)this.posZ+rand.nextInt(500)-250, false,0); - - PocketManager.instance.traverseDimDoor(worldObj, link, entityPlayer); - this.aggro=0; + Point4D destination = new Point4D( + (int) this.posX + MathHelper.getRandomIntegerInRange(rand, -250, 250), + (int) this.posY + 500, + (int) this.posZ + MathHelper.getRandomIntegerInRange(rand, -250, 250), + properties.LimboDimensionID); + DDTeleporter.teleport(worldObj, destination, entityPlayer); + this.aggro = 0; entityPlayer.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.crack",13, 1); - - - - } - if(!(this.worldObj.provider instanceof LimboProvider || this.worldObj.getClosestPlayerToEntity(this, 5)!=null)||this.aggro>300) + if (!(this.worldObj.provider instanceof LimboProvider || this.worldObj.getClosestPlayerToEntity(this, 5) != null) || this.aggro > 300) { - for (int i = 0; i < -1+this.textureState/2; ++i) { entityPlayer.worldObj.spawnParticle("portal", entityPlayer.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, entityPlayer.posY + this.rand.nextDouble() * (double)entityPlayer.height - 0.75D, entityPlayer.posZ + (this.rand.nextDouble() - 0.5D) * (double)entityPlayer.width, (this.rand.nextDouble() - 0.5D) * 2.0D, -this.rand.nextDouble(), (this.rand.nextDouble() - 0.5D) * 2.0D); } } - - - } else { @@ -205,12 +174,9 @@ public class MobMonolith extends EntityFlying implements IMob } } - - } else { - if(aggro>0) { aggro--; @@ -221,44 +187,23 @@ public class MobMonolith extends EntityFlying implements IMob } } } - if(soundTime>=0) + if (soundTime>=0) { soundTime--; } - - - - { - - - - - } - - this.textureState= (byte) (this.aggro/25); - if(!this.worldObj.isRemote) + if (!this.worldObj.isRemote) { - this.dataWatcher.updateObject(16, Byte.valueOf(this.textureState)); } - - - - - - } - + private boolean shouldAttackPlayer(EntityPlayer par1EntityPlayer) { return par1EntityPlayer.canEntityBeSeen(this); - } - - private boolean isCourseTraversable(double par1, double par3, double par5, double par7) { double d4 = (par1 - this.posX) / par7; @@ -275,9 +220,9 @@ public class MobMonolith extends EntityFlying implements IMob return false; } } - return true; } + public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) { if(!(par1DamageSource==DamageSource.inWall)) @@ -286,6 +231,7 @@ public class MobMonolith extends EntityFlying implements IMob } return false; } + public void faceEntity(Entity par1Entity, float par2, float par3) { double d0 = par1Entity.posX - this.posX; @@ -311,7 +257,6 @@ public class MobMonolith extends EntityFlying implements IMob this.rotationYaw = f2; this.rotationYawHead=f2; this.renderYawOffset=this.rotationYaw; - } private float updateRotation(float par1, float par2, float par3) @@ -336,8 +281,6 @@ public class MobMonolith extends EntityFlying implements IMob return 0.0F; } - - public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { super.writeEntityToNBT(par1NBTTagCompound); @@ -346,9 +289,8 @@ public class MobMonolith extends EntityFlying implements IMob par1NBTTagCompound.setInteger("aggroMax", this.aggroMax); par1NBTTagCompound.setByte("textureState", this.textureState); par1NBTTagCompound.setFloat("scaleFactor", this.scaleFactor); - } - + @Override public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { @@ -358,31 +300,27 @@ public class MobMonolith extends EntityFlying implements IMob this.aggroMax = par1NBTTagCompound.getInteger("aggroMax"); this.textureState = par1NBTTagCompound.getByte("textureState"); this.scaleFactor = par1NBTTagCompound.getFloat("scaleFactor"); - } - public boolean getCanSpawnHere() - { - List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this,AxisAlignedBB.getBoundingBox( this.posX-15, posY-4, this.posZ-15, this.posX+15, this.posY+15, this.posZ+15)); - - if(this.worldObj.provider.dimensionId==DDProperties.instance().LimboDimensionID) - { - if(list.size()>0) - { - return false; - } - - } - else if(this.worldObj.provider instanceof PocketProvider) - { - if(list.size()>5||this.worldObj.canBlockSeeTheSky((int)this.posX, (int)this.posY, (int)this.posZ)) - { - return false; - } - } - return this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox); - } + public boolean getCanSpawnHere() + { + List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, AxisAlignedBB.getBoundingBox( this.posX-15, posY-4, this.posZ-15, this.posX+15, this.posY+15, this.posZ+15)); + if(this.worldObj.provider.dimensionId==DDProperties.instance().LimboDimensionID) + { + if(list.size()>0) + { + return false; + } - + } + else if(this.worldObj.provider instanceof PocketProvider) + { + if(list.size()>5||this.worldObj.canBlockSeeTheSky((int)this.posX, (int)this.posY, (int)this.posZ)) + { + return false; + } + } + return this.worldObj.checkNoEntityCollision(this.boundingBox) && this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox); + } } \ No newline at end of file -- 2.39.5 From d9056e551fdc6f185f773936e923d0dea9f15c28 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 12:58:35 -0400 Subject: [PATCH 06/24] More Progress on Rewrite Continued fixing things across various classes to make them work with our new core classes. I've also cleaned up indentation and random code snippets along the way. --- .../mod_pocketDim/ConnectionHandler.java | 40 +-- .../mod_pocketDim/PacketHandler.java | 2 +- .../mod_pocketDim/blocks/dimDoor.java | 2 +- .../mod_pocketDim/items/ItemRiftBlade.java | 3 - .../items/ItemStabilizedRiftSignature.java | 46 ++- .../items/itemLinkSignature.java | 11 +- .../mod_pocketDim/items/itemRiftRemover.java | 85 +---- .../mod_pocketDim/mod_pocketDim.java | 4 +- .../ticking/LimboGatewayGenerator.java | 26 -- .../mod_pocketDim/ticking/MobMonolith.java | 2 +- .../mod_pocketDim/world/LimboGenerator.java | 31 +- .../mod_pocketDimClient/ClosingRiftFX.java | 305 +++++++++-------- .../mod_pocketDimClient/GoggleRiftFX.java | 312 +++++++++--------- .../mod_pocketDimClient/RenderDimDoor.java | 4 +- 14 files changed, 357 insertions(+), 516 deletions(-) delete mode 100644 StevenDimDoors/mod_pocketDim/ticking/LimboGatewayGenerator.java diff --git a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java index 0d0c9fd..7b855a5 100644 --- a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java +++ b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java @@ -1,11 +1,5 @@ package StevenDimDoors.mod_pocketDim; -import java.util.ArrayList; -import java.util.Collection; - -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - import net.minecraft.network.INetworkManager; import net.minecraft.network.NetLoginHandler; import net.minecraft.network.packet.NetHandler; @@ -14,45 +8,25 @@ import net.minecraft.server.MinecraftServer; import cpw.mods.fml.common.network.IConnectionHandler; import cpw.mods.fml.common.network.Player; -public class ConnectionHandler implements IConnectionHandler +public class ConnectionHandler implements IConnectionHandler { - private static boolean connected = false; - private static DDProperties properties = null; - - //sends a packet to clients containing all the information about the dims and links. Lots of packets, actually. @Override public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager) { - if (properties == null) - properties = DDProperties.instance(); - - PacketHandler.onClientJoinPacket(manager, PocketManager.dimList); - PacketHandler.onDimCreatedPacket(new NewDimData(properties.LimboDimensionID, false, 0, 0, 0, 0, 0)); + //Sends a packet to the client containing all the information about the dimensions and links. + //Lots of packets, actually. + PacketHandler.sendClientJoinPacket(manager); return null; } @Override - public void connectionOpened(NetHandler netClientHandler, String server,int port, INetworkManager manager) - { - connected = true; - } - + public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager) { } + @Override public void connectionOpened(NetHandler netClientHandler,MinecraftServer server, INetworkManager manager) { } @Override - public void connectionClosed(INetworkManager manager) - { - if (connected) - { - System.out.println("Clearing dim cache"); - PocketManager.instance.save(); - PocketManager.instance.unregsisterDims(); - PocketManager.dimList.clear(); - - } - connected = false; - } + public void connectionClosed(INetworkManager manager) { } @Override public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) { } diff --git a/StevenDimDoors/mod_pocketDim/PacketHandler.java b/StevenDimDoors/mod_pocketDim/PacketHandler.java index 2c5c18b..192b4a6 100644 --- a/StevenDimDoors/mod_pocketDim/PacketHandler.java +++ b/StevenDimDoors/mod_pocketDim/PacketHandler.java @@ -126,7 +126,7 @@ public class PacketHandler implements IPacketHandler } - public static void onClientJoinPacket(INetworkManager manager, HashMap dimList) + public static void sendClientJoinPacket(INetworkManager manager) { Collection dimIDs= dimList.keySet(); Collection dimDataSet= dimList.values(); diff --git a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java b/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java index 9344b59..e8a6319 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java @@ -200,7 +200,7 @@ public class dimDoor extends BlockContainer public dimDoor updateAttachedTile(World world, int x, int y, int z) { TileEntity tile = world.getBlockTileEntity(x, y, z); - if (tile instanceof TileEntityDimDoor ) + if (tile instanceof TileEntityDimDoor) { TileEntityDimDoor dimTile = (TileEntityDimDoor) tile; dimTile.openOrClosed = PocketManager.getLink(x, y, z, world.provider.dimensionId) != null; diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java index f8340f5..25847dd 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java @@ -5,14 +5,12 @@ import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.EnumAction; import net.minecraft.item.EnumToolMaterial; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.util.AxisAlignedBB; @@ -22,7 +20,6 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index 5933e56..01113d0 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -2,20 +2,16 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.List; -import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewLinkData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - import net.minecraft.block.Block; -import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -29,7 +25,7 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature this.setMaxStackSize(1); this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); this.setMaxDamage(0); - this.hasSubtypes=true; + this.hasSubtypes = true; if (properties == null) properties = DDProperties.instance(); } @@ -69,19 +65,19 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature { boolean hasEnder = false; // checks to see if the item has a link stored, if so, it creates it - if(par2EntityPlayer.inventory.hasItem(Item.enderPearl.itemID)||par2EntityPlayer.inventory.hasItem(properties.StableFabricItemID)) + if (par2EntityPlayer.inventory.hasItem(Item.enderPearl.itemID)||par2EntityPlayer.inventory.hasItem(properties.StableFabricItemID)) { - if(!par2EntityPlayer.inventory.consumeInventoryItem(properties.StableFabricItemID)) + if (!par2EntityPlayer.inventory.consumeInventoryItem(properties.StableFabricItemID)) { par2EntityPlayer.inventory.consumeInventoryItem(Item.enderPearl.itemID); } hasEnder=true; } - if(par3World.getBlockId(par4, par5, par6)==Block.snow.blockID) + if (par3World.getBlockId(par4, par5, par6)==Block.snow.blockID) { offset = 1; } - if(hasEnder&&!par3World.isRemote) + if (hasEnder&&!par3World.isRemote) { if(PocketManager.instance.getLinkDataFromCoords(linkCoords[0], linkCoords[1], linkCoords[2], par3World)==null) { @@ -92,20 +88,20 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature par2EntityPlayer.sendChatToPlayer("Rift Created"); } - else if(!par3World.isRemote) + else if (!par3World.isRemote) { par2EntityPlayer.sendChatToPlayer("No Ender Pearls!"); } } } - else if(!par3World.isRemote) + else if (!par3World.isRemote) { if(par3World.getBlockId(par4, par5, par6)==Block.snow.blockID) { offset = 1; } //otherwise, it creates the first half of the link. Next click will complete it. - key= PocketManager.instance.createUniqueInterDimLinkKey(); + key = PocketManager.instance.createUniqueInterDimLinkKey(); this.writeToNBT(par1ItemStack, par4, par5+offset, par6,par3World.provider.dimensionId); par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftStart", (float) .6, 1); @@ -114,28 +110,28 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature return true; } - @SideOnly(Side.CLIENT) - + /** * allows items to add custom lines of information to the mouseover description */ + @SuppressWarnings({ "rawtypes", "unchecked" }) + @SideOnly(Side.CLIENT) + @Override public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { - if(par1ItemStack.hasTagCompound()) + if (par1ItemStack.hasTagCompound()) { - if(par1ItemStack.stackTagCompound.getBoolean("isCreated")) + if (par1ItemStack.stackTagCompound.getBoolean("isCreated")) { Integer[] coords = this.readFromNBT(par1ItemStack); - par3List.add(String.valueOf("Leads to dim "+coords[3] +" with depth "+PocketManager.instance.getDimDepth(PocketManager.instance.getDimDepth(coords[3])))); - par3List.add("at x="+coords[0]+" y="+coords[1]+" z="+coords[2]); + par3List.add("Leads to (" + coords[0] + ", " + coords[1] + ", " + coords[2] + ") at dimension #" + coords[3]); } } else { - par3List.add("First click stores location,"); - par3List.add ("second click creates two rifts,"); - par3List.add("that link the first location"); - par3List.add("with the second location"); + par3List.add("First click stores a location,"); + par3List.add("second click creates two rifts"); + par3List.add("that link the locations together."); } } diff --git a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java index 0c19ba8..4a0538a 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java @@ -2,22 +2,17 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.List; -import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.ILinkData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - import net.minecraft.block.Block; -import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java index 4058789..02e8ed3 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java +++ b/StevenDimDoors/mod_pocketDim/items/itemRiftRemover.java @@ -2,12 +2,8 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.List; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; @@ -16,40 +12,25 @@ import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class itemRiftRemover extends Item { - private Material doorMaterial; - public itemRiftRemover(int par1, Material par2Material) { super(par1); this.setMaxStackSize(1); - // this.setTextureFile("/PocketBlockTextures.png"); this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - - // this.itemIcon=6; this.setMaxDamage(5); - this.hasSubtypes=true; - //TODO move to proxy + this.hasSubtypes = true; } - public void registerIcons(IconRegister par1IconRegister) { this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName()); - - } - - @SideOnly(Side.CLIENT) - @Override - public boolean hasEffect(ItemStack par1ItemStack) - { - // adds effect if item has a link stored - - return false; } public static MovingObjectPosition getBlockTarget(World par1World, EntityPlayer par2EntityPlayer, boolean par3) @@ -78,59 +59,27 @@ public class itemRiftRemover extends Item public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { - { - MovingObjectPosition hit = this.getBlockTarget(par3EntityPlayer.worldObj, par3EntityPlayer, false ); - if(hit!=null) - { - //System.out.println(hit.hitVec); - if(PocketManager.instance.removeRift(par2World, hit.blockX, hit.blockY, hit.blockZ, 1, par3EntityPlayer, par1ItemStack)) - { - par3EntityPlayer.worldObj.playSoundAtEntity(par3EntityPlayer,"mods.DimDoors.sfx.riftClose", (float) .8, 1); - - } - - } - // dimHelper.removeRift( par3World, par4, par5, par6, range, par2EntityPlayer, par1ItemStack); - - - } + MovingObjectPosition hit = getBlockTarget(par3EntityPlayer.worldObj, par3EntityPlayer, false); + if (hit != null) + { + if (PocketManager.removeRift(par2World, hit.blockX, hit.blockY, hit.blockZ, 1, par3EntityPlayer, par1ItemStack)) + { + par3EntityPlayer.worldObj.playSoundAtEntity(par3EntityPlayer,"mods.DimDoors.sfx.riftClose", 0.8f, 1); + } + } return par1ItemStack; } - - - @SideOnly(Side.CLIENT) - /** * allows items to add custom lines of information to the mouseover description */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + @SideOnly(Side.CLIENT) @Override public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { - - - par3List.add("Use near exposed rift"); - par3List.add ("to remove it and"); - par3List.add("any nearby rifts"); - - - - - } - @Override - public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - if(!par2World.isRemote) - { - /** - //creates the first half of the link on item creation - int key= dimHelper.instance.createUniqueInterDimLinkKey(); - LinkData linkData= new LinkData(par2World.provider.dimensionId,MathHelper.floor_double(par3EntityPlayer.posX),MathHelper.floor_double(par3EntityPlayer.posY),MathHelper.floor_double(par3EntityPlayer.posZ)); - System.out.println(key); - - dimHelper.instance.interDimLinkList.put(key, linkData); - par1ItemStack.setItemDamage(key); - **/ - } - } + par3List.add("Use near exposed rift"); + par3List.add("to remove it and"); + par3List.add("any nearby rifts."); + } } diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 7ef8f78..390bb86 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -104,7 +104,7 @@ public class mod_pocketDim public static Block exitDoor; public static Block unstableDoor; public static Block blockLimbo; - public static Block dimensionalDoor; + public static dimDoor dimensionalDoor; public static Block blockDimWall; public static Block dimHatch; public static Block blockDimWallPerm; @@ -188,7 +188,7 @@ public class mod_pocketDim blockRift = (BlockRift) (new BlockRift(properties.RiftBlockID, 0, Material.air, properties).setHardness(1.0F) .setUnlocalizedName("rift")); blockLimbo = (new BlockLimbo(properties.LimboBlockID, 15, Material.iron, properties.LimboDimensionID, decay).setHardness(.2F).setUnlocalizedName("BlockLimbo").setLightValue(.0F)); unstableDoor = (new ChaosDoor(properties.UnstableDoorID, Material.iron).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); - dimensionalDoor = (new dimDoor(properties.DimensionalDoorID, Material.iron)).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor"); + dimensionalDoor = (dimDoor) (new dimDoor(properties.DimensionalDoorID, Material.iron)).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor"); dimHatch = (new dimHatch(properties.TransTrapdoorID, 84, Material.iron)).setHardness(1.0F) .setUnlocalizedName("dimHatch"); // dimRail = (new DimRail(dimRailID, 88, false)).setHardness(.5F) .setUnlocalizedName("dimRail"); diff --git a/StevenDimDoors/mod_pocketDim/ticking/LimboGatewayGenerator.java b/StevenDimDoors/mod_pocketDim/ticking/LimboGatewayGenerator.java deleted file mode 100644 index 3908bc9..0000000 --- a/StevenDimDoors/mod_pocketDim/ticking/LimboGatewayGenerator.java +++ /dev/null @@ -1,26 +0,0 @@ -package StevenDimDoors.mod_pocketDim.ticking; - -import java.util.ArrayList; -import java.util.Random; - -import net.minecraft.entity.Entity; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.GameRules; -import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.helpers.yCoordHelper; -import StevenDimDoors.mod_pocketDim.util.ChunkLocation; - -public class LimboGatewayGenerator implements IRegularTickReceiver -{ - - @Override - public void notifyTick() - { - - - } - -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java index f2e8ab3..e983edf 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java +++ b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java @@ -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(worldObj, destination, entityPlayer); + DDTeleporter.teleport(entityPlayer, destination); this.aggro = 0; entityPlayer.worldObj.playSoundAtEntity(entityPlayer,"mods.DimDoors.sfx.crack",13, 1); diff --git a/StevenDimDoors/mod_pocketDim/world/LimboGenerator.java b/StevenDimDoors/mod_pocketDim/world/LimboGenerator.java index 9ea9aa3..33a754f 100644 --- a/StevenDimDoors/mod_pocketDim/world/LimboGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/LimboGenerator.java @@ -12,18 +12,12 @@ import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.ChunkProviderGenerate; -import net.minecraft.world.gen.MapGenBase; -import net.minecraft.world.gen.MapGenRavine; import net.minecraft.world.gen.NoiseGeneratorOctaves; import net.minecraft.world.gen.feature.MapGenScatteredFeature; -import net.minecraft.world.gen.structure.MapGenMineshaft; -import net.minecraft.world.gen.structure.MapGenStronghold; -import net.minecraft.world.gen.structure.MapGenVillage; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.Event.Result; import net.minecraftforge.event.terraingen.ChunkProviderEvent; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; import StevenDimDoors.mod_pocketDim.ticking.MonolithSpawner; public class LimboGenerator extends ChunkProviderGenerate implements IChunkProvider @@ -46,8 +40,6 @@ public class LimboGenerator extends ChunkProviderGenerate implements IChunkProvi public NoiseGeneratorOctaves noiseGen5; public World world; - private final byte[] field_82700_c = new byte[256]; - private final byte[] field_82698_d = new byte[256]; /** A NoiseGeneratorOctaves used in generating terrain */ public NoiseGeneratorOctaves noiseGen6; @@ -56,27 +48,11 @@ public class LimboGenerator extends ChunkProviderGenerate implements IChunkProvi /** Reference to the World object. */ private World worldObj; - /** are map structures going to be generated (e.g. strongholds) */ - private final boolean mapFeaturesEnabled = false; - /** Holds the overall noise array used in chunk generation */ private double[] noiseArray; - private double[] stoneNoise = new double[256]; - private MapGenBase caveGenerator = new CustomCaveGen(); - - /** Holds Stronghold Generator */ - private MapGenStronghold strongholdGenerator = new MapGenStronghold(); - - /** Holds Village Generator */ - private MapGenVillage villageGenerator = new MapGenVillage(); - - /** Holds Mineshaft Generator */ - private MapGenMineshaft mineshaftGenerator = new MapGenMineshaft(); + private MapGenScatteredFeature scatteredFeatureGenerator = new MapGenScatteredFeature(); - /** Holds ravine generator */ - private MapGenBase ravineGenerator = new MapGenRavine(); - /** The biomes that are used to generate the chunk */ private BiomeGenBase[] biomesForGeneration = new BiomeGenBase[1]; @@ -137,10 +113,11 @@ public class LimboGenerator extends ChunkProviderGenerate implements IChunkProvi } @Override - public boolean chunkExists(int var1, int var2) { - // TODO Auto-generated method stub + public boolean chunkExists(int var1, int var2) + { return super.chunkExists(var1, var2); } + @Override public void replaceBlocksForBiome(int par1, int par2, byte[] par3ArrayOfByte, BiomeGenBase[] par4ArrayOfBiomeGenBase) { diff --git a/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java b/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java index 416b3fe..d252ba8 100644 --- a/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java +++ b/StevenDimDoors/mod_pocketDimClient/ClosingRiftFX.java @@ -12,181 +12,172 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class ClosingRiftFX extends EntityFX { - private int field_92049_a = 160; - private boolean field_92054_ax; - private boolean field_92048_ay; - private final EffectRenderer field_92047_az; - private float field_92050_aA; - private float field_92051_aB; - private float field_92052_aC; - private boolean field_92053_aD; + private int field_92049_a = 160; + private boolean field_92054_ax; + private boolean field_92048_ay; + private final EffectRenderer field_92047_az; + private float field_92050_aA; + private float field_92051_aB; + private float field_92052_aC; + private boolean field_92053_aD; - public ClosingRiftFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12, EffectRenderer par14EffectRenderer) - { - - super(par1World, par2, par4, par6); - this.motionX = par8; - this.motionY = par10; - this.motionZ = par12; - this.field_92047_az = par14EffectRenderer; - this.particleScale *= .55F; - this.particleMaxAge = 30 + this.rand.nextInt(16); - this.noClip = false; - } + public ClosingRiftFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12, EffectRenderer par14EffectRenderer) + { - public void func_92045_e(boolean par1) - { - this.field_92054_ax = par1; - } + super(par1World, par2, par4, par6); + this.motionX = par8; + this.motionY = par10; + this.motionZ = par12; + this.field_92047_az = par14EffectRenderer; + this.particleScale *= .55F; + this.particleMaxAge = 30 + this.rand.nextInt(16); + this.noClip = false; + } - public void func_92043_f(boolean par1) - { - this.field_92048_ay = par1; - } + public void func_92045_e(boolean par1) + { + this.field_92054_ax = par1; + } - public void func_92044_a(int par1) - { - float var2 = (float)((par1 & 16711680) >> 16) / 255.0F; - float var3 = (float)((par1 & 65280) >> 8) / 255.0F; - float var4 = (float)((par1 & 255) >> 0) / 255.0F; - float var5 = 1.0F; - this.setRBGColorF(var2 * var5, var3 * var5, var4 * var5); - } + public void func_92043_f(boolean par1) + { + this.field_92048_ay = par1; + } - public void func_92046_g(int par1) - { - this.field_92050_aA = (float)((par1 & 16711680) >> 16) / 255.0F; - this.field_92051_aB = (float)((par1 & 65280) >> 8) / 255.0F; - this.field_92052_aC = (float)((par1 & 255) >> 0) / 255.0F; - this.field_92053_aD = true; - } + public void func_92044_a(int par1) + { + float var2 = (float)((par1 & 16711680) >> 16) / 255.0F; + float var3 = (float)((par1 & 65280) >> 8) / 255.0F; + float var4 = (float)((par1 & 255) >> 0) / 255.0F; + float var5 = 1.0F; + this.setRBGColorF(var2 * var5, var3 * var5, var4 * var5); + } - /** -* returns the bounding box for this entity -*/ - public AxisAlignedBB getBoundingBox() - { - return null; - } + public void func_92046_g(int par1) + { + this.field_92050_aA = (float)((par1 & 16711680) >> 16) / 255.0F; + this.field_92051_aB = (float)((par1 & 65280) >> 8) / 255.0F; + this.field_92052_aC = (float)((par1 & 255) >> 0) / 255.0F; + this.field_92053_aD = true; + } - /** -* Returns true if this entity should push and be pushed by other entities when colliding. -*/ - public boolean canBePushed() - { - return false; - } + /** + * returns the bounding box for this entity + */ + public AxisAlignedBB getBoundingBox() + { + return null; + } - public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) - { - if (!this.field_92048_ay || this.particleAge < this.particleMaxAge / 3 || (this.particleAge + this.particleMaxAge) / 3 % 2 == 0) - { - this.doRenderParticle(par1Tessellator, par2, par3, par4, par5, par6, par7); - } - } - - public void doRenderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) - { - float var8 = (float)(super.particleTextureIndexX % 16) / 16.0F; - float var9 = var8 + 0.0624375F; - float var10 = (float)(this.particleTextureIndexX / 16) / 16.0F; - float var11 = var10 + 0.0624375F; - float var12 = 0.1F * this.particleScale; - float var13 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX); - float var14 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY); - float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ); - float var16 = .8F; - try - { - if(PocketManager.instance.getDimData(this.worldObj.provider.dimensionId).isPocket) - { - var16=.4F; - } - else - { - - } - } - catch(Exception E) - { - - } - par1Tessellator.setColorRGBA_F(this.particleRed * var16, this.particleGreen * var16, this.particleBlue * var16, (float) .7); + /** + * Returns true if this entity should push and be pushed by other entities when colliding. + */ + public boolean canBePushed() + { + return false; + } - par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 - par5 * var12 - par7 * var12), (double)var9, (double)var11); - par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 - par5 * var12 + par7 * var12), (double)var9, (double)var10); - par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 + par5 * var12 + par7 * var12), (double)var8, (double)var10); - par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 + par5 * var12 - par7 * var12), (double)var8, (double)var11); - } + public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) + { + if (!this.field_92048_ay || this.particleAge < this.particleMaxAge / 3 || (this.particleAge + this.particleMaxAge) / 3 % 2 == 0) + { + this.doRenderParticle(par1Tessellator, par2, par3, par4, par5, par6, par7); + } + } - /** -* Called to update the entity's position/logic. -*/ - public void onUpdate() - { - this.prevPosX = this.posX; - this.prevPosY = this.posY; - this.prevPosZ = this.posZ; + public void doRenderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) + { + float var8 = (float)(super.particleTextureIndexX % 16) / 16.0F; + float var9 = var8 + 0.0624375F; + float var10 = (float)(this.particleTextureIndexX / 16) / 16.0F; + float var11 = var10 + 0.0624375F; + float var12 = 0.1F * this.particleScale; + float var13 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX); + float var14 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY); + float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ); + float var16 = 0.8F; - if (this.particleAge++ >= this.particleMaxAge) - { - this.setDead(); - } + if (PocketManager.getDimensionData(worldObj).isPocketDimension()) + { + var16 = 0.4F; + } + + par1Tessellator.setColorRGBA_F(this.particleRed * var16, this.particleGreen * var16, this.particleBlue * var16, (float) .7); - if (this.particleAge > this.particleMaxAge / 2) - { - this.setAlphaF(1.0F - ((float)this.particleAge - (float)(this.particleMaxAge / 2)) / (float)this.particleMaxAge); + par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 - par5 * var12 - par7 * var12), (double)var9, (double)var11); + par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 - par5 * var12 + par7 * var12), (double)var9, (double)var10); + par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 + par5 * var12 + par7 * var12), (double)var8, (double)var10); + par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 + par5 * var12 - par7 * var12), (double)var8, (double)var11); + } - if (this.field_92053_aD) - { - this.particleRed += (this.field_92050_aA - this.particleRed) * 0.2F; - this.particleGreen += (this.field_92051_aB - this.particleGreen) * 0.2F; - this.particleBlue += (this.field_92052_aC - this.particleBlue) * 0.2F; - } - } + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; - this.setParticleTextureIndex(this.field_92049_a + (7 - this.particleAge * 8 / this.particleMaxAge)); - // this.motionY -= 0.004D; - this.moveEntity(this.motionX, this.motionY, this.motionZ); - this.motionX *= 0.9100000262260437D; - this.motionY *= 0.9100000262260437D; - this.motionZ *= 0.9100000262260437D; + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } - if (this.onGround) - { - this.motionX *= 0.699999988079071D; - this.motionZ *= 0.699999988079071D; - } + if (this.particleAge > this.particleMaxAge / 2) + { + this.setAlphaF(1.0F - ((float)this.particleAge - (float)(this.particleMaxAge / 2)) / (float)this.particleMaxAge); - if (this.field_92054_ax && this.particleAge < this.particleMaxAge / 2 && (this.particleAge + this.particleMaxAge) % 2 == 0) - { - ClosingRiftFX var1 = new ClosingRiftFX(this.worldObj, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, this.field_92047_az); - var1.setRBGColorF(this.particleRed, this.particleGreen, this.particleBlue); - var1.particleAge = var1.particleMaxAge / 2; + if (this.field_92053_aD) + { + this.particleRed += (this.field_92050_aA - this.particleRed) * 0.2F; + this.particleGreen += (this.field_92051_aB - this.particleGreen) * 0.2F; + this.particleBlue += (this.field_92052_aC - this.particleBlue) * 0.2F; + } + } - if (this.field_92053_aD) - { - var1.field_92053_aD = true; - var1.field_92050_aA = this.field_92050_aA; - var1.field_92051_aB = this.field_92051_aB; - var1.field_92052_aC = this.field_92052_aC; - } + this.setParticleTextureIndex(this.field_92049_a + (7 - this.particleAge * 8 / this.particleMaxAge)); + // this.motionY -= 0.004D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9100000262260437D; + this.motionY *= 0.9100000262260437D; + this.motionZ *= 0.9100000262260437D; - var1.field_92048_ay = this.field_92048_ay; - this.field_92047_az.addEffect(var1); - } - } + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } - public int getBrightnessForRender(float par1) - { - return 15728880; - } + if (this.field_92054_ax && this.particleAge < this.particleMaxAge / 2 && (this.particleAge + this.particleMaxAge) % 2 == 0) + { + ClosingRiftFX var1 = new ClosingRiftFX(this.worldObj, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, this.field_92047_az); + var1.setRBGColorF(this.particleRed, this.particleGreen, this.particleBlue); + var1.particleAge = var1.particleMaxAge / 2; - /** -* Gets how bright this entity is. -*/ - public float getBrightness(float par1) - { - return 1.0F; - } + if (this.field_92053_aD) + { + var1.field_92053_aD = true; + var1.field_92050_aA = this.field_92050_aA; + var1.field_92051_aB = this.field_92051_aB; + var1.field_92052_aC = this.field_92052_aC; + } + + var1.field_92048_ay = this.field_92048_ay; + this.field_92047_az.addEffect(var1); + } + } + + public int getBrightnessForRender(float par1) + { + return 15728880; + } + + /** + * Gets how bright this entity is. + */ + public float getBrightness(float par1) + { + return 1.0F; + } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java b/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java index 0a8eb72..2f8999f 100644 --- a/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java +++ b/StevenDimDoors/mod_pocketDimClient/GoggleRiftFX.java @@ -1,195 +1,185 @@ package StevenDimDoors.mod_pocketDimClient; -import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.client.particle.EffectRenderer; -import net.minecraft.client.particle.EntityFX; import net.minecraft.client.particle.EntityFireworkSparkFX; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GoggleRiftFX extends EntityFireworkSparkFX { - private int field_92049_a = 160; - private boolean field_92054_ax; - private boolean field_92048_ay; - private final EffectRenderer field_92047_az; - private float field_92050_aA; - private float field_92051_aB; - private float field_92052_aC; - private boolean field_92053_aD; + private int field_92049_a = 160; + private boolean field_92054_ax; + private boolean field_92048_ay; + private final EffectRenderer field_92047_az; + private float field_92050_aA; + private float field_92051_aB; + private float field_92052_aC; + private boolean field_92053_aD; - public GoggleRiftFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12, EffectRenderer par14EffectRenderer) - { - - super(par1World, par2, par4, par6, par12, par12, par12, par14EffectRenderer); - this.motionX = par8; - this.motionY = par10; - this.motionZ = par12; - this.field_92047_az = par14EffectRenderer; - this.particleScale *= .55F; - this.particleMaxAge = 30 + this.rand.nextInt(16); - this.noClip = false; - } - public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) - { - if (!this.field_92048_ay || this.particleAge < this.particleMaxAge / 3 || (this.particleAge + this.particleMaxAge) / 3 % 2 == 0) - { - this.doRenderParticle(par1Tessellator, par2, par3, par4, par5, par6, par7); - } - } - - public void doRenderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) - { - float var8 = (float)(super.particleTextureIndexX % 16) / 16.0F; - float var9 = var8 + 0.0624375F; - float var10 = (float)(this.particleTextureIndexX / 16) / 16.0F; - float var11 = var10 + 0.0624375F; - float var12 = 0.1F * this.particleScale; - float var13 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX); - float var14 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY); - float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ); - float var16 = .0F; - try - { - if(PocketManager.instance.getDimData(this.worldObj.provider.dimensionId).isPocket) - { - var16=.7F; - } - else - { - - } - } - catch(Exception E) - { - - } - par1Tessellator.setColorRGBA_F(this.particleRed * var16, this.particleGreen * var16, this.particleBlue * var16, (float) .7); + public GoggleRiftFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12, EffectRenderer par14EffectRenderer) + { - par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 - par5 * var12 - par7 * var12), (double)var9, (double)var11); - par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 - par5 * var12 + par7 * var12), (double)var9, (double)var10); - par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 + par5 * var12 + par7 * var12), (double)var8, (double)var10); - par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 + par5 * var12 - par7 * var12), (double)var8, (double)var11); - } + super(par1World, par2, par4, par6, par12, par12, par12, par14EffectRenderer); + this.motionX = par8; + this.motionY = par10; + this.motionZ = par12; + this.field_92047_az = par14EffectRenderer; + this.particleScale *= .55F; + this.particleMaxAge = 30 + this.rand.nextInt(16); + this.noClip = false; + } + public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) + { + if (!this.field_92048_ay || this.particleAge < this.particleMaxAge / 3 || (this.particleAge + this.particleMaxAge) / 3 % 2 == 0) + { + this.doRenderParticle(par1Tessellator, par2, par3, par4, par5, par6, par7); + } + } + + public void doRenderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7) + { + float var8 = (float)(super.particleTextureIndexX % 16) / 16.0F; + float var9 = var8 + 0.0624375F; + float var10 = (float)(this.particleTextureIndexX / 16) / 16.0F; + float var11 = var10 + 0.0624375F; + float var12 = 0.1F * this.particleScale; + float var13 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX); + float var14 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY); + float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ); + float var16 = .0F; + + if (PocketManager.getDimensionData(worldObj).isPocketDimension()) + { + var16 = .7F; + } + + par1Tessellator.setColorRGBA_F(this.particleRed * var16, this.particleGreen * var16, this.particleBlue * var16, (float) .7); + + par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 - par5 * var12 - par7 * var12), (double)var9, (double)var11); + par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 - par5 * var12 + par7 * var12), (double)var9, (double)var10); + par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 + par5 * var12 + par7 * var12), (double)var8, (double)var10); + par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 + par5 * var12 - par7 * var12), (double)var8, (double)var11); + } - public void func_92045_e(boolean par1) - { - this.field_92054_ax = par1; - } + public void func_92045_e(boolean par1) + { + this.field_92054_ax = par1; + } - public void func_92043_f(boolean par1) - { - this.field_92048_ay = par1; - } + public void func_92043_f(boolean par1) + { + this.field_92048_ay = par1; + } - public void func_92044_a(int par1) - { - float var2 = (float)((par1 & 16711680) >> 16) / 255.0F; - float var3 = (float)((par1 & 65280) >> 8) / 255.0F; - float var4 = (float)((par1 & 255) >> 0) / 255.0F; - float var5 = 1.0F; - this.setRBGColorF(var2 * var5, var3 * var5, var4 * var5); - } + public void func_92044_a(int par1) + { + float var2 = (float)((par1 & 16711680) >> 16) / 255.0F; + float var3 = (float)((par1 & 65280) >> 8) / 255.0F; + float var4 = (float)((par1 & 255) >> 0) / 255.0F; + float var5 = 1.0F; + this.setRBGColorF(var2 * var5, var3 * var5, var4 * var5); + } - public void func_92046_g(int par1) - { - this.field_92050_aA = (float)((par1 & 16711680) >> 16) / 255.0F; - this.field_92051_aB = (float)((par1 & 65280) >> 8) / 255.0F; - this.field_92052_aC = (float)((par1 & 255) >> 0) / 255.0F; - this.field_92053_aD = true; - } + public void func_92046_g(int par1) + { + this.field_92050_aA = (float)((par1 & 16711680) >> 16) / 255.0F; + this.field_92051_aB = (float)((par1 & 65280) >> 8) / 255.0F; + this.field_92052_aC = (float)((par1 & 255) >> 0) / 255.0F; + this.field_92053_aD = true; + } - /** - * returns the bounding box for this entity - */ - public AxisAlignedBB getBoundingBox() - { - return null; - } + /** + * returns the bounding box for this entity + */ + public AxisAlignedBB getBoundingBox() + { + return null; + } - /** - * Returns true if this entity should push and be pushed by other entities when colliding. - */ - public boolean canBePushed() - { - return false; - } + /** + * Returns true if this entity should push and be pushed by other entities when colliding. + */ + public boolean canBePushed() + { + return false; + } - - - /** - * Called to update the entity's position/logic. - */ - public void onUpdate() - { - this.prevPosX = this.posX; - this.prevPosY = this.posY; - this.prevPosZ = this.posZ; - if (this.particleAge++ >= this.particleMaxAge) - { - this.setDead(); - } - if (this.particleAge > this.particleMaxAge / 2) - { - this.setAlphaF(1.0F - ((float)this.particleAge - (float)(this.particleMaxAge / 2)) / (float)this.particleMaxAge); + /** + * Called to update the entity's position/logic. + */ + public void onUpdate() + { + this.prevPosX = this.posX; + this.prevPosY = this.posY; + this.prevPosZ = this.posZ; - if (this.field_92053_aD) - { - this.particleRed += (this.field_92050_aA - this.particleRed) * 0.2F; - this.particleGreen += (this.field_92051_aB - this.particleGreen) * 0.2F; - this.particleBlue += (this.field_92052_aC - this.particleBlue) * 0.2F; - } - } + if (this.particleAge++ >= this.particleMaxAge) + { + this.setDead(); + } - this.setParticleTextureIndex(this.field_92049_a + (7 - this.particleAge * 8 / this.particleMaxAge)); - // this.motionY -= 0.004D; - this.moveEntity(this.motionX, this.motionY, this.motionZ); - this.motionX *= 0.9100000262260437D; - this.motionY *= 0.9100000262260437D; - this.motionZ *= 0.9100000262260437D; + if (this.particleAge > this.particleMaxAge / 2) + { + this.setAlphaF(1.0F - ((float)this.particleAge - (float)(this.particleMaxAge / 2)) / (float)this.particleMaxAge); - if (this.onGround) - { - this.motionX *= 0.699999988079071D; - this.motionZ *= 0.699999988079071D; - } + if (this.field_92053_aD) + { + this.particleRed += (this.field_92050_aA - this.particleRed) * 0.2F; + this.particleGreen += (this.field_92051_aB - this.particleGreen) * 0.2F; + this.particleBlue += (this.field_92052_aC - this.particleBlue) * 0.2F; + } + } - if (this.field_92054_ax && this.particleAge < this.particleMaxAge / 2 && (this.particleAge + this.particleMaxAge) % 2 == 0) - { - GoggleRiftFX var1 = new GoggleRiftFX(this.worldObj, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, this.field_92047_az); - var1.setRBGColorF(this.particleRed, this.particleGreen, this.particleBlue); - var1.particleAge = var1.particleMaxAge / 2; + this.setParticleTextureIndex(this.field_92049_a + (7 - this.particleAge * 8 / this.particleMaxAge)); + // this.motionY -= 0.004D; + this.moveEntity(this.motionX, this.motionY, this.motionZ); + this.motionX *= 0.9100000262260437D; + this.motionY *= 0.9100000262260437D; + this.motionZ *= 0.9100000262260437D; - if (this.field_92053_aD) - { - var1.field_92053_aD = true; - var1.field_92050_aA = this.field_92050_aA; - var1.field_92051_aB = this.field_92051_aB; - var1.field_92052_aC = this.field_92052_aC; - } + if (this.onGround) + { + this.motionX *= 0.699999988079071D; + this.motionZ *= 0.699999988079071D; + } - var1.field_92048_ay = this.field_92048_ay; - this.field_92047_az.addEffect(var1); - } - } + if (this.field_92054_ax && this.particleAge < this.particleMaxAge / 2 && (this.particleAge + this.particleMaxAge) % 2 == 0) + { + GoggleRiftFX var1 = new GoggleRiftFX(this.worldObj, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, this.field_92047_az); + var1.setRBGColorF(this.particleRed, this.particleGreen, this.particleBlue); + var1.particleAge = var1.particleMaxAge / 2; - public int getBrightnessForRender(float par1) - { - return 15728880; - } + if (this.field_92053_aD) + { + var1.field_92053_aD = true; + var1.field_92050_aA = this.field_92050_aA; + var1.field_92051_aB = this.field_92051_aB; + var1.field_92052_aC = this.field_92052_aC; + } - /** - * Gets how bright this entity is. - */ - public float getBrightness(float par1) - { - return 1.0F; - } + var1.field_92048_ay = this.field_92048_ay; + this.field_92047_az.addEffect(var1); + } + } + + public int getBrightnessForRender(float par1) + { + return 15728880; + } + + /** + * Gets how bright this entity is. + */ + public float getBrightness(float par1) + { + return 1.0F; + } } diff --git a/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java b/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java index 240f417..f0ea38a 100644 --- a/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java +++ b/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java @@ -40,12 +40,10 @@ public class RenderDimDoor extends TileEntitySpecialRenderer { try { - dimDoor.class.cast(Block.blocksList[properties.DimensionalDoorID]).updateAttatchedTile(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord).getFullMetadata(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord); - + mod_pocketDim.dimensionalDoor.updateAttachedTile(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord); } catch(Exception e) { - e.printStackTrace(); } -- 2.39.5 From f34b06b834ef30a8b93d585467fc3e601751724c Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 16:00:18 -0400 Subject: [PATCH 07/24] More Progress on Rewrite More cleaning up errors and code. There were a lot of things that needed simplifying. Rather than fix the 3 or 5 copies of the same function throughout the code, I made an effort to use the same function and delete its copies. Created the BaseItemDoor class to hold all the basic door item methods that don't vary between types. That helped cut down on fixing things. Also renamed the door item classes to match their in-game names. There is still a ton of duplicate code out there. --- .../mod_pocketDim/core/PocketManager.java | 5 + .../mod_pocketDim/helpers/DungeonHelper.java | 4 +- .../mod_pocketDim/items/BaseItemDoor.java | 146 +++++++ .../mod_pocketDim/items/ItemChaosDoor.java | 32 -- .../items/ItemDimensionalDoor.java | 48 +++ .../mod_pocketDim/items/ItemRiftBlade.java | 314 +++++--------- .../mod_pocketDim/items/ItemRiftGoggles.java | 3 - .../mod_pocketDim/items/ItemUnstableDoor.java | 45 ++ .../items/ItemUnstableRiftSignature.java | 1 - .../mod_pocketDim/items/ItemWarpDoor.java | 48 +++ .../mod_pocketDim/items/itemDimDoor.java | 207 --------- .../mod_pocketDim/items/itemExitDoor.java | 51 --- .../items/itemLinkSignature.java | 394 +++++++++--------- .../mod_pocketDim/mod_pocketDim.java | 23 +- .../mod_pocketDim/schematic/BlockRotator.java | 2 +- .../mod_pocketDim/world/GatewayGenerator.java | 4 +- .../mod_pocketDimClient/RiftFX.java | 24 +- 17 files changed, 620 insertions(+), 731 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java delete mode 100644 StevenDimDoors/mod_pocketDim/items/ItemChaosDoor.java create mode 100644 StevenDimDoors/mod_pocketDim/items/ItemDimensionalDoor.java create mode 100644 StevenDimDoors/mod_pocketDim/items/ItemUnstableDoor.java delete mode 100644 StevenDimDoors/mod_pocketDim/items/ItemUnstableRiftSignature.java create mode 100644 StevenDimDoors/mod_pocketDim/items/ItemWarpDoor.java delete mode 100644 StevenDimDoors/mod_pocketDim/items/itemDimDoor.java delete mode 100644 StevenDimDoors/mod_pocketDim/items/itemExitDoor.java diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 862332a..a905e7e 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -605,6 +605,11 @@ public class PocketManager { return dimensionData.values(); } + + public static IDimLink getLink(int x, int y, int z, World world) + { + return getLink(x, y, z, world.provider.dimensionId); + } public static IDimLink getLink(int x, int y, int z, int dimensionID) { diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index f7741ab..3913932 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -30,7 +30,7 @@ import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfig; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPackConfigReader; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType; -import StevenDimDoors.mod_pocketDim.items.itemDimDoor; +import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; import StevenDimDoors.mod_pocketDim.util.ConfigurationProcessingException; import StevenDimDoors.mod_pocketDim.util.WeightedContainer; @@ -281,7 +281,7 @@ public class DungeonHelper IDimLink link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); //Place a Warp Door linked to that pocket - itemDimDoor.placeDoorBlock(world, x, y, z, 3, mod_pocketDim.exitDoor); + ItemDimensionalDoor.placeDoorBlock(world, x, y, z, 3, mod_pocketDim.warpDoor); return link; } diff --git a/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java b/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java new file mode 100644 index 0000000..88600bc --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java @@ -0,0 +1,146 @@ +package StevenDimDoors.mod_pocketDim.items; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemDoor; +import net.minecraft.item.ItemStack; +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.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.PocketManager; + +public abstract class BaseItemDoor extends ItemDoor +{ + private static DDProperties properties = null; + + public BaseItemDoor(int itemID, Material material) + { + super(itemID, material); + this.setMaxStackSize(64); + this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); + if (properties == null) + properties = DDProperties.instance(); + } + + public void registerIcons(IconRegister par1IconRegister) + { + this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); + } + + @SuppressWarnings({ "rawtypes" }) + @Override + public abstract void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4); + + @Override + public abstract boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10); + + public static boolean tryItemUse(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, boolean requireLink, boolean reduceStack) + { + //FIXME: Without any sort of this documentation, this condition is like magic -_- ~SenseiKiwi + if (par7 == 1 && !world.isRemote) + { + int blockID = world.getBlockId(x, y, z); + if (blockID != 0) + { + if (!Block.blocksList[blockID].isBlockReplaceable(world, x, y, z)) + { + y++; + } + } + + if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) && + player.canPlayerEdit(x, y, z, par7, stack) && player.canPlayerEdit(x, y + 1, z, par7, stack) && + (!requireLink || PocketManager.getLink(x, y + 1, z, world) != null)) + { + int orientation = MathHelper.floor_double((double) ((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + placeDoorBlock(world, x, y, z, orientation, doorBlock); + + if (!player.capabilities.isCreativeMode && reduceStack) + { + stack.stackSize--; + } + return true; + } + } + return false; + } + + @Override + public final MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) + { + float var4 = 1.0F; + float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; + float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; + double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4; + double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset; + double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4; + Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); + float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI); + float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI); + float var16 = -MathHelper.cos(-var5 * 0.017453292F); + float var17 = MathHelper.sin(-var5 * 0.017453292F); + float var18 = var15 * var16; + float var20 = var14 * var16; + double var21 = 5.0D; + if (par2EntityPlayer instanceof EntityPlayerMP) + { + var21 = 4; + } + Vec3 var23 = var13.addVector((double) var18 * var21, (double)var17 * var21, (double)var20 * var21); + return par1World.rayTraceBlocks_do_do(var13, var23, true, false); + } + + @Override + public abstract ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player); + + public boolean tryPlacingDoor(Block doorBlock, World world, EntityPlayer player, ItemStack item) + { + if (world.isRemote) + { + return false; + } + + MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(player.worldObj, player, false); + if (hit != null) + { + if (world.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID) + { + IDimLink link = PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world.provider.dimensionId); + if (link != null) + { + int x = hit.blockX; + int y = hit.blockY; + int z = hit.blockZ; + int par7 = 0; + + if (player.canPlayerEdit(x, y, z, par7, item) && player.canPlayerEdit(x, y - 1, z, par7, item)) + { + if (canPlace(world, x, y, z) && canPlace(world, x, y - 1, z)) + { + int orientation = MathHelper.floor_double(((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + placeDoorBlock(world, x, y - 1, z, orientation, doorBlock); + return true; + } + } + } + } + } + return false; + } + + public static boolean canPlace(World world, int x, int y, int z) + { + int id = world.getBlockId(x, y, z); + + return (id == properties.RiftBlockID || id == 0 || Block.blocksList[id].blockMaterial.isReplaceable()); + } +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/items/ItemChaosDoor.java b/StevenDimDoors/mod_pocketDim/items/ItemChaosDoor.java deleted file mode 100644 index c218cd2..0000000 --- a/StevenDimDoors/mod_pocketDim/items/ItemChaosDoor.java +++ /dev/null @@ -1,32 +0,0 @@ -package StevenDimDoors.mod_pocketDim.items; - -import java.util.List; - -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; - -public class ItemChaosDoor extends itemDimDoor -{ - public ItemChaosDoor(int par1, Material par2Material) - { - super(par1, par2Material); - this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - } - - public void registerIcons(IconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName()); - - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) - { - par3List.add("Caution: Leads to random destination"); - } - -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/items/ItemDimensionalDoor.java b/StevenDimDoors/mod_pocketDim/items/ItemDimensionalDoor.java new file mode 100644 index 0000000..6804e28 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/items/ItemDimensionalDoor.java @@ -0,0 +1,48 @@ +package StevenDimDoors.mod_pocketDim.items; + +import java.util.List; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; + +public class ItemDimensionalDoor extends BaseItemDoor +{ + public ItemDimensionalDoor(int itemID, Material material) + { + super(itemID, material); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { + par3List.add("Place on the block under a rift"); + par3List.add("to activate that rift or place"); + par3List.add("anywhere else to create a"); + par3List.add("pocket dimension."); + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) + { + if (!world.isRemote) + { + if (tryPlacingDoor(mod_pocketDim.dimensionalDoor, world, player, stack) && + !player.capabilities.isCreativeMode) + { + stack.stackSize--; + } + } + return stack; + } + + @Override + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, + int z, int par7, float par8, float par9, float par10) + { + return tryItemUse(mod_pocketDim.dimensionalDoor, stack, player, world, x, y, z, par7, false, true); + } +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java index 25847dd..727fc24 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java @@ -20,36 +20,35 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ItemRiftBlade extends ItemSword { - public ItemRiftBlade(int par1) + private static DDProperties properties = null; + + public ItemRiftBlade(int itemID, EnumToolMaterial material) { - super(par1, EnumToolMaterial.GOLD); + super(itemID, material); - // this.setTextureFile("/PocketBlockTextures.png"); - this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); + this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); this.setMaxStackSize(1); - - // this.itemIcon=5; this.setMaxDamage(500); - this.hasSubtypes=false; - //TODO move to proxy + this.hasSubtypes = false; if (properties == null) properties = DDProperties.instance(); } - private static DDProperties properties = null; - @SideOnly(Side.CLIENT) public boolean isFull3D() { return true; } + @Override public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) { if (par2Block.blockID == Block.web.blockID) @@ -68,20 +67,22 @@ public class ItemRiftBlade extends ItemSword public boolean hasEffect(ItemStack par1ItemStack) { return true; - } + @Override public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving) { par1ItemStack.damageItem(1, par3EntityLiving); return true; } + @Override public int getDamageVsEntity(Entity par1Entity) { return 7; } + @Override public MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) { float var4 = 1.0F; @@ -106,11 +107,10 @@ public class ItemRiftBlade extends ItemSword return par1World.rayTraceBlocks_do_do(var13, var23, true, false); } - protected boolean teleportToEntity(ItemStack item, Entity par1Entity, EntityPlayer holder) + private boolean teleportToEntity(ItemStack item, Entity par1Entity, EntityPlayer holder) { Vec3 var2 = holder.worldObj.getWorldVec3Pool().getVecFromPool(holder.posX - par1Entity.posX, holder.boundingBox.minY + (double)(holder.height / 2.0F) - par1Entity.posY + (double)par1Entity.getEyeHeight(), holder.posZ - par1Entity.posZ); - double cooef =( var2.lengthVector()-2.5)/var2.lengthVector(); var2.xCoord*=cooef; var2.yCoord*=cooef; @@ -120,7 +120,6 @@ public class ItemRiftBlade extends ItemSword double var7 =holder.worldObj.getHeightValue(MathHelper.floor_double(var5), MathHelper.floor_double(var9)); if((Math.abs((holder.posY - var2.yCoord)-var7)>2)) { - var7 = MathHelper.floor_double(holder.posY - var2.yCoord) ; int var14 = MathHelper.floor_double(var5); @@ -133,262 +132,169 @@ public class ItemRiftBlade extends ItemSword var7=var15; } - holder.setPositionAndUpdate(var5, var7, var9); holder.playSound("mob.endermen.portal", 1.0F, 1.0F); holder.worldObj.playSoundEffect(holder.posX, holder.posY, holder.posZ, "mob.endermen.portal", 1.0F, 1.0F); - - + return true; } - public ItemStack onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - return par1ItemStack; - } /** * How long it takes to use or consume an item */ - public int getMaxItemUseDuration(ItemStack par1ItemStack) + @Override + public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 72000; } - public EnumAction getItemUseAction(ItemStack par1ItemStack) + @Override + public EnumAction getItemUseAction(ItemStack stack) { return properties.RiftBladeRiftCreationEnabled ? EnumAction.bow : EnumAction.block; } - public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) + @Override + public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int itemInUseCount) { //Condition for disabling rift creation if (!properties.RiftBladeRiftCreationEnabled) return; - Vec3 var2 = par3EntityPlayer.getLook(1.0F); + if (world.isRemote) + return; + + Vec3 var2 = player.getLook(1.0F); double cooef = -2; - var2.xCoord*=cooef; - var2.yCoord*=cooef; - var2.zCoord*=cooef; - double var5 = par3EntityPlayer.posX - var2.xCoord; - double var9 = par3EntityPlayer.posZ - var2.zCoord; - double var7 = par3EntityPlayer.posY - var2.yCoord+2; + var2.xCoord *= cooef; + var2.yCoord *= cooef; + var2.zCoord *= cooef; + double var5 = player.posX - var2.xCoord; + double var9 = player.posZ - var2.zCoord; + double var7 = player.posY - var2.yCoord + 2; int x = MathHelper.floor_double(var5); int y = MathHelper.floor_double(var7); int z = MathHelper.floor_double(var9); - int rotation = (int) (MathHelper.floor_double((double)((par3EntityPlayer.rotationYaw+90) * 4.0F / 360.0F) + 0.5D) & 3); - NewLinkData link = new NewLinkData(par2World.provider.dimensionId, 0, x, y, z, x, y, z, true,rotation); + int orientation = (int) (MathHelper.floor_double((double) ((player.rotationYaw + 90) * 4.0F / 360.0F) + 0.5D) & 3); - if(this.getMaxItemUseDuration(par1ItemStack)-par4>12&&!par2World.isRemote&&itemDimDoor.canPlace(par2World, x, y, z, rotation)) + //TODO: This looks weird. Shouldn't we aim to only create rifts on maxed-out usage time? i.e. "<= 0" + if (this.getMaxItemUseDuration(stack) - itemInUseCount > 12 && + ItemDimensionalDoor.canPlace(world, x, y, z) && ItemDimensionalDoor.canPlace(world, x, y + 1, z)) { - - if(PocketManager.instance.getDimData(par2World.provider.dimensionId)!=null) + NewDimData dimension = PocketManager.getDimensionData(world); + if (!dimension.isPocketDimension() && dimension.getLink(x, y + 1, z) == null) { - if(PocketManager.instance.getDimData(par2World.provider.dimensionId).depth==0) - { - PocketManager.instance.createPocket(link,true, false); - } - } - else - { - PocketManager.instance.createPocket(link,true, false); - } - par3EntityPlayer.worldObj.playSoundAtEntity(par3EntityPlayer,"mods.DimDoors.sfx.riftDoor", (float) .6, 1); - itemDimDoor.placeDoorBlock(par2World, x, y-1, z, rotation, mod_pocketDim.transientDoor); + dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); + player.worldObj.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1); + ItemDimensionalDoor.placeDoorBlock(world, x, y, z, orientation, mod_pocketDim.transientDoor); + } } } - public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { - Boolean didFindThing=false; - MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(par3EntityPlayer.worldObj, par3EntityPlayer, false ); - if(hit!=null&&!par2World.isRemote) + if (!world.isRemote) { - if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ)==properties.RiftBlockID) + @SuppressWarnings("unchecked") + List list = (List) world.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getBoundingBox(player.posX-8,player.posY-8, player.posZ-8, player.posX+8,player.posY+8, player.posZ+8)); + list.remove(player); + + for (EntityLiving ent : list) { - NewLinkData link = PocketManager.instance.getLinkDataFromCoords(hit.blockX, hit.blockY, hit.blockZ, par2World); - if(link!=null) - { - - Block var11 = mod_pocketDim.transientDoor; - int par4 = hit.blockX; - int par5 = hit.blockY; - int par6 = hit.blockZ; - int par7 = 0 ; - - - - - if (par3EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par3EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)&&!par2World.isRemote) - { - int var12 = MathHelper.floor_double((double)((par3EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - - if (!itemDimDoor.canPlace(par2World, par4, par5, par6, var12)||!itemDimDoor.canPlace(par2World, par4, par5-1, par6, var12)||PocketManager.instance.getLinkDataFromCoords(par4, par5, par6, par2World)==null) - { - return par1ItemStack; - } - else - { - - itemDimDoor.placeDoorBlock(par2World, par4, par5-1, par6, var12, var11); - par3EntityPlayer.worldObj.playSoundAtEntity(par3EntityPlayer,"mods.DimDoors.sfx.riftDoor", (float) .6, 1); - - didFindThing=true; - - - par1ItemStack.damageItem(10, par3EntityPlayer); - - } - } - } - } - else if(par2World.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.TransientDoorID) - { - didFindThing=true; - } - - } - - - - - if(!par3EntityPlayer.worldObj.isRemote) - { - List list = par3EntityPlayer.worldObj.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getBoundingBox( par3EntityPlayer.posX-8,par3EntityPlayer.posY-8, par3EntityPlayer.posZ-8, par3EntityPlayer.posX+8,par3EntityPlayer.posY+8, par3EntityPlayer.posZ+8)); - list.remove(par3EntityPlayer); - - - for(EntityLiving ent : list) - { - - Vec3 var3 = par3EntityPlayer.getLook(1.0F).normalize(); - Vec3 var4 = par3EntityPlayer.worldObj.getWorldVec3Pool().getVecFromPool(ent.posX - par3EntityPlayer.posX, ent.boundingBox.minY + (double)((ent.height) / 2.0F) - ( par3EntityPlayer.posY + (double) par3EntityPlayer.getEyeHeight()), ent.posZ - par3EntityPlayer.posZ); + Vec3 var3 = player.getLook(1.0F).normalize(); + Vec3 var4 = player.worldObj.getWorldVec3Pool().getVecFromPool(ent.posX - player.posX, ent.boundingBox.minY + (double)((ent.height) / 2.0F) - ( player.posY + (double) player.getEyeHeight()), ent.posZ - player.posZ); double var5 = var4.lengthVector(); var4 = var4.normalize(); double var7 = var3.dotProduct(var4); - if( (var7+.1) > 1.0D - 0.025D / var5 ? par3EntityPlayer.canEntityBeSeen(ent) : false) + if( (var7+.1) > 1.0D - 0.025D / var5 ? player.canEntityBeSeen(ent) : false) { - System.out.println(list.size()); - ItemRiftBlade.class.cast(par1ItemStack.getItem()).teleportToEntity(par1ItemStack,ent, par3EntityPlayer); - didFindThing=true; - break; - - //ItemRiftBlade.class.cast(item.getItem()).teleportTo(event.entityPlayer, ent.posX, ent.posY, ent.posZ); + ((ItemRiftBlade) stack.getItem()).teleportToEntity(stack, ent, player); + return stack; } } + MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(world, player, false); + if (hit != null) + { + if (world.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID) + { + if (PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world) != null) + { + Block var11 = mod_pocketDim.transientDoor; + int par4 = hit.blockX; + int par5 = hit.blockY; + int par6 = hit.blockZ; + int par7 = 0; - } - // if(dimHelper.instance.getDimData(par2World.provider.dimensionId)!=null&&!par2World.isRemote&&!didFindThing) - { - - par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack)); + if (player.canPlayerEdit(par4, par5, par6, par7, stack) && player.canPlayerEdit(par4, par5 + 1, par6, par7, stack)&&!world.isRemote) + { + int var12 = MathHelper.floor_double((double)((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + if (BaseItemDoor.canPlace(world, par4, par5, par6) && + BaseItemDoor.canPlace(world, par4, par5 - 1, par6)) + { + ItemDimensionalDoor.placeDoorBlock(world, par4, par5 - 1, par6, var12, var11); + player.worldObj.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1); + stack.damageItem(10, player); + } + } + } + return stack; + } + } + + //FIXME: Should this be inside or after this IF? + player.setItemInUse(stack, this.getMaxItemUseDuration(stack)); } - - - - return par1ItemStack; - + return stack; } + + @Override public void registerIcons(IconRegister par1IconRegister) { this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName()); - } - public int getItemEnchantability() - { - return EnumToolMaterial.GOLD.getEnchantability(); - } - /** - * Return the name for this tool's material. - */ - public String getToolMaterialName() - { - return EnumToolMaterial.GOLD.toString(); - } - - /** - * Return whether this item is repairable in an anvil. - */ - public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) - { - return mod_pocketDim.itemStableFabric.itemID == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); - } - - public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) + /** + * Return whether this item is repairable in an anvil. + */ + @Override + public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { - if (par7 != 1) + //Don't include a call to super.getIsRepairable()! + //That would cause this sword to accept gold as a repair material (since we set material = Gold). + return mod_pocketDim.itemStableFabric.itemID == par2ItemStack.itemID ? true : false; + } + + @Override + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, + int z, int par7, float par8, float par9, float par10) + { + if (BaseItemDoor.tryItemUse(mod_pocketDim.transientDoor, stack, player, world, x, y, z, par7, true, false)) { - return false; + world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1); + return true; } else { - ++par5; - Block var11; - - - - var11 = mod_pocketDim.transientDoor; - if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)&&!par3World.isRemote) - { - int var12 = MathHelper.floor_double((double)((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - - if (!itemDimDoor.canPlace(par3World, par4, par5, par6, var12)||PocketManager.instance.getLinkDataFromCoords(par4, par5+1, par6, par3World)==null) - { - return false; - } - else - { - - itemDimDoor.placeDoorBlock(par3World, par4, par5, par6, var12, var11); - par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.rift", (float) .6, 1); - - - par1ItemStack.damageItem(10, par2EntityPlayer); - return true; - } - } - else - { - return false; - } + return false; } } - - - @SideOnly(Side.CLIENT) - /** * allows items to add custom lines of information to the mouseover description */ - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + @SuppressWarnings({ "unchecked", "rawtypes" }) + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { - par3List.add("Opens a temporary doors,"); - par3List.add ("special teleport attack,"); - par3List.add ("and rotates existing doors"); - } - - @Override - public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - if(!par2World.isRemote) - { - /** - //creates the first half of the link on item creation - int key= dimHelper.instance.createUniqueInterDimLinkKey(); - LinkData linkData= new LinkData(par2World.provider.dimensionId,MathHelper.floor_double(par3EntityPlayer.posX),MathHelper.floor_double(par3EntityPlayer.posY),MathHelper.floor_double(par3EntityPlayer.posZ)); - System.out.println(key); - - dimHelper.instance.interDimLinkList.put(key, linkData); - par1ItemStack.setItemDamage(key); - **/ - } + par3List.add("Opens a temporary door, has"); + par3List.add("a special teleport attack,"); + par3List.add("and rotates existing doors."); } } diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftGoggles.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftGoggles.java index 815f4b9..dfaedeb 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftGoggles.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftGoggles.java @@ -1,14 +1,11 @@ package StevenDimDoors.mod_pocketDim.items; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.EnumArmorMaterial; import net.minecraft.item.ItemArmor; public class ItemRiftGoggles extends ItemArmor { - private Material doorMaterial; public ItemRiftGoggles(int par1, int par2, int par3) { diff --git a/StevenDimDoors/mod_pocketDim/items/ItemUnstableDoor.java b/StevenDimDoors/mod_pocketDim/items/ItemUnstableDoor.java new file mode 100644 index 0000000..a7d63ec --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/items/ItemUnstableDoor.java @@ -0,0 +1,45 @@ +package StevenDimDoors.mod_pocketDim.items; + +import java.util.List; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; + +public class ItemUnstableDoor extends BaseItemDoor +{ + public ItemUnstableDoor(int itemID, Material material) + { + super(itemID, material); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { + par3List.add("Caution: Leads to random destination"); + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) + { + if (!world.isRemote) + { + if (tryPlacingDoor(mod_pocketDim.unstableDoor, world, player, stack) && + !player.capabilities.isCreativeMode) + { + stack.stackSize--; + } + } + return stack; + } + + @Override + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, + int z, int par7, float par8, float par9, float par10) + { + return tryItemUse(mod_pocketDim.unstableDoor, stack, player, world, x, y, z, par7, false, true); + } +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/items/ItemUnstableRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemUnstableRiftSignature.java deleted file mode 100644 index bb245f5..0000000 --- a/StevenDimDoors/mod_pocketDim/items/ItemUnstableRiftSignature.java +++ /dev/null @@ -1 +0,0 @@ -package StevenDimDoors.mod_pocketDim.items; diff --git a/StevenDimDoors/mod_pocketDim/items/ItemWarpDoor.java b/StevenDimDoors/mod_pocketDim/items/ItemWarpDoor.java new file mode 100644 index 0000000..0309a3f --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/items/ItemWarpDoor.java @@ -0,0 +1,48 @@ +package StevenDimDoors.mod_pocketDim.items; + +import java.util.List; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; + +public class ItemWarpDoor extends BaseItemDoor +{ + public ItemWarpDoor(int itemID, Material material) + { + super(itemID, material); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { + par3List.add("Place on the block under"); + par3List.add("a rift to create a portal,"); + par3List.add("or place anywhere in a"); + par3List.add("pocket dimension to exit."); + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) + { + if (!world.isRemote) + { + if (tryPlacingDoor(mod_pocketDim.warpDoor, world, player, stack) && + !player.capabilities.isCreativeMode) + { + stack.stackSize--; + } + } + return stack; + } + + @Override + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, + int z, int par7, float par8, float par9, float par10) + { + return tryItemUse(mod_pocketDim.warpDoor, stack, player, world, x, y, z, par7, false, true); + } +} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java b/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java deleted file mode 100644 index 6b9edce..0000000 --- a/StevenDimDoors/mod_pocketDim/items/itemDimDoor.java +++ /dev/null @@ -1,207 +0,0 @@ -package StevenDimDoors.mod_pocketDim.items; - -import java.util.List; - -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.ItemDoor; -import net.minecraft.item.ItemStack; -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.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; -import StevenDimDoors.mod_pocketDim.core.PocketManager; - -public class itemDimDoor extends ItemDoor -{ - private static DDProperties properties = null; - - public itemDimDoor(int par1, Material par2Material) - { - super(par1, par2Material); - this.setMaxStackSize(64); - this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - if (properties == null) - properties = DDProperties.instance(); - } - - public void registerIcons(IconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) - { - par3List.add("Place on the block under a rift"); - par3List.add("to activate that rift or place"); - par3List.add("anywhere else to create a"); - par3List.add("pocket dimension."); - } - - @Override - public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) - { - if (par7 != 1) - { - return false; - } - else - { - ++par5; - Block var11; - - - if(par1ItemStack.getItem() instanceof itemExitDoor) - { - var11 = mod_pocketDim.exitDoor; - } - - else if (par1ItemStack.getItem() instanceof ItemChaosDoor) - { - var11 = mod_pocketDim.unstableDoor; - } - else if (par1ItemStack.getItem() instanceof itemDimDoor) - { - var11 = mod_pocketDim.dimensionalDoor; - } - else - { - //Do nothing - return false; - } - - if (par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack) && par2EntityPlayer.canPlayerEdit(par4, par5 + 1, par6, par7, par1ItemStack)&&!par3World.isRemote) - { - int var12 = MathHelper.floor_double((double)((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - - if (!canPlace(par3World, par4, par5, par6) || !canPlace(par3World, par4, par5+1, par6)) - { - return false; - } - else - { - int offset = 0; - int idBlock = par3World.getBlockId(par4, par5-1, par6); - - if(Block.blocksList.length>idBlock&&idBlock!=0) - { - if(Block.blocksList[idBlock].isBlockReplaceable(par3World, par4, par5-1, par6)) - { - offset = 1; - } - } - - placeDoorBlock(par3World, par4, par5-offset, par6, var12, var11); - - --par1ItemStack.stackSize; - return true; - } - } - else - { - return false; - } - } - } - - public MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean par3) - { - float var4 = 1.0F; - float var5 = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * var4; - float var6 = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * var4; - double var7 = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * (double)var4; - double var9 = par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par2EntityPlayer.yOffset; - double var11 = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * (double)var4; - Vec3 var13 = par1World.getWorldVec3Pool().getVecFromPool(var7, var9, var11); - float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI); - float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI); - float var16 = -MathHelper.cos(-var5 * 0.017453292F); - float var17 = MathHelper.sin(-var5 * 0.017453292F); - float var18 = var15 * var16; - float var20 = var14 * var16; - double var21 = 5.0D; - if (par2EntityPlayer instanceof EntityPlayerMP) - { - var21 = 4; - } - Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21); - return par1World.rayTraceBlocks_do_do(var13, var23, true, false); - } - - public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) - { - if (world.isRemote) - { - return stack; - } - - MovingObjectPosition hit = this.getMovingObjectPositionFromPlayer(player.worldObj, player, false ); - if (hit != null) - { - if (world.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID) - { - IDimLink link = PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world.provider.dimensionId); - if (link != null) - { - Block block; - if (stack.getItem() instanceof itemExitDoor) - { - block = mod_pocketDim.exitDoor; - } - else if (stack.getItem() instanceof ItemChaosDoor) - { - block = mod_pocketDim.unstableDoor; - } - else if (stack.getItem() instanceof itemDimDoor) - { - block = mod_pocketDim.dimensionalDoor; - } - else - { - //Do nothing - return stack; - } - - int x = hit.blockX; - int y = hit.blockY; - int z = hit.blockZ; - int par7 = 0; - - if (player.canPlayerEdit(x, y, z, par7, stack) && player.canPlayerEdit(x, y - 1, z, par7, stack)) - { - int orientation = MathHelper.floor_double((double) ((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - - if (!canPlace(world, x, y, z) || !canPlace(world, x, y - 1, z)) - { - return stack; - } - else - { - placeDoorBlock(world, x, y - 1, z, orientation, block); - if (!player.capabilities.isCreativeMode) - { - stack.stackSize--; - } - } - } - } - } - } - return stack; - } - - private static boolean canPlace(World world, int x, int y, int z) - { - int id = world.getBlockId(x, y, z); - - return (id == properties.RiftBlockID || id == 0 || Block.blocksList[id].blockMaterial.isReplaceable()); - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/items/itemExitDoor.java b/StevenDimDoors/mod_pocketDim/items/itemExitDoor.java deleted file mode 100644 index 50312ba..0000000 --- a/StevenDimDoors/mod_pocketDim/items/itemExitDoor.java +++ /dev/null @@ -1,51 +0,0 @@ -package StevenDimDoors.mod_pocketDim.items; - -import java.util.List; - -import StevenDimDoors.mod_pocketDim.mod_pocketDim; - -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemDoor; -import net.minecraft.item.ItemStack; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; - -public class itemExitDoor extends itemDimDoor -{ - private Material doorMaterial; - - public itemExitDoor(int par1, Material par2Material) - { - super(par1, par2Material); - this.doorMaterial = par2Material; - this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - - } - - public void registerIcons(IconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); - - } - - - @Override - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) - { - - - par3List.add("Place on the block under a rift"); - par3List.add ("in any dimension,"); - par3List.add("or place anywhere in pocket dim"); - par3List.add("to approach surface"); - - - - } - - -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java index 4a0538a..2d9ce99 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java @@ -19,243 +19,239 @@ import cpw.mods.fml.relauncher.SideOnly; public class itemLinkSignature extends Item { - public itemLinkSignature(int par1) - { - super(par1); - this.setMaxStackSize(1); - // this.setTextureFile("/PocketBlockTextures.png"); - this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - - // this.itemIcon=5; - this.setMaxDamage(0); - this.hasSubtypes=true; - //TODO move to proxy + public itemLinkSignature(int itemID) + { + super(itemID); + this.setMaxStackSize(1); + this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); + this.setMaxDamage(0); + this.hasSubtypes = true; if (properties == null) properties = DDProperties.instance(); } - + private static DDProperties properties = null; - - @SideOnly(Side.CLIENT) - @Override - public boolean hasEffect(ItemStack par1ItemStack) - { - // adds effect if item has a link stored - - - if(par1ItemStack.hasTagCompound()) - { - if(par1ItemStack.stackTagCompound.getBoolean("isCreated")) - { - return true; - } - } - return false; - } - - - public void registerIcons(IconRegister par1IconRegister) - { - this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName()); - } + @SideOnly(Side.CLIENT) + @Override + public boolean hasEffect(ItemStack par1ItemStack) + { + // adds effect if item has a link stored - @Override - public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) - { - int key; - ILinkData linkData; + + if(par1ItemStack.hasTagCompound()) + { + if(par1ItemStack.stackTagCompound.getBoolean("isCreated")) + { + return true; + } + } + return false; + } + + + public void registerIcons(IconRegister par1IconRegister) + { + this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName()); + + } + + @Override + public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) + { + int key; + ILinkData linkData; int thisWorldID=par3World.provider.dimensionId; - - - - if(!par3World.isRemote) - { - + + + + if(!par3World.isRemote) + { + //par1ItemStack= par2EntityPlayer.getCurrentEquippedItem(); Integer[] linkCoords =this.readFromNBT(par1ItemStack); - - - - //System.out.println(key); - int offset = 2; - int idBlock = par3World.getBlockId(par4, par5, par6); - - if(Block.blocksList.length>idBlock&&idBlock!=0) - { - if(Block.blocksList[idBlock].isBlockReplaceable(par3World, par4, par5, par6)) - { - offset = 1; - } - } + + + + //System.out.println(key); + int offset = 2; + int idBlock = par3World.getBlockId(par4, par5, par6); + + if(Block.blocksList.length>idBlock&&idBlock!=0) + { + if(Block.blocksList[idBlock].isBlockReplaceable(par3World, par4, par5, par6)) + { + offset = 1; + } + } if(par3World.getBlockId(par4, par5, par6) == properties.DimensionalDoorID && par3World.getBlockId(par4, par5 + 1, par6) == properties.DimensionalDoorID) { offset = 1; } else - if(par3World.getBlockId(par4, par5, par6)==properties.WarpDoorID&&par3World.getBlockId(par4, par5+1, par6)==properties.WarpDoorID) - { - offset = 1; - } - else - if (par3World.getBlockId(par4, par5, par6)==properties.DimensionalDoorID&&par3World.getBlockId(par4, par5-1, par6)==properties.DimensionalDoorID) - { - offset = 0; - } - else - if (par3World.getBlockId(par4, par5, par6) == properties.WarpDoorID && par3World.getBlockId(par4, par5-1, par6)==properties.WarpDoorID) - { - offset = 0; - } - + if(par3World.getBlockId(par4, par5, par6)==properties.WarpDoorID&&par3World.getBlockId(par4, par5+1, par6)==properties.WarpDoorID) + { + offset = 1; + } + else + if (par3World.getBlockId(par4, par5, par6)==properties.DimensionalDoorID&&par3World.getBlockId(par4, par5-1, par6)==properties.DimensionalDoorID) + { + offset = 0; + } + else + if (par3World.getBlockId(par4, par5, par6) == properties.WarpDoorID && par3World.getBlockId(par4, par5-1, par6)==properties.WarpDoorID) + { + offset = 0; + } + int orientation = MathHelper.floor_double((double)((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - + for(int count = 0;count<3;count++) { if(PocketManager.instance.getLinkDataFromCoords(par4, par5+count, par6,par3World)!=null) { int id= (par3World.getBlockId(par4, par5+count, par6)); - + if(id == properties.DimensionalDoorID||id==properties.WarpDoorID||id== properties.UnstableDoorID) { orientation = PocketManager.instance.getLinkDataFromCoords(par4, par5+count, par6,par3World).linkOrientation; } } - + } - - if(par1ItemStack.getTagCompound()!=null) - { - if(par1ItemStack.getTagCompound().getBoolean("isCreated")) - { - // checks to see if the item has a link stored, if so, it creates it - - - PocketManager.instance.createLink(par3World.provider.dimensionId, linkCoords[3], par4, par5+offset, par6, linkCoords[0], linkCoords[1], linkCoords[2],orientation); - PocketManager.instance.createLink(linkCoords[3], par3World.provider.dimensionId, linkCoords[0], linkCoords[1], linkCoords[2],par4, par5+offset, par6,linkCoords[4]); - - + if(par1ItemStack.getTagCompound()!=null) + { + if(par1ItemStack.getTagCompound().getBoolean("isCreated")) + { + // checks to see if the item has a link stored, if so, it creates it - --par1ItemStack.stackSize; - par2EntityPlayer.sendChatToPlayer("Rift Created"); - par1ItemStack.stackTagCompound=null; + + + PocketManager.instance.createLink(par3World.provider.dimensionId, linkCoords[3], par4, par5+offset, par6, linkCoords[0], linkCoords[1], linkCoords[2],orientation); + PocketManager.instance.createLink(linkCoords[3], par3World.provider.dimensionId, linkCoords[0], linkCoords[1], linkCoords[2],par4, par5+offset, par6,linkCoords[4]); + + + + --par1ItemStack.stackSize; + par2EntityPlayer.sendChatToPlayer("Rift Created"); + par1ItemStack.stackTagCompound=null; par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftEnd", (float) .6, 1); - } - } - else - { + } + } + else + { - - //otherwise, it creates the first half of the link. Next click will complete it. - key= PocketManager.instance.createUniqueInterDimLinkKey(); - this.writeToNBT(par1ItemStack, par4, par5+offset, par6,par3World.provider.dimensionId,orientation); - par2EntityPlayer.sendChatToPlayer("Rift Signature Stored"); + + //otherwise, it creates the first half of the link. Next click will complete it. + key= PocketManager.instance.createUniqueInterDimLinkKey(); + this.writeToNBT(par1ItemStack, par4, par5+offset, par6,par3World.provider.dimensionId,orientation); + par2EntityPlayer.sendChatToPlayer("Rift Signature Stored"); par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftStart", (float) .6, 1); - } - //dimHelper.instance.save(); - } - - - return true; - - - } - - @SideOnly(Side.CLIENT) - - /** - * allows items to add custom lines of information to the mouseover description - */ - public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) - { - - if(par1ItemStack.hasTagCompound()) - { - if(par1ItemStack.stackTagCompound.getBoolean("isCreated")) - { - Integer[] coords = this.readFromNBT(par1ItemStack); - - par3List.add(String.valueOf("Leads to dim "+coords[3] +" with depth "+(PocketManager.instance.getDimDepth(coords[3])))); - par3List.add("at x="+coords[0]+" y="+coords[1]+" z="+coords[2]); - - } - - } - else - { - par3List.add("First click stores location,"); - par3List.add ("second click creates two rifts,"); - par3List.add("that link the first location"); - par3List.add("with the second location"); + } + //dimHelper.instance.save(); + } - } - } - - public void writeToNBT(ItemStack itemStack,int x, int y, int z, int dimID,int orientation) - { - NBTTagCompound tag; + return true; - if(itemStack.hasTagCompound()) - { - tag = itemStack.getTagCompound(); - - } - else - { - tag= new NBTTagCompound(); - } - - tag.setInteger("linkX", x); - tag.setInteger("linkY", y); - tag.setInteger("linkZ", z); - tag.setInteger("linkDimID", dimID); - tag.setBoolean("isCreated", true); - tag.setInteger("orientation", orientation); - itemStack.setTagCompound(tag); + } - } + @SideOnly(Side.CLIENT) - /** - * Read the stack fields from a NBT object. - */ - public Integer[] readFromNBT(ItemStack itemStack) - { - - NBTTagCompound tag; - Integer[] linkCoords = new Integer[5]; - if(itemStack.hasTagCompound()) - { - tag = itemStack.getTagCompound(); + /** + * allows items to add custom lines of information to the mouseover description + */ + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { - if(!tag.getBoolean("isCreated")) - { - return null; - } - linkCoords[0]=tag.getInteger("linkX"); - linkCoords[1]=tag.getInteger("linkY"); - linkCoords[2]=tag.getInteger("linkZ"); - linkCoords[3]=tag.getInteger("linkDimID"); - linkCoords[4]=tag.getInteger("orientation"); + if(par1ItemStack.hasTagCompound()) + { + if(par1ItemStack.stackTagCompound.getBoolean("isCreated")) + { + Integer[] coords = this.readFromNBT(par1ItemStack); - - - } - return linkCoords; - - } - - - @Override - public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - if(!par2World.isRemote) - { - /** + par3List.add(String.valueOf("Leads to dim "+coords[3] +" with depth "+(PocketManager.instance.getDimDepth(coords[3])))); + par3List.add("at x="+coords[0]+" y="+coords[1]+" z="+coords[2]); + + } + + } + else + { + par3List.add("First click stores location,"); + par3List.add ("second click creates two rifts,"); + par3List.add("that link the first location"); + par3List.add("with the second location"); + + + } + } + + public void writeToNBT(ItemStack itemStack,int x, int y, int z, int dimID,int orientation) + { + NBTTagCompound tag; + + if(itemStack.hasTagCompound()) + { + tag = itemStack.getTagCompound(); + + } + else + { + tag= new NBTTagCompound(); + } + + tag.setInteger("linkX", x); + tag.setInteger("linkY", y); + tag.setInteger("linkZ", z); + tag.setInteger("linkDimID", dimID); + tag.setBoolean("isCreated", true); + tag.setInteger("orientation", orientation); + + itemStack.setTagCompound(tag); + + } + + /** + * Read the stack fields from a NBT object. + */ + public Integer[] readFromNBT(ItemStack itemStack) + { + + NBTTagCompound tag; + Integer[] linkCoords = new Integer[5]; + if(itemStack.hasTagCompound()) + { + tag = itemStack.getTagCompound(); + + if(!tag.getBoolean("isCreated")) + { + return null; + } + linkCoords[0]=tag.getInteger("linkX"); + linkCoords[1]=tag.getInteger("linkY"); + linkCoords[2]=tag.getInteger("linkZ"); + linkCoords[3]=tag.getInteger("linkDimID"); + linkCoords[4]=tag.getInteger("orientation"); + + + + } + return linkCoords; + + } + + + @Override + public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) + { + if(!par2World.isRemote) + { + /** //creates the first half of the link on item creation int key= dimHelper.instance.createUniqueInterDimLinkKey(); LinkData linkData= new LinkData(par2World.provider.dimensionId,MathHelper.floor_double(par3EntityPlayer.posX),MathHelper.floor_double(par3EntityPlayer.posY),MathHelper.floor_double(par3EntityPlayer.posZ)); @@ -263,7 +259,7 @@ public class itemLinkSignature extends Item dimHelper.instance.interDimLinkList.put(key, linkData); par1ItemStack.setItemDamage(key); - **/ - } - } + **/ + } + } } diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 390bb86..07fa2a0 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -10,6 +10,7 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityEggInfo; import net.minecraft.entity.EntityList; import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.EnumToolMaterial; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.biome.BiomeGenBase; @@ -36,12 +37,12 @@ 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.ItemChaosDoor; +import StevenDimDoors.mod_pocketDim.items.ItemUnstableDoor; import StevenDimDoors.mod_pocketDim.items.ItemRiftBlade; import StevenDimDoors.mod_pocketDim.items.ItemStabilizedRiftSignature; import StevenDimDoors.mod_pocketDim.items.ItemStableFabric; -import StevenDimDoors.mod_pocketDim.items.itemDimDoor; -import StevenDimDoors.mod_pocketDim.items.itemExitDoor; +import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; +import StevenDimDoors.mod_pocketDim.items.ItemWarpDoor; import StevenDimDoors.mod_pocketDim.items.itemLinkSignature; import StevenDimDoors.mod_pocketDim.items.itemRiftRemover; import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; @@ -101,7 +102,7 @@ public class mod_pocketDim public static mod_pocketDim instance = new mod_pocketDim(); public static Block transientDoor; - public static Block exitDoor; + public static Block warpDoor; public static Block unstableDoor; public static Block blockLimbo; public static dimDoor dimensionalDoor; @@ -184,7 +185,7 @@ public class mod_pocketDim blockDimWall = (new BlockDimWall(properties.FabricBlockID, 0, Material.iron)).setLightValue(1.0F).setHardness(0.1F).setUnlocalizedName("blockDimWall"); blockDimWallPerm = (new BlockDimWallPerm(properties.PermaFabricBlockID, 0, Material.iron)).setLightValue(1.0F).setBlockUnbreakable().setResistance(6000000.0F).setUnlocalizedName("blockDimWallPerm"); - exitDoor = (new ExitDoor(properties.WarpDoorID, Material.wood)).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); + warpDoor = (new ExitDoor(properties.WarpDoorID, Material.wood)).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); blockRift = (BlockRift) (new BlockRift(properties.RiftBlockID, 0, Material.air, properties).setHardness(1.0F) .setUnlocalizedName("rift")); blockLimbo = (new BlockLimbo(properties.LimboBlockID, 15, Material.iron, properties.LimboDimensionID, decay).setHardness(.2F).setUnlocalizedName("BlockLimbo").setLightValue(.0F)); unstableDoor = (new ChaosDoor(properties.UnstableDoorID, Material.iron).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); @@ -192,13 +193,13 @@ public class mod_pocketDim dimHatch = (new dimHatch(properties.TransTrapdoorID, 84, Material.iron)).setHardness(1.0F) .setUnlocalizedName("dimHatch"); // dimRail = (new DimRail(dimRailID, 88, false)).setHardness(.5F) .setUnlocalizedName("dimRail"); - itemDimDoor = (new itemDimDoor(properties.DimensionalDoorItemID, Material.iron)).setUnlocalizedName("itemDimDoor"); - itemExitDoor = (new itemExitDoor(properties.WarpDoorItemID, Material.wood)).setUnlocalizedName("itemDimDoorWarp"); + itemDimDoor = (new ItemDimensionalDoor(properties.DimensionalDoorItemID, Material.iron)).setUnlocalizedName("itemDimDoor"); + itemExitDoor = (new ItemWarpDoor(properties.WarpDoorItemID, Material.wood)).setUnlocalizedName("itemDimDoorWarp"); itemLinkSignature = (new itemLinkSignature(properties.RiftSignatureItemID)).setUnlocalizedName("itemLinkSignature"); itemRiftRemover = (new itemRiftRemover(properties.RiftRemoverItemID, Material.wood)).setUnlocalizedName("itemRiftRemover"); itemStableFabric = (new ItemStableFabric(properties.StableFabricItemID, 0)).setUnlocalizedName("itemStableFabric"); - itemChaosDoor = (new ItemChaosDoor(properties.UnstableDoorItemID, Material.iron)).setUnlocalizedName("itemChaosDoor"); - itemRiftBlade = (new ItemRiftBlade(properties.RiftBladeItemID)).setUnlocalizedName("ItemRiftBlade"); + itemChaosDoor = (new ItemUnstableDoor(properties.UnstableDoorItemID, Material.iron)).setUnlocalizedName("itemChaosDoor"); + itemRiftBlade = (new ItemRiftBlade(properties.RiftBladeItemID, EnumToolMaterial.GOLD)).setUnlocalizedName("ItemRiftBlade"); itemStabilizedLinkSignature = (new ItemStabilizedRiftSignature(properties.StabilizedRiftSignatureItemID)).setUnlocalizedName("itemStabilizedRiftSig"); mod_pocketDim.limboBiome= (new BiomeGenLimbo(properties.LimboBiomeID)); @@ -207,7 +208,7 @@ public class mod_pocketDim GameRegistry.registerWorldGenerator(mod_pocketDim.riftGen); GameRegistry.registerBlock(unstableDoor, "Unstable Door"); - GameRegistry.registerBlock(exitDoor, "Warp Door"); + GameRegistry.registerBlock(warpDoor, "Warp Door"); GameRegistry.registerBlock(blockRift, "Rift"); GameRegistry.registerBlock(blockLimbo, "Unraveled Fabric"); GameRegistry.registerBlock(dimensionalDoor, "Dimensional Door"); @@ -226,7 +227,7 @@ public class mod_pocketDim LanguageRegistry.addName(transientDoor , "transientDoor"); LanguageRegistry.addName(blockRift , "Rift"); LanguageRegistry.addName(blockLimbo , "Unraveled Fabric"); - LanguageRegistry.addName(exitDoor , "Warp Door"); + LanguageRegistry.addName(warpDoor , "Warp Door"); LanguageRegistry.addName(unstableDoor , "Unstable Door"); LanguageRegistry.addName(blockDimWall , "Fabric of Reality"); LanguageRegistry.addName(blockDimWallPerm , "Eternal Fabric"); diff --git a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java index dfc4a21..9fa5a04 100644 --- a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java +++ b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java @@ -65,7 +65,7 @@ public class BlockRotator hasOrientations[Block.rail.blockID] = true; hasOrientations[mod_pocketDim.dimensionalDoor.blockID] = true; - hasOrientations[mod_pocketDim.exitDoor.blockID] = true; + hasOrientations[mod_pocketDim.warpDoor.blockID] = true; } diff --git a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java index db56e71..abbc7ea 100644 --- a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java @@ -12,7 +12,7 @@ import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.IDimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.items.itemDimDoor; +import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; import cpw.mods.fml.common.IWorldGenerator; public class GatewayGenerator implements IWorldGenerator @@ -145,7 +145,7 @@ public class GatewayGenerator implements IWorldGenerator } //Place the shiny transient door into a dungeon - itemDimDoor.placeDoorBlock(world, x, y + 1, z, 0, mod_pocketDim.transientDoor); + ItemDimensionalDoor.placeDoorBlock(world, x, y + 1, z, 0, mod_pocketDim.transientDoor); } } } diff --git a/StevenDimDoors/mod_pocketDimClient/RiftFX.java b/StevenDimDoors/mod_pocketDimClient/RiftFX.java index 0157b91..69310f0 100644 --- a/StevenDimDoors/mod_pocketDimClient/RiftFX.java +++ b/StevenDimDoors/mod_pocketDimClient/RiftFX.java @@ -1,12 +1,11 @@ package StevenDimDoors.mod_pocketDimClient; -import StevenDimDoors.mod_pocketDim.core.PocketManager; import net.minecraft.client.particle.EffectRenderer; import net.minecraft.client.particle.EntityFX; -import net.minecraft.client.particle.EntityFireworkSparkFX; import net.minecraft.client.renderer.Tessellator; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -108,23 +107,12 @@ public class RiftFX extends EntityFX float f12 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY); float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ); float f14 = 0F; - - try - { - if(PocketManager.instance.getDimData(this.worldObj.provider.dimensionId).isPocket) - { - f14=.7F; - } - else - { - - } - } - catch(Exception E) - { - - } + if (PocketManager.getDimensionData(worldObj).isPocketDimension()) + { + f14 = 0.7F; + } + par1Tessellator.setColorRGBA_F(this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, (float) .7); par1Tessellator.addVertexWithUV((double)(f11 - par3 * f10 - par6 * f10), (double)(f12 - par4 * f10), (double)(f13 - par5 * f10 - par7 * f10), (double)f7, (double)f9); par1Tessellator.addVertexWithUV((double)(f11 - par3 * f10 + par6 * f10), (double)(f12 + par4 * f10), (double)(f13 - par5 * f10 + par7 * f10), (double)f7, (double)f8); -- 2.39.5 From 4b5870339b93b58d2af4acea177ad52cd44dcbf8 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 16:30:41 -0400 Subject: [PATCH 08/24] Removed Obsolete Code from PocketManager Removed obsolete code from PocketManager. Much of that functionality has already been reimplemented in other classes. --- .../mod_pocketDim/core/PocketManager.java | 203 ------------------ 1 file changed, 203 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index a905e7e..2769ebe 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -7,34 +7,17 @@ import java.io.ObjectOutputStream; import java.util.HashMap; import java.util.Random; -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.packet.Packet41EntityEffect; -import net.minecraft.network.packet.Packet43Experience; -import net.minecraft.network.packet.Packet9Respawn; -import net.minecraft.potion.PotionEffect; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.DDTeleporter; import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream; -import StevenDimDoors.mod_pocketDim.PacketHandler; import StevenDimDoors.mod_pocketDim.TileEntityRift; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder; -import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; import StevenDimDoors.mod_pocketDim.util.Point4D; import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.registry.GameRegistry; -import cpw.mods.fml.relauncher.Side; /** * This class regulates all the operations involving the storage and manipulation of dimensions. It handles saving dim data, teleporting the player, and @@ -74,112 +57,6 @@ public class PocketManager return isInitialized; } - public ILinkData createLink(ILinkData link) - { - DDProperties properties = DDProperties.instance(); - - if(!PocketManager.dimList.containsKey(link.locDimID)) - { - NewDimData locationDimData= new NewDimData(link.locDimID, false, 0, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); - PocketManager.dimList.put(link.locDimID, locationDimData); - link.isLocPocket=false; - } - if(!dimList.containsKey(link.destDimID)) - { - PocketManager.dimList.put(link.destDimID, new NewDimData(link.destDimID, false, 0, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord)); - } - NewDimData locationDimData= PocketManager.instance.getDimData(link.locDimID); - link.isLocPocket=locationDimData.isPocket; - locationDimData.addLinkToDim(link); - - World world = PocketManager.getWorld(link.locDimID); - if (world != null) - { - if (!mod_pocketDim.blockRift.isBlockImmune(world, link.locXCoord, link.locYCoord, link.locZCoord)) - { - world.setBlock(link.locXCoord, link.locYCoord, link.locZCoord, properties.RiftBlockID); - } - } - //Notifies other players that a link has been created. - //TODO: Couldn't we use the serverside/clientside annotations to achieve this instead? Seems safer. ~SenseiKiwi - if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER) - { - PacketHandler.onLinkCreatedPacket(link); - } - return link; - } - - /** - * properly deletes a link at the given coordinates. used by the rift remover. Also notifies clients of change. - * @param locationDimID - * @param locationXCoord - * @param locationYCoord - * @param locationZCoord - */ - public void removeLink( int locationDimID, int locationXCoord, int locationYCoord, int locationZCoord) - { - if(!PocketManager.dimList.containsKey(locationDimID)) - { - NewDimData locationDimData= new NewDimData(locationDimID, false, 0, locationDimID,locationXCoord,locationYCoord,locationZCoord); - PocketManager.dimList.put(locationDimID, locationDimData); - } - ILinkData link = this.getLinkDataFromCoords(locationXCoord, locationYCoord, locationZCoord, locationDimID); - PocketManager.instance.getDimData(locationDimID).removeLinkAtCoords(link); - //updates clients that a rift has been removed - if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER) - { - PacketHandler.onLinkRemovedPacket(link); - this.save(); - } - } - - /** - * generates a door based on what door was used to teleport. Only functions once per linking. - * @param world- door - * @param incLink - */ - public void generateDoor(World world, ILinkData incLink) - { - int locX = incLink.locXCoord; - int locY = incLink.locYCoord; - int locZ = incLink.locZCoord; - - int destX = incLink.destXCoord; - int destY = incLink.destYCoord; - int destZ = incLink.destZCoord; - - DDProperties properties = DDProperties.instance(); - - if(!incLink.hasGennedDoor) - { - int destinationID = incLink.destDimID; - - int id =world.getBlockId(locX, locY, locZ); - if(id==properties.WarpDoorID||id==properties.DimensionalDoorID||id==properties.TransientDoorID) - { - int doorTypeToPlace=id; - if(DimensionManager.getWorld(destinationID)==null) - { - DimensionManager.initDimension(destinationID); - } - ILinkData destLink = this.getLinkDataFromCoords(destX, destY, destZ, destinationID); - int destOrientation = 0; - if(destLink!=null) - { - destOrientation = destLink.linkOrientation; - destLink.hasGennedDoor=true; - } - int blockToReplace= DimensionManager.getWorld(destinationID).getBlockId(destX, destY, destZ); - if(blockToReplace!=properties.DimensionalDoorID&&blockToReplace!=properties.WarpDoorID&&blockToReplace != properties.TransientDoorID) - { - DimensionManager.getWorld(destinationID).setBlock(destX, destY-1, destZ, doorTypeToPlace,destOrientation,2); - DimensionManager.getWorld(destinationID).setBlock(destX, destY, destZ, doorTypeToPlace,8,2); - } - incLink.hasGennedDoor=true; - } - } - } - /** * 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 @@ -283,86 +160,6 @@ public class PocketManager while (keyLinkMapping.containsKey(linkKey)); return linkKey; } - - /** - * Method used to create and register a new pocket dimension. Creates a reverse link if necessary. - * Populates the destination as well. - */ - private NewDimData createDestinationPocket(IDimLink link) - { - //First check the destination type - if (link.linkType() != IDimLink.TYPE_DUNGEON && link.linkType() != IDimLink.TYPE_POCKET) - { - throw new IllegalArgumentException("The link must lead to a dimensional dungeon or a pocket dimension."); - } - - DDProperties properties = DDProperties.instance(); - - //FIXME: This code had a check for whether dimension 0 was null. Why? Removed it for the time being. ~SenseiKiwi - - - if (PocketManager.getWorld(link.locDimID) == null) - { - PocketManager.initDimension(link.locDimID); - } - - int dimensionID; - int depth = this.getDimDepth(link.locDimID); - dimensionID = getNextFreeDimId(); - registerDimension(dimensionID, properties.PocketProviderID); - NewDimData locationDimData; - NewDimData destDimData; - - if(PocketManager.dimList.containsKey(link.locDimID)&&!DimensionManager.getWorld(link.locDimID).isRemote) //checks to see if dim is already registered. If not, it creates a DimData entry for it later - { - //randomizes exit if deep enough - locationDimData= dimList.get(DimensionManager.getWorld(link.locDimID).provider.dimensionId); - - if(depth>5) - { - if(depth>=12) - { - depth=11; - } - if(rand.nextInt(13-depth)==0) - { - ILinkData link1=getRandomLinkData(false); - } - } - if(locationDimData.isPocket) //determines the qualites of the pocket dim being created, based on parent dim. - { - if(isGoingDown) - { - destDimData= new NewDimData(dimensionID, true, locationDimData.depth+1, locationDimData.exitDimLink); - } - else - { - destDimData= new NewDimData(dimensionID, true, locationDimData.depth-1, locationDimData.exitDimLink); - } - } - else - { - destDimData= new NewDimData(dimensionID, true, 1, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); - } - - } - else - { - locationDimData= new NewDimData(link.locDimID, false, 0, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); - destDimData= new NewDimData(dimensionID, true, 1, link.locDimID,link.locXCoord,link.locYCoord,link.locZCoord); - } - destDimData.isDimRandomRift=isRandomRift; - PocketManager.dimList.put(DimensionManager.getWorld(link.locDimID).provider.dimensionId, locationDimData); - PocketManager.dimList.put(dimensionID, destDimData); - - if(FMLCommonHandler.instance().getEffectiveSide()==Side.SERVER)//sends packet to clients notifying them that a new dim has been created. - { - PacketHandler.onDimCreatedPacket(destDimData); - } - link = this.createLink(DimensionManager.getWorld(link.locDimID).provider.dimensionId,dimensionID,link.locXCoord,link.locYCoord,link.locZCoord, link.destXCoord,constrainPocketY(link.destYCoord),link.destZCoord,link.linkOrientation); //creates and registers the two rifts that link the parent and pocket dim. - this.createLink(dimensionID,DimensionManager.getWorld(link.locDimID).provider.dimensionId, link.destXCoord,constrainPocketY(link.destYCoord),link.destZCoord, link.locXCoord,link.locYCoord,link.locZCoord, BlockRotator.transformMetadata(link.linkOrientation, 2, Block.doorWood.blockID)); - return link; - } /** * Function that saves all dim data in a hashMap. Calling too often can cause Concurrent modification exceptions, so be careful. -- 2.39.5 From ea1fc5f4c0828a4041048f67a64afaf2b50ca4c2 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 16:43:18 -0400 Subject: [PATCH 09/24] Reorganized and Renamed Classes Moved tile entity classes to a separate package. Renamed some block classes to match their in-game names (e.g. ChaosDoor -> UnstableDoor). Moved TransientDoor to the blocks package. Cleaned up a little bit of the code and automatically updated references to the classes that were modified. --- .../mod_pocketDim/blocks/BlockRift.java | 2 +- .../{dimDoor.java => DimensionalDoor.java} | 10 ++-- .../{ => blocks}/TransientDoor.java | 25 +++----- .../{ChaosDoor.java => UnstableDoor.java} | 9 +-- .../blocks/{ExitDoor.java => WarpDoor.java} | 4 +- .../mod_pocketDim/blocks/linkDimDoor.java | 56 ------------------ .../mod_pocketDim/blocks/linkExitDoor.java | 57 ------------------- .../mod_pocketDim/core/PocketManager.java | 2 +- .../mod_pocketDim/mod_pocketDim.java | 21 ++++--- .../mod_pocketDim/schematic/BlockRotator.java | 4 +- .../ticking/RiftRegenerator.java | 2 +- .../{ => tileentities}/TileEntityDimDoor.java | 2 +- .../{ => tileentities}/TileEntityDimRail.java | 2 +- .../{ => tileentities}/TileEntityRift.java | 3 +- .../mod_pocketDimClient/ClientProxy.java | 4 +- .../mod_pocketDimClient/RenderDimDoor.java | 4 +- .../mod_pocketDimClient/RenderDimRail.java | 6 +- .../mod_pocketDimClient/RenderRift.java | 6 +- 18 files changed, 48 insertions(+), 171 deletions(-) rename StevenDimDoors/mod_pocketDim/blocks/{dimDoor.java => DimensionalDoor.java} (98%) rename StevenDimDoors/mod_pocketDim/{ => blocks}/TransientDoor.java (87%) rename StevenDimDoors/mod_pocketDim/blocks/{ChaosDoor.java => UnstableDoor.java} (90%) rename StevenDimDoors/mod_pocketDim/blocks/{ExitDoor.java => WarpDoor.java} (95%) delete mode 100644 StevenDimDoors/mod_pocketDim/blocks/linkDimDoor.java delete mode 100644 StevenDimDoors/mod_pocketDim/blocks/linkExitDoor.java rename StevenDimDoors/mod_pocketDim/{ => tileentities}/TileEntityDimDoor.java (96%) rename StevenDimDoors/mod_pocketDim/{ => tileentities}/TileEntityDimRail.java (95%) rename StevenDimDoors/mod_pocketDim/{ => tileentities}/TileEntityRift.java (98%) diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java index 869bb8e..bca54b5 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockRift.java @@ -16,9 +16,9 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.Point3D; -import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDimClient.ClosingRiftFX; import StevenDimDoors.mod_pocketDimClient.GoggleRiftFX; import StevenDimDoors.mod_pocketDimClient.RiftFX; diff --git a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java similarity index 98% rename from StevenDimDoors/mod_pocketDim/blocks/dimDoor.java rename to StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java index e8a6319..1d0cd0d 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/dimDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java @@ -19,21 +19,21 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.DDTeleporter; -import StevenDimDoors.mod_pocketDim.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.IDimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class dimDoor extends BlockContainer +public class DimensionalDoor extends BlockContainer { - private static DDProperties properties = null; + protected static DDProperties properties = null; private Icon blockIconBottom; - public dimDoor(int par1, Material material) + public DimensionalDoor(int par1, Material material) { super(par1, material); @@ -197,7 +197,7 @@ public class dimDoor extends BlockContainer //Called to update the render information on the tile entity. Could probably implement a data watcher, //but this works fine and is more versatile I think. - public dimDoor updateAttachedTile(World world, int x, int y, int z) + public DimensionalDoor updateAttachedTile(World world, int x, int y, int z) { TileEntity tile = world.getBlockTileEntity(x, y, z); if (tile instanceof TileEntityDimDoor) diff --git a/StevenDimDoors/mod_pocketDim/TransientDoor.java b/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java similarity index 87% rename from StevenDimDoors/mod_pocketDim/TransientDoor.java rename to StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java index 7e02a31..6fbbc93 100644 --- a/StevenDimDoors/mod_pocketDim/TransientDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java @@ -1,4 +1,4 @@ -package StevenDimDoors.mod_pocketDim; +package StevenDimDoors.mod_pocketDim.blocks; import java.util.Random; @@ -10,43 +10,34 @@ import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.blocks.ExitDoor; +import StevenDimDoors.mod_pocketDim.DDTeleporter; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.IDimLink; import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class TransientDoor extends ExitDoor +public class TransientDoor extends WarpDoor { - - protected TransientDoor(int par1, Material material) + public TransientDoor(int blockID, Material material) { - super(par1, Material.grass); - // this.blockIndexInTexture = 18; - - if (properties == null) - properties = DDProperties.instance(); + super(blockID, material); } - private static DDProperties properties = null; - public void registerIcons(IconRegister par1IconRegister) { this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); - } - @SideOnly(Side.CLIENT) /** * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side */ + @SideOnly(Side.CLIENT) public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) { - return this.blockIcon; - - } + public boolean isCollidable() { return false; diff --git a/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java similarity index 90% rename from StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java rename to StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java index f4c01e5..74a0f73 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/ChaosDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java @@ -1,12 +1,8 @@ package StevenDimDoors.mod_pocketDim.blocks; -import java.util.Random; - import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.entity.Entity; import net.minecraft.util.Icon; -import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; @@ -17,12 +13,12 @@ import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class ChaosDoor extends dimDoor +public class UnstableDoor extends DimensionalDoor { private Icon blockIconBottom; private static DDProperties properties = null; - public ChaosDoor(int par1, Material material) + public UnstableDoor(int par1, Material material) { super(par1, material); if (properties == null) @@ -33,7 +29,6 @@ public class ChaosDoor extends dimDoor { this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); this.blockIconBottom = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_bottom"); - } @SideOnly(Side.CLIENT) diff --git a/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java similarity index 95% rename from StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java rename to StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java index 1e4feb9..cbe5159 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/ExitDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java @@ -15,11 +15,11 @@ import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class ExitDoor extends dimDoor +public class WarpDoor extends DimensionalDoor { private Icon blockIconBottom; - public ExitDoor(int blockID, Material material) + public WarpDoor(int blockID, Material material) { super(blockID, material); } diff --git a/StevenDimDoors/mod_pocketDim/blocks/linkDimDoor.java b/StevenDimDoors/mod_pocketDim/blocks/linkDimDoor.java deleted file mode 100644 index 1f97f82..0000000 --- a/StevenDimDoors/mod_pocketDim/blocks/linkDimDoor.java +++ /dev/null @@ -1,56 +0,0 @@ -package StevenDimDoors.mod_pocketDim.blocks; - -import java.util.Random; - -import StevenDimDoors.mod_pocketDim.mod_pocketDim; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.Item; -import net.minecraft.util.Icon; -import net.minecraft.util.MathHelper; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - -public class linkDimDoor extends dimDoor -{ - private Icon blockIconBottom; - public linkDimDoor(int par1, Material material) { - - super(par1, material); - // TODO Auto-generated constructor stub - - } - - - @SideOnly(Side.CLIENT) - - /** - * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side - */ - public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) - { - if(par1IBlockAccess.getBlockId(par2, par3-1, par4)==this.blockID) - { - return this.blockIcon; - } - else - { - return this.blockIconBottom; - } - } - public void registerIcons(IconRegister par1IconRegister) - { - this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); - this.blockIconBottom = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_bottom"); - - } - -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/linkExitDoor.java b/StevenDimDoors/mod_pocketDim/blocks/linkExitDoor.java deleted file mode 100644 index ac8211e..0000000 --- a/StevenDimDoors/mod_pocketDim/blocks/linkExitDoor.java +++ /dev/null @@ -1,57 +0,0 @@ -package StevenDimDoors.mod_pocketDim.blocks; - -import java.util.Random; - -import StevenDimDoors.mod_pocketDim.mod_pocketDim; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; -import net.minecraft.util.Icon; -import net.minecraft.util.MathHelper; -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; - -public class linkExitDoor extends ExitDoor -{ - private Icon blockIconBottom; - public linkExitDoor(int par1,Material par2Material) - { - - super(par1, Material.wood); - //this.blockIndexInTexture = 20; - - - - // TODO Auto-generated constructor stub - } - @SideOnly(Side.CLIENT) - - /** - * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side - */ - public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) - { - if(par1IBlockAccess.getBlockId(par2, par3-1, par4)==this.blockID) - { - return this.blockIcon; - } - else - { - return this.blockIconBottom; - } - } - - public void registerIcons(IconRegister par1IconRegister) - { - this.blockIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_top"); - this.blockIconBottom = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName2()+"_bottom"); - - } -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 2769ebe..99e5548 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -14,8 +14,8 @@ import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream; -import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDim.util.Point4D; import cpw.mods.fml.common.FMLCommonHandler; diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 07fa2a0..1720449 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -20,9 +20,10 @@ import StevenDimDoors.mod_pocketDim.blocks.BlockDimWall; import StevenDimDoors.mod_pocketDim.blocks.BlockDimWallPerm; import StevenDimDoors.mod_pocketDim.blocks.BlockLimbo; import StevenDimDoors.mod_pocketDim.blocks.BlockRift; -import StevenDimDoors.mod_pocketDim.blocks.ChaosDoor; -import StevenDimDoors.mod_pocketDim.blocks.ExitDoor; -import StevenDimDoors.mod_pocketDim.blocks.dimDoor; +import StevenDimDoors.mod_pocketDim.blocks.DimensionalDoor; +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; @@ -37,11 +38,11 @@ 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.ItemUnstableDoor; +import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; import StevenDimDoors.mod_pocketDim.items.ItemRiftBlade; import StevenDimDoors.mod_pocketDim.items.ItemStabilizedRiftSignature; import StevenDimDoors.mod_pocketDim.items.ItemStableFabric; -import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; +import StevenDimDoors.mod_pocketDim.items.ItemUnstableDoor; import StevenDimDoors.mod_pocketDim.items.ItemWarpDoor; import StevenDimDoors.mod_pocketDim.items.itemLinkSignature; import StevenDimDoors.mod_pocketDim.items.itemRiftRemover; @@ -50,6 +51,8 @@ import StevenDimDoors.mod_pocketDim.ticking.LimboDecay; import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; import StevenDimDoors.mod_pocketDim.ticking.MonolithSpawner; import StevenDimDoors.mod_pocketDim.ticking.RiftRegenerator; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDim.world.BiomeGenLimbo; import StevenDimDoors.mod_pocketDim.world.BiomeGenPocket; import StevenDimDoors.mod_pocketDim.world.GatewayGenerator; @@ -105,7 +108,7 @@ public class mod_pocketDim public static Block warpDoor; public static Block unstableDoor; public static Block blockLimbo; - public static dimDoor dimensionalDoor; + public static DimensionalDoor dimensionalDoor; public static Block blockDimWall; public static Block dimHatch; public static Block blockDimWallPerm; @@ -185,11 +188,11 @@ public class mod_pocketDim blockDimWall = (new BlockDimWall(properties.FabricBlockID, 0, Material.iron)).setLightValue(1.0F).setHardness(0.1F).setUnlocalizedName("blockDimWall"); blockDimWallPerm = (new BlockDimWallPerm(properties.PermaFabricBlockID, 0, Material.iron)).setLightValue(1.0F).setBlockUnbreakable().setResistance(6000000.0F).setUnlocalizedName("blockDimWallPerm"); - warpDoor = (new ExitDoor(properties.WarpDoorID, Material.wood)).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); + warpDoor = (new WarpDoor(properties.WarpDoorID, Material.wood)).setHardness(1.0F) .setUnlocalizedName("dimDoorWarp"); blockRift = (BlockRift) (new BlockRift(properties.RiftBlockID, 0, Material.air, properties).setHardness(1.0F) .setUnlocalizedName("rift")); blockLimbo = (new BlockLimbo(properties.LimboBlockID, 15, Material.iron, properties.LimboDimensionID, decay).setHardness(.2F).setUnlocalizedName("BlockLimbo").setLightValue(.0F)); - unstableDoor = (new ChaosDoor(properties.UnstableDoorID, Material.iron).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); - dimensionalDoor = (dimDoor) (new dimDoor(properties.DimensionalDoorID, Material.iron)).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor"); + unstableDoor = (new UnstableDoor(properties.UnstableDoorID, Material.iron).setHardness(.2F).setUnlocalizedName("chaosDoor").setLightValue(.0F) ); + dimensionalDoor = (DimensionalDoor) (new DimensionalDoor(properties.DimensionalDoorID, Material.iron)).setHardness(1.0F).setResistance(2000.0F) .setUnlocalizedName("dimDoor"); dimHatch = (new dimHatch(properties.TransTrapdoorID, 84, Material.iron)).setHardness(1.0F) .setUnlocalizedName("dimHatch"); // dimRail = (new DimRail(dimRailID, 88, false)).setHardness(.5F) .setUnlocalizedName("dimRail"); diff --git a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java index 9fa5a04..06f14c8 100644 --- a/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java +++ b/StevenDimDoors/mod_pocketDim/schematic/BlockRotator.java @@ -7,7 +7,7 @@ import net.minecraft.block.BlockRedstoneRepeater; import net.minecraft.block.BlockStairs; import StevenDimDoors.mod_pocketDim.Point3D; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.blocks.dimDoor; +import StevenDimDoors.mod_pocketDim.blocks.DimensionalDoor; public class BlockRotator { @@ -379,7 +379,7 @@ public class BlockRotator break; } } - else if(Block.blocksList[blockID] instanceof BlockRedstoneRepeater || Block.blocksList[blockID] instanceof BlockDoor || Block.blocksList[blockID] instanceof dimDoor || blockID== Block.tripWireSource.blockID || Block.blocksList[blockID] instanceof BlockComparator) + else if(Block.blocksList[blockID] instanceof BlockRedstoneRepeater || Block.blocksList[blockID] instanceof BlockDoor || Block.blocksList[blockID] instanceof DimensionalDoor || blockID== Block.tripWireSource.blockID || Block.blocksList[blockID] instanceof BlockComparator) { switch (metadata) { diff --git a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index 6fb2ff1..950c505 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -3,11 +3,11 @@ package StevenDimDoors.mod_pocketDim.ticking; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.IDimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDim.util.Point4D; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; diff --git a/StevenDimDoors/mod_pocketDim/TileEntityDimDoor.java b/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java similarity index 96% rename from StevenDimDoors/mod_pocketDim/TileEntityDimDoor.java rename to StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java index b96aad6..9f27d4e 100644 --- a/StevenDimDoors/mod_pocketDim/TileEntityDimDoor.java +++ b/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimDoor.java @@ -1,4 +1,4 @@ -package StevenDimDoors.mod_pocketDim; +package StevenDimDoors.mod_pocketDim.tileentities; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; diff --git a/StevenDimDoors/mod_pocketDim/TileEntityDimRail.java b/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimRail.java similarity index 95% rename from StevenDimDoors/mod_pocketDim/TileEntityDimRail.java rename to StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimRail.java index 4ae98cb..2e1098b 100644 --- a/StevenDimDoors/mod_pocketDim/TileEntityDimRail.java +++ b/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimRail.java @@ -1,4 +1,4 @@ -package StevenDimDoors.mod_pocketDim; +package StevenDimDoors.mod_pocketDim.tileentities; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; diff --git a/StevenDimDoors/mod_pocketDim/TileEntityRift.java b/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java similarity index 98% rename from StevenDimDoors/mod_pocketDim/TileEntityRift.java rename to StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java index 72565c4..dfa27b5 100644 --- a/StevenDimDoors/mod_pocketDim/TileEntityRift.java +++ b/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java @@ -1,4 +1,4 @@ -package StevenDimDoors.mod_pocketDim; +package StevenDimDoors.mod_pocketDim.tileentities; @@ -16,6 +16,7 @@ import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; +import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.core.IDimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; diff --git a/StevenDimDoors/mod_pocketDimClient/ClientProxy.java b/StevenDimDoors/mod_pocketDimClient/ClientProxy.java index f2a1bfb..b1428c3 100644 --- a/StevenDimDoors/mod_pocketDimClient/ClientProxy.java +++ b/StevenDimDoors/mod_pocketDimClient/ClientProxy.java @@ -9,11 +9,11 @@ import net.minecraft.src.ModLoader; import net.minecraftforge.client.MinecraftForgeClient; import StevenDimDoors.mod_pocketDim.CommonProxy; import StevenDimDoors.mod_pocketDim.Spells; -import StevenDimDoors.mod_pocketDim.TileEntityDimDoor; -import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; public class ClientProxy extends CommonProxy diff --git a/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java b/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java index f0ea38a..6239fc8 100644 --- a/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java +++ b/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java @@ -14,9 +14,9 @@ import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.blocks.dimDoor; +import StevenDimDoors.mod_pocketDim.blocks.DimensionalDoor; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/StevenDimDoors/mod_pocketDimClient/RenderDimRail.java b/StevenDimDoors/mod_pocketDimClient/RenderDimRail.java index 886b5cd..e3e39b2 100644 --- a/StevenDimDoors/mod_pocketDimClient/RenderDimRail.java +++ b/StevenDimDoors/mod_pocketDimClient/RenderDimRail.java @@ -14,9 +14,9 @@ import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.blocks.dimDoor; +import StevenDimDoors.mod_pocketDim.blocks.DimensionalDoor; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -40,7 +40,7 @@ public class RenderDimRail extends TileEntitySpecialRenderer { try { - dimDoor.class.cast(Block.blocksList[properties.DimensionalDoorID]).updateAttatchedTile(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord).getFullMetadata(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord); + DimensionalDoor.class.cast(Block.blocksList[properties.DimensionalDoorID]).updateAttatchedTile(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord).getFullMetadata(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord); } catch(Exception e) diff --git a/StevenDimDoors/mod_pocketDimClient/RenderRift.java b/StevenDimDoors/mod_pocketDimClient/RenderRift.java index 2e3f308..adb4f13 100644 --- a/StevenDimDoors/mod_pocketDimClient/RenderRift.java +++ b/StevenDimDoors/mod_pocketDimClient/RenderRift.java @@ -16,10 +16,10 @@ import org.lwjgl.opengl.GL11; import static org.lwjgl.opengl.GL11.*; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.TileEntityDimDoor; -import StevenDimDoors.mod_pocketDim.TileEntityRift; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.blocks.dimDoor; +import StevenDimDoors.mod_pocketDim.blocks.DimensionalDoor; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; +import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -- 2.39.5 From 1cc1c374f6d7a205e808f5151d9a216d35dcf764 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 16:46:40 -0400 Subject: [PATCH 10/24] Removed DimRail Files Removed files related to DimRail since they seem to be left over from a scrapped idea. We can revert this commit later to restore them. --- .../tileentities/TileEntityDimRail.java | 68 ----- .../mod_pocketDimClient/RenderDimRail.java | 283 ------------------ 2 files changed, 351 deletions(-) delete mode 100644 StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimRail.java delete mode 100644 StevenDimDoors/mod_pocketDimClient/RenderDimRail.java diff --git a/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimRail.java b/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimRail.java deleted file mode 100644 index 2e1098b..0000000 --- a/StevenDimDoors/mod_pocketDim/tileentities/TileEntityDimRail.java +++ /dev/null @@ -1,68 +0,0 @@ -package StevenDimDoors.mod_pocketDim.tileentities; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; - -public class TileEntityDimRail extends TileEntity - -{ - - public int orientation; - public boolean hasExit; - - - - - - public boolean canUpdate() - { - return false; - } - - public void updateEntity() - { - - - } - - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - int i = nbt.getInteger(("Size")); - - try - { - - this.orientation = nbt.getInteger("orientation"); - - this.hasExit = nbt.getBoolean("hasExit"); - - - - - - - } - catch (Exception e) - { - - } - } - - @Override - public void writeToNBT(NBTTagCompound nbt) - { - int i = 0; - super.writeToNBT(nbt); - - - nbt.setBoolean("hasExit", this.hasExit); - - nbt.setInteger("orientation", this.orientation); - - - - - } -} diff --git a/StevenDimDoors/mod_pocketDimClient/RenderDimRail.java b/StevenDimDoors/mod_pocketDimClient/RenderDimRail.java deleted file mode 100644 index e3e39b2..0000000 --- a/StevenDimDoors/mod_pocketDimClient/RenderDimRail.java +++ /dev/null @@ -1,283 +0,0 @@ -package StevenDimDoors.mod_pocketDimClient; - -import java.nio.FloatBuffer; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ActiveRenderInfo; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.tileentity.TileEntity; - -import org.lwjgl.opengl.GL11; - -import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.blocks.DimensionalDoor; -import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class RenderDimRail extends TileEntitySpecialRenderer -{ - FloatBuffer field_76908_a = GLAllocation.createDirectFloatBuffer(16); - - public RenderDimRail() - { - if (properties == null) - properties = DDProperties.instance(); - } - - private static DDProperties properties = null; - - /** - * Renders the dimdoor. - */ - public void renderDimDoorTileEntity(TileEntityDimDoor tile, double x, double y, double z, float par8) - { - try - { - DimensionalDoor.class.cast(Block.blocksList[properties.DimensionalDoorID]).updateAttatchedTile(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord).getFullMetadata(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord); - - } - catch(Exception e) - { - e.printStackTrace(); - } - - - float playerX = (float)this.tileEntityRenderer.playerX; - float playerY = (float)this.tileEntityRenderer.playerY; - float playerZ = (float)this.tileEntityRenderer.playerZ; - - float distance = (float) tile.getDistanceFrom(playerX, playerY, playerZ); - GL11.glDisable(GL11.GL_LIGHTING); - Random rand = new Random(31100L); - float var13 = 0.75F; - - for (int count = 0; count < 16; ++count) - { - GL11.glPushMatrix(); - float var15 = (float)(16 - count); - float var16 = 0.2625F; - float var17 = 1.0F / (var15 + 1.0F); - - if (count == 0) - { - this.bindTextureByName("/RIFT.png"); - var17 = 0.1F; - var15 = 25.0F; - var16 = 0.125F; - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - } - - if (count == 1) - { - this.bindTextureByName("/WARP.png"); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); - var16 = .5F; - } - - float startY = (float)(+(y + (double)var13)); - float ratioY = startY + ActiveRenderInfo.objectY; - float ratioY2 = startY + var15 + ActiveRenderInfo.objectY; - float yConverted = ratioY / ratioY2; - - float startZ = (float)(+(z + (double)var13)); - float ratioZ = startZ + ActiveRenderInfo.objectZ; - float ratioZ2 = startZ + var15 + ActiveRenderInfo.objectZ; - float zConverted = ratioZ / ratioZ2; - - float startX = (float)(+(x + (double)var13)); - float ratioX = startX + ActiveRenderInfo.objectX; - float ratioX2 = startX + var15 + ActiveRenderInfo.objectX; - float xConverted = ratioX / ratioX2; - - - - - yConverted += (float)(y + (double)var13); - xConverted += (float)(x + (double)var13); - zConverted += (float)(z + (double)var13); - - GL11.glTranslatef( (float)(Minecraft.getSystemTime() % 200000L) / 200000.0F,0, 0.0F); - GL11.glTranslatef(0, (float)(Minecraft.getSystemTime() % 200000L) / 200000.0F, 0.0F); - - GL11.glTranslatef(0,0, (float)(Minecraft.getSystemTime() % 200000L) / 200000.0F); - - GL11.glTexGeni(GL11.GL_S, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR); - GL11.glTexGeni(GL11.GL_T, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR); - GL11.glTexGeni(GL11.GL_R, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR); - GL11.glTexGeni(GL11.GL_Q, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR); - switch ((tile.orientation%4)+4) - { - case 4: - GL11.glTexGen(GL11.GL_S, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 1.0F, 0.0F, 0.0F)); - GL11.glTexGen(GL11.GL_T, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 1.0F, 0.0F)); - GL11.glTexGen(GL11.GL_R, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 0.0F, 1.0F)); - GL11.glTexGen(GL11.GL_Q, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(1.0F, 0.0F, 0.0F, 0.0F)); - - break; - case 5: - - GL11.glTexGen(GL11.GL_S, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 1.0F, 0.0F, 0.0F)); - GL11.glTexGen(GL11.GL_T, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(1.0F, 0.0F, 0.0F, 0.0F)); - GL11.glTexGen(GL11.GL_R, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 0.0F, 1.0F)); - GL11.glTexGen(GL11.GL_Q, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 1.0F, 0.0F)); - break; - case 6: - GL11.glTexGen(GL11.GL_S, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 1.0F, 0.0F, 0.0F)); - GL11.glTexGen(GL11.GL_T, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 1.0F, 0.0F)); - GL11.glTexGen(GL11.GL_R, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 0.0F, 1.0F)); - GL11.glTexGen(GL11.GL_Q, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(1.0F, 0.0F, 0.0F, 0.0F)); - - break; - case 7: - GL11.glTexGen(GL11.GL_S, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 1.0F, 0.0F, 0.0F)); - GL11.glTexGen(GL11.GL_T, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(1.0F, 0.0F, 0.0F, 0.0F)); - GL11.glTexGen(GL11.GL_R, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 0.0F, 1.0F)); - GL11.glTexGen(GL11.GL_Q, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 1.0F, 0.0F)); - break; - - - - } - - - GL11.glEnable(GL11.GL_TEXTURE_GEN_S); - GL11.glEnable(GL11.GL_TEXTURE_GEN_T); - GL11.glEnable(GL11.GL_TEXTURE_GEN_R); - GL11.glEnable(GL11.GL_TEXTURE_GEN_Q); - GL11.glPopMatrix(); - GL11.glMatrixMode(GL11.GL_TEXTURE); - GL11.glPushMatrix(); - GL11.glLoadIdentity(); - GL11.glTranslatef(0.0F, (float)(Minecraft.getSystemTime() % 200000L) / 200000.0F*var15, 0.0F); - GL11.glScalef(var16, var16, var16); - GL11.glTranslatef(0.5F, 0.5F, 0.5F); - GL11.glRotatef((float)(count * count * 4321 + count * 9) * 2.0F, 0.0F, 0.0F, 1.0F); - GL11.glTranslatef(0.5F, 0.5F, 0.5F); - - Tessellator var24 = Tessellator.instance; - var24.startDrawingQuads(); - - - - float var21 = rand.nextFloat() * 0.5F + 0.1F; - float var22 = rand.nextFloat() * 0.4F + 0.4F; - float var23 = rand.nextFloat() * 0.6F + 0.5F; - - if (count == 0) - { - var23 = 1.0F; - var22 = 1.0F; - yConverted = 1.0F; - } - var24.setColorRGBA_F(var21 * var17, var22 * var17, var23 * var17, 1.0F); - if(tile.openOrClosed) - { - - switch (tile.orientation) - { - case 0: - - var24.addVertex(x+.01F, y-1 , z); - var24.addVertex(x+.01, y-1, z+1.0D); - var24.addVertex(x+.01 , y+1 , z + 1.0D); - var24.addVertex(x+.01 , y+1 , z); - break; - case 1: - var24.addVertex(x , y+1 , z+.01); - var24.addVertex(x+1 , y+1 , z+.01); - var24.addVertex(x+1, y-1, z+.01); - var24.addVertex(x, y-1, z+.01); - - - - break; - case 2: // - var24.addVertex(x+.99 , y+1 , z); - var24.addVertex(x+.99 , y+1 , z + 1.0D); - var24.addVertex(x+.99, y-1, z+1.0D); - var24.addVertex(x+.99, y-1, z); - break; - case 3: - var24.addVertex(x, y-1, z+.99); - var24.addVertex(x+1, y-1, z+.99); - var24.addVertex(x+1 , y+1 , z+.99); - var24.addVertex(x , y+1 , z+.99); - break; - case 4:// - // GL11.glTranslatef(); - - var24.addVertex(x+.15F, y-1 , z); - var24.addVertex(x+.15, y-1, z+1.0D); - var24.addVertex(x+.15 , y+1 , z + 1.0D); - var24.addVertex(x+.15 , y+1 , z); - break; - case 5: - var24.addVertex(x , y+1 , z+.15); - var24.addVertex(x+1 , y+1 , z+.15); - var24.addVertex(x+1, y-1, z+.15); - var24.addVertex(x, y-1, z+.15); - - - - break; - case 6: // - var24.addVertex(x+.85 , y+1 , z); - var24.addVertex(x+.85 , y+1 , z + 1.0D); - var24.addVertex(x+.85, y-1, z+1.0D); - var24.addVertex(x+.85, y-1, z); - break; - case 7: - var24.addVertex(x, y-1, z+.85); - var24.addVertex(x+1, y-1, z+.85); - var24.addVertex(x+1 , y+1 , z+.85); - var24.addVertex(x , y+1 , z+.85); - break; - default: - break; - } - } - - - - - - - var24.draw(); - - GL11.glPopMatrix(); - GL11.glMatrixMode(GL11.GL_MODELVIEW); - } - - GL11.glDisable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_TEXTURE_GEN_S); - GL11.glDisable(GL11.GL_TEXTURE_GEN_T); - GL11.glDisable(GL11.GL_TEXTURE_GEN_R); - GL11.glDisable(GL11.GL_TEXTURE_GEN_Q); - GL11.glEnable(GL11.GL_LIGHTING); - } - - private FloatBuffer getFloatBuffer(float par1, float par2, float par3, float par4) - { - this.field_76908_a.clear(); - this.field_76908_a.put(par1).put(par2).put(par3).put(par4); - this.field_76908_a.flip(); - return this.field_76908_a; - } - - public void renderTileEntityAt(TileEntity par1TileEntity, double par2, double par4, double par6, float par8) - { - if (properties.DoorRenderingEnabled) - { - this.renderDimDoorTileEntity((TileEntityDimDoor)par1TileEntity, par2, par4, par6, par8); - } - } -} -- 2.39.5 From 4f3ab403d3d3e6b1552e578d96c9abe414de4ff6 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 20:44:31 -0400 Subject: [PATCH 11/24] More Progress on Rewrite Fixed the code in ItemLinkSignature and ItemStabilizedRiftSignature. Removed obsolete code from PocketManager - we don't need to worry about storing link keys anymore. All the data is stored in NBT, which means no more generating unique keys or worrying about saving and loading them. --- .../mod_pocketDim/core/PocketManager.java | 45 +-- .../items/ItemStabilizedRiftSignature.java | 177 ++--------- .../items/itemLinkSignature.java | 279 ++++++------------ 3 files changed, 121 insertions(+), 380 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 99e5548..39519bd 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -5,7 +5,6 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectOutputStream; import java.util.HashMap; -import java.util.Random; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -44,14 +43,10 @@ public class PocketManager private static boolean isInitialized = false; private static boolean isSaving = false; - private static Random random = new Random(); //HashMap containing all the dims registered with DimDoors, sorted by dim ID. loaded on startup private static HashMap dimensionData = new HashMap(); - //HashMap for temporary storage of Link Signature damage hash values. See itemLinkSignature for more details - private static HashMap keyLinkMapping = new HashMap(); - public static boolean isInitialized() { return isInitialized; @@ -89,7 +84,7 @@ public class PocketManager } } - public boolean resetPocket(NewDimData dimension) + public boolean clearPocket(NewDimData dimension) { if (!dimension.isPocketDimension() || DimensionManager.getWorld(dimension.id()) != null) { @@ -103,7 +98,7 @@ public class PocketManager return true; } - public static boolean pruneDimension(NewDimData dimension, boolean deleteFolder) + public static boolean deletePocket(NewDimData dimension, boolean deleteFolder) { //FIXME: Shouldn't the links in and out of this dimension be altered somehow? Otherwise we have links pointing //into a deleted dimension! @@ -112,7 +107,6 @@ public class PocketManager if (dimension.isPocketDimension() && DimensionManager.getWorld(dimension.id()) == null) { dimensionData.remove(dimension.id()); - //FIXME: I added the following line. Seems like a good idea. Is it? DimensionManager.unregisterDimension(dimension.id()); if (deleteFolder) { @@ -146,21 +140,6 @@ public class PocketManager } } - /** - * Used to associate a damage value on a Rift Signature with a link pair. See LinkSignature for details. - * @return - */ - public static int createUniqueLinkKey() - { - int linkKey; - do - { - linkKey = random.nextInt(30000); - } - while (keyLinkMapping.containsKey(linkKey)); - return linkKey; - } - /** * Function that saves all dim data in a hashMap. Calling too often can cause Concurrent modification exceptions, so be careful. * @return @@ -184,7 +163,6 @@ public class PocketManager isSaving = true; HashMap comboSave = new HashMap(); comboSave.put("dimensionData", dimensionData); - comboSave.put("keyLinkMapping", keyLinkMapping); FileOutputStream saveFile = null; try @@ -246,15 +224,6 @@ public class PocketManager ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); HashMap comboSave = (HashMap) save.readObject(); - try - { - keyLinkMapping = (HashMap) comboSave.get("keyLinkMapping"); - } - catch (Exception e) - { - System.out.println("Could not load Link Signature list. Link Sig items will lose their stored locations."); - } - try { dimensionData = (HashMap) comboSave.get("dimensionData"); @@ -283,15 +252,6 @@ public class PocketManager ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); HashMap comboSave = (HashMap) save.readObject(); - try - { - keyLinkMapping = (HashMap) comboSave.get("keyLinkMapping"); - } - catch (Exception e2) - { - System.out.println("Could not load Link Signature list. Link Sig items will loose restored locations."); - } - try { dimensionData = (HashMap) comboSave.get("dimensionData"); @@ -395,7 +355,6 @@ public class PocketManager save(); unregisterDimensions(); dimensionData.clear(); - keyLinkMapping.clear(); } public static Iterable getDimensions() diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index 01113d0..cf61d4f 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -2,47 +2,21 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.List; -import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.util.Point4D; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ItemStabilizedRiftSignature extends itemLinkSignature { - private static DDProperties properties = null; - - public ItemStabilizedRiftSignature(int par) + public ItemStabilizedRiftSignature(int itemID) { - super(par); - this.setMaxStackSize(1); - this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); - this.setMaxDamage(0); - this.hasSubtypes = true; - if (properties == null) - properties = DDProperties.instance(); - } - - @SideOnly(Side.CLIENT) - @Override - public boolean hasEffect(ItemStack par1ItemStack) - { - // adds effect if item has a link stored - if(par1ItemStack.hasTagCompound()) - { - if(par1ItemStack.stackTagCompound.getBoolean("isCreated")) - { - return true; - } - } - return false; + super(itemID); } public void registerIcons(IconRegister par1IconRegister) @@ -51,66 +25,29 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature } @Override - public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) { - int key; - NewLinkData linkData; - int thisWorldID=par3World.provider.dimensionId; - Integer[] linkCoords =this.readFromNBT(par1ItemStack); - - int offset = 2; - if(par1ItemStack.getTagCompound()!=null) + //Check if the Stabilized Rift Signature has been initialized + Point4D source = getSource(stack); + if (source != null) { - if(par1ItemStack.getTagCompound().getBoolean("isCreated")) + //Yes, it's initialized. Check if the player can pay an Ender Pearl to create a rift. + if (player.inventory.hasItem(Item.enderPearl.itemID)) { - boolean hasEnder = false; - // checks to see if the item has a link stored, if so, it creates it - if (par2EntityPlayer.inventory.hasItem(Item.enderPearl.itemID)||par2EntityPlayer.inventory.hasItem(properties.StableFabricItemID)) - { - if (!par2EntityPlayer.inventory.consumeInventoryItem(properties.StableFabricItemID)) - { - par2EntityPlayer.inventory.consumeInventoryItem(Item.enderPearl.itemID); - } - hasEnder=true; - } - if (par3World.getBlockId(par4, par5, par6)==Block.snow.blockID) - { - offset = 1; - } - if (hasEnder&&!par3World.isRemote) - { - if(PocketManager.instance.getLinkDataFromCoords(linkCoords[0], linkCoords[1], linkCoords[2], par3World)==null) - { - PocketManager.instance.createLink(linkCoords[3], par3World.provider.dimensionId, linkCoords[0], linkCoords[1], linkCoords[2],par4, par5+offset, par6); - } - PocketManager.instance.createLink(par3World.provider.dimensionId, linkCoords[3], par4, par5+offset, par6, linkCoords[0], linkCoords[1], linkCoords[2]); - par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftEnd", (float) .6, 1); - - par2EntityPlayer.sendChatToPlayer("Rift Created"); - } - else if (!par3World.isRemote) - { - par2EntityPlayer.sendChatToPlayer("No Ender Pearls!"); - } + if (tryItemUse(stack, player, world, x, y, z) && !player.capabilities.isCreativeMode) + { + player.inventory.consumeInventoryItem(Item.enderPearl.itemID); + } } } - else if (!par3World.isRemote) - { - if(par3World.getBlockId(par4, par5, par6)==Block.snow.blockID) - { - offset = 1; - } - //otherwise, it creates the first half of the link. Next click will complete it. - key = PocketManager.instance.createUniqueInterDimLinkKey(); - this.writeToNBT(par1ItemStack, par4, par5+offset, par6,par3World.provider.dimensionId); - par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftStart", (float) .6, 1); - - par2EntityPlayer.sendChatToPlayer("Rift Signature Stored"); - } - return true; + else + { + //Initialization doesn't cost any materials + tryItemUse(stack, player, world, x, y, z); + } + return true; } - /** * allows items to add custom lines of information to the mouseover description */ @@ -119,80 +56,16 @@ public class ItemStabilizedRiftSignature extends itemLinkSignature @Override public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { - if (par1ItemStack.hasTagCompound()) - { - if (par1ItemStack.stackTagCompound.getBoolean("isCreated")) - { - Integer[] coords = this.readFromNBT(par1ItemStack); - par3List.add("Leads to (" + coords[0] + ", " + coords[1] + ", " + coords[2] + ") at dimension #" + coords[3]); - } - } - else + Point4D source = getSource(par1ItemStack); + if (source != null) + { + par3List.add("Leads to (" + source.getX() + ", " + source.getY() + ", " + source.getZ() + ") at dimension #" + source.getDimension()); + } + else { par3List.add("First click stores a location,"); par3List.add("second click creates two rifts"); par3List.add("that link the locations together."); } } - - public void writeToNBT(ItemStack itemStack,int x, int y, int z, int dimID) - { - NBTTagCompound tag; - - if(itemStack.hasTagCompound()) - { - tag = itemStack.getTagCompound(); - } - else - { - tag= new NBTTagCompound(); - } - tag.setInteger("linkX", x); - tag.setInteger("linkY", y); - tag.setInteger("linkZ", z); - tag.setInteger("linkDimID", dimID); - tag.setBoolean("isCreated", true); - itemStack.setTagCompound(tag); - } - - /** - * Read the stack fields from a NBT object. - */ - public Integer[] readFromNBT(ItemStack itemStack) - { - NBTTagCompound tag; - Integer[] linkCoords = new Integer[5]; - if(itemStack.hasTagCompound()) - { - tag = itemStack.getTagCompound(); - - if(!tag.getBoolean("isCreated")) - { - return null; - } - linkCoords[0]=tag.getInteger("linkX"); - linkCoords[1]=tag.getInteger("linkY"); - linkCoords[2]=tag.getInteger("linkZ"); - linkCoords[3]=tag.getInteger("linkDimID"); - } - return linkCoords; - } - - - @Override - public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - if(!par2World.isRemote) - { - /** - //creates the first half of the link on item creation - int key= dimHelper.instance.createUniqueInterDimLinkKey(); - LinkData linkData= new LinkData(par2World.provider.dimensionId,MathHelper.floor_double(par3EntityPlayer.posX),MathHelper.floor_double(par3EntityPlayer.posY),MathHelper.floor_double(par3EntityPlayer.posZ)); - System.out.println(key); - - dimHelper.instance.interDimLinkList.put(key, linkData); - par1ItemStack.setItemDamage(key); - **/ - } - } } diff --git a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java index 2d9ce99..14e539d 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java @@ -2,23 +2,23 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.List; -import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import StevenDimDoors.mod_pocketDim.DDProperties; +import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.util.Point4D; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class itemLinkSignature extends Item { - public itemLinkSignature(int itemID) { super(itemID); @@ -26,240 +26,149 @@ public class itemLinkSignature extends Item this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); this.setMaxDamage(0); this.hasSubtypes = true; - if (properties == null) - properties = DDProperties.instance(); } - private static DDProperties properties = null; - @SideOnly(Side.CLIENT) @Override - public boolean hasEffect(ItemStack par1ItemStack) + public boolean hasEffect(ItemStack stack) { - // adds effect if item has a link stored - - - if(par1ItemStack.hasTagCompound()) - { - if(par1ItemStack.stackTagCompound.getBoolean("isCreated")) - { - return true; - } - } - return false; + //Make the item glow if it has one endpoint stored + return (stack.getItemDamage() != 0); } - public void registerIcons(IconRegister par1IconRegister) { this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName()); - } @Override - public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) + public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10) { - int key; - ILinkData linkData; - int thisWorldID=par3World.provider.dimensionId; - - - - - if(!par3World.isRemote) - { - - //par1ItemStack= par2EntityPlayer.getCurrentEquippedItem(); - Integer[] linkCoords =this.readFromNBT(par1ItemStack); - - - - //System.out.println(key); - int offset = 2; - int idBlock = par3World.getBlockId(par4, par5, par6); - - if(Block.blocksList.length>idBlock&&idBlock!=0) + tryItemUse(stack, player, world, x, y, z); + return true; + } + + protected boolean tryItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z) + { + if (!world.isRemote) + { + //We don't check for replaceable blocks. The user can deal with that. <_< + + y += 2; //Increase y by 2 to place the rift at head level + if (!player.canPlayerEdit(x, y, z, 0, stack)) { - if(Block.blocksList[idBlock].isBlockReplaceable(par3World, par4, par5, par6)) - { - offset = 1; - } + return false; } - if(par3World.getBlockId(par4, par5, par6) == properties.DimensionalDoorID && par3World.getBlockId(par4, par5 + 1, par6) == properties.DimensionalDoorID) + + Point4D source = getSource(stack); + if (source != null) { - offset = 1; - } - else - if(par3World.getBlockId(par4, par5, par6)==properties.WarpDoorID&&par3World.getBlockId(par4, par5+1, par6)==properties.WarpDoorID) + //The link was used before and already has an endpoint stored. Create links connecting the two endpoints. + NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); + NewDimData destinationDimension = PocketManager.getDimensionData(world); + IDimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ()).setLinkType(IDimLink.TYPE_NORMAL); + IDimLink reverse = destinationDimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_NORMAL); + link.setDestination(x, y, z, destinationDimension); + reverse.setDestination(source.getX(), source.getY(), source.getZ(), sourceDimension); + + //Try placing a rift at the destination point + if (!mod_pocketDim.blockRift.isBlockImmune(world, x, y, z)) { - offset = 1; + world.setBlock(x, y, z, mod_pocketDim.blockRift.blockID); } - else - if (par3World.getBlockId(par4, par5, par6)==properties.DimensionalDoorID&&par3World.getBlockId(par4, par5-1, par6)==properties.DimensionalDoorID) - { - offset = 0; - } - else - if (par3World.getBlockId(par4, par5, par6) == properties.WarpDoorID && par3World.getBlockId(par4, par5-1, par6)==properties.WarpDoorID) - { - offset = 0; - } - - int orientation = MathHelper.floor_double((double)((par2EntityPlayer.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; - - for(int count = 0;count<3;count++) - { - if(PocketManager.instance.getLinkDataFromCoords(par4, par5+count, par6,par3World)!=null) + + //Try placing a rift at the source point, but check if its world is loaded first + World sourceWorld = DimensionManager.getWorld(sourceDimension.id()); + if (sourceWorld != null && + !mod_pocketDim.blockRift.isBlockImmune(sourceWorld, source.getX(), source.getY(), source.getZ())) { - int id= (par3World.getBlockId(par4, par5+count, par6)); - - if(id == properties.DimensionalDoorID||id==properties.WarpDoorID||id== properties.UnstableDoorID) - { - orientation = PocketManager.instance.getLinkDataFromCoords(par4, par5+count, par6,par3World).linkOrientation; - } + sourceWorld.setBlock(source.getX(), source.getY(), source.getY(), mod_pocketDim.blockRift.blockID); } - - - } - - if(par1ItemStack.getTagCompound()!=null) - { - if(par1ItemStack.getTagCompound().getBoolean("isCreated")) + + if (!player.capabilities.isCreativeMode) { - // checks to see if the item has a link stored, if so, it creates it - - - - PocketManager.instance.createLink(par3World.provider.dimensionId, linkCoords[3], par4, par5+offset, par6, linkCoords[0], linkCoords[1], linkCoords[2],orientation); - PocketManager.instance.createLink(linkCoords[3], par3World.provider.dimensionId, linkCoords[0], linkCoords[1], linkCoords[2],par4, par5+offset, par6,linkCoords[4]); - - - - --par1ItemStack.stackSize; - par2EntityPlayer.sendChatToPlayer("Rift Created"); - par1ItemStack.stackTagCompound=null; - par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftEnd", (float) .6, 1); + stack.stackSize--; } + clearSource(stack); + player.sendChatToPlayer("Rift Created"); + world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftEnd", 0.6f, 1); } else { - - - //otherwise, it creates the first half of the link. Next click will complete it. - key= PocketManager.instance.createUniqueInterDimLinkKey(); - this.writeToNBT(par1ItemStack, par4, par5+offset, par6,par3World.provider.dimensionId,orientation); - par2EntityPlayer.sendChatToPlayer("Rift Signature Stored"); - par2EntityPlayer.worldObj.playSoundAtEntity(par2EntityPlayer,"mods.DimDoors.sfx.riftStart", (float) .6, 1); - } - //dimHelper.instance.save(); + //The link signature has not been used. Store its current target as the first location. + setSource(stack, x, y, z, PocketManager.getDimensionData(world)); + player.sendChatToPlayer("Location Stored in Rift Signature"); + world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftStart", 0.6f, 1); + } + return true; } - - - return true; - - + return false; } - @SideOnly(Side.CLIENT) - /** * allows items to add custom lines of information to the mouseover description */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + @SideOnly(Side.CLIENT) public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { - - if(par1ItemStack.hasTagCompound()) + Point4D source = getSource(par1ItemStack); + if (source != null) { - if(par1ItemStack.stackTagCompound.getBoolean("isCreated")) - { - Integer[] coords = this.readFromNBT(par1ItemStack); - - par3List.add(String.valueOf("Leads to dim "+coords[3] +" with depth "+(PocketManager.instance.getDimDepth(coords[3])))); - par3List.add("at x="+coords[0]+" y="+coords[1]+" z="+coords[2]); - - } - + par3List.add("Leads to (" + source.getX() + ", " + source.getY() + ", " + source.getZ() + ") at dimension #" + source.getDimension()); } else { - par3List.add("First click stores location,"); - par3List.add ("second click creates two rifts,"); - par3List.add("that link the first location"); - par3List.add("with the second location"); - - + par3List.add("First click stores a location;"); + par3List.add("second click creates a pair of"); + par3List.add("rifts linking the two locations."); } } - public void writeToNBT(ItemStack itemStack,int x, int y, int z, int dimID,int orientation) + public static void setSource(ItemStack itemStack, int x, int y, int z, NewDimData dimension) { - NBTTagCompound tag; - - if(itemStack.hasTagCompound()) - { - tag = itemStack.getTagCompound(); - - } - else - { - tag= new NBTTagCompound(); - } + NBTTagCompound tag = new NBTTagCompound(); tag.setInteger("linkX", x); tag.setInteger("linkY", y); tag.setInteger("linkZ", z); - tag.setInteger("linkDimID", dimID); - tag.setBoolean("isCreated", true); - tag.setInteger("orientation", orientation); + tag.setInteger("linkDimID", dimension.id()); itemStack.setTagCompound(tag); - + itemStack.setItemDamage(1); } - - /** - * Read the stack fields from a NBT object. - */ - public Integer[] readFromNBT(ItemStack itemStack) + + public static void clearSource(ItemStack itemStack) { - - NBTTagCompound tag; - Integer[] linkCoords = new Integer[5]; - if(itemStack.hasTagCompound()) + //Don't just set the tag to null since there may be other data there (e.g. for renamed items) + NBTTagCompound tag = itemStack.getTagCompound(); + tag.removeTag("linkX"); + tag.removeTag("linkY"); + tag.removeTag("linkZ"); + tag.removeTag("linkDimID"); + itemStack.setItemDamage(0); + } + + public static Point4D getSource(ItemStack itemStack) + { + if (itemStack.getItemDamage() != 0) { - tag = itemStack.getTagCompound(); - - if(!tag.getBoolean("isCreated")) + if (itemStack.hasTagCompound()) { - return null; + NBTTagCompound tag = itemStack.getTagCompound(); + + Integer x = tag.getInteger("linkX"); + Integer y = tag.getInteger("linkY"); + Integer z = tag.getInteger("linkZ"); + Integer dimID = tag.getInteger("linkDimID"); + + if (x != null && y != null && z != null && dimID != null) + { + return new Point4D(x, y, z, dimID); + } } - linkCoords[0]=tag.getInteger("linkX"); - linkCoords[1]=tag.getInteger("linkY"); - linkCoords[2]=tag.getInteger("linkZ"); - linkCoords[3]=tag.getInteger("linkDimID"); - linkCoords[4]=tag.getInteger("orientation"); - - - - } - return linkCoords; - - } - - - @Override - public void onCreated(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) - { - if(!par2World.isRemote) - { - /** - //creates the first half of the link on item creation - int key= dimHelper.instance.createUniqueInterDimLinkKey(); - LinkData linkData= new LinkData(par2World.provider.dimensionId,MathHelper.floor_double(par3EntityPlayer.posX),MathHelper.floor_double(par3EntityPlayer.posY),MathHelper.floor_double(par3EntityPlayer.posZ)); - System.out.println(key); - - dimHelper.instance.interDimLinkList.put(key, linkData); - par1ItemStack.setItemDamage(key); - **/ + itemStack.setItemDamage(0); } + return null; } } -- 2.39.5 From b795885f1c937879b6319baed41f90d3e97e3fbb Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 20:46:20 -0400 Subject: [PATCH 12/24] Renamed ItemLinkSignature to ItemRiftSignature Renamed ItemLinkSignature to ItemRiftSignature to match its in-game name. Automatically updated references to the old class name. --- .../items/{itemLinkSignature.java => ItemRiftSignature.java} | 4 ++-- .../mod_pocketDim/items/ItemStabilizedRiftSignature.java | 2 +- StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename StevenDimDoors/mod_pocketDim/items/{itemLinkSignature.java => ItemRiftSignature.java} (98%) diff --git a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java similarity index 98% rename from StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java rename to StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index 14e539d..bd3c74b 100644 --- a/StevenDimDoors/mod_pocketDim/items/itemLinkSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -17,9 +17,9 @@ import StevenDimDoors.mod_pocketDim.util.Point4D; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class itemLinkSignature extends Item +public class ItemRiftSignature extends Item { - public itemLinkSignature(int itemID) + public ItemRiftSignature(int itemID) { super(itemID); this.setMaxStackSize(1); diff --git a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index cf61d4f..5ea3f9e 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -12,7 +12,7 @@ import StevenDimDoors.mod_pocketDim.util.Point4D; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class ItemStabilizedRiftSignature extends itemLinkSignature +public class ItemStabilizedRiftSignature extends ItemRiftSignature { public ItemStabilizedRiftSignature(int itemID) { diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 1720449..756fe57 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -44,7 +44,7 @@ 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.itemLinkSignature; +import StevenDimDoors.mod_pocketDim.items.ItemRiftSignature; import StevenDimDoors.mod_pocketDim.items.itemRiftRemover; import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; import StevenDimDoors.mod_pocketDim.ticking.LimboDecay; @@ -198,7 +198,7 @@ public class mod_pocketDim itemDimDoor = (new ItemDimensionalDoor(properties.DimensionalDoorItemID, Material.iron)).setUnlocalizedName("itemDimDoor"); itemExitDoor = (new ItemWarpDoor(properties.WarpDoorItemID, Material.wood)).setUnlocalizedName("itemDimDoorWarp"); - itemLinkSignature = (new itemLinkSignature(properties.RiftSignatureItemID)).setUnlocalizedName("itemLinkSignature"); + itemLinkSignature = (new ItemRiftSignature(properties.RiftSignatureItemID)).setUnlocalizedName("itemLinkSignature"); itemRiftRemover = (new itemRiftRemover(properties.RiftRemoverItemID, Material.wood)).setUnlocalizedName("itemRiftRemover"); itemStableFabric = (new ItemStableFabric(properties.StableFabricItemID, 0)).setUnlocalizedName("itemStableFabric"); itemChaosDoor = (new ItemUnstableDoor(properties.UnstableDoorItemID, Material.iron)).setUnlocalizedName("itemChaosDoor"); -- 2.39.5 From 4086e75ead4abc973545fddda4d1f54e37f307d2 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 1 Sep 2013 09:21:27 -0400 Subject: [PATCH 13/24] 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. --- .../mod_pocketDim/DDProperties.java | 4 +- .../mod_pocketDim/DDTeleporter.java | 297 +++++++++--------- .../mod_pocketDim/EventHookContainer.java | 9 +- .../mod_pocketDim/PacketHandler.java | 59 +--- .../mod_pocketDim/PlayerRespawnTracker.java | 9 +- .../blocks/BlockDimWallPerm.java | 2 +- .../commands/CommandCreatePocket.java | 2 +- .../mod_pocketDim/core/PocketManager.java | 72 +++-- .../mod_pocketDim/mod_pocketDim.java | 57 +--- .../ticking/CommonTickHandler.java | 6 +- .../mod_pocketDim/ticking/MobMonolith.java | 2 +- .../mod_pocketDim/world/GatewayGenerator.java | 13 +- 12 files changed, 239 insertions(+), 293 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/DDProperties.java b/StevenDimDoors/mod_pocketDim/DDProperties.java index 2d21924..a18218d 100644 --- a/StevenDimDoors/mod_pocketDim/DDProperties.java +++ b/StevenDimDoors/mod_pocketDim/DDProperties.java @@ -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); diff --git a/StevenDimDoors/mod_pocketDim/DDTeleporter.java b/StevenDimDoors/mod_pocketDim/DDTeleporter.java index 1203cd5..e390ca7 100644 --- a/StevenDimDoors/mod_pocketDim/DDTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/DDTeleporter.java @@ -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; } } diff --git a/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 4ed540e..025a24f 100644 --- a/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -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(); } diff --git a/StevenDimDoors/mod_pocketDim/PacketHandler.java b/StevenDimDoors/mod_pocketDim/PacketHandler.java index 192b4a6..644d9f6 100644 --- a/StevenDimDoors/mod_pocketDim/PacketHandler.java +++ b/StevenDimDoors/mod_pocketDim/PacketHandler.java @@ -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 >> linkList = data.linksInThisDim.values(); + Collection >> linkList = data.linksInThisDim.values(); for(HashMap map : linkList ) { - Collection > linkList2 = map.values(); + Collection > linkList2 = map.values(); for(HashMap map2 : linkList2) { - Collection linkList3 = map2.values(); + Collection 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); diff --git a/StevenDimDoors/mod_pocketDim/PlayerRespawnTracker.java b/StevenDimDoors/mod_pocketDim/PlayerRespawnTracker.java index 706334f..d6b34fe 100644 --- a/StevenDimDoors/mod_pocketDim/PlayerRespawnTracker.java +++ b/StevenDimDoors/mod_pocketDim/PlayerRespawnTracker.java @@ -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 diff --git a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java index bdf14a9..5789fb3 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java +++ b/StevenDimDoors/mod_pocketDim/blocks/BlockDimWallPerm.java @@ -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 ); diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java b/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java index 6365d74..5360cff 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandCreatePocket.java @@ -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; diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 39519bd..09f2e61 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -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 dimensionData = new HashMap(); - 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(); } diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 756fe57..bcac33e 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -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(); } } diff --git a/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java b/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java index 6cf3ecd..a190039 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java +++ b/StevenDimDoors/mod_pocketDim/ticking/CommonTickHandler.java @@ -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--; } } diff --git a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java index e983edf..2fed8ab 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java +++ b/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java @@ -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); diff --git a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java index abbc7ea..5bc6fb0 100644 --- a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java @@ -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); -- 2.39.5 From efa5b3eb4c4645fec609da079890d1c3252bff6d Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 1 Sep 2013 10:50:20 -0400 Subject: [PATCH 14/24] Modified NewDimData and IDimLink Modified how links are created so that the caller must specify a link type when the link is created, rather than setting it later. This was done to avoid having to send two link data packets following the way links would be handled logically. Turns out this was good idea overall for ensuring link integrity, because there was one case where I forgot to set the link type after creating the link. --- .../mod_pocketDim/blocks/DimensionalDoor.java | 2 +- .../mod_pocketDim/blocks/UnstableDoor.java | 2 +- .../mod_pocketDim/blocks/WarpDoor.java | 2 +- .../mod_pocketDim/core/IDimLink.java | 1 - .../mod_pocketDim/core/NewDimData.java | 67 +++++++++++-------- .../dungeon/DungeonSchematic.java | 6 +- .../mod_pocketDim/helpers/DungeonHelper.java | 2 +- .../mod_pocketDim/items/ItemRiftBlade.java | 2 +- .../items/ItemRiftSignature.java | 4 +- .../mod_pocketDim/world/GatewayGenerator.java | 4 +- 10 files changed, 51 insertions(+), 41 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java index 1d0cd0d..fbd0281 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java @@ -172,7 +172,7 @@ public class DimensionalDoor extends BlockContainer IDimLink link = dimension.getLink(x, y, z); if (link == null) { - dimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_POCKET); + dimension.createLink(x, y, z, IDimLink.TYPE_POCKET); } } world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); diff --git a/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java index 74a0f73..d53e576 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java @@ -54,7 +54,7 @@ public class UnstableDoor extends DimensionalDoor if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { NewDimData dimension = PocketManager.getDimensionData(world); - dimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_RANDOM); + dimension.createLink(x, y, z, IDimLink.TYPE_RANDOM); } } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java index cbe5159..410a052 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java @@ -41,7 +41,7 @@ public class WarpDoor extends DimensionalDoor IDimLink link = dimension.getLink(x, y, z); if (link == null) { - dimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_SAFE_EXIT); + dimension.createLink(x, y, z, IDimLink.TYPE_SAFE_EXIT); } } world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); diff --git a/StevenDimDoors/mod_pocketDim/core/IDimLink.java b/StevenDimDoors/mod_pocketDim/core/IDimLink.java index 34d2f9b..cb62dc3 100644 --- a/StevenDimDoors/mod_pocketDim/core/IDimLink.java +++ b/StevenDimDoors/mod_pocketDim/core/IDimLink.java @@ -27,5 +27,4 @@ public interface IDimLink extends Serializable public IDimLink parent(); public int linkType(); public IDimLink setDestination(int x, int y, int z, NewDimData dimension); - public IDimLink setLinkType(int linkType); } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index f8c9941..40c3333 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -27,7 +27,7 @@ public abstract class NewDimData implements Serializable private ArrayList children; public DimLink(Point4D source, DimLink parent) - { + { this.parent = parent; this.source = source; this.tail = parent.tail; @@ -35,11 +35,16 @@ public abstract class NewDimData implements Serializable parent.children.add(this); } - public DimLink(Point4D source) + public DimLink(Point4D source, int linkType) { + if (linkType < IDimLink.TYPE_ENUM_MIN || linkType > IDimLink.TYPE_ENUM_MAX) + { + throw new IllegalArgumentException("The specified link type is invalid."); + } + this.parent = null; this.source = source; - this.tail = new LinkTail(0, null); + this.tail = new LinkTail(linkType, null); this.children = new ArrayList(EXPECTED_CHILDREN); } @@ -72,18 +77,6 @@ public abstract class NewDimData implements Serializable tail.setDestination(new Point4D(x, y, z, dimension.id())); return this; } - - @Override - public IDimLink setLinkType(int linkType) - { - if (linkType < IDimLink.TYPE_ENUM_MIN || linkType > IDimLink.TYPE_ENUM_MAX) - { - throw new IllegalArgumentException("The specified link type is invalid."); - } - - tail.setLinkType(linkType); - return this; - } @Override public Iterable children() @@ -131,6 +124,11 @@ public abstract class NewDimData implements Serializable public void overwrite(DimLink nextParent) { + if (nextParent == null) + { + throw new IllegalArgumentException("nextParent cannot be null."); + } + if (this == nextParent) { //Ignore this request silently @@ -152,15 +150,28 @@ public abstract class NewDimData implements Serializable //Attach to new parent parent = nextParent; + tail = nextParent.tail; + nextParent.children.add(this); + } + + public void overwrite(int linkType) + { + //Release children + for (IDimLink child : children) + { + ((DimLink) child).parent = null; + } + children.clear(); + + //Release parent if (parent != null) { - tail = parent.tail; - parent.children.add(this); - } - else - { - tail = new LinkTail(0, null); + parent.children.remove(this); } + + //Attach to new parent + parent = null; + tail = new LinkTail(linkType, null); } @Override @@ -224,7 +235,7 @@ public abstract class NewDimData implements Serializable public IDimLink findNearestRift(World world, int range, int x, int y, int z) { - //TODO: Rewrite this later to use an octtree, remove World parameter + //TODO: Rewrite this later to use an octtree //Sanity check... if (world.provider.dimensionId != id) @@ -271,24 +282,24 @@ public abstract class NewDimData implements Serializable return Math.abs(i) + Math.abs(j) + Math.abs(k); } - public IDimLink createLink(int x, int y, int z) + public IDimLink createLink(int x, int y, int z, int linkType) { - return createLink(new Point4D(x, y, z, id)); + return createLink(new Point4D(x, y, z, id), linkType); } - private IDimLink createLink(Point4D source) - { + private IDimLink createLink(Point4D source, int linkType) + { //Return an existing link if there is one to avoid creating multiple links starting at the same point. DimLink link = linkMapping.get(source); if (link == null) { - link = new DimLink(source); + link = new DimLink(source, linkType); linkMapping.put(source, link); linkList.add(link); } else { - link.overwrite(null); + link.overwrite(linkType); } return link; } diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index ab6013a..1c0663d 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -284,7 +284,7 @@ public class DungeonSchematic extends Schematic { private static void createEntranceReverseLink(NewDimData dimension, Point3D pocketCenter, IDimLink entryLink) { - IDimLink link = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ()); + IDimLink link = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), IDimLink.TYPE_NORMAL); Point4D destination = link.source(); link.setDestination(destination.getX(), destination.getY(), destination.getZ(), PocketManager.getDimensionData(destination.getDimension())); @@ -295,7 +295,7 @@ public class DungeonSchematic extends Schematic { //Transform the door's location to the pocket coordinate system Point3D location = point.clone(); BlockRotator.transformPoint(location, entrance, rotation, pocketCenter); - dimension.createLink(location.getX(), location.getY(), location.getZ()).setLinkType(IDimLink.TYPE_DUNGEON_EXIT); + dimension.createLink(location.getX(), location.getY(), location.getZ(), IDimLink.TYPE_DUNGEON_EXIT); } private static void createDimensionalDoorLink(NewDimData dimension, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) @@ -303,7 +303,7 @@ public class DungeonSchematic extends Schematic { //Transform the door's location to the pocket coordinate system Point3D location = point.clone(); BlockRotator.transformPoint(location, entrance, rotation, pocketCenter); - dimension.createLink(location.getX(), location.getY(), location.getZ()).setLinkType(IDimLink.TYPE_DUNGEON); + dimension.createLink(location.getX(), location.getY(), location.getZ(), IDimLink.TYPE_DUNGEON); } private static void spawnMonolith(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 3913932..cc9cfdb 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -278,7 +278,7 @@ public class DungeonHelper { //Create a link above the specified position. Link to a new pocket dimension. NewDimData dimension = PocketManager.getDimensionData(world); - IDimLink link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); + IDimLink link = dimension.createLink(x, y + 1, z, IDimLink.TYPE_POCKET); //Place a Warp Door linked to that pocket ItemDimensionalDoor.placeDoorBlock(world, x, y, z, 3, mod_pocketDim.warpDoor); diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java index 727fc24..c6eec69 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java @@ -187,7 +187,7 @@ public class ItemRiftBlade extends ItemSword NewDimData dimension = PocketManager.getDimensionData(world); if (!dimension.isPocketDimension() && dimension.getLink(x, y + 1, z) == null) { - dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); + dimension.createLink(x, y + 1, z, IDimLink.TYPE_POCKET); player.worldObj.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1); ItemDimensionalDoor.placeDoorBlock(world, x, y, z, orientation, mod_pocketDim.transientDoor); } diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index bd3c74b..fc521bf 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -66,8 +66,8 @@ public class ItemRiftSignature extends Item //The link was used before and already has an endpoint stored. Create links connecting the two endpoints. NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); NewDimData destinationDimension = PocketManager.getDimensionData(world); - IDimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ()).setLinkType(IDimLink.TYPE_NORMAL); - IDimLink reverse = destinationDimension.createLink(x, y, z).setLinkType(IDimLink.TYPE_NORMAL); + IDimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), IDimLink.TYPE_NORMAL); + IDimLink reverse = destinationDimension.createLink(x, y, z, IDimLink.TYPE_NORMAL); link.setDestination(x, y, z, destinationDimension); reverse.setDestination(source.getX(), source.getY(), source.getZ(), sourceDimension); diff --git a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java index 5bc6fb0..2a2e0f0 100644 --- a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java @@ -97,7 +97,7 @@ public class GatewayGenerator implements IWorldGenerator if (link == null) { dimension = PocketManager.getDimensionData(world); - link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_POCKET); + link = dimension.createLink(x, y + 1, z, IDimLink.TYPE_POCKET); } else { @@ -132,7 +132,7 @@ public class GatewayGenerator implements IWorldGenerator { //Create a partial link to a dungeon. dimension = PocketManager.getDimensionData(world); - link = dimension.createLink(x, y + 1, z).setLinkType(IDimLink.TYPE_DUNGEON); + link = dimension.createLink(x, y + 1, z, IDimLink.TYPE_DUNGEON); //If the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks if (dimension.id() != properties.LimboDimensionID) -- 2.39.5 From 62fed83e2f7e75b4aa0caf6969f3843bf234773b Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 1 Sep 2013 22:01:17 -0400 Subject: [PATCH 15/24] Started Rewriting Packet Handling Started rewriting our packet handling code. Deleted PacketHandler in favor of using sided (Server-, Client-) packet handlers to make it easier to follow what's going on in our code. Added some event-based handling of updates which greatly simplified signaling that data needs to be sent, but it's not completely done yet. --- StevenDimDoors/mod_pocketDim/CommonProxy.java | 14 +- .../mod_pocketDim/ConnectionHandler.java | 36 ++- .../mod_pocketDim/PacketConstants.java | 15 + StevenDimDoors/mod_pocketDim/Point3D.java | 2 + .../mod_pocketDim/ServerPacketHandler.java | 86 +++++- .../mod_pocketDim/core/IDimLink.java | 5 +- .../mod_pocketDim/core/NewDimData.java | 93 ++++-- .../mod_pocketDim/core/PocketManager.java | 279 +++++++++--------- .../mod_pocketDim/dungeon/DungeonData.java | 5 +- .../dungeon/DungeonSchematic.java | 4 +- .../items/ItemRiftSignature.java | 4 +- .../mod_pocketDim/mod_pocketDim.java | 8 +- .../mod_pocketDim/watcher/IOpaqueMessage.java | 8 + .../mod_pocketDim/watcher/IOpaqueReader.java | 8 + .../mod_pocketDim/watcher/IUpdateWatcher.java | 8 + .../watcher/UpdateWatcherProxy.java | 51 ++++ .../ClientPacketHandler.java | 16 +- 17 files changed, 421 insertions(+), 221 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/PacketConstants.java create mode 100644 StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java create mode 100644 StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java create mode 100644 StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java create mode 100644 StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java diff --git a/StevenDimDoors/mod_pocketDim/CommonProxy.java b/StevenDimDoors/mod_pocketDim/CommonProxy.java index 951244e..ada7b95 100644 --- a/StevenDimDoors/mod_pocketDim/CommonProxy.java +++ b/StevenDimDoors/mod_pocketDim/CommonProxy.java @@ -1,10 +1,7 @@ package StevenDimDoors.mod_pocketDim; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; -import StevenDimDoors.mod_pocketDimClient.ClientTickHandler; - import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.CompressedStreamTools; @@ -47,7 +44,6 @@ public class CommonProxy implements IGuiHandler public void writeNBTToFile(World world) { boolean flag = true; - boolean secondTry = false; try { @@ -58,7 +54,6 @@ public class CommonProxy implements IGuiHandler if (!flag) { dirFolder.replace("saves/", FMLCommonHandler.instance().getMinecraftServerInstance().getFolderName()); - secondTry = true; } File file = new File(dirFolder, "GGMData.dat"); @@ -91,7 +86,6 @@ public class CommonProxy implements IGuiHandler public void readNBTFromFile(World world) { boolean flag = true; - boolean secondTry = false; try { @@ -102,7 +96,6 @@ public class CommonProxy implements IGuiHandler if (!flag) { dirFolder.replace("saves/", FMLCommonHandler.instance().getMinecraftServerInstance().getFolderName()); - secondTry = true; } File file = new File(dirFolder, "GGMData.dat"); @@ -117,12 +110,9 @@ public class CommonProxy implements IGuiHandler fileoutputstream.close(); } - FileInputStream fileinputstream = new FileInputStream(file); + /*FileInputStream fileinputstream = new FileInputStream(file); NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(fileinputstream); - - - - fileinputstream.close(); + fileinputstream.close();*/ } catch (Exception exception) { diff --git a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java index 7b855a5..0b13248 100644 --- a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java +++ b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java @@ -1,21 +1,25 @@ package StevenDimDoors.mod_pocketDim; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; + import net.minecraft.network.INetworkManager; import net.minecraft.network.NetLoginHandler; import net.minecraft.network.packet.NetHandler; import net.minecraft.network.packet.Packet1Login; +import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.server.MinecraftServer; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.watcher.IOpaqueMessage; import cpw.mods.fml.common.network.IConnectionHandler; import cpw.mods.fml.common.network.Player; public class ConnectionHandler implements IConnectionHandler { @Override - public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager) + public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager) { - //Sends a packet to the client containing all the information about the dimensions and links. - //Lots of packets, actually. - PacketHandler.sendClientJoinPacket(manager); return null; } @@ -32,5 +36,27 @@ public class ConnectionHandler implements IConnectionHandler public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) { } @Override - public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) { } + public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) + { + //Send information about all the registered dimensions and links to the client + try + { + IOpaqueMessage message = PocketManager.getState(); + Packet250CustomPayload packet = new Packet250CustomPayload(); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + DataOutputStream writer = new DataOutputStream(buffer); + writer.writeByte(PacketConstants.CLIENT_JOIN_PACKET_ID); + message.writeToStream(writer); + writer.close(); + packet.channel = PacketConstants.CHANNEL_NAME; + packet.data = buffer.toByteArray(); + packet.length = packet.data.length; + manager.addToSendQueue(packet); + } + catch (IOException e) + { + //This shouldn't happen... + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/PacketConstants.java b/StevenDimDoors/mod_pocketDim/PacketConstants.java new file mode 100644 index 0000000..67d4e60 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/PacketConstants.java @@ -0,0 +1,15 @@ +package StevenDimDoors.mod_pocketDim; + +public class PacketConstants +{ + private PacketConstants() { } + + public static final byte CLIENT_JOIN_PACKET_ID = 1; + public static final byte CREATE_DIM_PACKET_ID = 2; + public static final byte UPDATE_DIM_PACKET_ID = 3; + public static final byte DELETE_DIM_PACKET_ID = 4; + public static final byte CREATE_LINK_PACKET_ID = 5; + public static final byte UPDATE_LINK_PACKET_ID = 6; + public static final byte DELETE_LINK_PACKET_ID = 7; + public static final String CHANNEL_NAME = "DimDoorsPackets"; +} diff --git a/StevenDimDoors/mod_pocketDim/Point3D.java b/StevenDimDoors/mod_pocketDim/Point3D.java index 4a8e72a..7a3d357 100644 --- a/StevenDimDoors/mod_pocketDim/Point3D.java +++ b/StevenDimDoors/mod_pocketDim/Point3D.java @@ -4,6 +4,8 @@ import java.io.Serializable; public class Point3D implements Serializable { + private static final long serialVersionUID = -9044026830605287190L; + private int x; private int y; private int z; diff --git a/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java b/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java index fff2079..310b84a 100644 --- a/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java +++ b/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java @@ -1,15 +1,93 @@ package StevenDimDoors.mod_pocketDim; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; + import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.watcher.IOpaqueMessage; +import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; import cpw.mods.fml.common.network.IPacketHandler; +import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.Player; public class ServerPacketHandler implements IPacketHandler { - @Override - public void onPacketData(INetworkManager manager, - Packet250CustomPayload packet, Player player) + public ServerPacketHandler() { + PocketManager.registerDimWatcher(new DimWatcher()); + PocketManager.registerLinkWatcher(new LinkWatcher()); } -} \ No newline at end of file + + @Override + public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) + { + + } + + private class DimWatcher implements IUpdateWatcher + { + @Override + public void onCreated(IOpaqueMessage message) + { + sendMessageToAllPlayers(PacketConstants.CREATE_DIM_PACKET_ID, message); + } + + @Override + public void onUpdated(IOpaqueMessage message) + { + sendMessageToAllPlayers(PacketConstants.UPDATE_DIM_PACKET_ID, message); + } + + @Override + public void onDeleted(IOpaqueMessage message) + { + sendMessageToAllPlayers(PacketConstants.DELETE_DIM_PACKET_ID, message); + } + } + + private class LinkWatcher implements IUpdateWatcher + { + @Override + public void onCreated(IOpaqueMessage message) + { + sendMessageToAllPlayers(PacketConstants.CREATE_LINK_PACKET_ID, message); + } + + @Override + public void onUpdated(IOpaqueMessage message) + { + sendMessageToAllPlayers(PacketConstants.UPDATE_LINK_PACKET_ID, message); + } + + @Override + public void onDeleted(IOpaqueMessage message) + { + sendMessageToAllPlayers(PacketConstants.DELETE_LINK_PACKET_ID, message); + } + } + + private static void sendMessageToAllPlayers(byte id, IOpaqueMessage message) + { + try + { + Packet250CustomPayload packet = new Packet250CustomPayload(); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + DataOutputStream writer = new DataOutputStream(buffer); + writer.writeByte(id); + message.writeToStream(writer); + writer.close(); + packet.channel = PacketConstants.CHANNEL_NAME; + packet.data = buffer.toByteArray(); + packet.length = packet.data.length; + PacketDispatcher.sendPacketToAllPlayers(packet); + } + catch (IOException e) + { + //This shouldn't happen... + e.printStackTrace(); + } + } +} diff --git a/StevenDimDoors/mod_pocketDim/core/IDimLink.java b/StevenDimDoors/mod_pocketDim/core/IDimLink.java index cb62dc3..4ed15b0 100644 --- a/StevenDimDoors/mod_pocketDim/core/IDimLink.java +++ b/StevenDimDoors/mod_pocketDim/core/IDimLink.java @@ -1,10 +1,8 @@ package StevenDimDoors.mod_pocketDim.core; -import java.io.Serializable; - import StevenDimDoors.mod_pocketDim.util.Point4D; -public interface IDimLink extends Serializable +public interface IDimLink { public final int TYPE_ENUM_MIN = 0; public final int TYPE_ENUM_MAX = 8; @@ -26,5 +24,4 @@ public interface IDimLink extends Serializable public int childCount(); public IDimLink parent(); public int linkType(); - public IDimLink setDestination(int x, int y, int z, NewDimData dimension); } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 40c3333..c7e0c2e 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -1,5 +1,4 @@ package StevenDimDoors.mod_pocketDim.core; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -11,14 +10,15 @@ import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; import StevenDimDoors.mod_pocketDim.util.Point4D; +import StevenDimDoors.mod_pocketDim.watcher.IOpaqueMessage; +import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; -public abstract class NewDimData implements Serializable +public abstract class NewDimData { private static class DimLink implements IDimLink { //DimLink is an inner class here to make it immutable to code outside NewDimData - private static final long serialVersionUID = 1462177151401498444L; private static final int EXPECTED_CHILDREN = 2; private Point4D source; @@ -66,16 +66,9 @@ public abstract class NewDimData implements Serializable return (tail.getDestination() != null); } - @Override - public IDimLink setDestination(int x, int y, int z, NewDimData dimension) + public void setDestination(int x, int y, int z, NewDimData dimension) { - if (dimension == null) - { - throw new IllegalArgumentException("dimension cannot be null."); - } - tail.setDestination(new Point4D(x, y, z, dimension.id())); - return this; } @Override @@ -179,9 +172,18 @@ public abstract class NewDimData implements Serializable { return source + " -> " + (hasDestination() ? destination() : ""); } - } - private static final long serialVersionUID = 89361974746997260L; + public IOpaqueMessage toMessage() + { + return null; + } + + public IOpaqueMessage toKey() + { + return null; + } + } + private static Random random = new Random(); private final int id; @@ -197,8 +199,11 @@ public abstract class NewDimData implements Serializable private Point4D origin; private int orientation; private DungeonData dungeon; + private final IUpdateWatcher dimWatcher; + private final IUpdateWatcher linkWatcher; - protected NewDimData(int id, NewDimData parent, boolean isPocket, boolean isDungeon) + protected NewDimData(int id, NewDimData parent, boolean isPocket, boolean isDungeon, + IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher) { //The isPocket flag is redundant. It's meant as an integrity safeguard. if (isPocket == (parent != null)) @@ -215,24 +220,33 @@ public abstract class NewDimData implements Serializable this.linkList = new ArrayList(); //Should be stored in oct tree -- temporary solution this.children = new ArrayList(); this.parent = parent; - this.root = (parent != null ? parent.root : this); - this.depth = (parent != null ? parent.depth + 1 : 0); this.packDepth = 0; this.isDungeon = isDungeon; this.isFilled = false; this.orientation = 0; this.origin = null; this.dungeon = null; + this.dimWatcher = dimWatcher; + this.linkWatcher = linkWatcher; //Register with parent - addChildDimension(this); + if (parent != null) + { + //We don't need to raise an update event for adding a child because the child's creation will be signaled. + this.root = parent.root; + this.depth = parent.depth + 1; + parent.children.add(this); + } + else + { + this.root = this; + this.depth = 0; + } } - private void addChildDimension(NewDimData child) - { - children.add(child); - } - + protected abstract IOpaqueMessage toMessage(); + protected abstract IOpaqueMessage toKey(); + public IDimLink findNearestRift(World world, int range, int x, int y, int z) { //TODO: Rewrite this later to use an octtree @@ -301,6 +315,8 @@ public abstract class NewDimData implements Serializable { link.overwrite(linkType); } + //Link created! + linkWatcher.onCreated(link.toMessage()); return link; } @@ -330,7 +346,8 @@ public abstract class NewDimData implements Serializable { link.overwrite(parent); } - + //Link created! + linkWatcher.onCreated(link.toMessage()); return link; } @@ -344,6 +361,8 @@ public abstract class NewDimData implements Serializable if (target != null) { linkList.remove(target); + //Raise deletion event + linkWatcher.onDeleted(target.toKey()); target.clear(); } return (target != null); @@ -356,6 +375,8 @@ public abstract class NewDimData implements Serializable if (target != null) { linkList.remove(target); + //Raise deletion event + linkWatcher.onDeleted(target.toKey()); target.clear(); } return (target != null); @@ -400,6 +421,8 @@ public abstract class NewDimData implements Serializable public void setFilled(boolean isFilled) { this.isFilled = isFilled; + //Raise the dim update event + dimWatcher.onUpdated(this.toMessage()); } public int id() @@ -457,7 +480,7 @@ public abstract class NewDimData implements Serializable return children; } - public void initializeDungeon(int originX, int originY, int originZ, int orientation, IDimLink link, DungeonData dungeon) + public void initializeDungeon(int originX, int originY, int originZ, int orientation, IDimLink incoming, DungeonData dungeon) { if (!isDungeon) { @@ -468,11 +491,13 @@ public abstract class NewDimData implements Serializable throw new IllegalStateException("The dimension has already been initialized."); } - link.setDestination(originX, originY, originZ, this); - this.origin = link.destination(); + setDestination(incoming, originX, originY, originZ); + this.origin = incoming.destination(); this.orientation = orientation; this.dungeon = dungeon; this.packDepth = calculatePackDepth(parent, dungeon); + //Raise the dim update event + dimWatcher.onUpdated(this.toMessage()); } private static int calculatePackDepth(NewDimData parent, DungeonData current) @@ -507,7 +532,7 @@ public abstract class NewDimData implements Serializable } } - public void initializePocket(int originX, int originY, int originZ, int orientation, IDimLink link) + public void initializePocket(int originX, int originY, int originZ, int orientation, IDimLink incoming) { if (!isPocketDimension()) { @@ -518,9 +543,19 @@ public abstract class NewDimData implements Serializable throw new IllegalStateException("The dimension has already been initialized."); } - link.setDestination(originX, originY, originZ, this); - this.origin = link.destination(); + setDestination(incoming, originX, originY, originZ); + this.origin = incoming.destination(); this.orientation = orientation; + //Raise the dim update event + dimWatcher.onUpdated(this.toMessage()); + } + + public void setDestination(IDimLink incoming, int x, int y, int z) + { + DimLink link = (DimLink) incoming; + link.setDestination(x, y, z, this); + //Raise update event + linkWatcher.onUpdated(link.toMessage()); } public IDimLink getRandomLink() diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 09f2e61..3555915 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -1,9 +1,10 @@ package StevenDimDoors.mod_pocketDim.core; +import java.io.DataOutputStream; import java.io.File; -import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.ObjectOutputStream; +import java.io.IOException; import java.util.HashMap; import net.minecraft.entity.player.EntityPlayer; @@ -12,11 +13,12 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream; import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDim.util.Point4D; -import cpw.mods.fml.common.FMLCommonHandler; +import StevenDimDoors.mod_pocketDim.watcher.IOpaqueMessage; +import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; +import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy; /** * This class regulates all the operations involving the storage and manipulation of dimensions. It handles saving dim data, teleporting the player, and @@ -30,19 +32,35 @@ public class PocketManager //a public constructor from NewDimData. It's meant to stop us from constructing instances //of NewDimData without using PocketManager's functions. In turn, that enforces that any //link destinations must be real dimensions controlled by PocketManager. - - private static final long serialVersionUID = -3497038894870586232L; - public InnerDimData(int id, NewDimData parent, boolean isPocket, boolean isDungeon) + public InnerDimData(int id, NewDimData parent, boolean isPocket, boolean isDungeon, + IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher) { - super(id, parent, isPocket, isDungeon); + super(id, parent, isPocket, isDungeon, dimWatcher, linkWatcher); + } + + @Override + protected IOpaqueMessage toMessage() + { + // TODO Auto-generated method stub + return null; + } + + @Override + protected IOpaqueMessage toKey() + { + // TODO Auto-generated method stub + return null; } } private static int OVERWORLD_DIMENSION_ID = 0; - private static boolean isLoaded = false; - private static boolean isSaving = false; + private static volatile boolean isLoading = false; + private static volatile boolean isLoaded = false; + private static volatile boolean isSaving = false; + private static UpdateWatcherProxy linkWatcher = null; + private static UpdateWatcherProxy dimWatcher = null; //HashMap that maps all the dimension IDs registered with DimDoors to their DD data. private static HashMap dimensionData = new HashMap(); @@ -62,8 +80,17 @@ public class PocketManager { throw new IllegalStateException("Pocket dimensions have already been loaded!"); } + if (isLoading) + { + return; + } + + isLoading = true; + + //Set up watcher proxies + dimWatcher = new UpdateWatcherProxy(); + linkWatcher = new UpdateWatcherProxy(); - isLoaded = true; loadInternal(); //Register Limbo @@ -72,6 +99,9 @@ public class PocketManager //Register pocket dimensions registerPockets(properties); + + isLoaded = true; + isLoading = false; } public boolean clearPocket(NewDimData dimension) @@ -103,6 +133,9 @@ public class PocketManager File save = new File(DimensionManager.getCurrentSaveRootDirectory() + "/DimensionalDoors/pocketDimID" + dimension.id()); DeleteFolder.deleteFolder(save); } + //Raise the dim deleted event + dimWatcher.onDeleted(dimension.toKey()); + //dimension.implode()??? -- more like delete, but yeah return true; } else @@ -149,65 +182,6 @@ public class PocketManager } } - /** - * Function that saves all dim data in a hashMap. Calling too often can cause Concurrent modification exceptions, so be careful. - * @return - */ - public static void save() - { - //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; - } - World world = DimensionManager.getWorld(OVERWORLD_DIMENSION_ID); - if (world == null || world.isRemote) - { - return; - } - if (DimensionManager.getCurrentSaveRootDirectory() != null) - { - isSaving = true; - HashMap comboSave = new HashMap(); - comboSave.put("dimensionData", dimensionData); - - FileOutputStream saveFile = null; - try - { - String saveFileName=DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataTEMP"; - saveFile = new FileOutputStream(saveFileName); - - ObjectOutputStream save = new ObjectOutputStream(saveFile); - save.writeObject(comboSave); - save.close(); - saveFile.close(); - - if (new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD").exists()) - { - new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD").delete(); - } - new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsData").renameTo(new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD")); - - new File(saveFileName).renameTo( new File(DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsData")); - } - catch(Exception e) - { - e.printStackTrace(); - System.err.println("Could not save data-- SEVERE"); - } - finally - { - isSaving = false; - } - } - } - /** * loads the dim data from the saved hashMap. Also handles compatibility with old saves, see OldSaveHandler * @return @@ -215,81 +189,68 @@ public class PocketManager @SuppressWarnings("unchecked") 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 - //be a function so that you can apply it to the save file first, then the "backup", instead of duplicating - //so much code. >_< + // SenseiKiwi: This is a temporary function for testing purposes. + // We'll move on to using a text-based format in the future. - boolean firstRun = false; - System.out.println("Loading DimDoors data"); - FileInputStream saveFile = null; - - if (!DimensionManager.getWorld(OVERWORLD_DIMENSION_ID).isRemote && DimensionManager.getCurrentSaveRootDirectory()!=null) + if (!DimensionManager.getWorld(OVERWORLD_DIMENSION_ID).isRemote && + DimensionManager.getCurrentSaveRootDirectory() != null) { - try - { - File dataStore = new File( DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsData"); - if (!dataStore.exists()) - { - if (!new File( DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoorsDataOLD").exists()) - { - firstRun=true; - } - } - saveFile = new FileInputStream(dataStore); - ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); - HashMap comboSave = (HashMap) save.readObject(); + System.out.println("Loading Dimensional Doors save data..."); + File saveFile = new File(DimensionManager.getCurrentSaveRootDirectory() + "/dimdoors.dat"); + //Missing code for converting the binary data in the file into an IOpaqueMessage + IOpaqueMessage saveData; + setState(saveData); + System.out.println("Loaded successfully!"); + } + } + + public static void save() + { + // SenseiKiwi: This is a temporary function for testing purposes. + // We'll move on to using a text-based format in the future. - try - { - dimensionData = (HashMap) comboSave.get("dimensionData"); - } - catch(Exception e) - { - System.out.println("Could not load pocket dimension list. Saves are probably lost, but repairable. Move the files from individual pocket dim files to active ones. See MC thread for details."); - } + if (!isLoaded) + { + return; + } + World world = DimensionManager.getWorld(OVERWORLD_DIMENSION_ID); + if (world == null || world.isRemote || DimensionManager.getCurrentSaveRootDirectory() != null) + { + return; + } + //Check this last to make sure we set the flag shortly after. + if (isSaving) + { + return; + } - save.close(); - saveFile.close(); - } - catch (Exception e) - { - try - { - if (!firstRun) - { - System.out.println("Save data damaged, trying backup..."); - } - World world=FMLCommonHandler.instance().getMinecraftServerInstance().worldServers[0]; - File dataStore =new File( world.getSaveHandler().getMapFileFromName("idcounts").getParentFile().getParent()+"/DimensionalDoorsDataOLD"); - - - saveFile = new FileInputStream(dataStore); - ObjectSaveInputStream save = new ObjectSaveInputStream(saveFile); - HashMap comboSave = (HashMap) save.readObject(); - - try - { - dimensionData = (HashMap) comboSave.get("dimensionData"); - } - catch (Exception e2) - { - System.out.println("Could not load pocket dim list. Saves probably lost, but repairable. Move the files from indivual pocket dim files to active ones. See MC thread for details."); - } - - save.close(); - saveFile.close(); - } - catch (Exception e2) - { - if (!firstRun) - { - System.err.println("Could not read data-- SEVERE"); - e2.printStackTrace(); - } - } - } - } + isSaving = true; + try + { + System.out.println("Writing Dimensional Doors save data..."); + String tempPath = DimensionManager.getCurrentSaveRootDirectory() + "/dimdoors.tmp"; + String savePath = DimensionManager.getCurrentSaveRootDirectory() + "/dimdoors.dat"; + File tempFile = new File(tempPath); + File saveFile = new File(savePath); + DataOutputStream writer = new DataOutputStream(new FileOutputStream(tempFile)); + getState().writeToStream(writer); + writer.close(); + saveFile.delete(); + tempFile.renameTo(saveFile); + System.out.println("Saved successfully!"); + } + catch (FileNotFoundException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } + finally + { + isSaving = false; + } } public static boolean removeRift(World world, int x, int y, int z, int range, EntityPlayer player, ItemStack item) @@ -340,7 +301,7 @@ public class PocketManager throw new IllegalArgumentException("Cannot register a dimension with ID = " + dimensionID + " because it has already been registered."); } - NewDimData dimension = new InnerDimData(dimensionID, parent, isPocket, isDungeon); + NewDimData dimension = new InnerDimData(dimensionID, parent, isPocket, isDungeon, dimWatcher, linkWatcher); dimensionData.put(dimensionID, dimension); return dimension; } @@ -395,4 +356,38 @@ public class PocketManager return null; } } + + public static void registerDimWatcher(IUpdateWatcher watcher) + { + dimWatcher.registerReceiver(watcher); + } + + public static boolean unregisterDimWatcher(IUpdateWatcher watcher) + { + return dimWatcher.unregisterReceiver(watcher); + } + + public static void registerLinkWatcher(IUpdateWatcher watcher) + { + linkWatcher.registerReceiver(watcher); + } + + public static boolean unregisterLinkWatcher(IUpdateWatcher watcher) + { + return linkWatcher.unregisterReceiver(watcher); + } + + public static IOpaqueMessage getState() + { + + } + + public static void setState(IOpaqueMessage state) + { + if (isLoaded) + { + throw new IllegalStateException("Pocket dimensions have already been loaded!"); + } + + } } diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java index 6d57e7d..7c298df 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java @@ -1,16 +1,13 @@ package StevenDimDoors.mod_pocketDim.dungeon; import java.io.FileNotFoundException; -import java.io.Serializable; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; import StevenDimDoors.mod_pocketDim.schematic.InvalidSchematicException; -public class DungeonData implements Serializable +public class DungeonData { - private static final long serialVersionUID = -5624866366474710161L; - private final int weight; private final boolean isOpen; private final boolean isInternal; diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index 1c0663d..9426174 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -286,8 +286,8 @@ public class DungeonSchematic extends Schematic { { IDimLink link = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), IDimLink.TYPE_NORMAL); Point4D destination = link.source(); - link.setDestination(destination.getX(), destination.getY(), destination.getZ(), - PocketManager.getDimensionData(destination.getDimension())); + NewDimData prevDim = PocketManager.getDimensionData(destination.getDimension()); + prevDim.setDestination(link, destination.getX(), destination.getY(), destination.getZ()); } private static void createExitDoorLink(NewDimData dimension, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index fc521bf..36c2757 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -68,8 +68,8 @@ public class ItemRiftSignature extends Item NewDimData destinationDimension = PocketManager.getDimensionData(world); IDimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), IDimLink.TYPE_NORMAL); IDimLink reverse = destinationDimension.createLink(x, y, z, IDimLink.TYPE_NORMAL); - link.setDestination(x, y, z, destinationDimension); - reverse.setDestination(source.getX(), source.getY(), source.getZ(), sourceDimension); + destinationDimension.setDestination(link, x, y, z); + sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ()); //Try placing a rift at the destination point if (!mod_pocketDim.blockRift.isBlockImmune(world, x, y, z)) diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index bcac33e..cde2099 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -74,13 +74,11 @@ import cpw.mods.fml.relauncher.Side; @Mod(modid = mod_pocketDim.modid, name = "Dimensional Doors", version = mod_pocketDim.version) - -@NetworkMod(clientSideRequired = true, serverSideRequired = false, +@NetworkMod(clientSideRequired = true, serverSideRequired = false, connectionHandler=ConnectionHandler.class, clientPacketHandlerSpec = -@SidedPacketHandler(channels = {"pocketDim" }, packetHandler = ClientPacketHandler.class), +@SidedPacketHandler(channels = {PacketConstants.CHANNEL_NAME}, packetHandler = ClientPacketHandler.class), serverPacketHandlerSpec = -@SidedPacketHandler(channels = {"pocketDim" }, packetHandler = ServerPacketHandler.class), -channels={"DimDoorPackets"}, packetHandler = PacketHandler.class, connectionHandler=ConnectionHandler.class) +@SidedPacketHandler(channels = {PacketConstants.CHANNEL_NAME}, packetHandler = ServerPacketHandler.class)) public class mod_pocketDim { diff --git a/StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java b/StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java new file mode 100644 index 0000000..a3add2e --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java @@ -0,0 +1,8 @@ +package StevenDimDoors.mod_pocketDim.watcher; + +import java.io.DataOutputStream; + +public interface IOpaqueMessage +{ + void writeToStream(DataOutputStream stream); +} diff --git a/StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java b/StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java new file mode 100644 index 0000000..8250094 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java @@ -0,0 +1,8 @@ +package StevenDimDoors.mod_pocketDim.watcher; + +import com.google.common.io.ByteArrayDataInput; + +public interface IOpaqueReader +{ + IOpaqueMessage read(ByteArrayDataInput source); +} diff --git a/StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java b/StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java new file mode 100644 index 0000000..31f5a85 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java @@ -0,0 +1,8 @@ +package StevenDimDoors.mod_pocketDim.watcher; + +public interface IUpdateWatcher +{ + public void onCreated(IOpaqueMessage message); + public void onUpdated(IOpaqueMessage message); + public void onDeleted(IOpaqueMessage message); +} diff --git a/StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java b/StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java new file mode 100644 index 0000000..49874f2 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java @@ -0,0 +1,51 @@ +package StevenDimDoors.mod_pocketDim.watcher; + +import java.util.ArrayList; +import java.util.List; + +public class UpdateWatcherProxy implements IUpdateWatcher +{ + private List watchers; + + public UpdateWatcherProxy() + { + watchers = new ArrayList(); + } + + @Override + public void onCreated(IOpaqueMessage message) + { + for (IUpdateWatcher receiver : watchers) + { + receiver.onCreated(message); + } + } + + @Override + public void onUpdated(IOpaqueMessage message) + { + for (IUpdateWatcher receiver : watchers) + { + receiver.onUpdated(message); + } + } + + @Override + public void onDeleted(IOpaqueMessage message) + { + for (IUpdateWatcher receiver : watchers) + { + receiver.onDeleted(message); + } + } + + public void registerReceiver(IUpdateWatcher receiver) + { + watchers.add(receiver); + } + + public boolean unregisterReceiver(IUpdateWatcher receiver) + { + return watchers.remove(receiver); + } +} diff --git a/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java b/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java index c86e15a..9100b78 100644 --- a/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java +++ b/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java @@ -1,23 +1,15 @@ - - -// This is my package declaration, do not mess with the standard (package net.minecraft.src;) like I did, -// Because I know what Im doing in this part, If you don't know what your doing keep it the normal (package net.minecraft.src;) package StevenDimDoors.mod_pocketDimClient; -// Theses are all the imports you need import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.Player; -// Create a class and implement IPacketHandler -// This just handles the data packets in the server -public class ClientPacketHandler implements IPacketHandler{ - +public class ClientPacketHandler implements IPacketHandler +{ @Override - public void onPacketData(INetworkManager manager, - Packet250CustomPayload packet, Player player) { - // TODO Auto-generated method stub + public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) + { } } -- 2.39.5 From 0bd7ef959379e7fff7e6817e17881d64c03d80ae Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 1 Sep 2013 22:02:05 -0400 Subject: [PATCH 16/24] Deleted PacketHandler Forgot to commit this change before. --- .../mod_pocketDim/PacketHandler.java | 271 ------------------ 1 file changed, 271 deletions(-) delete mode 100644 StevenDimDoors/mod_pocketDim/PacketHandler.java diff --git a/StevenDimDoors/mod_pocketDim/PacketHandler.java b/StevenDimDoors/mod_pocketDim/PacketHandler.java deleted file mode 100644 index 644d9f6..0000000 --- a/StevenDimDoors/mod_pocketDim/PacketHandler.java +++ /dev/null @@ -1,271 +0,0 @@ -package StevenDimDoors.mod_pocketDim; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.util.Collection; -import java.util.HashMap; -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; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; - -import cpw.mods.fml.common.network.IPacketHandler; -import cpw.mods.fml.common.network.PacketDispatcher; -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 = 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) - { - if (packet.channel.equals("DimDoorPackets")) - { - processPacket(packet, player); - } - } - - private void processPacket(Packet250CustomPayload packet, Player player) - { - ByteArrayDataInput data = ByteStreams.newDataInput(packet.data); - int id = data.readByte(); - if (id == REGISTER_DIM_PACKET_ID) - { - int dimId = data.readInt(); - try - { - NewDimData dimDataToAdd = new NewDimData(dimId, data.readBoolean(), data.readInt(), data.readInt(), data.readInt(), data.readInt(), data.readInt()); - - if(!PocketManager.dimList.containsKey(dimId)) - { - PocketManager.dimList.put(dimId, dimDataToAdd); - } - if (dimDataToAdd.isPocket) - { - DDProperties properties = DDProperties.instance(); - PocketManager.registerDimension(dimId, properties.PocketProviderID); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - else if (id == REGISTER_LINK_PACKET_ID) - { - int dimId = data.readInt(); - try - { - NewDimData dimDataToAddLink= PocketManager.instance.getDimData(dimId); - - 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); - - } - catch (Exception e) - { - System.err.println("Tried to update client link data and failed!"); - e.printStackTrace(); - } - } - else if (id == REMOVE_LINK_PACKET_ID) - { - int dimId = data.readInt(); - try - { - NewDimData dimDataToRemoveFrom= PocketManager.instance.getDimData(dimId); - - 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) - { - System.out.println("Tried to update client link data & failed!"); - e.printStackTrace(); - } - } - } - - private static void processRegisterDimPacket() - { - - } - - private static void processUpdateDimPacket() - { - - } - - private static void processRegisterLinkPacket() - { - - } - - private static void processRemoveLinkPacket() - { - - } - - public static void sendClientJoinPacket(INetworkManager manager) - { - Collection dimIDs= dimList.keySet(); - Collection dimDataSet= dimList.values(); - Collection packetsToSend = new HashSet(); - - for(NewDimData data : dimDataSet) - { - manager.addToSendQueue(PacketHandler.onDimCreatedPacket(data)); - - Collection >> linkList = data.linksInThisDim.values(); - - for(HashMap map : linkList ) - { - Collection > linkList2 = map.values(); - for(HashMap map2 : linkList2) - { - Collection linkList3 = map2.values(); - - for(IDimLink link : linkList3) - { - packetsToSend.add(( PacketHandler.onLinkCreatedPacket(link))); - } - } - } - } - - for (Packet250CustomPayload packet : packetsToSend) - { - manager.addToSendQueue(packet); - } - } - - public static void sendLinkCreatedPacket(IDimLink link) - { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - DataOutputStream dataOut = new DataOutputStream(bos); - - try - { - dataOut.writeByte(PacketHandler.registerLinkPacketID); - dataOut.writeInt(link.locDimID); - dataOut.writeInt(link.destDimID); - dataOut.writeInt(link.locXCoord); - dataOut.writeInt(link.locYCoord); - dataOut.writeInt(link.locZCoord); - dataOut.writeInt(link.destXCoord); - dataOut.writeInt(link.destYCoord); - dataOut.writeInt(link.destZCoord); - dataOut.writeBoolean(link.isLocPocket); - - dataOut.writeInt(link.linkOrientation); - dataOut.writeBoolean(link.hasGennedDoor); - } - catch (IOException e) - { - e.printStackTrace(); - } - - Packet250CustomPayload packet= new Packet250CustomPayload(); - packet.channel = "DimDoorPackets"; - packet.data = bos.toByteArray(); - packet.length = bos.size();; - PacketDispatcher.sendPacketToAllPlayers(packet); - return packet; - } - - public static void sendLinkRemovedPacket(IDimLink link) - { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - DataOutputStream dataOut = new DataOutputStream(bos); - - try - { - dataOut.writeByte(PacketHandler.removeLinkPacketID); - dataOut.writeInt(link.locDimID); - dataOut.writeInt(link.destDimID); - dataOut.writeInt(link.locXCoord); - dataOut.writeInt(link.locYCoord); - dataOut.writeInt(link.locZCoord); - dataOut.writeInt(link.destXCoord); - dataOut.writeInt(link.destYCoord); - dataOut.writeInt(link.destZCoord); - dataOut.writeBoolean(link.isLocPocket); - } - 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 sendDimCreatedPacket(NewDimData data) - { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - DataOutputStream dataOut = new DataOutputStream(bos); - - try - { - dataOut.writeByte(PacketHandler.regsiterDimPacketID); - dataOut.writeInt(data.dimID); - dataOut.writeBoolean(data.isPocket); - - dataOut.writeInt(data.depth); - dataOut.writeInt(data.exitDimLink.destDimID); - dataOut.writeInt(data.exitDimLink.destXCoord); - dataOut.writeInt(data.exitDimLink.destYCoord); - dataOut.writeInt(data.exitDimLink.destZCoord); - } - catch (IOException e) - { - e.printStackTrace(); - } - - Packet250CustomPayload packet= new Packet250CustomPayload(); - packet.channel="DimDoorPackets"; - packet.data = bos.toByteArray(); - packet.length = bos.size(); - - PacketDispatcher.sendPacketToAllPlayers(packet); - return packet; - } - - public static void sendDimObject(NewDimData dim) - { - try - { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream dataOut = new ObjectOutputStream(bos); - dataOut.writeObject(dim); - - Packet250CustomPayload packet= new Packet250CustomPayload(); - packet.channel="DimDoorPackets"; - packet.data = bos.toByteArray(); - packet.length = bos.size();; - PacketDispatcher.sendPacketToAllPlayers(packet); - } - catch (IOException e) - { - e.printStackTrace(); - } - } -} \ No newline at end of file -- 2.39.5 From 56ecb0cd9ea7c9fbdacf76e7f0bb4b840275b42d Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 2 Sep 2013 11:47:12 -0400 Subject: [PATCH 17/24] Reorganized DimLink Code Moved the DimLink code out of NewDimData in order to reduce clutter inside that class and made it a separate class, except for functions that should only be available for NewDimData. Deleted IDimLink and changed all references to it to use DimLink instead. DimLink is now an abstract class, which achieves the same encapsulation and protection we had before by having DimLink implement IDimLink from within NewDimData. NewDimData has a new class inside, InnerDimLink, which provides it access to special functions that would be dangerous to expose. This is the same mechanism used to protect NewDimData's dangerous functions. These changes are in preparation for adding more code for packet handling. --- .../mod_pocketDim/DDTeleporter.java | 13 +- .../mod_pocketDim/blocks/DimensionalDoor.java | 9 +- .../mod_pocketDim/blocks/TransientDoor.java | 4 +- .../mod_pocketDim/blocks/UnstableDoor.java | 4 +- .../mod_pocketDim/blocks/WarpDoor.java | 7 +- .../commands/CommandCreateDungeonRift.java | 4 +- .../mod_pocketDim/core/DimLink.java | 77 ++++++++ .../mod_pocketDim/core/IDimLink.java | 27 --- .../mod_pocketDim/core/LinkTypes.java | 19 ++ .../mod_pocketDim/core/NewDimData.java | 164 ++++++------------ .../mod_pocketDim/core/PocketManager.java | 6 +- .../dungeon/DungeonSchematic.java | 15 +- .../mod_pocketDim/helpers/DungeonHelper.java | 7 +- .../mod_pocketDim/items/BaseItemDoor.java | 4 +- .../mod_pocketDim/items/ItemRiftBlade.java | 4 +- .../items/ItemRiftSignature.java | 7 +- .../ticking/RiftRegenerator.java | 4 +- .../tileentities/TileEntityRift.java | 6 +- .../mod_pocketDim/world/GatewayGenerator.java | 9 +- .../mod_pocketDim/world/PocketBuilder.java | 8 +- 20 files changed, 206 insertions(+), 192 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/core/DimLink.java delete mode 100644 StevenDimDoors/mod_pocketDim/core/IDimLink.java create mode 100644 StevenDimDoors/mod_pocketDim/core/LinkTypes.java diff --git a/StevenDimDoors/mod_pocketDim/DDTeleporter.java b/StevenDimDoors/mod_pocketDim/DDTeleporter.java index e390ca7..06b7289 100644 --- a/StevenDimDoors/mod_pocketDim/DDTeleporter.java +++ b/StevenDimDoors/mod_pocketDim/DDTeleporter.java @@ -16,7 +16,8 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.world.PocketBuilder; @@ -312,7 +313,7 @@ public class DDTeleporter * @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 link, Entity entity) + public static void traverseDimDoor(World world, DimLink link, Entity entity) { if (world == null) { @@ -349,7 +350,7 @@ public class DDTeleporter entity.worldObj.playSoundEffect(entity.posX, entity.posY, entity.posZ, "mob.endermen.portal", 1.0F, 1.0F); } - private static boolean initializeDestination(IDimLink link, DDProperties properties) + private static boolean initializeDestination(DimLink link, DDProperties properties) { //FIXME: Change this later to support rooms that have been wiped and must be regenerated. if (link.hasDestination()) @@ -362,11 +363,11 @@ public class DDTeleporter //FIXME: Add code for restoring the destination-side door. switch (link.linkType()) { - case IDimLink.TYPE_DUNGEON: + case LinkTypes.DUNGEON: return PocketBuilder.generateNewDungeonPocket(link, properties); - case IDimLink.TYPE_POCKET: + case LinkTypes.POCKET: return PocketBuilder.generateNewPocket(link, properties); - case IDimLink.TYPE_NORMAL: + case LinkTypes.NORMAL: return true; default: throw new IllegalArgumentException("link has an unrecognized link type."); diff --git a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java index fbd0281..95de79d 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/DimensionalDoor.java @@ -20,7 +20,8 @@ import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.DDTeleporter; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; @@ -59,7 +60,7 @@ public class DimensionalDoor extends BlockContainer { this.onPoweredBlockChange(world, x, y, z, false); - IDimLink link = PocketManager.getLink(x, y, z, world.provider.dimensionId); + DimLink link = PocketManager.getLink(x, y, z, world.provider.dimensionId); if (link != null) { DDTeleporter.traverseDimDoor(world, link, entity); @@ -169,10 +170,10 @@ public class DimensionalDoor extends BlockContainer if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { NewDimData dimension = PocketManager.getDimensionData(world); - IDimLink link = dimension.getLink(x, y, z); + DimLink link = dimension.getLink(x, y, z); if (link == null) { - dimension.createLink(x, y, z, IDimLink.TYPE_POCKET); + dimension.createLink(x, y, z, LinkTypes.POCKET); } } world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); diff --git a/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java b/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java index 6fbbc93..48ce75e 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/TransientDoor.java @@ -12,7 +12,7 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDTeleporter; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -66,7 +66,7 @@ public class TransientDoor extends WarpDoor { this.onPoweredBlockChange(world, x, y, z, false); - IDimLink link = PocketManager.getLink(x, y, z, world.provider.dimensionId); + DimLink link = PocketManager.getLink(x, y, z, world.provider.dimensionId); if (link != null) { DDTeleporter.traverseDimDoor(world, link, entity); diff --git a/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java index d53e576..c4875ed 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/UnstableDoor.java @@ -7,7 +7,7 @@ import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; @@ -54,7 +54,7 @@ public class UnstableDoor extends DimensionalDoor if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { NewDimData dimension = PocketManager.getDimensionData(world); - dimension.createLink(x, y, z, IDimLink.TYPE_RANDOM); + dimension.createLink(x, y, z, LinkTypes.RANDOM); } } } \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java index 410a052..445d8d9 100644 --- a/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java +++ b/StevenDimDoors/mod_pocketDim/blocks/WarpDoor.java @@ -9,7 +9,8 @@ import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; @@ -38,10 +39,10 @@ public class WarpDoor extends DimensionalDoor if (!world.isRemote && world.getBlockId(x, y - 1, z) == this.blockID) { NewDimData dimension = PocketManager.getDimensionData(world); - IDimLink link = dimension.getLink(x, y, z); + DimLink link = dimension.getLink(x, y, z); if (link == null) { - dimension.createLink(x, y, z, IDimLink.TYPE_SAFE_EXIT); + dimension.createLink(x, y, z, LinkTypes.SAFE_EXIT); } } world.setBlockTileEntity(x, y, z, this.createNewTileEntity(world)); diff --git a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java index 8a055f8..c15b458 100644 --- a/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java +++ b/StevenDimDoors/mod_pocketDim/commands/CommandCreateDungeonRift.java @@ -4,7 +4,7 @@ import java.util.Collection; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.MathHelper; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper; @@ -55,7 +55,7 @@ public class CommandCreateDungeonRift extends DDCommandBase } else { - IDimLink link; + DimLink link; DungeonData result; int x = MathHelper.floor_double(sender.posX); int y = MathHelper.floor_double(sender.posY); diff --git a/StevenDimDoors/mod_pocketDim/core/DimLink.java b/StevenDimDoors/mod_pocketDim/core/DimLink.java new file mode 100644 index 0000000..c0cf6de --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/core/DimLink.java @@ -0,0 +1,77 @@ +package StevenDimDoors.mod_pocketDim.core; + +import java.util.ArrayList; + +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public abstract class DimLink +{ + private static final int EXPECTED_CHILDREN = 2; + + protected Point4D source; + protected DimLink parent; + protected LinkTail tail; + protected ArrayList children; + + public DimLink(Point4D source, DimLink parent) + { + this.parent = parent; + this.source = source; + this.tail = parent.tail; + this.children = new ArrayList(EXPECTED_CHILDREN); + parent.children.add(this); + } + + public DimLink(Point4D source, int linkType) + { + if (linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX) + { + throw new IllegalArgumentException("The specified link type is invalid."); + } + + this.parent = null; + this.source = source; + this.tail = new LinkTail(linkType, null); + this.children = new ArrayList(EXPECTED_CHILDREN); + } + + public Point4D source() + { + return source; + } + + public Point4D destination() + { + return tail.getDestination(); + } + + public boolean hasDestination() + { + return (tail.getDestination() != null); + } + + public Iterable children() + { + return children; + } + + public int childCount() + { + return children.size(); + } + + public DimLink parent() + { + return parent; + } + + public int linkType() + { + return tail.getLinkType(); + } + + public String toString() + { + return source + " -> " + (hasDestination() ? destination() : ""); + } +} diff --git a/StevenDimDoors/mod_pocketDim/core/IDimLink.java b/StevenDimDoors/mod_pocketDim/core/IDimLink.java deleted file mode 100644 index 4ed15b0..0000000 --- a/StevenDimDoors/mod_pocketDim/core/IDimLink.java +++ /dev/null @@ -1,27 +0,0 @@ -package StevenDimDoors.mod_pocketDim.core; - -import StevenDimDoors.mod_pocketDim.util.Point4D; - -public interface IDimLink -{ - public final int TYPE_ENUM_MIN = 0; - public final int TYPE_ENUM_MAX = 8; - - public final int TYPE_NORMAL = 0; - public final int TYPE_LIMBO = 1; - public final int TYPE_POCKET = 2; - public final int TYPE_DUNGEON = 3; - public final int TYPE_RANDOM = 4; - public final int TYPE_DUNGEON_EXIT = 5; - public final int TYPE_SAFE_EXIT = 6; - public final int TYPE_UNSAFE_EXIT = 7; - public final int TYPE_RANDOM_DUNGEON = 8; - - public Point4D source(); - public Point4D destination(); - public boolean hasDestination(); - public Iterable children(); - public int childCount(); - public IDimLink parent(); - public int linkType(); -} \ No newline at end of file diff --git a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java new file mode 100644 index 0000000..b493e6c --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java @@ -0,0 +1,19 @@ +package StevenDimDoors.mod_pocketDim.core; + +public class LinkTypes +{ + private LinkTypes() { } + + public static final int ENUM_MIN = 0; + public static final int ENUM_MAX = 8; + + public static final int NORMAL = 0; + public static final int LIMBO = 1; + public static final int POCKET = 2; + public static final int DUNGEON = 3; + public static final int RANDOM = 4; + public static final int DUNGEON_EXIT = 5; + public static final int SAFE_EXIT = 6; + public static final int UNSAFE_EXIT = 7; + public static final int RANDOM_DUNGEON = 8; +} diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index c7e0c2e..02ba5c4 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -1,4 +1,5 @@ package StevenDimDoors.mod_pocketDim.core; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -15,92 +16,29 @@ import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; public abstract class NewDimData { - private static class DimLink implements IDimLink + private static class InnerDimLink extends DimLink { - //DimLink is an inner class here to make it immutable to code outside NewDimData - - private static final int EXPECTED_CHILDREN = 2; - - private Point4D source; - private DimLink parent; - private LinkTail tail; - private ArrayList children; - - public DimLink(Point4D source, DimLink parent) + public InnerDimLink(Point4D source, DimLink parent) { - this.parent = parent; - this.source = source; - this.tail = parent.tail; - this.children = new ArrayList(EXPECTED_CHILDREN); - parent.children.add(this); + super(source, parent); } - public DimLink(Point4D source, int linkType) + public InnerDimLink(Point4D source, int linkType) { - if (linkType < IDimLink.TYPE_ENUM_MIN || linkType > IDimLink.TYPE_ENUM_MAX) - { - throw new IllegalArgumentException("The specified link type is invalid."); - } - - this.parent = null; - this.source = source; - this.tail = new LinkTail(linkType, null); - this.children = new ArrayList(EXPECTED_CHILDREN); + super(source, linkType); } - @Override - public Point4D source() - { - return source; - } - - @Override - public Point4D destination() - { - return tail.getDestination(); - } - - @Override - public boolean hasDestination() - { - return (tail.getDestination() != null); - } - public void setDestination(int x, int y, int z, NewDimData dimension) { tail.setDestination(new Point4D(x, y, z, dimension.id())); } - - @Override - public Iterable children() - { - return children; - } - - @Override - public int childCount() - { - return children.size(); - } - - @Override - public IDimLink parent() - { - return parent; - } - - @Override - public int linkType() - { - return tail.getLinkType(); - } public void clear() { //Release children - for (IDimLink child : children) + for (DimLink child : children) { - ((DimLink) child).parent = null; + ((InnerDimLink) child).parent = null; } children.clear(); @@ -115,7 +53,7 @@ public abstract class NewDimData tail = new LinkTail(0, null); } - public void overwrite(DimLink nextParent) + public boolean overwrite(InnerDimLink nextParent) { if (nextParent == null) { @@ -125,13 +63,13 @@ public abstract class NewDimData if (this == nextParent) { //Ignore this request silently - return; + return false; } //Release children - for (IDimLink child : children) + for (DimLink child : children) { - ((DimLink) child).parent = null; + ((InnerDimLink) child).parent = null; } children.clear(); @@ -145,14 +83,15 @@ public abstract class NewDimData parent = nextParent; tail = nextParent.tail; nextParent.children.add(this); + return true; } public void overwrite(int linkType) { //Release children - for (IDimLink child : children) + for (DimLink child : children) { - ((DimLink) child).parent = null; + ((InnerDimLink) child).parent = null; } children.clear(); @@ -166,12 +105,6 @@ public abstract class NewDimData parent = null; tail = new LinkTail(linkType, null); } - - @Override - public String toString() - { - return source + " -> " + (hasDestination() ? destination() : ""); - } public IOpaqueMessage toMessage() { @@ -187,8 +120,8 @@ public abstract class NewDimData private static Random random = new Random(); private final int id; - private final Map linkMapping; - private final List linkList; + private final Map linkMapping; + private final List linkList; private final boolean isDungeon; private boolean isFilled; private final int depth; @@ -216,8 +149,8 @@ public abstract class NewDimData } this.id = id; - this.linkMapping = new TreeMap(); //Should be stored in oct tree -- temporary solution - this.linkList = new ArrayList(); //Should be stored in oct tree -- temporary solution + this.linkMapping = new TreeMap(); //Should be stored in oct tree -- temporary solution + this.linkList = new ArrayList(); //Should be stored in oct tree -- temporary solution this.children = new ArrayList(); this.parent = parent; this.packDepth = 0; @@ -247,7 +180,7 @@ public abstract class NewDimData protected abstract IOpaqueMessage toMessage(); protected abstract IOpaqueMessage toKey(); - public IDimLink findNearestRift(World world, int range, int x, int y, int z) + public DimLink findNearestRift(World world, int range, int x, int y, int z) { //TODO: Rewrite this later to use an octtree @@ -260,8 +193,8 @@ public abstract class NewDimData //Note: Only detect rifts at a distance > 1, so we ignore the rift //that called this function and any adjacent rifts. - IDimLink nearest = null; - IDimLink link; + DimLink nearest = null; + DimLink link; int distance; int minDistance = Integer.MAX_VALUE; @@ -296,18 +229,18 @@ public abstract class NewDimData return Math.abs(i) + Math.abs(j) + Math.abs(k); } - public IDimLink createLink(int x, int y, int z, int linkType) + public DimLink createLink(int x, int y, int z, int linkType) { return createLink(new Point4D(x, y, z, id), linkType); } - private IDimLink createLink(Point4D source, int linkType) + private DimLink createLink(Point4D source, int linkType) { //Return an existing link if there is one to avoid creating multiple links starting at the same point. - DimLink link = linkMapping.get(source); + InnerDimLink link = linkMapping.get(source); if (link == null) { - link = new DimLink(source, linkType); + link = new InnerDimLink(source, linkType); linkMapping.put(source, link); linkList.add(link); } @@ -320,44 +253,49 @@ public abstract class NewDimData return link; } - public IDimLink createChildLink(int x, int y, int z, IDimLink parent) + public DimLink createChildLink(int x, int y, int z, DimLink parent) { if (parent == null) { throw new IllegalArgumentException("parent cannot be null."); } - return createChildLink(new Point4D(x, y, z, id), (DimLink) parent); + return createChildLink(new Point4D(x, y, z, id), (InnerDimLink) parent); } - private IDimLink createChildLink(Point4D source, DimLink parent) + private DimLink createChildLink(Point4D source, InnerDimLink parent) { //To avoid having multiple links at a single point, if we find an existing link then we overwrite //its destination data instead of creating a new instance. - DimLink link = linkMapping.get(source); + InnerDimLink link = linkMapping.get(source); if (link == null) { - link = new DimLink(source, parent); + link = new InnerDimLink(source, parent); linkMapping.put(source, link); linkList.add(link); + + //Link created! + linkWatcher.onCreated(link.toMessage()); } else { - link.overwrite(parent); + if (link.overwrite(parent)) + { + //Link created! + linkWatcher.onCreated(link.toMessage()); + } } - //Link created! - linkWatcher.onCreated(link.toMessage()); return link; } - public boolean deleteLink(IDimLink link) + public boolean deleteLink(DimLink link) { if (link.source().getDimension() != id) { throw new IllegalArgumentException("Attempted to delete a link from another dimension."); } - DimLink target = linkMapping.remove(link.source()); + InnerDimLink target = linkMapping.remove(link.source()); if (target != null) { linkList.remove(target); @@ -371,7 +309,7 @@ public abstract class NewDimData public boolean deleteLink(int x, int y, int z) { Point4D location = new Point4D(x, y, z, id); - DimLink target = linkMapping.remove(location); + InnerDimLink target = linkMapping.remove(location); if (target != null) { linkList.remove(target); @@ -382,13 +320,13 @@ public abstract class NewDimData return (target != null); } - public IDimLink getLink(int x, int y, int z) + public DimLink getLink(int x, int y, int z) { Point4D location = new Point4D(x, y, z, id); return linkMapping.get(location); } - public IDimLink getLink(Point4D location) + public DimLink getLink(Point4D location) { if (location.getDimension() != id) return null; @@ -396,9 +334,9 @@ public abstract class NewDimData return linkMapping.get(location); } - public ArrayList getAllLinks() + public ArrayList getAllLinks() { - ArrayList results = new ArrayList(linkMapping.size()); + ArrayList results = new ArrayList(linkMapping.size()); results.addAll(linkMapping.values()); return results; } @@ -480,7 +418,7 @@ public abstract class NewDimData return children; } - public void initializeDungeon(int originX, int originY, int originZ, int orientation, IDimLink incoming, DungeonData dungeon) + public void initializeDungeon(int originX, int originY, int originZ, int orientation, DimLink incoming, DungeonData dungeon) { if (!isDungeon) { @@ -532,7 +470,7 @@ public abstract class NewDimData } } - public void initializePocket(int originX, int originY, int originZ, int orientation, IDimLink incoming) + public void initializePocket(int originX, int originY, int originZ, int orientation, DimLink incoming) { if (!isPocketDimension()) { @@ -550,15 +488,15 @@ public abstract class NewDimData dimWatcher.onUpdated(this.toMessage()); } - public void setDestination(IDimLink incoming, int x, int y, int z) + public void setDestination(DimLink incoming, int x, int y, int z) { - DimLink link = (DimLink) incoming; + InnerDimLink link = (InnerDimLink) incoming; link.setDestination(x, y, z, this); //Raise update event linkWatcher.onUpdated(link.toMessage()); } - public IDimLink getRandomLink() + public DimLink getRandomLink() { if (linkMapping.isEmpty()) { diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 3555915..92ff1e2 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -259,7 +259,7 @@ public class PocketManager //Does not actually unregister the rift data, see deleteRift for that. NewDimData dimension = getDimensionData(world); - IDimLink nearest = dimension.findNearestRift(world, range, x, y, z); + DimLink nearest = dimension.findNearestRift(world, range, x, y, z); if (nearest != null) { @@ -339,12 +339,12 @@ public class PocketManager return dimensionData.values(); } - public static IDimLink getLink(int x, int y, int z, World world) + public static DimLink getLink(int x, int y, int z, World world) { return getLink(x, y, z, world.provider.dimensionId); } - public static IDimLink getLink(int x, int y, int z, int dimensionID) + public static DimLink getLink(int x, int y, int z, int dimensionID) { NewDimData dimension = dimensionData.get(dimensionID); if (dimension != null) diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index 9426174..c118c17 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -17,7 +17,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.Point3D; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.schematic.BlockRotator; @@ -167,7 +168,7 @@ public class DungeonSchematic extends Schematic { return new DungeonSchematic(Schematic.copyFromWorld(world, x, y, z, width, height, length, doCompactBounds)); } - public void copyToWorld(World world, Point3D pocketCenter, int dungeonOrientation, IDimLink entryLink, Random random) + public void copyToWorld(World world, Point3D pocketCenter, int dungeonOrientation, DimLink entryLink, Random random) { //TODO: This function is an improvised solution so we can get the release moving. In the future, //we should generalize block transformations and implement support for them at the level of Schematic, @@ -224,7 +225,7 @@ public class DungeonSchematic extends Schematic { setUpDungeon(PocketManager.getDimensionData(world), world, pocketCenter, turnAngle, entryLink, random); } - private void setUpDungeon(NewDimData dimension, World world, Point3D pocketCenter, int turnAngle, IDimLink entryLink, Random random) + private void setUpDungeon(NewDimData dimension, World world, Point3D pocketCenter, int turnAngle, DimLink entryLink, Random random) { //Transform dungeon corners Point3D minCorner = new Point3D(0, 0, 0); @@ -282,9 +283,9 @@ public class DungeonSchematic extends Schematic { } } - private static void createEntranceReverseLink(NewDimData dimension, Point3D pocketCenter, IDimLink entryLink) + private static void createEntranceReverseLink(NewDimData dimension, Point3D pocketCenter, DimLink entryLink) { - IDimLink link = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), IDimLink.TYPE_NORMAL); + DimLink link = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), LinkTypes.NORMAL); Point4D destination = link.source(); NewDimData prevDim = PocketManager.getDimensionData(destination.getDimension()); prevDim.setDestination(link, destination.getX(), destination.getY(), destination.getZ()); @@ -295,7 +296,7 @@ public class DungeonSchematic extends Schematic { //Transform the door's location to the pocket coordinate system Point3D location = point.clone(); BlockRotator.transformPoint(location, entrance, rotation, pocketCenter); - dimension.createLink(location.getX(), location.getY(), location.getZ(), IDimLink.TYPE_DUNGEON_EXIT); + dimension.createLink(location.getX(), location.getY(), location.getZ(), LinkTypes.DUNGEON_EXIT); } private static void createDimensionalDoorLink(NewDimData dimension, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) @@ -303,7 +304,7 @@ public class DungeonSchematic extends Schematic { //Transform the door's location to the pocket coordinate system Point3D location = point.clone(); BlockRotator.transformPoint(location, entrance, rotation, pocketCenter); - dimension.createLink(location.getX(), location.getY(), location.getZ(), IDimLink.TYPE_DUNGEON); + dimension.createLink(location.getX(), location.getY(), location.getZ(), LinkTypes.DUNGEON); } private static void spawnMonolith(World world, Point3D point, Point3D entrance, int rotation, Point3D pocketCenter) diff --git a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index cc9cfdb..cebfefb 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -21,7 +21,8 @@ import net.minecraft.util.WeightedRandom; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; @@ -274,11 +275,11 @@ public class DungeonHelper return pack; } - public IDimLink createCustomDungeonDoor(World world, int x, int y, int z) + public DimLink createCustomDungeonDoor(World world, int x, int y, int z) { //Create a link above the specified position. Link to a new pocket dimension. NewDimData dimension = PocketManager.getDimensionData(world); - IDimLink link = dimension.createLink(x, y + 1, z, IDimLink.TYPE_POCKET); + DimLink link = dimension.createLink(x, y + 1, z, LinkTypes.POCKET); //Place a Warp Door linked to that pocket ItemDimensionalDoor.placeDoorBlock(world, x, y, z, 3, mod_pocketDim.warpDoor); diff --git a/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java b/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java index 88600bc..9517b95 100644 --- a/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java +++ b/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java @@ -15,7 +15,7 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.PocketManager; public abstract class BaseItemDoor extends ItemDoor @@ -114,7 +114,7 @@ public abstract class BaseItemDoor extends ItemDoor { if (world.getBlockId(hit.blockX, hit.blockY, hit.blockZ) == properties.RiftBlockID) { - IDimLink link = PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world.provider.dimensionId); + DimLink link = PocketManager.getLink(hit.blockX, hit.blockY, hit.blockZ, world.provider.dimensionId); if (link != null) { int x = hit.blockX; diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java index c6eec69..ba49480 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftBlade.java @@ -20,7 +20,7 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import cpw.mods.fml.relauncher.Side; @@ -187,7 +187,7 @@ public class ItemRiftBlade extends ItemSword NewDimData dimension = PocketManager.getDimensionData(world); if (!dimension.isPocketDimension() && dimension.getLink(x, y + 1, z) == null) { - dimension.createLink(x, y + 1, z, IDimLink.TYPE_POCKET); + dimension.createLink(x, y + 1, z, LinkTypes.POCKET); player.worldObj.playSoundAtEntity(player,"mods.DimDoors.sfx.riftDoor", 0.6f, 1); ItemDimensionalDoor.placeDoorBlock(world, x, y, z, orientation, mod_pocketDim.transientDoor); } diff --git a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index 36c2757..088b93d 100644 --- a/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -10,7 +10,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.util.Point4D; @@ -66,8 +67,8 @@ public class ItemRiftSignature extends Item //The link was used before and already has an endpoint stored. Create links connecting the two endpoints. NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); NewDimData destinationDimension = PocketManager.getDimensionData(world); - IDimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), IDimLink.TYPE_NORMAL); - IDimLink reverse = destinationDimension.createLink(x, y, z, IDimLink.TYPE_NORMAL); + DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL); + DimLink reverse = destinationDimension.createLink(x, y, z, LinkTypes.NORMAL); destinationDimension.setDestination(link, x, y, z); sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ()); diff --git a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index 950c505..4c82dc1 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -4,7 +4,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; @@ -46,7 +46,7 @@ public class RiftRegenerator implements IRegularTickReceiver { { for (int count = 0; count < RIFTS_REGENERATED_PER_DIMENSION; count++) { - IDimLink link = dimension.getRandomLink(); + DimLink link = dimension.getRandomLink(); Point4D source = link.source(); if (!mod_pocketDim.blockRift.isBlockImmune(world, source.getX(), source.getY(), source.getZ())) { diff --git a/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java b/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java index dfa27b5..fc74f69 100644 --- a/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java +++ b/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java @@ -17,7 +17,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.util.Point4D; @@ -38,7 +38,7 @@ public class TileEntityRift extends TileEntity public int age = 0; public HashMap renderingCenters = new HashMap(); - public IDimLink nearestRiftData; + public DimLink nearestRiftData; public int spawnedEndermenID=0; DataWatcher watcher = new DataWatcher(); @@ -240,7 +240,7 @@ public class TileEntityRift extends TileEntity if (growCount < 100) { NewDimData dimension = PocketManager.getDimensionData(worldObj); - IDimLink link = dimension.getLink(xCoord, yCoord, zCoord); + DimLink link = dimension.getLink(xCoord, yCoord, zCoord); if (link != null) { if (!this.hasGrownRifts && random.nextInt(3) == 0) diff --git a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java index 2a2e0f0..bc52bf7 100644 --- a/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java +++ b/StevenDimDoors/mod_pocketDim/world/GatewayGenerator.java @@ -9,7 +9,8 @@ import net.minecraft.world.chunk.IChunkProvider; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.items.ItemDimensionalDoor; @@ -57,7 +58,7 @@ public class GatewayGenerator implements IWorldGenerator int attempts; int correction; boolean valid; - IDimLink link; + DimLink link; NewDimData dimension; //Check if we're generating things in the Nether @@ -97,7 +98,7 @@ public class GatewayGenerator implements IWorldGenerator if (link == null) { dimension = PocketManager.getDimensionData(world); - link = dimension.createLink(x, y + 1, z, IDimLink.TYPE_POCKET); + link = dimension.createLink(x, y + 1, z, LinkTypes.POCKET); } else { @@ -132,7 +133,7 @@ public class GatewayGenerator implements IWorldGenerator { //Create a partial link to a dungeon. dimension = PocketManager.getDimensionData(world); - link = dimension.createLink(x, y + 1, z, IDimLink.TYPE_DUNGEON); + link = dimension.createLink(x, y + 1, z, LinkTypes.DUNGEON); //If the current dimension isn't Limbo, build a Rift Gateway out of Stone Bricks if (dimension.id() != properties.LimboDimensionID) diff --git a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index cc524fd..1f9aa7b 100644 --- a/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -10,7 +10,7 @@ import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.Point3D; -import StevenDimDoors.mod_pocketDim.core.IDimLink; +import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; @@ -36,7 +36,7 @@ public class PocketBuilder private PocketBuilder() { } - public static boolean generateNewDungeonPocket(IDimLink link, DDProperties properties) + public static boolean generateNewDungeonPocket(DimLink link, DDProperties properties) { if (link == null) { @@ -214,7 +214,7 @@ public class PocketBuilder schematic.getLength() <= DungeonHelper.MAX_DUNGEON_LENGTH); } - public static boolean generateNewPocket(IDimLink link, DDProperties properties) + public static boolean generateNewPocket(DimLink link, DDProperties properties) { return generateNewPocket(link, DEFAULT_POCKET_SIZE, DEFAULT_POCKET_WALL_THICKNESS, properties); } @@ -240,7 +240,7 @@ public class PocketBuilder return orientation; } - public static boolean generateNewPocket(IDimLink link, int size, int wallThickness, DDProperties properties) + public static boolean generateNewPocket(DimLink link, int size, int wallThickness, DDProperties properties) { if (link == null) { -- 2.39.5 From 307d2258d14f4ca2f51e28db403ec9a7fac6db8b Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Mon, 2 Sep 2013 16:51:20 -0400 Subject: [PATCH 18/24] Progress on Rewriting Packet Handling Continued building a system for transferring the complete internal states of our dimensions from the server to the client. However, Steven suggested that clients only need minimal data to operate properly, as opposed to the server. My motivation for this more complicated system was the concern that minimal information wouldn't be enough. I'm going to commit my progress, then tear it down and write a much simpler version. --- .../mod_pocketDim/ConnectionHandler.java | 4 +- .../mod_pocketDim/ServerPacketHandler.java | 18 +-- .../mod_pocketDim/core/DimLink.java | 4 +- .../mod_pocketDim/core/NewDimData.java | 18 +-- .../mod_pocketDim/core/PocketManager.java | 30 ++-- .../messages/DimMessageBuilder.java | 116 +++++++++++++++ .../mod_pocketDim/messages/IDataMessage.java | 9 ++ .../messages/IMessageBuilder.java | 11 ++ .../messages/IUpdateWatcher.java | 8 ++ .../messages/LinkMessageBuilder.java | 134 ++++++++++++++++++ .../UpdateWatcherProxy.java | 8 +- .../mod_pocketDim/util/Point4D.java | 28 ++++ .../mod_pocketDim/watcher/IOpaqueMessage.java | 8 -- .../mod_pocketDim/watcher/IOpaqueReader.java | 8 -- .../mod_pocketDim/watcher/IUpdateWatcher.java | 8 -- 15 files changed, 348 insertions(+), 64 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/messages/DimMessageBuilder.java create mode 100644 StevenDimDoors/mod_pocketDim/messages/IDataMessage.java create mode 100644 StevenDimDoors/mod_pocketDim/messages/IMessageBuilder.java create mode 100644 StevenDimDoors/mod_pocketDim/messages/IUpdateWatcher.java create mode 100644 StevenDimDoors/mod_pocketDim/messages/LinkMessageBuilder.java rename StevenDimDoors/mod_pocketDim/{watcher => messages}/UpdateWatcherProxy.java (79%) delete mode 100644 StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java delete mode 100644 StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java delete mode 100644 StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java diff --git a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java index 0b13248..2abf8d3 100644 --- a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java +++ b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java @@ -11,7 +11,7 @@ import net.minecraft.network.packet.Packet1Login; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.server.MinecraftServer; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.watcher.IOpaqueMessage; +import StevenDimDoors.mod_pocketDim.messages.IDataMessage; import cpw.mods.fml.common.network.IConnectionHandler; import cpw.mods.fml.common.network.Player; @@ -41,7 +41,7 @@ public class ConnectionHandler implements IConnectionHandler //Send information about all the registered dimensions and links to the client try { - IOpaqueMessage message = PocketManager.getState(); + IDataMessage message = PocketManager.getState(); Packet250CustomPayload packet = new Packet250CustomPayload(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DataOutputStream writer = new DataOutputStream(buffer); diff --git a/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java b/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java index 310b84a..d33c613 100644 --- a/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java +++ b/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java @@ -7,8 +7,8 @@ import java.io.IOException; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.watcher.IOpaqueMessage; -import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; +import StevenDimDoors.mod_pocketDim.messages.IDataMessage; +import StevenDimDoors.mod_pocketDim.messages.IUpdateWatcher; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.Player; @@ -30,19 +30,19 @@ public class ServerPacketHandler implements IPacketHandler private class DimWatcher implements IUpdateWatcher { @Override - public void onCreated(IOpaqueMessage message) + public void onCreated(IDataMessage message) { sendMessageToAllPlayers(PacketConstants.CREATE_DIM_PACKET_ID, message); } @Override - public void onUpdated(IOpaqueMessage message) + public void onUpdated(IDataMessage message) { sendMessageToAllPlayers(PacketConstants.UPDATE_DIM_PACKET_ID, message); } @Override - public void onDeleted(IOpaqueMessage message) + public void onDeleted(IDataMessage message) { sendMessageToAllPlayers(PacketConstants.DELETE_DIM_PACKET_ID, message); } @@ -51,25 +51,25 @@ public class ServerPacketHandler implements IPacketHandler private class LinkWatcher implements IUpdateWatcher { @Override - public void onCreated(IOpaqueMessage message) + public void onCreated(IDataMessage message) { sendMessageToAllPlayers(PacketConstants.CREATE_LINK_PACKET_ID, message); } @Override - public void onUpdated(IOpaqueMessage message) + public void onUpdated(IDataMessage message) { sendMessageToAllPlayers(PacketConstants.UPDATE_LINK_PACKET_ID, message); } @Override - public void onDeleted(IOpaqueMessage message) + public void onDeleted(IDataMessage message) { sendMessageToAllPlayers(PacketConstants.DELETE_LINK_PACKET_ID, message); } } - private static void sendMessageToAllPlayers(byte id, IOpaqueMessage message) + private static void sendMessageToAllPlayers(byte id, IDataMessage message) { try { diff --git a/StevenDimDoors/mod_pocketDim/core/DimLink.java b/StevenDimDoors/mod_pocketDim/core/DimLink.java index c0cf6de..a8c296b 100644 --- a/StevenDimDoors/mod_pocketDim/core/DimLink.java +++ b/StevenDimDoors/mod_pocketDim/core/DimLink.java @@ -13,7 +13,7 @@ public abstract class DimLink protected LinkTail tail; protected ArrayList children; - public DimLink(Point4D source, DimLink parent) + protected DimLink(Point4D source, DimLink parent) { this.parent = parent; this.source = source; @@ -22,7 +22,7 @@ public abstract class DimLink parent.children.add(this); } - public DimLink(Point4D source, int linkType) + protected DimLink(Point4D source, int linkType) { if (linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX) { diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 02ba5c4..7ff3160 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -10,9 +10,10 @@ import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; +import StevenDimDoors.mod_pocketDim.messages.IDataMessage; +import StevenDimDoors.mod_pocketDim.messages.IUpdateWatcher; +import StevenDimDoors.mod_pocketDim.messages.LinkMessageBuilder; import StevenDimDoors.mod_pocketDim.util.Point4D; -import StevenDimDoors.mod_pocketDim.watcher.IOpaqueMessage; -import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; public abstract class NewDimData { @@ -106,17 +107,18 @@ public abstract class NewDimData tail = new LinkTail(linkType, null); } - public IOpaqueMessage toMessage() + public IDataMessage toMessage() { - return null; + return linkMessageBuilder.createMessage(this); } - public IOpaqueMessage toKey() + public IDataMessage toKey() { - return null; + return linkMessageBuilder.createKey(this); } } + private static LinkMessageBuilder linkMessageBuilder = new LinkMessageBuilder(); private static Random random = new Random(); private final int id; @@ -177,8 +179,8 @@ public abstract class NewDimData } } - protected abstract IOpaqueMessage toMessage(); - protected abstract IOpaqueMessage toKey(); + protected abstract IDataMessage toMessage(); + protected abstract IDataMessage toKey(); public DimLink findNearestRift(World world, int range, int x, int y, int z) { diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 92ff1e2..91f90ca 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -14,18 +14,19 @@ import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder; +import StevenDimDoors.mod_pocketDim.messages.DimMessageBuilder; +import StevenDimDoors.mod_pocketDim.messages.IDataMessage; +import StevenDimDoors.mod_pocketDim.messages.IUpdateWatcher; +import StevenDimDoors.mod_pocketDim.messages.UpdateWatcherProxy; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDim.util.Point4D; -import StevenDimDoors.mod_pocketDim.watcher.IOpaqueMessage; -import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; -import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy; /** * This class regulates all the operations involving the storage and manipulation of dimensions. It handles saving dim data, teleporting the player, and * creating/registering new dimensions as well as loading old dimensions on startup */ public class PocketManager -{ +{ private static class InnerDimData extends NewDimData { //This inner class allows us to instantiate NewDimData indirectly without exposing @@ -40,22 +41,21 @@ public class PocketManager } @Override - protected IOpaqueMessage toMessage() + protected IDataMessage toMessage() { - // TODO Auto-generated method stub - return null; + return dimMessageBuilder.createMessage(this); } @Override - protected IOpaqueMessage toKey() + protected IDataMessage toKey() { - // TODO Auto-generated method stub - return null; + return dimMessageBuilder.createKey(this); } } - + + private static DimMessageBuilder dimMessageBuilder = new DimMessageBuilder(); private static int OVERWORLD_DIMENSION_ID = 0; - + private static volatile boolean isLoading = false; private static volatile boolean isLoaded = false; private static volatile boolean isSaving = false; @@ -198,7 +198,7 @@ public class PocketManager System.out.println("Loading Dimensional Doors save data..."); File saveFile = new File(DimensionManager.getCurrentSaveRootDirectory() + "/dimdoors.dat"); //Missing code for converting the binary data in the file into an IOpaqueMessage - IOpaqueMessage saveData; + IDataMessage saveData; setState(saveData); System.out.println("Loaded successfully!"); } @@ -377,12 +377,12 @@ public class PocketManager return linkWatcher.unregisterReceiver(watcher); } - public static IOpaqueMessage getState() + public static IDataMessage getState() { } - public static void setState(IOpaqueMessage state) + public static void setState(IDataMessage state) { if (isLoaded) { diff --git a/StevenDimDoors/mod_pocketDim/messages/DimMessageBuilder.java b/StevenDimDoors/mod_pocketDim/messages/DimMessageBuilder.java new file mode 100644 index 0000000..cb46451 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/messages/DimMessageBuilder.java @@ -0,0 +1,116 @@ +package StevenDimDoors.mod_pocketDim.messages; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.core.NewDimData.InnerDimLink; +import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; +import StevenDimDoors.mod_pocketDim.util.Point4D; + +import com.google.common.collect.ImmutableList; + +public class DimMessageBuilder implements IMessageBuilder +{ + public static class DimMessage implements IDataMessage + { + //We'll use public fields here since this is a data container object and all the fields are immutable + //We will not transfer dungeon, link data, or any data on child dimensions + //As far as I can tell, the children will handle updating their parents anyway + + public final int ID; + public final boolean IsDungeon; + public final boolean IsFilled; + public final int Depth; + public final int PackDepth; + public final Integer ParentID; + public final int RootID; + public final Point4D Origin; + public final int Orientation; + + private DimMessage(NewDimData dimension) + { + ID = dimension.id(); + IsDungeon = dimension.isDungeon(); + IsFilled = dimension.isFilled(); + Depth = dimension.depth(); + PackDepth = dimension.packDepth(); + ParentID = (dimension.parent() != null) ? dimension.parent().id() : null; + RootID = dimension.root().id(); + Origin = dimension.origin(); + Orientation = dimension.orientation(); + } + + private DimMessage(DataInputStream stream) throws IOException + { + ID = stream.readInt(); + IsDungeon = stream.readBoolean(); + IsFilled = stream.readBoolean(); + Depth = stream.readInt(); + PackDepth = stream.readInt(); + ParentID = stream. + } + + @Override + public void writeToStream(DataOutputStream stream) throws IOException + { + //Write a flag indicating that this is a full message and not a key + stream.writeBoolean(true); + + } + } + + public static class DimKeyMessage implements IDataMessage + { + //We'll use public fields here since this is a data container object and all the fields are immutable + public final int ID; + + private DimKeyMessage(NewDimData dimension) + { + ID = dimension.id(); + } + + private DimKeyMessage(DataInputStream stream) throws IOException + { + ID = stream.readInt(); + } + + @Override + public void writeToStream(DataOutputStream stream) throws IOException + { + //Write a flag indicating that this is a key + stream.writeBoolean(false); + stream.writeInt(ID); + } + } + + @Override + public IDataMessage createKey(NewDimData target) + { + return new DimKeyMessage(target); + } + + @Override + public IDataMessage createMessage(NewDimData target) + { + return new DimMessage(target); + } + + @Override + public IDataMessage read(DataInputStream source) throws IOException + { + //Check whether the message is a full message or just a key + if (source.readBoolean()) + { + return new DimMessage(source); + } + else + { + return new DimKeyMessage(source); + } + } +} diff --git a/StevenDimDoors/mod_pocketDim/messages/IDataMessage.java b/StevenDimDoors/mod_pocketDim/messages/IDataMessage.java new file mode 100644 index 0000000..8ee841d --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/messages/IDataMessage.java @@ -0,0 +1,9 @@ +package StevenDimDoors.mod_pocketDim.messages; + +import java.io.DataOutputStream; +import java.io.IOException; + +public interface IDataMessage +{ + public void writeToStream(DataOutputStream stream) throws IOException; +} diff --git a/StevenDimDoors/mod_pocketDim/messages/IMessageBuilder.java b/StevenDimDoors/mod_pocketDim/messages/IMessageBuilder.java new file mode 100644 index 0000000..297f8e5 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/messages/IMessageBuilder.java @@ -0,0 +1,11 @@ +package StevenDimDoors.mod_pocketDim.messages; + +import java.io.DataInputStream; +import java.io.IOException; + +public interface IMessageBuilder +{ + public IDataMessage createKey(T target); + public IDataMessage createMessage(T target); + public IDataMessage read(DataInputStream source) throws IOException; +} diff --git a/StevenDimDoors/mod_pocketDim/messages/IUpdateWatcher.java b/StevenDimDoors/mod_pocketDim/messages/IUpdateWatcher.java new file mode 100644 index 0000000..3bc24fd --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/messages/IUpdateWatcher.java @@ -0,0 +1,8 @@ +package StevenDimDoors.mod_pocketDim.messages; + +public interface IUpdateWatcher +{ + public void onCreated(IDataMessage message); + public void onUpdated(IDataMessage message); + public void onDeleted(IDataMessage message); +} diff --git a/StevenDimDoors/mod_pocketDim/messages/LinkMessageBuilder.java b/StevenDimDoors/mod_pocketDim/messages/LinkMessageBuilder.java new file mode 100644 index 0000000..d9d21bc --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/messages/LinkMessageBuilder.java @@ -0,0 +1,134 @@ +package StevenDimDoors.mod_pocketDim.messages; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.util.Point4D; + +import com.google.common.collect.ImmutableList; + +public class LinkMessageBuilder implements IMessageBuilder +{ + public static class LinkMessage implements IDataMessage + { + //We'll use public fields here since this is a data container object and all the fields are immutable + public final Point4D Source; + public final Point4D Destination; + public final int LinkType; + public final Point4D Parent; + public final ImmutableList Children; + + private LinkMessage(DimLink link) + { + // TODO: In the case that a child's parent has been removed but the rest of the group still exists, + // this group bond will be lost to this link on the client side. Currently, that's not a problem since + // destination data and groups don't matter to the client, but it's something to think about later. + + Source = link.source(); + Destination = link.destination(); + LinkType = link.linkType(); + Parent = link.parent().source(); + ImmutableList.Builder builder = new ImmutableList.Builder(); + for (DimLink child : link.children()) + { + builder.add(child.source()); + } + Children = builder.build(); + } + + private LinkMessage(DataInputStream stream) throws IOException + { + Source = Point4D.read(stream); + Parent = Point4D.read(stream); + if (Parent == null) + { + Destination = Point4D.read(stream); + LinkType = stream.readInt(); + } + else + { + Destination = null; + LinkType = -1; + } + int childCount = stream.readInt(); + ImmutableList.Builder builder = new ImmutableList.Builder(); + for (int k = 0; k < childCount; k++) + { + builder.add(Point4D.read(stream)); + } + Children = builder.build(); + } + + @Override + public void writeToStream(DataOutputStream stream) throws IOException + { + //Write a flag indicating that this is a full message and not a key + stream.writeBoolean(true); + Point4D.write(Source, stream); + Point4D.write(Parent, stream); + //A link only has its own destination information if it has no parent to provide it + if (Parent == null) + { + Point4D.write(Destination, stream); + stream.writeInt(LinkType); + } + stream.writeInt(Children.size()); + for (Point4D child : Children) + { + Point4D.write(child, stream); + } + } + } + + public static class LinkKeyMessage implements IDataMessage + { + //We'll use public fields here since this is a data container object and all the fields are immutable + public final Point4D Source; + + private LinkKeyMessage(DimLink link) + { + Source = link.source(); + } + + private LinkKeyMessage(DataInputStream stream) throws IOException + { + Source = Point4D.read(stream); + } + + @Override + public void writeToStream(DataOutputStream stream) throws IOException + { + //Write a flag indicating that this is a key + stream.writeBoolean(false); + Point4D.write(Source, stream); + } + } + + @Override + public IDataMessage createKey(DimLink target) + { + return new LinkKeyMessage(target); + } + + @Override + public IDataMessage createMessage(DimLink target) + { + return new LinkMessage(target); + } + + @Override + public IDataMessage read(DataInputStream source) throws IOException + { + //Check whether the message is a full message or just a key + if (source.readBoolean()) + { + return new LinkMessage(source); + } + else + { + return new LinkKeyMessage(source); + } + } +} diff --git a/StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java b/StevenDimDoors/mod_pocketDim/messages/UpdateWatcherProxy.java similarity index 79% rename from StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java rename to StevenDimDoors/mod_pocketDim/messages/UpdateWatcherProxy.java index 49874f2..1326151 100644 --- a/StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java +++ b/StevenDimDoors/mod_pocketDim/messages/UpdateWatcherProxy.java @@ -1,4 +1,4 @@ -package StevenDimDoors.mod_pocketDim.watcher; +package StevenDimDoors.mod_pocketDim.messages; import java.util.ArrayList; import java.util.List; @@ -13,7 +13,7 @@ public class UpdateWatcherProxy implements IUpdateWatcher } @Override - public void onCreated(IOpaqueMessage message) + public void onCreated(IDataMessage message) { for (IUpdateWatcher receiver : watchers) { @@ -22,7 +22,7 @@ public class UpdateWatcherProxy implements IUpdateWatcher } @Override - public void onUpdated(IOpaqueMessage message) + public void onUpdated(IDataMessage message) { for (IUpdateWatcher receiver : watchers) { @@ -31,7 +31,7 @@ public class UpdateWatcherProxy implements IUpdateWatcher } @Override - public void onDeleted(IOpaqueMessage message) + public void onDeleted(IDataMessage message) { for (IUpdateWatcher receiver : watchers) { diff --git a/StevenDimDoors/mod_pocketDim/util/Point4D.java b/StevenDimDoors/mod_pocketDim/util/Point4D.java index e8c6214..08164a8 100644 --- a/StevenDimDoors/mod_pocketDim/util/Point4D.java +++ b/StevenDimDoors/mod_pocketDim/util/Point4D.java @@ -1,5 +1,9 @@ package StevenDimDoors.mod_pocketDim.util; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + public final class Point4D implements Comparable { @@ -155,4 +159,28 @@ public final class Point4D implements Comparable { return "(" + x + ", " + y + ", " + z + ", " + dimension + ")"; } + + public static void write(Point4D point, DataOutputStream stream) throws IOException + { + stream.writeBoolean(point != null); + if (point != null) + { + stream.writeInt(point.x); + stream.writeInt(point.y); + stream.writeInt(point.z); + stream.writeInt(point.dimension); + } + } + + public static Point4D read(DataInputStream stream) throws IOException + { + if (stream.readBoolean()) + { + return new Point4D( stream.readInt(), stream.readInt(), stream.readInt(), stream.readInt() ); + } + else + { + return null; + } + } } diff --git a/StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java b/StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java deleted file mode 100644 index a3add2e..0000000 --- a/StevenDimDoors/mod_pocketDim/watcher/IOpaqueMessage.java +++ /dev/null @@ -1,8 +0,0 @@ -package StevenDimDoors.mod_pocketDim.watcher; - -import java.io.DataOutputStream; - -public interface IOpaqueMessage -{ - void writeToStream(DataOutputStream stream); -} diff --git a/StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java b/StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java deleted file mode 100644 index 8250094..0000000 --- a/StevenDimDoors/mod_pocketDim/watcher/IOpaqueReader.java +++ /dev/null @@ -1,8 +0,0 @@ -package StevenDimDoors.mod_pocketDim.watcher; - -import com.google.common.io.ByteArrayDataInput; - -public interface IOpaqueReader -{ - IOpaqueMessage read(ByteArrayDataInput source); -} diff --git a/StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java b/StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java deleted file mode 100644 index 31f5a85..0000000 --- a/StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java +++ /dev/null @@ -1,8 +0,0 @@ -package StevenDimDoors.mod_pocketDim.watcher; - -public interface IUpdateWatcher -{ - public void onCreated(IOpaqueMessage message); - public void onUpdated(IOpaqueMessage message); - public void onDeleted(IOpaqueMessage message); -} -- 2.39.5 From 3568d223ffedcb99875ca3e739e5fbcb0ff50e3f Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 3 Sep 2013 15:33:09 -0400 Subject: [PATCH 19/24] Overhauled Server-Side Packet Handling Threw out the complicated architecture that I'd made for synchronizing server and client data perfectly. Instead, we now send just enough data to the client and the resulting code is simpler. Some of the client-side code is also done so all packet handling should be finished soon. --- .../mod_pocketDim/ConnectionHandler.java | 4 +- .../mod_pocketDim/ServerPacketHandler.java | 68 ++++---- .../mod_pocketDim/core/DimLink.java | 15 +- .../core/IDimRegistrationCallback.java | 6 + .../mod_pocketDim/core/LinkTypes.java | 2 + .../mod_pocketDim/core/NewDimData.java | 78 +++++---- .../mod_pocketDim/core/PocketManager.java | 165 ++++++++++++------ .../mod_pocketDim/helpers/Compactor.java | 83 +++++++++ .../messages/DimMessageBuilder.java | 116 ------------ .../mod_pocketDim/messages/IDataMessage.java | 9 - .../messages/IMessageBuilder.java | 11 -- .../messages/IUpdateWatcher.java | 8 - .../messages/LinkMessageBuilder.java | 134 -------------- .../messages/UpdateWatcherProxy.java | 51 ------ .../mod_pocketDim/watcher/ClientDimData.java | 37 ++++ .../mod_pocketDim/watcher/IUpdateWatcher.java | 7 + .../watcher/UpdateWatcherProxy.java | 42 +++++ 17 files changed, 377 insertions(+), 459 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/core/IDimRegistrationCallback.java create mode 100644 StevenDimDoors/mod_pocketDim/helpers/Compactor.java delete mode 100644 StevenDimDoors/mod_pocketDim/messages/DimMessageBuilder.java delete mode 100644 StevenDimDoors/mod_pocketDim/messages/IDataMessage.java delete mode 100644 StevenDimDoors/mod_pocketDim/messages/IMessageBuilder.java delete mode 100644 StevenDimDoors/mod_pocketDim/messages/IUpdateWatcher.java delete mode 100644 StevenDimDoors/mod_pocketDim/messages/LinkMessageBuilder.java delete mode 100644 StevenDimDoors/mod_pocketDim/messages/UpdateWatcherProxy.java create mode 100644 StevenDimDoors/mod_pocketDim/watcher/ClientDimData.java create mode 100644 StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java create mode 100644 StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java diff --git a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java index 2abf8d3..07a0b77 100644 --- a/StevenDimDoors/mod_pocketDim/ConnectionHandler.java +++ b/StevenDimDoors/mod_pocketDim/ConnectionHandler.java @@ -11,7 +11,6 @@ import net.minecraft.network.packet.Packet1Login; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.server.MinecraftServer; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.messages.IDataMessage; import cpw.mods.fml.common.network.IConnectionHandler; import cpw.mods.fml.common.network.Player; @@ -41,12 +40,11 @@ public class ConnectionHandler implements IConnectionHandler //Send information about all the registered dimensions and links to the client try { - IDataMessage message = PocketManager.getState(); Packet250CustomPayload packet = new Packet250CustomPayload(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DataOutputStream writer = new DataOutputStream(buffer); writer.writeByte(PacketConstants.CLIENT_JOIN_PACKET_ID); - message.writeToStream(writer); + PocketManager.writePacket(writer); writer.close(); packet.channel = PacketConstants.CHANNEL_NAME; packet.data = buffer.toByteArray(); diff --git a/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java b/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java index d33c613..e8eb51a 100644 --- a/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java +++ b/StevenDimDoors/mod_pocketDim/ServerPacketHandler.java @@ -7,8 +7,9 @@ import java.io.IOException; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.messages.IDataMessage; -import StevenDimDoors.mod_pocketDim.messages.IUpdateWatcher; +import StevenDimDoors.mod_pocketDim.util.Point4D; +import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; +import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.Player; @@ -22,54 +23,39 @@ public class ServerPacketHandler implements IPacketHandler } @Override - public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) - { - - } + public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { } - private class DimWatcher implements IUpdateWatcher + private static class DimWatcher implements IUpdateWatcher { @Override - public void onCreated(IDataMessage message) + public void onCreated(ClientDimData message) { - sendMessageToAllPlayers(PacketConstants.CREATE_DIM_PACKET_ID, message); + sendDimPacket(PacketConstants.CREATE_DIM_PACKET_ID, message); } @Override - public void onUpdated(IDataMessage message) + public void onDeleted(ClientDimData message) { - sendMessageToAllPlayers(PacketConstants.UPDATE_DIM_PACKET_ID, message); - } - - @Override - public void onDeleted(IDataMessage message) - { - sendMessageToAllPlayers(PacketConstants.DELETE_DIM_PACKET_ID, message); + sendDimPacket(PacketConstants.DELETE_DIM_PACKET_ID, message); } } - private class LinkWatcher implements IUpdateWatcher + private static class LinkWatcher implements IUpdateWatcher { @Override - public void onCreated(IDataMessage message) + public void onCreated(Point4D message) { - sendMessageToAllPlayers(PacketConstants.CREATE_LINK_PACKET_ID, message); + sendLinkPacket(PacketConstants.CREATE_LINK_PACKET_ID, message); } @Override - public void onUpdated(IDataMessage message) + public void onDeleted(Point4D message) { - sendMessageToAllPlayers(PacketConstants.UPDATE_LINK_PACKET_ID, message); - } - - @Override - public void onDeleted(IDataMessage message) - { - sendMessageToAllPlayers(PacketConstants.DELETE_LINK_PACKET_ID, message); + sendLinkPacket(PacketConstants.DELETE_LINK_PACKET_ID, message); } } - private static void sendMessageToAllPlayers(byte id, IDataMessage message) + private static void sendDimPacket(byte id, ClientDimData data) { try { @@ -77,7 +63,29 @@ public class ServerPacketHandler implements IPacketHandler ByteArrayOutputStream buffer = new ByteArrayOutputStream(); DataOutputStream writer = new DataOutputStream(buffer); writer.writeByte(id); - message.writeToStream(writer); + data.write(writer); + writer.close(); + packet.channel = PacketConstants.CHANNEL_NAME; + packet.data = buffer.toByteArray(); + packet.length = packet.data.length; + PacketDispatcher.sendPacketToAllPlayers(packet); + } + catch (IOException e) + { + //This shouldn't happen... + e.printStackTrace(); + } + } + + private static void sendLinkPacket(byte id, Point4D data) + { + try + { + Packet250CustomPayload packet = new Packet250CustomPayload(); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + DataOutputStream writer = new DataOutputStream(buffer); + writer.writeByte(id); + Point4D.write(data, writer); writer.close(); packet.channel = PacketConstants.CHANNEL_NAME; packet.data = buffer.toByteArray(); diff --git a/StevenDimDoors/mod_pocketDim/core/DimLink.java b/StevenDimDoors/mod_pocketDim/core/DimLink.java index a8c296b..af8c7aa 100644 --- a/StevenDimDoors/mod_pocketDim/core/DimLink.java +++ b/StevenDimDoors/mod_pocketDim/core/DimLink.java @@ -1,30 +1,29 @@ package StevenDimDoors.mod_pocketDim.core; -import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; import StevenDimDoors.mod_pocketDim.util.Point4D; public abstract class DimLink -{ - private static final int EXPECTED_CHILDREN = 2; - +{ protected Point4D source; protected DimLink parent; protected LinkTail tail; - protected ArrayList children; + protected List children; protected DimLink(Point4D source, DimLink parent) { this.parent = parent; this.source = source; this.tail = parent.tail; - this.children = new ArrayList(EXPECTED_CHILDREN); + this.children = new LinkedList(); parent.children.add(this); } protected DimLink(Point4D source, int linkType) { - if (linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX) + if (linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX && linkType != LinkTypes.UNKNOWN) { throw new IllegalArgumentException("The specified link type is invalid."); } @@ -32,7 +31,7 @@ public abstract class DimLink this.parent = null; this.source = source; this.tail = new LinkTail(linkType, null); - this.children = new ArrayList(EXPECTED_CHILDREN); + this.children = new LinkedList(); } public Point4D source() diff --git a/StevenDimDoors/mod_pocketDim/core/IDimRegistrationCallback.java b/StevenDimDoors/mod_pocketDim/core/IDimRegistrationCallback.java new file mode 100644 index 0000000..04a0c38 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/core/IDimRegistrationCallback.java @@ -0,0 +1,6 @@ +package StevenDimDoors.mod_pocketDim.core; + +public interface IDimRegistrationCallback +{ + public NewDimData registerDimension(int dimensionID, int rootID); +} diff --git a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java index b493e6c..f5fe139 100644 --- a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java +++ b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java @@ -7,6 +7,8 @@ public class LinkTypes public static final int ENUM_MIN = 0; public static final int ENUM_MAX = 8; + public static final int UNKNOWN = -1337; + public static final int NORMAL = 0; public static final int LIMBO = 1; public static final int POCKET = 2; diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 7ff3160..de313b9 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -10,10 +10,8 @@ import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack; -import StevenDimDoors.mod_pocketDim.messages.IDataMessage; -import StevenDimDoors.mod_pocketDim.messages.IUpdateWatcher; -import StevenDimDoors.mod_pocketDim.messages.LinkMessageBuilder; import StevenDimDoors.mod_pocketDim.util.Point4D; +import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; public abstract class NewDimData { @@ -106,19 +104,8 @@ public abstract class NewDimData parent = null; tail = new LinkTail(linkType, null); } - - public IDataMessage toMessage() - { - return linkMessageBuilder.createMessage(this); - } - - public IDataMessage toKey() - { - return linkMessageBuilder.createKey(this); - } } - private static LinkMessageBuilder linkMessageBuilder = new LinkMessageBuilder(); private static Random random = new Random(); private final int id; @@ -134,13 +121,12 @@ public abstract class NewDimData private Point4D origin; private int orientation; private DungeonData dungeon; - private final IUpdateWatcher dimWatcher; - private final IUpdateWatcher linkWatcher; + private final IUpdateWatcher linkWatcher; protected NewDimData(int id, NewDimData parent, boolean isPocket, boolean isDungeon, - IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher) + IUpdateWatcher linkWatcher) { - //The isPocket flag is redundant. It's meant as an integrity safeguard. + // The isPocket flag is redundant. It's meant as an integrity safeguard. if (isPocket == (parent != null)) { throw new NullPointerException("Dimensions can be pocket dimensions if and only if they have a parent dimension."); @@ -161,7 +147,6 @@ public abstract class NewDimData this.orientation = 0; this.origin = null; this.dungeon = null; - this.dimWatcher = dimWatcher; this.linkWatcher = linkWatcher; //Register with parent @@ -179,8 +164,32 @@ public abstract class NewDimData } } - protected abstract IDataMessage toMessage(); - protected abstract IDataMessage toKey(); + protected NewDimData(int id, NewDimData root) + { + // This constructor is meant for client-side code only + this.id = id; + this.linkMapping = new TreeMap(); //Should be stored in oct tree -- temporary solution + this.linkList = new ArrayList(); //Should be stored in oct tree -- temporary solution + this.children = new ArrayList(); + this.parent = null; + this.packDepth = 0; + this.isDungeon = false; + this.isFilled = false; + this.orientation = 0; + this.origin = null; + this.dungeon = null; + this.linkWatcher = null; + this.depth = 0; + if (root != null) + { + this.root = root; + } + else + { + this.root = this; + } + + } public DimLink findNearestRift(World world, int range, int x, int y, int z) { @@ -251,7 +260,7 @@ public abstract class NewDimData link.overwrite(linkType); } //Link created! - linkWatcher.onCreated(link.toMessage()); + linkWatcher.onCreated(link.source); return link; } @@ -278,14 +287,14 @@ public abstract class NewDimData linkList.add(link); //Link created! - linkWatcher.onCreated(link.toMessage()); + linkWatcher.onCreated(link.source); } else { if (link.overwrite(parent)) { //Link created! - linkWatcher.onCreated(link.toMessage()); + linkWatcher.onCreated(link.source); } } return link; @@ -302,7 +311,7 @@ public abstract class NewDimData { linkList.remove(target); //Raise deletion event - linkWatcher.onDeleted(target.toKey()); + linkWatcher.onDeleted(target.source); target.clear(); } return (target != null); @@ -316,7 +325,7 @@ public abstract class NewDimData { linkList.remove(target); //Raise deletion event - linkWatcher.onDeleted(target.toKey()); + linkWatcher.onDeleted(target.source); target.clear(); } return (target != null); @@ -345,7 +354,7 @@ public abstract class NewDimData public boolean isPocketDimension() { - return (parent != null); + return (root != this); } public boolean isDungeon() @@ -361,8 +370,6 @@ public abstract class NewDimData public void setFilled(boolean isFilled) { this.isFilled = isFilled; - //Raise the dim update event - dimWatcher.onUpdated(this.toMessage()); } public int id() @@ -412,7 +419,7 @@ public abstract class NewDimData public int linkCount() { - return linkMapping.size(); + return linkList.size(); } public Iterable children() @@ -420,6 +427,11 @@ public abstract class NewDimData return children; } + public Iterable links() + { + return linkList; + } + public void initializeDungeon(int originX, int originY, int originZ, int orientation, DimLink incoming, DungeonData dungeon) { if (!isDungeon) @@ -436,8 +448,6 @@ public abstract class NewDimData this.orientation = orientation; this.dungeon = dungeon; this.packDepth = calculatePackDepth(parent, dungeon); - //Raise the dim update event - dimWatcher.onUpdated(this.toMessage()); } private static int calculatePackDepth(NewDimData parent, DungeonData current) @@ -486,16 +496,12 @@ public abstract class NewDimData setDestination(incoming, originX, originY, originZ); this.origin = incoming.destination(); this.orientation = orientation; - //Raise the dim update event - dimWatcher.onUpdated(this.toMessage()); } public void setDestination(DimLink incoming, int x, int y, int z) { InnerDimLink link = (InnerDimLink) incoming; link.setDestination(x, y, z, this); - //Raise update event - linkWatcher.onUpdated(link.toMessage()); } public DimLink getRandomLink() diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index 91f90ca..fc1f854 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -1,9 +1,8 @@ package StevenDimDoors.mod_pocketDim.core; +import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; import java.util.HashMap; @@ -13,13 +12,13 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import StevenDimDoors.mod_pocketDim.DDProperties; +import StevenDimDoors.mod_pocketDim.helpers.Compactor; import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder; -import StevenDimDoors.mod_pocketDim.messages.DimMessageBuilder; -import StevenDimDoors.mod_pocketDim.messages.IDataMessage; -import StevenDimDoors.mod_pocketDim.messages.IUpdateWatcher; -import StevenDimDoors.mod_pocketDim.messages.UpdateWatcherProxy; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDim.util.Point4D; +import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; +import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; +import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy; /** * This class regulates all the operations involving the storage and manipulation of dimensions. It handles saving dim data, teleporting the player, and @@ -29,41 +28,40 @@ public class PocketManager { private static class InnerDimData extends NewDimData { - //This inner class allows us to instantiate NewDimData indirectly without exposing - //a public constructor from NewDimData. It's meant to stop us from constructing instances - //of NewDimData without using PocketManager's functions. In turn, that enforces that any - //link destinations must be real dimensions controlled by PocketManager. + // This class allows us to instantiate NewDimData indirectly without exposing + // a public constructor from NewDimData. It's meant to stop us from constructing + // instances of NewDimData going through PocketManager. In turn, that enforces + // that any link destinations must be real dimensions controlled by PocketManager. - public InnerDimData(int id, NewDimData parent, boolean isPocket, boolean isDungeon, - IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher) + public InnerDimData(int id, InnerDimData parent, boolean isPocket, boolean isDungeon, + IUpdateWatcher linkWatcher) { - super(id, parent, isPocket, isDungeon, dimWatcher, linkWatcher); + super(id, parent, isPocket, isDungeon, linkWatcher); } - - @Override - protected IDataMessage toMessage() + + public InnerDimData(int id, InnerDimData root) { - return dimMessageBuilder.createMessage(this); + // This constructor is meant for client-side code only + super(id, root); } - - @Override - protected IDataMessage toKey() + + public InnerDimData(int id) { - return dimMessageBuilder.createKey(this); + // This constructor is meant for client-side code only + super(id, null); } } - private static DimMessageBuilder dimMessageBuilder = new DimMessageBuilder(); private static int OVERWORLD_DIMENSION_ID = 0; private static volatile boolean isLoading = false; private static volatile boolean isLoaded = false; private static volatile boolean isSaving = false; - private static UpdateWatcherProxy linkWatcher = null; - private static UpdateWatcherProxy dimWatcher = null; + private static UpdateWatcherProxy linkWatcher = null; + private static UpdateWatcherProxy dimWatcher = null; //HashMap that maps all the dimension IDs registered with DimDoors to their DD data. - private static HashMap dimensionData = new HashMap(); + private static HashMap dimensionData = null; public static boolean isLoaded() { @@ -87,16 +85,17 @@ public class PocketManager isLoading = true; - //Set up watcher proxies - dimWatcher = new UpdateWatcherProxy(); - linkWatcher = new UpdateWatcherProxy(); - - loadInternal(); + //Set up fields + dimensionData = new HashMap(); + dimWatcher = new UpdateWatcherProxy(); + linkWatcher = new UpdateWatcherProxy(); //Register Limbo DDProperties properties = DDProperties.instance(); registerDimension(properties.LimboDimensionID, null, false, false); + loadInternal(); + //Register pocket dimensions registerPockets(properties); @@ -134,7 +133,7 @@ public class PocketManager DeleteFolder.deleteFolder(save); } //Raise the dim deleted event - dimWatcher.onDeleted(dimension.toKey()); + dimWatcher.onDeleted(new ClientDimData(dimension)); //dimension.implode()??? -- more like delete, but yeah return true; } @@ -184,9 +183,7 @@ public class PocketManager /** * loads the dim data from the saved hashMap. Also handles compatibility with old saves, see OldSaveHandler - * @return */ - @SuppressWarnings("unchecked") private static void loadInternal() { // SenseiKiwi: This is a temporary function for testing purposes. @@ -196,10 +193,9 @@ public class PocketManager DimensionManager.getCurrentSaveRootDirectory() != null) { System.out.println("Loading Dimensional Doors save data..."); - File saveFile = new File(DimensionManager.getCurrentSaveRootDirectory() + "/dimdoors.dat"); - //Missing code for converting the binary data in the file into an IOpaqueMessage - IDataMessage saveData; - setState(saveData); + /*File saveFile = new File(DimensionManager.getCurrentSaveRootDirectory() + "/dimdoors.dat"); + + setState(saveData);*/ System.out.println("Loaded successfully!"); } } @@ -228,7 +224,7 @@ public class PocketManager try { System.out.println("Writing Dimensional Doors save data..."); - String tempPath = DimensionManager.getCurrentSaveRootDirectory() + "/dimdoors.tmp"; + /*String tempPath = DimensionManager.getCurrentSaveRootDirectory() + "/dimdoors.tmp"; String savePath = DimensionManager.getCurrentSaveRootDirectory() + "/dimdoors.dat"; File tempFile = new File(tempPath); File saveFile = new File(savePath); @@ -236,17 +232,17 @@ public class PocketManager getState().writeToStream(writer); writer.close(); saveFile.delete(); - tempFile.renameTo(saveFile); + tempFile.renameTo(saveFile);*/ System.out.println("Saved successfully!"); } - catch (FileNotFoundException e) + /*catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); - } + }*/ finally { isSaving = false; @@ -291,17 +287,17 @@ public class PocketManager DDProperties properties = DDProperties.instance(); int dimensionID = DimensionManager.getNextFreeDimId(); DimensionManager.registerDimension(dimensionID, properties.PocketProviderID); - return registerDimension(dimensionID, parent, true, isDungeon); + return registerDimension(dimensionID, (InnerDimData) parent, true, isDungeon); } - private static NewDimData registerDimension(int dimensionID, NewDimData parent, boolean isPocket, boolean isDungeon) + private static NewDimData registerDimension(int dimensionID, InnerDimData parent, boolean isPocket, boolean isDungeon) { if (dimensionData.containsKey(dimensionID)) { throw new IllegalArgumentException("Cannot register a dimension with ID = " + dimensionID + " because it has already been registered."); } - NewDimData dimension = new InnerDimData(dimensionID, parent, isPocket, isDungeon, dimWatcher, linkWatcher); + InnerDimData dimension = new InnerDimData(dimensionID, parent, isPocket, isDungeon, linkWatcher); dimensionData.put(dimensionID, dimension); return dimension; } @@ -330,14 +326,18 @@ public class PocketManager public static void unload() { save(); + dimWatcher = null; + linkWatcher = null; + dimensionData = null; unregisterPockets(); - dimensionData.clear(); } + /* + * This isn't needed right now and it's causing me problems due to the iterator's generic type -_- public static Iterable getDimensions() { return dimensionData.values(); - } + }*/ public static DimLink getLink(int x, int y, int z, World world) { @@ -357,37 +357,96 @@ public class PocketManager } } - public static void registerDimWatcher(IUpdateWatcher watcher) + public static void registerDimWatcher(IUpdateWatcher watcher) { dimWatcher.registerReceiver(watcher); } - public static boolean unregisterDimWatcher(IUpdateWatcher watcher) + public static boolean unregisterDimWatcher(IUpdateWatcher watcher) { return dimWatcher.unregisterReceiver(watcher); } - public static void registerLinkWatcher(IUpdateWatcher watcher) + public static void registerLinkWatcher(IUpdateWatcher watcher) { linkWatcher.registerReceiver(watcher); } - public static boolean unregisterLinkWatcher(IUpdateWatcher watcher) + public static boolean unregisterLinkWatcher(IUpdateWatcher watcher) { return linkWatcher.unregisterReceiver(watcher); } - public static IDataMessage getState() + public static void writePacket(DataOutputStream output) throws IOException { - + // Write a very compact description of our dimensions and links to be sent to a client + Compactor.write(dimensionData.values(), output); } - public static void setState(IDataMessage state) + public static void readPacket(DataInputStream input) throws IOException { if (isLoaded) { throw new IllegalStateException("Pocket dimensions have already been loaded!"); } + if (isLoading) + { + throw new IllegalStateException("Pocket dimensions are already loading!"); + } + + isLoading = true; + // Set up fields + dimensionData = new HashMap(); + dimWatcher = new UpdateWatcherProxy(); + linkWatcher = new UpdateWatcherProxy(); + + // Load compacted client-side dimension data + Compactor.readDimensions(input, new DimRegistrationCallback()); + + // Register pocket dimensions + DDProperties properties = DDProperties.instance(); + registerPockets(properties); + + isLoaded = true; + isLoading = false; + } + + private static class DimRegistrationCallback implements IDimRegistrationCallback + { + // We use this class to provide Compactor with the ability to send us dim data without + // having to instantiate a bunch of data containers and without exposing an "unsafe" + // creation method for anyone to call. Integrity protection for the win! It's like + // exposing a private constructor ONLY to a very specific trusted class. + + @Override + public NewDimData registerDimension(int dimensionID, int rootID) + { + // No need to raise events here since this code should only run on the client side + // We assume that the root dimension has already been registered to avoid dependency issues + + InnerDimData root = dimensionData.get(rootID); + InnerDimData dimension; + + if (rootID != dimensionID) + { + dimension = dimensionData.get(dimensionID); + if (dimension == null) + { + dimension = new InnerDimData(dimensionID, root); + dimensionData.put(dimension.id(), dimension); + } + } + else + { + if (root == null) + { + root = new InnerDimData(rootID); + dimensionData.put(root.id(), root); + } + dimension = root; + } + return dimension; + } } } diff --git a/StevenDimDoors/mod_pocketDim/helpers/Compactor.java b/StevenDimDoors/mod_pocketDim/helpers/Compactor.java new file mode 100644 index 0000000..6d5f5d5 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/helpers/Compactor.java @@ -0,0 +1,83 @@ +package StevenDimDoors.mod_pocketDim.helpers; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashSet; + +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.core.IDimRegistrationCallback; +import StevenDimDoors.mod_pocketDim.core.LinkTypes; +import StevenDimDoors.mod_pocketDim.core.NewDimData; +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public class Compactor +{ + + private static class DimComparator implements Comparator + { + @Override + public int compare(NewDimData a, NewDimData b) + { + return a.id() - b.id(); + } + } + + public static void write(Collection values, DataOutputStream output) throws IOException + { + // SenseiKiwi: Just encode the data straight up for now. I'll implement fancier compression later. + output.writeInt(values.size()); + for (NewDimData dimension : values) + { + output.writeInt(dimension.id()); + output.writeInt(dimension.root().id()); + output.writeInt(dimension.linkCount()); + for (DimLink link : dimension.links()) + { + Point4D.write(link.source(), output); + } + } + + + // Note to self: the root ID can be "compressed" by grouping + // dimensions by their root ID and then only sending it once + + /* + // To compress the dimension IDs, we'll sort them by ID + // and write the _difference_ between their ID numbers. + NewDimData[] dimensions = new NewDimData[values.size()]; + dimensions = values.toArray(dimensions); + Arrays.sort(dimensions, new DimComparator()); + */ + } + + public static void readDimensions(DataInputStream input, IDimRegistrationCallback callback) throws IOException + { + // Read in the dimensions one by one. Make sure we register root dimensions before + // attempting to register the dimensions under them. + + HashSet rootIDs = new HashSet(); + + int dimCount = input.readInt(); + for (int k = 0; k < dimCount; k++) + { + int id = input.readInt(); + int rootID = input.readInt(); + + if (rootIDs.add(rootID)) + { + callback.registerDimension(rootID, rootID); + } + // Don't check if (id != rootID) - we want to retrieve the reference anyway + NewDimData dimension = callback.registerDimension(id, rootID); + int linkCount = input.readInt(); + for (int h = 0; h < linkCount; h++) + { + Point4D source = Point4D.read(input); + dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.UNKNOWN); + } + } + } +} diff --git a/StevenDimDoors/mod_pocketDim/messages/DimMessageBuilder.java b/StevenDimDoors/mod_pocketDim/messages/DimMessageBuilder.java deleted file mode 100644 index cb46451..0000000 --- a/StevenDimDoors/mod_pocketDim/messages/DimMessageBuilder.java +++ /dev/null @@ -1,116 +0,0 @@ -package StevenDimDoors.mod_pocketDim.messages; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import StevenDimDoors.mod_pocketDim.core.DimLink; -import StevenDimDoors.mod_pocketDim.core.NewDimData; -import StevenDimDoors.mod_pocketDim.core.NewDimData.InnerDimLink; -import StevenDimDoors.mod_pocketDim.dungeon.DungeonData; -import StevenDimDoors.mod_pocketDim.util.Point4D; - -import com.google.common.collect.ImmutableList; - -public class DimMessageBuilder implements IMessageBuilder -{ - public static class DimMessage implements IDataMessage - { - //We'll use public fields here since this is a data container object and all the fields are immutable - //We will not transfer dungeon, link data, or any data on child dimensions - //As far as I can tell, the children will handle updating their parents anyway - - public final int ID; - public final boolean IsDungeon; - public final boolean IsFilled; - public final int Depth; - public final int PackDepth; - public final Integer ParentID; - public final int RootID; - public final Point4D Origin; - public final int Orientation; - - private DimMessage(NewDimData dimension) - { - ID = dimension.id(); - IsDungeon = dimension.isDungeon(); - IsFilled = dimension.isFilled(); - Depth = dimension.depth(); - PackDepth = dimension.packDepth(); - ParentID = (dimension.parent() != null) ? dimension.parent().id() : null; - RootID = dimension.root().id(); - Origin = dimension.origin(); - Orientation = dimension.orientation(); - } - - private DimMessage(DataInputStream stream) throws IOException - { - ID = stream.readInt(); - IsDungeon = stream.readBoolean(); - IsFilled = stream.readBoolean(); - Depth = stream.readInt(); - PackDepth = stream.readInt(); - ParentID = stream. - } - - @Override - public void writeToStream(DataOutputStream stream) throws IOException - { - //Write a flag indicating that this is a full message and not a key - stream.writeBoolean(true); - - } - } - - public static class DimKeyMessage implements IDataMessage - { - //We'll use public fields here since this is a data container object and all the fields are immutable - public final int ID; - - private DimKeyMessage(NewDimData dimension) - { - ID = dimension.id(); - } - - private DimKeyMessage(DataInputStream stream) throws IOException - { - ID = stream.readInt(); - } - - @Override - public void writeToStream(DataOutputStream stream) throws IOException - { - //Write a flag indicating that this is a key - stream.writeBoolean(false); - stream.writeInt(ID); - } - } - - @Override - public IDataMessage createKey(NewDimData target) - { - return new DimKeyMessage(target); - } - - @Override - public IDataMessage createMessage(NewDimData target) - { - return new DimMessage(target); - } - - @Override - public IDataMessage read(DataInputStream source) throws IOException - { - //Check whether the message is a full message or just a key - if (source.readBoolean()) - { - return new DimMessage(source); - } - else - { - return new DimKeyMessage(source); - } - } -} diff --git a/StevenDimDoors/mod_pocketDim/messages/IDataMessage.java b/StevenDimDoors/mod_pocketDim/messages/IDataMessage.java deleted file mode 100644 index 8ee841d..0000000 --- a/StevenDimDoors/mod_pocketDim/messages/IDataMessage.java +++ /dev/null @@ -1,9 +0,0 @@ -package StevenDimDoors.mod_pocketDim.messages; - -import java.io.DataOutputStream; -import java.io.IOException; - -public interface IDataMessage -{ - public void writeToStream(DataOutputStream stream) throws IOException; -} diff --git a/StevenDimDoors/mod_pocketDim/messages/IMessageBuilder.java b/StevenDimDoors/mod_pocketDim/messages/IMessageBuilder.java deleted file mode 100644 index 297f8e5..0000000 --- a/StevenDimDoors/mod_pocketDim/messages/IMessageBuilder.java +++ /dev/null @@ -1,11 +0,0 @@ -package StevenDimDoors.mod_pocketDim.messages; - -import java.io.DataInputStream; -import java.io.IOException; - -public interface IMessageBuilder -{ - public IDataMessage createKey(T target); - public IDataMessage createMessage(T target); - public IDataMessage read(DataInputStream source) throws IOException; -} diff --git a/StevenDimDoors/mod_pocketDim/messages/IUpdateWatcher.java b/StevenDimDoors/mod_pocketDim/messages/IUpdateWatcher.java deleted file mode 100644 index 3bc24fd..0000000 --- a/StevenDimDoors/mod_pocketDim/messages/IUpdateWatcher.java +++ /dev/null @@ -1,8 +0,0 @@ -package StevenDimDoors.mod_pocketDim.messages; - -public interface IUpdateWatcher -{ - public void onCreated(IDataMessage message); - public void onUpdated(IDataMessage message); - public void onDeleted(IDataMessage message); -} diff --git a/StevenDimDoors/mod_pocketDim/messages/LinkMessageBuilder.java b/StevenDimDoors/mod_pocketDim/messages/LinkMessageBuilder.java deleted file mode 100644 index d9d21bc..0000000 --- a/StevenDimDoors/mod_pocketDim/messages/LinkMessageBuilder.java +++ /dev/null @@ -1,134 +0,0 @@ -package StevenDimDoors.mod_pocketDim.messages; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import StevenDimDoors.mod_pocketDim.core.DimLink; -import StevenDimDoors.mod_pocketDim.util.Point4D; - -import com.google.common.collect.ImmutableList; - -public class LinkMessageBuilder implements IMessageBuilder -{ - public static class LinkMessage implements IDataMessage - { - //We'll use public fields here since this is a data container object and all the fields are immutable - public final Point4D Source; - public final Point4D Destination; - public final int LinkType; - public final Point4D Parent; - public final ImmutableList Children; - - private LinkMessage(DimLink link) - { - // TODO: In the case that a child's parent has been removed but the rest of the group still exists, - // this group bond will be lost to this link on the client side. Currently, that's not a problem since - // destination data and groups don't matter to the client, but it's something to think about later. - - Source = link.source(); - Destination = link.destination(); - LinkType = link.linkType(); - Parent = link.parent().source(); - ImmutableList.Builder builder = new ImmutableList.Builder(); - for (DimLink child : link.children()) - { - builder.add(child.source()); - } - Children = builder.build(); - } - - private LinkMessage(DataInputStream stream) throws IOException - { - Source = Point4D.read(stream); - Parent = Point4D.read(stream); - if (Parent == null) - { - Destination = Point4D.read(stream); - LinkType = stream.readInt(); - } - else - { - Destination = null; - LinkType = -1; - } - int childCount = stream.readInt(); - ImmutableList.Builder builder = new ImmutableList.Builder(); - for (int k = 0; k < childCount; k++) - { - builder.add(Point4D.read(stream)); - } - Children = builder.build(); - } - - @Override - public void writeToStream(DataOutputStream stream) throws IOException - { - //Write a flag indicating that this is a full message and not a key - stream.writeBoolean(true); - Point4D.write(Source, stream); - Point4D.write(Parent, stream); - //A link only has its own destination information if it has no parent to provide it - if (Parent == null) - { - Point4D.write(Destination, stream); - stream.writeInt(LinkType); - } - stream.writeInt(Children.size()); - for (Point4D child : Children) - { - Point4D.write(child, stream); - } - } - } - - public static class LinkKeyMessage implements IDataMessage - { - //We'll use public fields here since this is a data container object and all the fields are immutable - public final Point4D Source; - - private LinkKeyMessage(DimLink link) - { - Source = link.source(); - } - - private LinkKeyMessage(DataInputStream stream) throws IOException - { - Source = Point4D.read(stream); - } - - @Override - public void writeToStream(DataOutputStream stream) throws IOException - { - //Write a flag indicating that this is a key - stream.writeBoolean(false); - Point4D.write(Source, stream); - } - } - - @Override - public IDataMessage createKey(DimLink target) - { - return new LinkKeyMessage(target); - } - - @Override - public IDataMessage createMessage(DimLink target) - { - return new LinkMessage(target); - } - - @Override - public IDataMessage read(DataInputStream source) throws IOException - { - //Check whether the message is a full message or just a key - if (source.readBoolean()) - { - return new LinkMessage(source); - } - else - { - return new LinkKeyMessage(source); - } - } -} diff --git a/StevenDimDoors/mod_pocketDim/messages/UpdateWatcherProxy.java b/StevenDimDoors/mod_pocketDim/messages/UpdateWatcherProxy.java deleted file mode 100644 index 1326151..0000000 --- a/StevenDimDoors/mod_pocketDim/messages/UpdateWatcherProxy.java +++ /dev/null @@ -1,51 +0,0 @@ -package StevenDimDoors.mod_pocketDim.messages; - -import java.util.ArrayList; -import java.util.List; - -public class UpdateWatcherProxy implements IUpdateWatcher -{ - private List watchers; - - public UpdateWatcherProxy() - { - watchers = new ArrayList(); - } - - @Override - public void onCreated(IDataMessage message) - { - for (IUpdateWatcher receiver : watchers) - { - receiver.onCreated(message); - } - } - - @Override - public void onUpdated(IDataMessage message) - { - for (IUpdateWatcher receiver : watchers) - { - receiver.onUpdated(message); - } - } - - @Override - public void onDeleted(IDataMessage message) - { - for (IUpdateWatcher receiver : watchers) - { - receiver.onDeleted(message); - } - } - - public void registerReceiver(IUpdateWatcher receiver) - { - watchers.add(receiver); - } - - public boolean unregisterReceiver(IUpdateWatcher receiver) - { - return watchers.remove(receiver); - } -} diff --git a/StevenDimDoors/mod_pocketDim/watcher/ClientDimData.java b/StevenDimDoors/mod_pocketDim/watcher/ClientDimData.java new file mode 100644 index 0000000..7614a10 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/watcher/ClientDimData.java @@ -0,0 +1,37 @@ +package StevenDimDoors.mod_pocketDim.watcher; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import StevenDimDoors.mod_pocketDim.core.NewDimData; + +public class ClientDimData +{ + //We'll use public fields since this is just a data container and it's immutable + public final int ID; + public final int RootID; + + public ClientDimData(int id, int rootID) + { + ID = id; + RootID = rootID; + } + + public ClientDimData(NewDimData dimension) + { + ID = dimension.id(); + RootID = dimension.root().id(); + } + + public void write(DataOutputStream output) throws IOException + { + output.writeInt(ID); + output.writeInt(RootID); + } + + public static ClientDimData read(DataInputStream input) throws IOException + { + return new ClientDimData(input.readInt(), input.readInt()); + } +} diff --git a/StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java b/StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java new file mode 100644 index 0000000..eb8f920 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/watcher/IUpdateWatcher.java @@ -0,0 +1,7 @@ +package StevenDimDoors.mod_pocketDim.watcher; + +public interface IUpdateWatcher +{ + public void onCreated(T message); + public void onDeleted(T message); +} diff --git a/StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java b/StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java new file mode 100644 index 0000000..e105476 --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/watcher/UpdateWatcherProxy.java @@ -0,0 +1,42 @@ +package StevenDimDoors.mod_pocketDim.watcher; + +import java.util.ArrayList; +import java.util.List; + +public class UpdateWatcherProxy implements IUpdateWatcher +{ + private List> watchers; + + public UpdateWatcherProxy() + { + watchers = new ArrayList>(); + } + + @Override + public void onCreated(T message) + { + for (IUpdateWatcher receiver : watchers) + { + receiver.onCreated(message); + } + } + + @Override + public void onDeleted(T message) + { + for (IUpdateWatcher receiver : watchers) + { + receiver.onDeleted(message); + } + } + + public void registerReceiver(IUpdateWatcher receiver) + { + watchers.add(receiver); + } + + public boolean unregisterReceiver(IUpdateWatcher receiver) + { + return watchers.remove(receiver); + } +} -- 2.39.5 From 4cd7d3c0ae334122d4ad6a9b77dbe65ca1c68b59 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 3 Sep 2013 17:25:58 -0400 Subject: [PATCH 20/24] Completed Packet Handling Code Finished implementing all the packet handling code. It could be improved in the future to compress the initial packet sent to clients. With this, the code is complete enough to run! Commands have not been fixed yet but that will come in the future. --- .../mod_pocketDim/PacketConstants.java | 11 +- .../mod_pocketDim/core/DimLink.java | 2 +- .../mod_pocketDim/core/LinkTypes.java | 2 +- .../mod_pocketDim/core/NewDimData.java | 15 +-- .../mod_pocketDim/core/PocketManager.java | 125 ++++++++++++------ .../mod_pocketDim/helpers/Compactor.java | 2 +- .../mod_pocketDim/mod_pocketDim.java | 2 +- .../ticking/RiftRegenerator.java | 8 +- .../mod_pocketDim/watcher/IUpdateSource.java | 8 ++ .../ClientPacketHandler.java | 59 ++++++++- 10 files changed, 162 insertions(+), 72 deletions(-) create mode 100644 StevenDimDoors/mod_pocketDim/watcher/IUpdateSource.java diff --git a/StevenDimDoors/mod_pocketDim/PacketConstants.java b/StevenDimDoors/mod_pocketDim/PacketConstants.java index 67d4e60..847a5b0 100644 --- a/StevenDimDoors/mod_pocketDim/PacketConstants.java +++ b/StevenDimDoors/mod_pocketDim/PacketConstants.java @@ -3,13 +3,12 @@ package StevenDimDoors.mod_pocketDim; public class PacketConstants { private PacketConstants() { } + + public static final String CHANNEL_NAME = "DimDoorsPackets"; public static final byte CLIENT_JOIN_PACKET_ID = 1; public static final byte CREATE_DIM_PACKET_ID = 2; - public static final byte UPDATE_DIM_PACKET_ID = 3; - public static final byte DELETE_DIM_PACKET_ID = 4; - public static final byte CREATE_LINK_PACKET_ID = 5; - public static final byte UPDATE_LINK_PACKET_ID = 6; - public static final byte DELETE_LINK_PACKET_ID = 7; - public static final String CHANNEL_NAME = "DimDoorsPackets"; + public static final byte DELETE_DIM_PACKET_ID = 3; + public static final byte CREATE_LINK_PACKET_ID = 4; + public static final byte DELETE_LINK_PACKET_ID = 5; } diff --git a/StevenDimDoors/mod_pocketDim/core/DimLink.java b/StevenDimDoors/mod_pocketDim/core/DimLink.java index af8c7aa..cdf25a6 100644 --- a/StevenDimDoors/mod_pocketDim/core/DimLink.java +++ b/StevenDimDoors/mod_pocketDim/core/DimLink.java @@ -23,7 +23,7 @@ public abstract class DimLink protected DimLink(Point4D source, int linkType) { - if (linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX && linkType != LinkTypes.UNKNOWN) + if (linkType < LinkTypes.ENUM_MIN || linkType > LinkTypes.ENUM_MAX && linkType != LinkTypes.CLIENT_SIDE) { throw new IllegalArgumentException("The specified link type is invalid."); } diff --git a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java index f5fe139..5e64aff 100644 --- a/StevenDimDoors/mod_pocketDim/core/LinkTypes.java +++ b/StevenDimDoors/mod_pocketDim/core/LinkTypes.java @@ -7,7 +7,7 @@ public class LinkTypes public static final int ENUM_MIN = 0; public static final int ENUM_MAX = 8; - public static final int UNKNOWN = -1337; + public static final int CLIENT_SIDE = -1337; public static final int NORMAL = 0; public static final int LIMBO = 1; diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index de313b9..0be6468 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -167,6 +167,11 @@ public abstract class NewDimData protected NewDimData(int id, NewDimData root) { // This constructor is meant for client-side code only + if (root == null) + { + throw new IllegalArgumentException("root cannot be null."); + } + this.id = id; this.linkMapping = new TreeMap(); //Should be stored in oct tree -- temporary solution this.linkList = new ArrayList(); //Should be stored in oct tree -- temporary solution @@ -180,15 +185,7 @@ public abstract class NewDimData this.dungeon = null; this.linkWatcher = null; this.depth = 0; - if (root != null) - { - this.root = root; - } - else - { - this.root = this; - } - + this.root = root; } public DimLink findNearestRift(World world, int range, int x, int y, int z) diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index fc1f854..d590930 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -17,6 +17,7 @@ import StevenDimDoors.mod_pocketDim.helpers.DeleteFolder; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import StevenDimDoors.mod_pocketDim.util.Point4D; import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; +import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource; import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; import StevenDimDoors.mod_pocketDim.watcher.UpdateWatcherProxy; @@ -44,14 +45,54 @@ public class PocketManager // This constructor is meant for client-side code only super(id, root); } - - public InnerDimData(int id) + } + + private static class ClientLinkWatcher implements IUpdateWatcher + { + @Override + public void onCreated(Point4D source) { - // This constructor is meant for client-side code only - super(id, null); + NewDimData dimension = getDimensionData(source.getDimension()); + dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE); + } + + @Override + public void onDeleted(Point4D source) + { + NewDimData dimension = getDimensionData(source.getDimension()); + dimension.deleteLink(source.getX(), source.getY(), source.getZ()); + } + } + + private static class ClientDimWatcher implements IUpdateWatcher + { + @Override + public void onCreated(ClientDimData data) + { + registerClientDimension(data.ID, data.RootID); + } + + @Override + public void onDeleted(ClientDimData data) + { + deletePocket(getDimensionData(data.ID), false); } } + private static class DimRegistrationCallback implements IDimRegistrationCallback + { + // We use this class to provide Compactor with the ability to send us dim data without + // having to instantiate a bunch of data containers and without exposing an "unsafe" + // creation method for anyone to call. Integrity protection for the win! It's like + // exposing a private constructor ONLY to a very specific trusted class. + + @Override + public NewDimData registerDimension(int dimensionID, int rootID) + { + return registerClientDimension(dimensionID, rootID); + } + } + private static int OVERWORLD_DIMENSION_ID = 0; private static volatile boolean isLoading = false; @@ -301,6 +342,30 @@ public class PocketManager dimensionData.put(dimensionID, dimension); return dimension; } + + private static NewDimData registerClientDimension(int dimensionID, int rootID) + { + // No need to raise events here since this code should only run on the client side + // getDimensionData() always handles root dimensions properly, even if the weren't defined before + + InnerDimData root = (InnerDimData) getDimensionData(rootID); + InnerDimData dimension; + + if (rootID != dimensionID) + { + dimension = dimensionData.get(dimensionID); + if (dimension == null) + { + dimension = new InnerDimData(dimensionID, root); + dimensionData.put(dimension.id(), dimension); + } + } + else + { + dimension = root; + } + return dimension; + } public static NewDimData getDimensionData(World world) { @@ -323,6 +388,11 @@ public class PocketManager return dimension; } + public static Iterable getDimensions() + { + return dimensionData.values(); + } + public static void unload() { save(); @@ -376,6 +446,11 @@ public class PocketManager { return linkWatcher.unregisterReceiver(watcher); } + + public static void getWatchers(IUpdateSource updateSource) + { + updateSource.registerWatchers(new ClientDimWatcher(), new ClientLinkWatcher()); + } public static void writePacket(DataOutputStream output) throws IOException { @@ -398,8 +473,8 @@ public class PocketManager // Set up fields dimensionData = new HashMap(); - dimWatcher = new UpdateWatcherProxy(); - linkWatcher = new UpdateWatcherProxy(); + dimWatcher = null; // Clients shouldn't need to watch dims + linkWatcher = null; // Clients shouldn't need to watch links // Load compacted client-side dimension data Compactor.readDimensions(input, new DimRegistrationCallback()); @@ -411,42 +486,4 @@ public class PocketManager isLoaded = true; isLoading = false; } - - private static class DimRegistrationCallback implements IDimRegistrationCallback - { - // We use this class to provide Compactor with the ability to send us dim data without - // having to instantiate a bunch of data containers and without exposing an "unsafe" - // creation method for anyone to call. Integrity protection for the win! It's like - // exposing a private constructor ONLY to a very specific trusted class. - - @Override - public NewDimData registerDimension(int dimensionID, int rootID) - { - // No need to raise events here since this code should only run on the client side - // We assume that the root dimension has already been registered to avoid dependency issues - - InnerDimData root = dimensionData.get(rootID); - InnerDimData dimension; - - if (rootID != dimensionID) - { - dimension = dimensionData.get(dimensionID); - if (dimension == null) - { - dimension = new InnerDimData(dimensionID, root); - dimensionData.put(dimension.id(), dimension); - } - } - else - { - if (root == null) - { - root = new InnerDimData(rootID); - dimensionData.put(root.id(), root); - } - dimension = root; - } - return dimension; - } - } } diff --git a/StevenDimDoors/mod_pocketDim/helpers/Compactor.java b/StevenDimDoors/mod_pocketDim/helpers/Compactor.java index 6d5f5d5..e13d902 100644 --- a/StevenDimDoors/mod_pocketDim/helpers/Compactor.java +++ b/StevenDimDoors/mod_pocketDim/helpers/Compactor.java @@ -76,7 +76,7 @@ public class Compactor for (int h = 0; h < linkCount; h++) { Point4D source = Point4D.read(input); - dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.UNKNOWN); + dimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.CLIENT_SIDE); } } } diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index cde2099..c7cd467 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -164,7 +164,7 @@ public class mod_pocketDim //MonolithSpawner should be initialized before any provider instances are created //Register the other regular tick receivers as well spawner = new MonolithSpawner(commonTickHandler, properties); - new RiftRegenerator(commonTickHandler, properties); //No need to store the reference + new RiftRegenerator(commonTickHandler); //No need to store the reference LimboDecay decay = new LimboDecay(commonTickHandler, properties); transientDoor = (new TransientDoor(properties.TransientDoorID, Material.iron)).setHardness(1.0F) .setUnlocalizedName("transientDoor"); diff --git a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java index 4c82dc1..114fa35 100644 --- a/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java +++ b/StevenDimDoors/mod_pocketDim/ticking/RiftRegenerator.java @@ -7,22 +7,16 @@ 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_pocketDim.util.Point4D; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.relauncher.Side; public class RiftRegenerator implements IRegularTickReceiver { private static final int RIFT_REGENERATION_INTERVAL = 200; //Regenerate random rifts every 200 ticks private static final int RIFTS_REGENERATED_PER_DIMENSION = 5; - private DDProperties properties; - - public RiftRegenerator(IRegularTickSender sender, DDProperties properties) + public RiftRegenerator(IRegularTickSender sender) { sender.registerForTicking(this, RIFT_REGENERATION_INTERVAL, false); - this.properties = properties; } @Override diff --git a/StevenDimDoors/mod_pocketDim/watcher/IUpdateSource.java b/StevenDimDoors/mod_pocketDim/watcher/IUpdateSource.java new file mode 100644 index 0000000..98e260e --- /dev/null +++ b/StevenDimDoors/mod_pocketDim/watcher/IUpdateSource.java @@ -0,0 +1,8 @@ +package StevenDimDoors.mod_pocketDim.watcher; + +import StevenDimDoors.mod_pocketDim.util.Point4D; + +public interface IUpdateSource +{ + public void registerWatchers(IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher); +} diff --git a/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java b/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java index 9100b78..a98f115 100644 --- a/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java +++ b/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java @@ -1,15 +1,70 @@ package StevenDimDoors.mod_pocketDimClient; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; + import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; +import StevenDimDoors.mod_pocketDim.PacketConstants; +import StevenDimDoors.mod_pocketDim.core.PocketManager; +import StevenDimDoors.mod_pocketDim.util.Point4D; +import StevenDimDoors.mod_pocketDim.watcher.ClientDimData; +import StevenDimDoors.mod_pocketDim.watcher.IUpdateSource; +import StevenDimDoors.mod_pocketDim.watcher.IUpdateWatcher; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.Player; -public class ClientPacketHandler implements IPacketHandler +public class ClientPacketHandler implements IPacketHandler, IUpdateSource { + private IUpdateWatcher linkWatcher; + private IUpdateWatcher dimWatcher; + + public ClientPacketHandler() + { + PocketManager.getWatchers(this); + } + + @Override + public void registerWatchers(IUpdateWatcher dimWatcher, IUpdateWatcher linkWatcher) + { + this.dimWatcher = dimWatcher; + this.linkWatcher = linkWatcher; + } + @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { - + // TODO: Is this even necessary? I'm not convinced we can receive packets from other channels anyway! + if (!packet.channel.equals(PacketConstants.CHANNEL_NAME)) + return; + + try + { + DataInputStream input = new DataInputStream(new ByteArrayInputStream(packet.data)); + byte packetID = input.readByte(); + switch (packetID) + { + case PacketConstants.CLIENT_JOIN_PACKET_ID: + PocketManager.readPacket(input); + break; + case PacketConstants.CREATE_DIM_PACKET_ID: + dimWatcher.onCreated( ClientDimData.read(input) ); + break; + case PacketConstants.CREATE_LINK_PACKET_ID: + linkWatcher.onCreated( Point4D.read(input) ); + break; + case PacketConstants.DELETE_DIM_PACKET_ID: + dimWatcher.onDeleted( ClientDimData.read(input) ); + break; + case PacketConstants.DELETE_LINK_PACKET_ID: + linkWatcher.onDeleted( Point4D.read(input) ); + break; + } + } + catch (Exception e) + { + System.err.println("An exception occurred while processing a data packet:"); + e.printStackTrace(); + } } } -- 2.39.5 From 77bc0e833f69092971f66adb6774d93de4d86aa9 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 3 Sep 2013 17:47:02 -0400 Subject: [PATCH 21/24] Fixed Bugs Fixed bugs that would cause Minecraft to crash on startup. At least I can get to the main menu now. --- .../mod_pocketDim/core/PocketManager.java | 16 +++------------- .../mod_pocketDim/dungeon/DungeonData.java | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index d590930..b79ee2b 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -98,8 +98,8 @@ public class PocketManager private static volatile boolean isLoading = false; private static volatile boolean isLoaded = false; private static volatile boolean isSaving = false; - private static UpdateWatcherProxy linkWatcher = null; - private static UpdateWatcherProxy dimWatcher = null; + private static final UpdateWatcherProxy linkWatcher = new UpdateWatcherProxy(); + private static final UpdateWatcherProxy dimWatcher = new UpdateWatcherProxy(); //HashMap that maps all the dimension IDs registered with DimDoors to their DD data. private static HashMap dimensionData = null; @@ -125,11 +125,7 @@ public class PocketManager } isLoading = true; - - //Set up fields dimensionData = new HashMap(); - dimWatcher = new UpdateWatcherProxy(); - linkWatcher = new UpdateWatcherProxy(); //Register Limbo DDProperties properties = DDProperties.instance(); @@ -396,8 +392,6 @@ public class PocketManager public static void unload() { save(); - dimWatcher = null; - linkWatcher = null; dimensionData = null; unregisterPockets(); } @@ -470,12 +464,8 @@ public class PocketManager } isLoading = true; - - // Set up fields dimensionData = new HashMap(); - dimWatcher = null; // Clients shouldn't need to watch dims - linkWatcher = null; // Clients shouldn't need to watch links - + // Load compacted client-side dimension data Compactor.readDimensions(input, new DimRegistrationCallback()); diff --git a/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java b/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java index 7c298df..aa4bfa3 100644 --- a/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java +++ b/StevenDimDoors/mod_pocketDim/dungeon/DungeonData.java @@ -31,7 +31,7 @@ public class DungeonData int indexB = schematicPath.lastIndexOf('/'); indexA = Math.max(indexA, indexB) + 1; - return schematicPath.substring(indexA, schematicPath.length() - DungeonHelper.SCHEMATIC_FILE_EXTENSION.length() - indexA); + return schematicPath.substring(indexA, schematicPath.length() - DungeonHelper.SCHEMATIC_FILE_EXTENSION.length()); } public int weight() -- 2.39.5 From 8bfe9dc22ecd56b785e5c2c830dac55271a50f40 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 3 Sep 2013 18:28:42 -0400 Subject: [PATCH 22/24] Fixed More Bugs Fixed more bugs. Now it's possible to generate a world without crashing. Unfortunately, it's clear that there is a packet-sending loop going on. I'll have to add a check to prevent integrated servers from spamming themselves. --- .../mod_pocketDim/EventHookContainer.java | 13 ++++++++++++- StevenDimDoors/mod_pocketDim/core/NewDimData.java | 2 +- StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 025a24f..2e2756d 100644 --- a/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -36,7 +36,18 @@ public class EventHookContainer @ForgeSubscribe public void onWorldLoad(WorldEvent.Load event) { - RiftRegenerator.regenerateRiftsInAllWorlds(); + // We need to initialize PocketManager here because onServerAboutToStart fires before we can + // use DimensionManager and onServerStarting fires after the game tries to generate terrain. + // If a gateway tries to generate before PocketManager has initialized, we get a crash. + if (!PocketManager.isLoaded()) + { + PocketManager.load(); + } + + if (PocketManager.isLoaded()) + { + RiftRegenerator.regenerateRiftsInAllWorlds(); + } } @ForgeSubscribe diff --git a/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 0be6468..40fe18d 100644 --- a/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -127,7 +127,7 @@ public abstract class NewDimData IUpdateWatcher linkWatcher) { // The isPocket flag is redundant. It's meant as an integrity safeguard. - if (isPocket == (parent != null)) + if (isPocket != (parent != null)) { throw new NullPointerException("Dimensions can be pocket dimensions if and only if they have a parent dimension."); } diff --git a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index c7cd467..4ab5058 100644 --- a/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -384,6 +384,5 @@ public class mod_pocketDim CommandCreatePocket.instance().register(event); CommandTeleportPlayer.instance().register(event); */ - PocketManager.load(); } } -- 2.39.5 From 1a50aa2290a540905c336feae6b5d61a54b291cc Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 3 Sep 2013 19:31:19 -0400 Subject: [PATCH 23/24] Minor Changes Minor changes: removed unused imports and random blocks of whitespace --- .../mod_pocketDimClient/ClientProxy.java | 36 +++---------------- .../ClientTickHandler.java | 3 -- .../mod_pocketDimClient/RenderDimDoor.java | 3 -- .../mod_pocketDimClient/RenderMobObelisk.java | 3 -- .../mod_pocketDimClient/RenderRift.java | 21 +++++------ 5 files changed, 13 insertions(+), 53 deletions(-) diff --git a/StevenDimDoors/mod_pocketDimClient/ClientProxy.java b/StevenDimDoors/mod_pocketDimClient/ClientProxy.java index b1428c3..7cb1469 100644 --- a/StevenDimDoors/mod_pocketDimClient/ClientProxy.java +++ b/StevenDimDoors/mod_pocketDimClient/ClientProxy.java @@ -1,19 +1,10 @@ package StevenDimDoors.mod_pocketDimClient; -import java.io.File; - -import cpw.mods.fml.client.FMLClientHandler; -import cpw.mods.fml.client.registry.ClientRegistry; -import cpw.mods.fml.client.registry.RenderingRegistry; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.src.ModLoader; -import net.minecraftforge.client.MinecraftForgeClient; import StevenDimDoors.mod_pocketDim.CommonProxy; -import StevenDimDoors.mod_pocketDim.Spells; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.ticking.CommonTickHandler; import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; -import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; +import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.client.registry.RenderingRegistry; public class ClientProxy extends CommonProxy @@ -22,41 +13,24 @@ public class ClientProxy extends CommonProxy @Override public void registerRenderers() { - //MinecraftForgeClient.preloadTexture(BLOCK_PNG); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDimDoor.class, new RenderDimDoor()); //This code activates the new rift rendering, as well as a bit of code in TileEntityRift //ClientRegistry.bindTileEntitySpecialRenderer(TileEntityRift.class, new RenderRift()); - //MinecraftForgeClient.preloadTexture(RIFT2_PNG); - RenderingRegistry.registerEntityRenderingHandler(MobMonolith.class, new RenderMobObelisk(.5F)); - - - - + RenderingRegistry.registerEntityRenderingHandler(MobMonolith.class, new RenderMobObelisk(.5F)); } - - - @Override public void loadTextures() { - - - - - - - - } + @Override public void printStringClient(String string) - { - + { ModLoader.getMinecraftInstance().ingameGUI.getChatGUI().printChatMessage(string); } diff --git a/StevenDimDoors/mod_pocketDimClient/ClientTickHandler.java b/StevenDimDoors/mod_pocketDimClient/ClientTickHandler.java index 1b9ad55..cece273 100644 --- a/StevenDimDoors/mod_pocketDimClient/ClientTickHandler.java +++ b/StevenDimDoors/mod_pocketDimClient/ClientTickHandler.java @@ -1,9 +1,6 @@ package StevenDimDoors.mod_pocketDimClient; import java.util.EnumSet; -import StevenDimDoors.mod_pocketDim.Spells; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; - import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import cpw.mods.fml.common.ITickHandler; diff --git a/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java b/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java index 6239fc8..384ec97 100644 --- a/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java +++ b/StevenDimDoors/mod_pocketDimClient/RenderDimDoor.java @@ -3,11 +3,9 @@ package StevenDimDoors.mod_pocketDimClient; import java.nio.FloatBuffer; import java.util.Random; -import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; @@ -15,7 +13,6 @@ import org.lwjgl.opengl.GL11; import StevenDimDoors.mod_pocketDim.DDProperties; import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.blocks.DimensionalDoor; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/StevenDimDoors/mod_pocketDimClient/RenderMobObelisk.java b/StevenDimDoors/mod_pocketDimClient/RenderMobObelisk.java index e1060a9..2bbdbad 100644 --- a/StevenDimDoors/mod_pocketDimClient/RenderMobObelisk.java +++ b/StevenDimDoors/mod_pocketDimClient/RenderMobObelisk.java @@ -1,9 +1,6 @@ package StevenDimDoors.mod_pocketDimClient; -import StevenDimDoors.mod_pocketDim.ticking.MobMonolith; import net.minecraft.client.renderer.entity.RenderLiving; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/StevenDimDoors/mod_pocketDimClient/RenderRift.java b/StevenDimDoors/mod_pocketDimClient/RenderRift.java index adb4f13..07c1cf9 100644 --- a/StevenDimDoors/mod_pocketDimClient/RenderRift.java +++ b/StevenDimDoors/mod_pocketDimClient/RenderRift.java @@ -1,24 +1,19 @@ package StevenDimDoors.mod_pocketDimClient; -import java.nio.FloatBuffer; -import java.util.HashMap; -import java.util.Random; +import static org.lwjgl.opengl.GL11.GL_BLEND; +import static org.lwjgl.opengl.GL11.GL_LIGHTING; +import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_DST_COLOR; +import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D; +import static org.lwjgl.opengl.GL11.GL_ZERO; +import static org.lwjgl.opengl.GL11.glBlendFunc; + +import java.util.HashMap; -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ActiveRenderInfo; -import net.minecraft.client.renderer.GLAllocation; -import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; import org.lwjgl.opengl.GL11; -import static org.lwjgl.opengl.GL11.*; -import StevenDimDoors.mod_pocketDim.DDProperties; -import StevenDimDoors.mod_pocketDim.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.blocks.DimensionalDoor; -import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -- 2.39.5 From 549ee548527db96deed0a49f3a1be9a7cb2ce630 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Tue, 3 Sep 2013 21:41:54 -0400 Subject: [PATCH 24/24] Fixed More Bugs Fixed the issue with integrated servers causing circular updates between the combined server and client. We now check on the client side whether the connection we're receiving data from is a memory connection (which is presumably only used by integrated servers). If so, the client ignores any incoming packets. We don't just disable update events altogether because LAN games will require updating remote clients. Also fixed a bug in PocketManager.unload() - we weren't setting isLoaded to false after unloading everything and unregisterPockets() had to be called before setting dimensionData to null. --- .../mod_pocketDim/core/PocketManager.java | 15 +++++++-------- .../mod_pocketDimClient/ClientPacketHandler.java | 5 +++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/StevenDimDoors/mod_pocketDim/core/PocketManager.java b/StevenDimDoors/mod_pocketDim/core/PocketManager.java index b79ee2b..a03a7b9 100644 --- a/StevenDimDoors/mod_pocketDim/core/PocketManager.java +++ b/StevenDimDoors/mod_pocketDim/core/PocketManager.java @@ -391,17 +391,16 @@ public class PocketManager public static void unload() { + if (!isLoaded) + { + throw new IllegalStateException("Pocket dimensions have already been unloaded!"); + } + save(); - dimensionData = null; unregisterPockets(); + dimensionData = null; + isLoaded = false; } - - /* - * This isn't needed right now and it's causing me problems due to the iterator's generic type -_- - public static Iterable getDimensions() - { - return dimensionData.values(); - }*/ public static DimLink getLink(int x, int y, int z, World world) { diff --git a/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java b/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java index a98f115..a969a92 100644 --- a/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java +++ b/StevenDimDoors/mod_pocketDimClient/ClientPacketHandler.java @@ -38,6 +38,11 @@ public class ClientPacketHandler implements IPacketHandler, IUpdateSource if (!packet.channel.equals(PacketConstants.CHANNEL_NAME)) return; + // If this is a memory connection, then our client is running an integrated server. + // We can tell by checking if packet size is 0. + if (manager.packetSize() == 0) + return; + try { DataInputStream input = new DataInputStream(new ByteArrayInputStream(packet.data)); -- 2.39.5