From 8e8346864ef7297235195379a1f891f22f773dc2 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 30 Aug 2013 10:57:08 -0400 Subject: [PATCH 01/14] 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) From 993006877554a20a6d7599486311c0eb4cf983f5 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Fri, 30 Aug 2013 16:27:27 -0400 Subject: [PATCH 02/14] 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); From 5cabd3762eb0e9da191b4dee010c9045d8384704 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 07:39:52 -0400 Subject: [PATCH 03/14] 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 From d9056e551fdc6f185f773936e923d0dea9f15c28 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 12:58:35 -0400 Subject: [PATCH 04/14] 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(); } From f34b06b834ef30a8b93d585467fc3e601751724c Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 16:00:18 -0400 Subject: [PATCH 05/14] 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); From 4b5870339b93b58d2af4acea177ad52cd44dcbf8 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 16:30:41 -0400 Subject: [PATCH 06/14] 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. From ea1fc5f4c0828a4041048f67a64afaf2b50ca4c2 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 16:43:18 -0400 Subject: [PATCH 07/14] 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; From 1cc1c374f6d7a205e808f5151d9a216d35dcf764 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 16:46:40 -0400 Subject: [PATCH 08/14] 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); - } - } -} From 4f3ab403d3d3e6b1552e578d96c9abe414de4ff6 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 20:44:31 -0400 Subject: [PATCH 09/14] 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; } } From b795885f1c937879b6319baed41f90d3e97e3fbb Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sat, 31 Aug 2013 20:46:20 -0400 Subject: [PATCH 10/14] 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"); From 4086e75ead4abc973545fddda4d1f54e37f307d2 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 1 Sep 2013 09:21:27 -0400 Subject: [PATCH 11/14] 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); From efa5b3eb4c4645fec609da079890d1c3252bff6d Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 1 Sep 2013 10:50:20 -0400 Subject: [PATCH 12/14] 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) From 62fed83e2f7e75b4aa0caf6969f3843bf234773b Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 1 Sep 2013 22:01:17 -0400 Subject: [PATCH 13/14] 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) + { } } From 0bd7ef959379e7fff7e6817e17881d64c03d80ae Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Sun, 1 Sep 2013 22:02:05 -0400 Subject: [PATCH 14/14] 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