diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java index 24e58dff..7cc635d8 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java @@ -1,11 +1,12 @@ package StevenDimDoors.mod_pocketDim; -import StevenDimDoors.mod_pocketDim.config.DDProperties; import net.minecraft.block.Block; +import net.minecraft.block.BlockDispenser; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import StevenDimDoors.mod_pocketDim.config.DDProperties; +import StevenDimDoors.mod_pocketDim.items.behaviors.DispenserBehaviorStabilizedRS; import cpw.mods.fml.common.registry.GameRegistry; -import static StevenDimDoors.mod_pocketDim.mod_pocketDim.*; public class CraftingManager { @@ -18,19 +19,19 @@ public class CraftingManager switch (properties.WorldThreadRequirementLevel) { case 1: - GameRegistry.addShapelessRecipe(new ItemStack(itemStableFabric, 1), + GameRegistry.addShapelessRecipe(new ItemStack(mod_pocketDim.itemStableFabric, 1), Item.enderPearl, mod_pocketDim.itemWorldThread); break; case 2: - GameRegistry.addRecipe(new ItemStack(itemStableFabric, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemStableFabric, 1), "yxy", 'x', Item.enderPearl, 'y', mod_pocketDim.itemWorldThread); break; case 3: - GameRegistry.addRecipe(new ItemStack(itemStableFabric, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemStableFabric, 1), " y ", "yxy", " y ", 'x', Item.enderPearl, 'y', mod_pocketDim.itemWorldThread); break; default: - GameRegistry.addRecipe(new ItemStack(itemStableFabric, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemStableFabric, 1), "yyy", "yxy", "yyy", 'x', Item.enderPearl, 'y', mod_pocketDim.itemWorldThread); break; } @@ -38,48 +39,48 @@ public class CraftingManager if (properties.CraftingDimensionalDoorAllowed) { - GameRegistry.addRecipe(new ItemStack(itemDimensionalDoor, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemDimensionalDoor, 1), "yxy", 'x', mod_pocketDim.itemStableFabric, 'y', Item.doorIron); } if (properties.CraftingUnstableDoorAllowed) { - GameRegistry.addRecipe(new ItemStack(itemUnstableDoor, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemUnstableDoor, 1), "yxy", 'x', Item.eyeOfEnder, 'y', mod_pocketDim.itemDimensionalDoor); } if (properties.CraftingWarpDoorAllowed) { - GameRegistry.addRecipe(new ItemStack(itemWarpDoor, 1), - "yxy", 'x', mod_pocketDim.itemStableFabric, 'y', Item.doorWood); + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemWarpDoor, 1), + "yxy", 'x', Item.enderPearl, 'y', Item.doorWood); } if (properties.CraftingTransTrapdoorAllowed) { - GameRegistry.addRecipe(new ItemStack(transTrapdoor, 1), - "y", "x", "y", 'x', mod_pocketDim.itemStableFabric, 'y', Block.trapdoor); + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.transTrapdoor, 1), + "y", "x", "y", 'x', Item.enderPearl, 'y', Block.trapdoor); } if (properties.CraftingRiftSignatureAllowed) { - GameRegistry.addRecipe(new ItemStack(itemRiftSignature, 1), - " y ", "yxy", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotIron); + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemRiftSignature, 1), + " y ", "yxy", " y ", 'x', Item.enderPearl, 'y', Item.ingotIron); } if (properties.CraftingRiftRemoverAllowed) { - GameRegistry.addRecipe(new ItemStack(itemRiftRemover, 1), - "yyy", "yxy", "yyy", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotGold); + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemRiftRemover, 1), + "yyy", "yxy", "yyy", 'x', Item.enderPearl, 'y', Item.ingotGold); } if (properties.CraftingRiftBladeAllowed) { - GameRegistry.addRecipe(new ItemStack(itemRiftBlade, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemRiftBlade, 1), "x", "x", "y", 'x', mod_pocketDim.itemStableFabric, 'y', Item.blazeRod); } if (properties.CraftingStabilizedRiftSignatureAllowed) { - GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemStabilizedLinkSignature,1), - " y ", "yxy", " y ", 'x', mod_pocketDim.itemRiftSignature, 'y', mod_pocketDim.itemStableFabric); + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemStabilizedRiftSignature, 1), + " y ", "yxy", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotIron); } if (properties.CraftingGoldenDimensionalDoorAllowed) { - GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldenDimensionalDoor,1), - "yxy", 'x', mod_pocketDim.itemGoldenDoor, 'y', mod_pocketDim.itemStableFabric); + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldenDimensionalDoor, 1), + "yxy", 'x', mod_pocketDim.itemStableFabric, 'y', mod_pocketDim.itemGoldenDoor); } if (properties.CraftingGoldenDoorAllowed) { @@ -88,4 +89,9 @@ public class CraftingManager } } + public static void registerDispenserBehaviors() + { + // Register the dispenser behaviors for certain DD items + BlockDispenser.dispenseBehaviorRegistry.putObject(mod_pocketDim.itemStabilizedRiftSignature, new DispenserBehaviorStabilizedRS()); + } } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 4e47d8fc..4130aaf8 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -1,14 +1,11 @@ package StevenDimDoors.mod_pocketDim; -import net.minecraft.block.Block; import net.minecraft.client.audio.SoundManager; import net.minecraft.client.audio.SoundPoolEntry; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemDoor; import net.minecraft.item.ItemStack; -import net.minecraft.util.ChunkCoordinates; import net.minecraft.world.World; import net.minecraftforge.client.event.sound.PlayBackgroundMusicEvent; import net.minecraftforge.client.event.sound.SoundLoadEvent; @@ -20,7 +17,6 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; import net.minecraftforge.event.terraingen.InitMapGenEvent; import net.minecraftforge.event.world.WorldEvent; -import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor; import StevenDimDoors.mod_pocketDim.config.DDProperties; import StevenDimDoors.mod_pocketDim.core.DDTeleporter; import StevenDimDoors.mod_pocketDim.core.PocketManager; @@ -84,7 +80,7 @@ public class EventHookContainer public void onPlayerEvent(PlayerInteractEvent event) { // Handle all door placement here - if(event.action == Action.LEFT_CLICK_BLOCK) + if (event.action == Action.LEFT_CLICK_BLOCK) { return; } @@ -92,14 +88,11 @@ public class EventHookContainer ItemStack stack = event.entityPlayer.inventory.getCurrentItem(); if (stack != null && stack.getItem() instanceof ItemDoor) { - if(BaseItemDoor.getDoorToPlace(stack.getItem())!=null) + if (BaseItemDoor.tryToPlaceDoor(stack, event.entityPlayer, world, + event.x, event.y, event.z, event.face)) { - if (mod_pocketDim.itemDimensionalDoor.tryToPlaceDoor(stack, event.entityPlayer, world, - event.x, event.y, event.z, event.face)) - { - // Cancel the event so that we don't get two doors from vanilla doors - event.setCanceled(true); - } + // Cancel the event so that we don't get two doors from vanilla doors + event.setCanceled(true); } } } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java index 0c95b061..c7d0c2b7 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DDTeleporter.java @@ -574,7 +574,7 @@ public class DDTeleporter Point3D destination = yCoordHelper.findDropPoint(world, source.getX(), source.getY() + 1, source.getZ()); if (destination != null) { - current.root().setDestination(link, destination.getX(), destination.getY(), destination.getZ()); + current.root().setLinkDestination(link, destination.getX(), destination.getY(), destination.getZ()); return true; } } @@ -745,7 +745,7 @@ public class DDTeleporter int orientation = getDestinationOrientation(source, properties); NewDimData sourceDim = PocketManager.getDimensionData(link.source().getDimension()); DimLink reverse = destinationDim.createLink(x, y + 2, z, LinkTypes.REVERSE,orientation); - sourceDim.setDestination(reverse, source.getX(), source.getY(), source.getZ()); + sourceDim.setLinkDestination(reverse, source.getX(), source.getY(), source.getZ()); // Set up the warp door at the destination orientation = BlockRotator.transformMetadata(orientation, 2, properties.WarpDoorID); @@ -753,7 +753,7 @@ public class DDTeleporter // Complete the link to the destination // This comes last so the destination isn't set unless everything else works first - destinationDim.setDestination(link, x, y + 2, z); + destinationDim.setLinkDestination(link, x, y + 2, z); } return (destination != null); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java index 8ee3d9af..8b0e3d8f 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/DimLink.java @@ -60,6 +60,7 @@ public abstract class DimLink { return tail.getDestination(); } + public int getDestinationOrientation() { DimLink link = PocketManager.getLink(this.destination().getX(), this.destination().getY(), this.destination().getZ(), this.destination().getDimension()); @@ -69,6 +70,7 @@ public abstract class DimLink } return (this.orientation()+2)%4; } + public boolean hasDestination() { return (tail.getDestination() != null); @@ -94,6 +96,7 @@ public abstract class DimLink return tail.getLinkType(); } + @Override public String toString() { return link.point + " -> " + (hasDestination() ? destination() : ""); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java index 22b783f1..15182ed5 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/core/NewDimData.java @@ -503,7 +503,7 @@ public abstract class NewDimData { throw new IllegalArgumentException("orientation must be between 0 and 3, inclusive."); } - setDestination(incoming, originX, originY, originZ); + setLinkDestination(incoming, originX, originY, originZ); this.origin = incoming.destination(); this.orientation = orientation; this.dungeon = dungeon; @@ -566,13 +566,13 @@ public abstract class NewDimData throw new IllegalStateException("The dimension has already been initialized."); } - setDestination(incoming, originX, originY, originZ); + setLinkDestination(incoming, originX, originY, originZ); this.origin = incoming.destination(); this.orientation = orientation; this.modified = true; } - public void setDestination(DimLink incoming, int x, int y, int z) + public void setLinkDestination(DimLink incoming, int x, int y, int z) { InnerDimLink link = (InnerDimLink) incoming; link.setDestination(x, y, z, this); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java index 23bd064a..e9788320 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/DungeonSchematic.java @@ -325,7 +325,7 @@ public class DungeonSchematic extends Schematic { DimLink reverseLink = dimension.createLink(pocketCenter.getX(), pocketCenter.getY(), pocketCenter.getZ(), LinkTypes.REVERSE, orientation); Point4D destination = entryLink.source(); NewDimData prevDim = PocketManager.getDimensionData(destination.getDimension()); - prevDim.setDestination(reverseLink, destination.getX(), destination.getY(), destination.getZ()); + prevDim.setLinkDestination(reverseLink, destination.getX(), destination.getY(), destination.getZ()); initDoorTileEntity(world, pocketCenter); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java index dafcd913..3ad3a4b2 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java @@ -2,6 +2,7 @@ package StevenDimDoors.mod_pocketDim.items; import java.util.HashMap; import java.util.List; + import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; @@ -23,9 +24,9 @@ import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor; public abstract class BaseItemDoor extends ItemDoor { - // maps non-dimensional door items to their corresponding dimensional door - // item - private static HashMap vanillaDoorMapping = new HashMap(); + // Maps non-dimensional door items to their corresponding dimensional door item + // Also maps dimensional door items to themselves for simplicity + private static HashMap doorItemMapping = new HashMap(); private static DDProperties properties = null; /** @@ -34,7 +35,7 @@ public abstract class BaseItemDoor extends ItemDoor * @param material * @param door */ - public BaseItemDoor(int itemID, Material material, ItemDoor door) + public BaseItemDoor(int itemID, Material material, ItemDoor vanillaDoor) { super(itemID, material); this.setMaxStackSize(64); @@ -42,9 +43,10 @@ public abstract class BaseItemDoor extends ItemDoor if (properties == null) properties = DDProperties.instance(); - if(door!=null) + doorItemMapping.put(this, this); + if (vanillaDoor != null) { - vanillaDoorMapping.put(door, this); + doorItemMapping.put(vanillaDoor, this); } } @@ -64,7 +66,7 @@ public abstract class BaseItemDoor extends ItemDoor * * @return */ - protected abstract BaseDimDoor getDoortoItemMapping(); + protected abstract BaseDimDoor getDoorBlock(); /** * Overriden here to remove vanilla block placement functionality from @@ -73,27 +75,12 @@ public abstract class BaseItemDoor extends ItemDoor @Override public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - // TODO Auto-generated method stub return false; } - public static BaseDimDoor getDoorToPlace(Item item) - { - if (!(item instanceof BaseItemDoor)) - { - item = BaseItemDoor.vanillaDoorMapping.get(item); - } - if(item == null) - { - return null; - } - return ((BaseItemDoor) item).getDoortoItemMapping(); - } - /** - * Tries to place a door block, called in EventHookContainer + * Tries to place a door as a dimensional door * - * @param doorBlock * @param stack * @param player * @param world @@ -101,8 +88,6 @@ public abstract class BaseItemDoor extends ItemDoor * @param y * @param z * @param side - * @param requireLink - * @param reduceStack * @return */ public static boolean tryToPlaceDoor(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side) @@ -111,15 +96,20 @@ public abstract class BaseItemDoor extends ItemDoor { return false; } - if (!(stack.getItem() instanceof ItemDoor)) + // Retrieve the actual door type that we want to use here. + // It's okay if stack isn't an ItemDoor. In that case, the lookup will + // return null, just as if the item was an unrecognized door type. + BaseItemDoor mappedItem = doorItemMapping.get(stack.getItem()); + if (mappedItem == null) { - throw new IllegalArgumentException("The itemstack must correspond to some type of door"); + return false; } - if (BaseItemDoor.placeDoorOnBlock(getDoorToPlace(stack.getItem()), stack, player, world, x, y, z, side)) + BaseDimDoor doorBlock = mappedItem.getDoorBlock(); + if (BaseItemDoor.placeDoorOnBlock(doorBlock, stack, player, world, x, y, z, side)) { return true; } - return BaseItemDoor.placeDoorOnRift(getDoorToPlace(stack.getItem()), world, player, stack); + return BaseItemDoor.placeDoorOnRift(doorBlock, world, player, stack); } /** diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemDimensionalDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemDimensionalDoor.java index d6bb9ce8..18f123dd 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemDimensionalDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemDimensionalDoor.java @@ -28,7 +28,7 @@ public class ItemDimensionalDoor extends BaseItemDoor } @Override - protected BaseDimDoor getDoortoItemMapping() + protected BaseDimDoor getDoorBlock() { return (BaseDimDoor) mod_pocketDim.dimensionalDoor; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemGoldDimDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemGoldDimDoor.java index 9dde8f56..abf9f09c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemGoldDimDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemGoldDimDoor.java @@ -28,7 +28,7 @@ public class ItemGoldDimDoor extends BaseItemDoor } @Override - protected BaseDimDoor getDoortoItemMapping() + protected BaseDimDoor getDoorBlock() { return (BaseDimDoor) mod_pocketDim.goldenDimensionalDoor; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemGoldDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemGoldDoor.java index 204343d0..252c1b61 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemGoldDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemGoldDoor.java @@ -15,6 +15,7 @@ public class ItemGoldDoor extends ItemDoor public ItemGoldDoor(int par1, Material par2Material) { super(par1, par2Material); + this.setMaxStackSize(16); } @Override diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index a20bc468..9cc5053f 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -34,12 +34,13 @@ public class ItemRiftSignature extends Item @SideOnly(Side.CLIENT) @Override - public boolean hasEffect(ItemStack stack) + public boolean hasEffect(ItemStack stack, int pass) { //Make the item glow if it has one endpoint stored return (stack.getItemDamage() != 0); } + @Override public void registerIcons(IconRegister par1IconRegister) { this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", "")); @@ -60,14 +61,14 @@ public class ItemRiftSignature extends Item return false; } - y += 2; //Increase y by 2 to place the rift at head level - if (!player.canPlayerEdit(x, y, z, side, stack)) + //Increase y by 2 to place the rift at head level + int adjustedY = adjustYForSpecialBlocks(world, x, y + 2, z); + if (!player.canPlayerEdit(x, adjustedY, z, side, stack)) { return true; } - int adjustedY = adjustYForSpecialBlocks(world,x,y,z); Point4DOrientation source = getSource(stack); - int orientation = MathHelper.floor_double((double) ((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; + int orientation = MathHelper.floor_double(((player.rotationYaw + 180.0F) * 4.0F / 360.0F) - 0.5D) & 3; if (source != null) { //The link was used before and already has an endpoint stored. Create links connecting the two endpoints. @@ -75,8 +76,8 @@ public class ItemRiftSignature extends Item NewDimData destinationDimension = PocketManager.getDimensionData(world); DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL,source.getOrientation()); DimLink reverse = destinationDimension.createLink(x, adjustedY, z, LinkTypes.NORMAL,orientation); - destinationDimension.setDestination(link, x, adjustedY, z); - sourceDimension.setDestination(reverse, source.getX(), source.getY(), source.getZ()); + destinationDimension.setLinkDestination(link, x, adjustedY, z); + sourceDimension.setLinkDestination(reverse, source.getX(), source.getY(), source.getZ()); //Try placing a rift at the destination point if (!mod_pocketDim.blockRift.isBlockImmune(world, x, adjustedY, z)) @@ -113,6 +114,7 @@ public class ItemRiftSignature extends Item /** * allows items to add custom lines of information to the mouseover description */ + @Override @SuppressWarnings({ "unchecked", "rawtypes" }) @SideOnly(Side.CLIENT) public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) @@ -140,26 +142,28 @@ public class ItemRiftSignature extends Item */ public static int adjustYForSpecialBlocks(World world, int x, int y, int z) { - y=y-2;//get the block the player actually clicked on - Block block = Block.blocksList[world.getBlockId(x, y, z)]; - if(block==null) + int targetY = y - 2; // Get the block the player actually clicked on + Block block = Block.blocksList[world.getBlockId(x, targetY, z)]; + if (block == null) { - return y+2; + return targetY + 2; } - if(block.isBlockReplaceable(world, x, y, z)) + if (block.isBlockReplaceable(world, x, targetY, z)) { - return y+1;//move block placement down (-2+1) one so its directly over things like snow + return targetY + 1; // Move block placement down (-2+1) one so its directly over things like snow } - if(block instanceof BaseDimDoor) + if (block instanceof BaseDimDoor) { - if(world.getBlockId(x, y-1, z)==block.blockID&&world.getBlockMetadata(x, y, z)==8) + if (BaseDimDoor.isUpperDoorBlock(world.getBlockMetadata(x, targetY, z))) { - return y;//move rift placement down two so its in the right place on the door. + return targetY; // Move rift placement down two so its in the right place on the door. } - return y+1; + // Move rift placement down one so its in the right place on the door. + return targetY + 1; } - return y+2; + return targetY + 2; } + public static void setSource(ItemStack itemStack, int x, int y, int z, int orientation, NewDimData dimension) { NBTTagCompound tag = new NBTTagCompound(); @@ -200,11 +204,12 @@ public class ItemRiftSignature extends Item Integer orientation = tag.getInteger("orientation"); Integer dimID = tag.getInteger("linkDimID"); - if (x != null && y != null && z != null && dimID != null) + if (x != null && y != null && z != null && orientation != null && dimID != null) { - return new Point4DOrientation(x, y, z,orientation, dimID); + return new Point4DOrientation(x, y, z, orientation, dimID); } } + // Mark the item as uninitialized if its source couldn't be read itemStack.setItemDamage(0); } return null; @@ -214,10 +219,11 @@ public class ItemRiftSignature extends Item { private Point4D point; private int orientation; + Point4DOrientation(int x, int y, int z, int orientation, int dimID) { - this.point= new Point4D(x,y,z,dimID); - this.orientation=orientation; + this.point = new Point4D(x, y, z, dimID); + this.orientation = orientation; } int getX() @@ -239,10 +245,16 @@ public class ItemRiftSignature extends Item { return point.getDimension(); } + int getOrientation() { return orientation; } + + Point4D getPoint() + { + return point; + } } } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index 4d1cf840..b47bff6b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -14,7 +14,6 @@ import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.LinkTypes; import StevenDimDoors.mod_pocketDim.core.NewDimData; import StevenDimDoors.mod_pocketDim.core.PocketManager; -import StevenDimDoors.mod_pocketDim.util.Point4D; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -40,62 +39,77 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature return false; } - // 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, side, stack)) + // Adjust Y so the rift is at head level, depending on the presence of certain blocks + int adjustedY = adjustYForSpecialBlocks(world, x, y + 2, z); + if (!player.canPlayerEdit(x, adjustedY, z, side, stack)) { return true; } - Point4DOrientation source = getSource(stack); - int adjustedY = adjustYForSpecialBlocks(world,x,y,z); + int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3; // Check if the Stabilized Rift Signature has been initialized - int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3; + Point4DOrientation source = getSource(stack); if (source != null) { - // Yes, it's initialized. Check if the player is in creative - // or if the player can pay with Stable Fabric to create a rift. - if (!player.capabilities.isCreativeMode && !player.inventory.hasItem(mod_pocketDim.itemStableFabric.itemID)) - { - mod_pocketDim.sendChat(player, "You don't have any Stable Fabric!"); - // I won't do this, but this is the chance to localize chat - // messages sent to the player; look at ChatMessageComponent - // and how MFR does it with items like the safari net launcher - return true; - } - - //The link was used before and already has an endpoint stored. Create links connecting the two endpoints. + // Yes, it's initialized. NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); NewDimData destinationDimension = PocketManager.getDimensionData(world); - DimLink link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL,source.getOrientation()); - DimLink reverse = destinationDimension.createLink(x, adjustedY, z, LinkTypes.NORMAL,orientation); - destinationDimension.setDestination(link, x, adjustedY, 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, adjustedY, z)) + DimLink reverse = destinationDimension.getLink(x, adjustedY, z); + DimLink link; + + // Check whether the SRS is being used to restore one of its previous + // link pairs. In other words, the SRS is being used on a location + // that already has a link pointing to the SRS's source, with the + // intention of overwriting the source-side link to point there. + // Those benign redirection operations will be handled for free. + + if (reverse != null && source.getPoint().equals(reverse.destination())) { - world.setBlock(x, adjustedY, z, mod_pocketDim.blockRift.blockID); + // Only the source-to-destination link is needed. + link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL, source.getOrientation()); + destinationDimension.setLinkDestination(link, x, adjustedY, z); + } + else + { + // Check if the player is in creative mode, + // or if the player can pay with an Ender Pearl to create a rift. + if (!player.capabilities.isCreativeMode && + !player.inventory.consumeInventoryItem(Item.enderPearl.itemID)) + { + mod_pocketDim.sendChat(player, "You don't have any Ender Pearls!"); + // I won't do this, but this is the chance to localize chat + // messages sent to the player; look at ChatMessageComponent + // and how MFR does it with items like the safari net launcher + return true; + } + + // Create links connecting the two endpoints. + link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL, source.getOrientation()); + reverse = destinationDimension.createLink(x, adjustedY, z, LinkTypes.NORMAL, orientation); + destinationDimension.setLinkDestination(link, x, adjustedY, z); + sourceDimension.setLinkDestination(reverse, source.getX(), source.getY(), source.getZ()); + + // Try placing a rift at the destination point + if (!mod_pocketDim.blockRift.isBlockImmune(world, x, adjustedY, z)) + { + world.setBlock(x, adjustedY, z, mod_pocketDim.blockRift.blockID); + } } - //Try placing a rift at the source point, but check if its world is loaded first + // 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())) { sourceWorld.setBlock(source.getX(), source.getY(), source.getZ(), mod_pocketDim.blockRift.blockID); } - - if (!player.capabilities.isCreativeMode) - { - player.inventory.consumeInventoryItem(mod_pocketDim.itemStableFabric.itemID); - } - mod_pocketDim.sendChat(player,"Rift Created"); - world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftEnd", 0.6f, 1); + + mod_pocketDim.sendChat(player, "Rift Created"); + world.playSoundAtEntity(player, "mods.DimDoors.sfx.riftEnd", 0.6f, 1); } else { - //The link signature has not been used. Store its current target as the first location. + // The link signature has not been used. Store its current target as the first location. setSource(stack, x, adjustedY, z, orientation, PocketManager.getDimensionData(world)); mod_pocketDim.sendChat(player,"Location Stored in Stabilized Rift Signature"); world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftStart", 0.6f, 1); @@ -103,6 +117,54 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature return true; } + public static boolean useFromDispenser(ItemStack stack, World world, int x, int y, int z) + { + // Stabilized Rift Signatures can only be used from dispensers to restore + // a previous link pair. The operation would be free for a player, so + // dispensers can also perform it for free. Otherwise, the item does nothing. + if (world.isRemote) + { + return false; + } + + // Adjust Y so the rift is at head level, depending on the presence of certain blocks + int adjustedY = adjustYForSpecialBlocks(world, x, y + 2, z); + Point4DOrientation source = getSource(stack); + + // The SRS must have been initialized + if (source != null) + { + NewDimData sourceDimension = PocketManager.getDimensionData(source.getDimension()); + NewDimData destinationDimension = PocketManager.getDimensionData(world); + DimLink reverse = destinationDimension.getLink(x, adjustedY, z); + DimLink link; + + // Check whether the SRS is being used to restore one of its previous + // link pairs. In other words, the SRS is being used on a location + // that already has a link pointing to the SRS's source, with the + // intention of overwriting the source-side link to point there. + if (reverse != null && source.getPoint().equals(reverse.destination())) + { + // Only the source-to-destination link is needed. + link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL, source.getOrientation()); + destinationDimension.setLinkDestination(link, x, adjustedY, z); + + // 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())) + { + sourceWorld.setBlock(source.getX(), source.getY(), source.getZ(), mod_pocketDim.blockRift.blockID); + } + + // This call doesn't seem to be working... + world.playSoundEffect(x + 0.5, adjustedY + 0.5, z + 0.5, "mods.DimDoors.sfx.riftEnd", 0.6f, 1); + return true; + } + } + return false; + } + /** * allows items to add custom lines of information to the mouseover description */ diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemUnstableDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemUnstableDoor.java index c8594431..e51bcaa1 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemUnstableDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemUnstableDoor.java @@ -25,7 +25,7 @@ public class ItemUnstableDoor extends BaseItemDoor } @Override - protected BaseDimDoor getDoortoItemMapping() + protected BaseDimDoor getDoorBlock() { return (BaseDimDoor) mod_pocketDim.unstableDoor; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemWarpDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemWarpDoor.java index 35c57377..403bbc14 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemWarpDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemWarpDoor.java @@ -28,7 +28,7 @@ public class ItemWarpDoor extends BaseItemDoor } @Override - protected BaseDimDoor getDoortoItemMapping() + protected BaseDimDoor getDoorBlock() { return (BaseDimDoor) mod_pocketDim.warpDoor; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/behaviors/DispenserBehaviorStabilizedRS.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/behaviors/DispenserBehaviorStabilizedRS.java new file mode 100644 index 00000000..f79fe262 --- /dev/null +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/behaviors/DispenserBehaviorStabilizedRS.java @@ -0,0 +1,42 @@ +package StevenDimDoors.mod_pocketDim.items.behaviors; + +import net.minecraft.block.BlockDispenser; +import net.minecraft.dispenser.BehaviorDefaultDispenseItem; +import net.minecraft.dispenser.IBlockSource; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; +import StevenDimDoors.mod_pocketDim.items.ItemStabilizedRiftSignature; + +public class DispenserBehaviorStabilizedRS extends BehaviorDefaultDispenseItem +{ + @Override + public ItemStack dispenseStack(IBlockSource dispenser, ItemStack stack) + { + // Search for a non-air block up to 3 blocks in front of a dispenser. + // If it's found, call ItemStabilizedRiftSignature.useFromDispenser(). + int x = dispenser.getXInt(); + int y = dispenser.getYInt(); + int z = dispenser.getZInt(); + EnumFacing facing = BlockDispenser.getFacing(dispenser.getBlockMetadata()); + int dx = facing.getFrontOffsetX(); + int dy = facing.getFrontOffsetY(); + int dz = facing.getFrontOffsetZ(); + World world = dispenser.getWorld(); + + for (int k = 1; k <= 3; k++) + { + x += dx; + y += dy; + z += dz; + if (!world.isAirBlock(x, y, z)) + { + // Found a block. Activate the item. + ItemStabilizedRiftSignature.useFromDispenser(stack, world, x, y, z); + break; + } + } + // The item stack isn't modified + return stack; + } +} diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 239b1370..6554a6a0 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -135,7 +135,7 @@ public class mod_pocketDim public static Item itemRiftSignature; public static Item itemStableFabric; public static Item itemUnstableDoor; - public static Item itemStabilizedLinkSignature; + public static Item itemStabilizedRiftSignature; public static BiomeGenBase limboBiome; public static BiomeGenBase pocketBiome; @@ -218,7 +218,7 @@ public class mod_pocketDim itemStableFabric = (new ItemStableFabric(properties.StableFabricItemID, 0)).setUnlocalizedName("itemStableFabric"); itemUnstableDoor = (new ItemUnstableDoor(properties.UnstableDoorItemID, Material.iron, null)).setUnlocalizedName("itemChaosDoor"); itemRiftBlade = (new ItemRiftBlade(properties.RiftBladeItemID, properties)).setUnlocalizedName("ItemRiftBlade"); - itemStabilizedLinkSignature = (new ItemStabilizedRiftSignature(properties.StabilizedRiftSignatureItemID)).setUnlocalizedName("itemStabilizedRiftSig"); + itemStabilizedRiftSignature = (new ItemStabilizedRiftSignature(properties.StabilizedRiftSignatureItemID)).setUnlocalizedName("itemStabilizedRiftSig"); itemWorldThread = (new ItemWorldThread(properties.WorldThreadItemID)).setUnlocalizedName("itemWorldThread"); // Check if other biomes have been registered with the same IDs we want. If so, crash Minecraft @@ -265,7 +265,7 @@ public class mod_pocketDim LanguageRegistry.addName(itemRiftSignature, "Rift Signature"); LanguageRegistry.addName(itemGoldenDoor, "Golden Door"); LanguageRegistry.addName(itemGoldenDimensionalDoor, "Golden Dimensional Door"); - LanguageRegistry.addName(itemStabilizedLinkSignature, "Stabilized Rift Signature"); + LanguageRegistry.addName(itemStabilizedRiftSignature, "Stabilized Rift Signature"); LanguageRegistry.addName(itemRiftRemover, "Rift Remover"); LanguageRegistry.addName(itemStableFabric, "Stable Fabric"); LanguageRegistry.addName(itemUnstableDoor, "Unstable Door"); @@ -292,6 +292,7 @@ public class mod_pocketDim LanguageRegistry.instance().addStringLocalization("entity.DimDoors.Obelisk.name", "Monolith"); CraftingManager.registerRecipes(properties); + CraftingManager.registerDispenserBehaviors(); DungeonHelper.initialize(); gatewayGenerator = new GatewayGenerator(properties); GameRegistry.registerWorldGenerator(mod_pocketDim.gatewayGenerator); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java b/src/main/java/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java index 28929dcc..3a7bb701 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java @@ -201,7 +201,7 @@ public class DDSaveHandler Point4D destination = packedLink.tail.destination; if(destination!=null) { - PocketManager.getDimensionData(destination.getDimension()).setDestination(link, destination.getX(),destination.getY(),destination.getZ()); + PocketManager.getDimensionData(destination.getDimension()).setLinkDestination(link, destination.getX(),destination.getY(),destination.getZ()); } unpackedLinks.add(packedLink); } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java index e19aa654..f54f5159 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/ticking/MobMonolith.java @@ -145,9 +145,13 @@ public class MobMonolith extends EntityFlying implements IMob if (player != null) { this.facePlayer(player); - if (!this.worldObj.isRemote) + if (!this.worldObj.isRemote && !(this.worldObj.provider instanceof LimboProvider)) { - // Play sounds on the server side + // Play sounds on the server side, if the player isn't in Limbo. + // Limbo is excluded to avoid drowning out its background music. + // Also, since it's a large open area with many Monoliths, some + // of the sounds that would usually play for a moment would + // keep playing constantly and would get very annoying. this.playSounds(player); } @@ -161,7 +165,8 @@ public class MobMonolith extends EntityFlying implements IMob // Teleport the target player if various conditions are met if (aggro >= MAX_AGGRO && !this.worldObj.isRemote && - properties.MonolithTeleportationEnabled && !player.capabilities.isCreativeMode) + properties.MonolithTeleportationEnabled && !player.capabilities.isCreativeMode && + !(this.worldObj.provider instanceof LimboProvider)) { this.aggro = 0; Point4D destination = LimboProvider.getLimboSkySpawn(player, properties); @@ -239,7 +244,7 @@ public class MobMonolith extends EntityFlying implements IMob this.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, mod_pocketDim.modid + ":tearing", 1F, (float) (1 + this.rand.nextGaussian())); this.soundTime = 100 + this.rand.nextInt(75); } - if ((aggroPercent > 0.90) && this.soundTime < 200) + if ((aggroPercent > 0.80) && this.soundTime < 200) { this.worldObj.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, mod_pocketDim.modid + ":tearing", 7, 1F); this.soundTime = 250; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java index d6e781b6..13f9f96a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java @@ -1,17 +1,9 @@ package StevenDimDoors.mod_pocketDim.tileentities; - - import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Random; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.network.PacketDispatcher; - -import net.minecraft.block.Block; -import net.minecraft.entity.DataWatcher; import net.minecraft.entity.Entity; import net.minecraft.entity.monster.EntityEnderman; import net.minecraft.entity.player.EntityPlayer; @@ -19,12 +11,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet132TileEntityData; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.MathHelper; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.util.Vec3; -import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.ServerPacketHandler; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.config.DDProperties; @@ -44,119 +31,88 @@ public class TileEntityRift extends DDTileEntityBase private static final int MAX_RIFT_SPREAD_CHANCE = 256; private static final int HOSTILE_ENDERMAN_CHANCE = 1; private static final int MAX_HOSTILE_ENDERMAN_CHANCE = 3; - private static final float[] POCKET_RENDER_COLOR= {1,1,1,.7F}; - private static final float[] DEFAULT_RENDER_COLOR= {1,1,1,1}; + private static final int UPDATE_PERIOD = 200; + private static final int CLOSING_PERIOD = 40; private static Random random = new Random(); - private int age = 0; - private int updateTimer = 0; - private int riftCloseTimer = 0; + private int updateTimer; + private int closeTimer = 0; public int xOffset = 0; public int yOffset = 0; public int zOffset = 0; public boolean shouldClose = false; - private boolean hasUpdated = false; public DimLink nearestRiftData; public int spawnedEndermenID = 0; - public HashMap renderingCenters = new HashMap(); - + + public TileEntityRift() + { + // Vary the update times of rifts to prevent all the rifts in a cluster + // from updating at the same time. + updateTimer = random.nextInt(UPDATE_PERIOD); + } + @Override public void updateEntity() { - //Determines if rift should render white closing particles and spread closing effect to other rifts nearby - if (this.shouldClose) + if (PocketManager.getLink(xCoord, yCoord, zCoord, worldObj.provider.dimensionId) == null) { - closeRift(); - } - else if( PocketManager.getLink(xCoord, yCoord, zCoord, worldObj.provider.dimensionId) == null) - { - this.invalidate(); if (worldObj.getBlockId(xCoord, yCoord, zCoord) == mod_pocketDim.blockRift.blockID) { worldObj.setBlockToAir(xCoord, yCoord, zCoord); - worldObj.removeBlockTileEntity(xCoord, yCoord, zCoord); - this.invalidate(); - return; } + else + { + this.invalidate(); + } + return; } - + if (worldObj.getBlockId(xCoord, yCoord, zCoord) != mod_pocketDim.blockRift.blockID) { - worldObj.removeBlockTileEntity(xCoord, yCoord, zCoord); this.invalidate(); return; } - - //The code for the new rift rendering hooks in here, as well as in the ClientProxy to bind the TESR to the rift. - //It is inactive for now. - /** - if(rand.nextInt(15) == 1) - { - age = age + 1; - this.calculateNextRenderQuad(age, rand); - } - this.clearBlocksOnRift(); - **/ - - //This code should execute once every 10 seconds - if (updateTimer > 200) + + // Check if this rift should render white closing particles and + // spread the closing effect to other rifts nearby. + if (this.shouldClose) { - this.spawnEndermen(); - this.grow(mod_pocketDim.properties); + closeRift(); + return; + } + + if (updateTimer >= UPDATE_PERIOD) + { + this.spawnEndermen(mod_pocketDim.properties); updateTimer = 0; } - else if(updateTimer==0) + else if (updateTimer == UPDATE_PERIOD / 2) { - this.calculateOldParticleOffset(); //this also calculates the distance for the particle stuff. + this.calculateParticleOffsets(); + this.spread(mod_pocketDim.properties); } updateTimer++; } - - - private void clearBlocksOnRift() + private void spawnEndermen(DDProperties properties) { - //clears blocks for the new rending effect - for (double[] coord : this.renderingCenters.values()) - { - int x = MathHelper.floor_double(coord[0] + 0.5); - int y = MathHelper.floor_double(coord[1] + 0.5); - int z = MathHelper.floor_double(coord[2] + 0.5); - - // Right side - if (!mod_pocketDim.blockRift.isBlockImmune(worldObj, this.xCoord + x, this.yCoord + y, this.zCoord + z)) - { - worldObj.setBlockToAir(this.xCoord + x, this.yCoord + y, this.zCoord + z); - } - // Left side - if (!mod_pocketDim.blockRift.isBlockImmune(worldObj, this.xCoord - x, this.yCoord - y, this.zCoord - z)) - { - worldObj.setBlockToAir(this.xCoord - x, this.yCoord - y, this.zCoord - z); - } - } - } - - private void spawnEndermen() - { - if (worldObj.isRemote) + if (worldObj.isRemote || !properties.RiftsSpawnEndermenEnabled) { return; } - NewDimData dimension = PocketManager.getDimensionData(worldObj); - - //Ensure that this rift is only spawning one enderman at a time, to prevent hordes of endermen + // Ensure that this rift is only spawning one Enderman at a time, to prevent hordes of Endermen Entity entity = worldObj.getEntityByID(this.spawnedEndermenID); if (entity != null && entity instanceof EntityEnderman) { return; } - //enderman will only spawn in groups of rifts if (random.nextInt(MAX_ENDERMAN_SPAWNING_CHANCE) < ENDERMAN_SPAWNING_CHANCE) { + // Endermen will only spawn from groups of rifts if (updateNearestRift()) { List list = worldObj.getEntitiesWithinAABB(EntityEnderman.class, @@ -190,14 +146,14 @@ public class TileEntityRift extends DDTileEntityBase private void closeRift() { NewDimData dimension = PocketManager.getDimensionData(worldObj); - if (riftCloseTimer == 20) + if (closeTimer == CLOSING_PERIOD / 2) { - ArrayList rifts= dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord); - if (rifts.size()>0) + ArrayList riftLinks = dimension.findRiftsInRange(worldObj, 6, xCoord, yCoord, zCoord); + if (riftLinks.size() > 0) { - for(DimLink riftToClose : rifts) + for (DimLink riftLink : riftLinks) { - Point4D location = riftToClose.source(); + Point4D location = riftLink.source(); TileEntityRift rift = (TileEntityRift) worldObj.getBlockTileEntity(location.getX(), location.getY(), location.getZ()); if (rift != null) { @@ -207,96 +163,40 @@ public class TileEntityRift extends DDTileEntityBase } } } - if (riftCloseTimer > 40) + if (closeTimer >= CLOSING_PERIOD) { - this.invalidate(); - if(!this.worldObj.isRemote) + if (!this.worldObj.isRemote) { DimLink link = PocketManager.getLink(this.xCoord, this.yCoord, this.zCoord, worldObj); - if(link!=null) + if (link != null) { dimension.deleteLink(link); } } worldObj.setBlockToAir(xCoord, yCoord, zCoord); - worldObj.playSound(xCoord, yCoord, zCoord, "mods.DimDoors.sfx.riftClose", (float) .7, 1, true); - this.worldObj.removeBlockTileEntity(xCoord, yCoord, zCoord); - return; + worldObj.playSound(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "mods.DimDoors.sfx.riftClose", 0.7f, 1, false); } - riftCloseTimer++; + closeTimer++; } - private void calculateOldParticleOffset() + private void calculateParticleOffsets() { - updateNearestRift(); - if (nearestRiftData != null) + if (updateNearestRift()) { Point4D location = nearestRiftData.source(); this.xOffset = this.xCoord - location.getX(); this.yOffset = this.yCoord - location.getY(); this.zOffset = this.zCoord - location.getZ(); - int distance = Math.abs(xOffset) + Math.abs(yOffset) + Math.abs(zOffset); } else { - this.xOffset=0; - this.yOffset=0; - this.xOffset=0; + this.xOffset = 0; + this.yOffset = 0; + this.xOffset = 0; } this.onInventoryChanged(); } - - private void calculateNextRenderQuad(float age, Random rand) - { - int maxSize = MathHelper.floor_double((Math.log(Math.pow(age+1,2)))); - int iteration=0; - while(iteration< maxSize) - { - iteration++; - double fl =Math.log(iteration+1)/(iteration); - double[] coords= new double[4]; - double noise = ((rand.nextGaussian())/(2+iteration/3+1)); - - if(!this.renderingCenters.containsKey(iteration-1)) - { - if (rand.nextBoolean()) - { - coords[0] = fl*1.5; - coords[1] = rand.nextGaussian()/5; - coords[2] = 0; - coords[3] = 1; - } - else - { - coords[0] = 0; - coords[1] = rand.nextGaussian()/5; - coords[2] = fl*1.5; - coords[3] = 0; - } - this.renderingCenters.put(iteration-1,coords); - iteration--; - } - else if(!this.renderingCenters.containsKey(iteration)) - { - if(this.renderingCenters.get(iteration-1)[3]==0) - { - coords[0]=noise/2+this.renderingCenters.get(iteration-1)[0]; - coords[1]=noise/2+this.renderingCenters.get(iteration-1)[1]; - coords[2]= this.renderingCenters.get(iteration-1)[2]+fl; - coords[3] = 0; - } - else - { - coords[0]=this.renderingCenters.get(iteration-1)[0]+fl; - coords[1]=noise/2+this.renderingCenters.get(iteration-1)[1]; - coords[2]=noise/2+this.renderingCenters.get(iteration-1)[2]; - coords[3] = 1; - } - this.renderingCenters.put(iteration,coords); - } - } - } - + @Override public boolean shouldRenderInPass(int pass) { @@ -309,13 +209,10 @@ public class TileEntityRift extends DDTileEntityBase { return countAncestorLinks(link.parent()) + 1; } - else - { - return 0; - } + return 0; } - public void grow(DDProperties properties) + public void spread(DDProperties properties) { if (worldObj.isRemote || !properties.RiftSpreadEnabled || random.nextInt(MAX_RIFT_SPREAD_CHANCE) < RIFT_SPREAD_CHANCE || this.shouldClose) @@ -346,13 +243,10 @@ public class TileEntityRift extends DDTileEntityBase public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - this.renderingCenters = new HashMap(); - this.updateTimer = nbt.getInteger("count"); - this.riftCloseTimer = nbt.getInteger("count2"); + this.updateTimer = nbt.getInteger("updateTimer"); this.xOffset = nbt.getInteger("xOffset"); this.yOffset = nbt.getInteger("yOffset"); this.zOffset = nbt.getInteger("zOffset"); - this.age = nbt.getInteger("age"); this.shouldClose = nbt.getBoolean("shouldClose"); this.spawnedEndermenID = nbt.getInteger("spawnedEndermenID"); } @@ -361,9 +255,7 @@ public class TileEntityRift extends DDTileEntityBase public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - nbt.setInteger("age", this.age); - nbt.setInteger("count", this.updateTimer); - nbt.setInteger("count2", this.riftCloseTimer); + nbt.setInteger("updateTimer", this.updateTimer); nbt.setInteger("xOffset", this.xOffset); nbt.setInteger("yOffset", this.yOffset); nbt.setInteger("zOffset", this.zOffset); @@ -371,6 +263,7 @@ public class TileEntityRift extends DDTileEntityBase nbt.setInteger("spawnedEndermenID", this.spawnedEndermenID); } + @Override public Packet getDescriptionPacket() { if (PocketManager.getLink(xCoord, yCoord, zCoord, worldObj) != null) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/util/Point4D.java b/src/main/java/StevenDimDoors/mod_pocketDim/util/Point4D.java index 2b6c4c07..2693e63b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/util/Point4D.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/util/Point4D.java @@ -141,12 +141,14 @@ public final class Point4D implements Comparable public Point3D toPoint3D() { - return new Point3D(this.x,this.y,this.z); + return new Point3D(this.x, this.y, this.z); } + public int[] toIntArray() { - return new int[]{x,y,z,dimension}; + return new int[] {x, y, z, dimension}; } + public boolean equals(Point4D other) { if (this == other) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java index f26939b6..15ddecc1 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/world/PocketBuilder.java @@ -415,7 +415,7 @@ public class PocketBuilder //Place a link leading back out of the pocket DimLink reverseLink = dimension.createLink(source.getX(), destinationY, source.getZ(), LinkTypes.REVERSE,(link.orientation()+2)%4); - parent.setDestination(reverseLink, source.getX(), source.getY(), source.getZ()); + parent.setLinkDestination(reverseLink, source.getX(), source.getY(), source.getZ()); //Build the actual pocket area buildPocket(world, source.getX(), destinationY, source.getZ(), orientation, size, wallThickness, properties, door); diff --git a/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderRift.java b/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderRift.java deleted file mode 100644 index 07c1cf95..00000000 --- a/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderRift.java +++ /dev/null @@ -1,218 +0,0 @@ -package StevenDimDoors.mod_pocketDimClient; - -import static org.lwjgl.opengl.GL11.GL_BLEND; -import static org.lwjgl.opengl.GL11.GL_LIGHTING; -import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_DST_COLOR; -import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D; -import static org.lwjgl.opengl.GL11.GL_ZERO; -import static org.lwjgl.opengl.GL11.glBlendFunc; - -import java.util.HashMap; - -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.tileentity.TileEntity; - -import org.lwjgl.opengl.GL11; - -import StevenDimDoors.mod_pocketDim.tileentities.TileEntityRift; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class RenderRift extends TileEntitySpecialRenderer -{ - - @Override - public void renderTileEntityAt(TileEntity te, double xWorld, double yWorld, - double zWorld, float f) - { - yWorld = yWorld+.75; - GL11.glPushMatrix(); - - GL11.glDisable(GL11.GL_CULL_FACE); - GL11.glDisable(GL_TEXTURE_2D); - GL11.glDisable(GL_LIGHTING); - - //GL11.glLogicOp(GL11.GL_INVERT); - // GL11.glEnable(GL11.GL_COLOR_LOGIC_OP); - - GL11.glColor4f(.2F, .2F, .2F, 1F); - - GL11.glEnable(GL_BLEND); - glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); - - /** - * just draws the verticies - */ - this.drawCrack(TileEntityRift.class.cast(te).renderingCenters, xWorld, yWorld, zWorld); - this.drawCrackRotated(TileEntityRift.class.cast(te).renderingCenters, xWorld, yWorld, zWorld); - - - GL11.glEnable(GL11.GL_CULL_FACE); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL_TEXTURE_2D); - - GL11.glDisable(GL11.GL_COLOR_LOGIC_OP); - GL11.glPopMatrix(); - - } - - public void drawCrack(HashMap quads,double xWorld,double yWorld,double zWorld) - { - GL11.glBegin(GL11.GL_QUAD_STRIP); - - drawVertex(xWorld+.5, yWorld-Math.log(Math.pow(quads.size(),2)+1)/14, zWorld+.5); - drawVertex(xWorld+.5, yWorld+Math.log(Math.pow(quads.size(),2)+1)/14, zWorld+.5); - for(int i = 0;;i++) - { - if(!quads.containsKey(i)) - { - break; - } - double[] coords = quads.get(i); - double width=Math.log(Math.pow(quads.size(),2-Math.log(i+1))+1)/14; - if(coords[3]==0) - { - - if(quads.containsKey(i+1)) - { - - drawVertex(xWorld+coords[0]+.5, yWorld+coords[1]-width/2 , zWorld+coords[2]); - drawVertex(xWorld+coords[0]+.5 , yWorld+coords[1]+width/2 , zWorld+coords[2]); - - - - } - else - { - drawVertex(xWorld+coords[0]+.5, yWorld+coords[1]-width/200 , zWorld+coords[2]); - drawVertex(xWorld+coords[0]+.5 , yWorld+coords[1]+width/200 , zWorld+coords[2]); - } - } - else - { - - - - if(quads.containsKey(i+1)) - { - drawVertex(xWorld+coords[0], yWorld+coords[1]-width/2 , zWorld+coords[2]+.5); - drawVertex(xWorld+coords[0], yWorld+coords[1]+width/2 , zWorld+coords[2]+.5); - - - } - else - { - drawVertex(xWorld+coords[0], yWorld+coords[1]+width/200 , zWorld+coords[2]+.5); - drawVertex(xWorld+coords[0], yWorld+coords[1]-width/200, zWorld+coords[2]+.5); - } - - - } - - } - - - GL11.glEnd(); - - - } - - public void drawCrackRotated(HashMap quads,double xWorld,double yWorld,double zWorld) - { - GL11.glBegin(GL11.GL_QUAD_STRIP); - - drawVertex(xWorld+.5, yWorld+Math.log(Math.pow(quads.size(),2)+1)/14, zWorld+.5); - drawVertex(xWorld+.5, yWorld-Math.log(Math.pow(quads.size(),2)+1)/14, zWorld+.5); - for(int i = 0;;i++) - { - if(!quads.containsKey(i)) - { - break; - } - double[] coords = quads.get(i); - double width=Math.log(Math.pow(quads.size(),2-Math.log(i+1))+1)/14; - if(coords[3]==0) - { - - - if(quads.containsKey(i+1)) - { - drawVertex(xWorld+coords[0]+.5, yWorld-(coords[1]-width/2) , zWorld-coords[2]+1); - drawVertex(xWorld+coords[0]+.5 , yWorld-(coords[1]+width/2) , zWorld-coords[2]+1); - - } - else - { - - drawVertex(xWorld+coords[0]+.5, yWorld-(coords[1]-width/200) , zWorld-coords[2]+1); - drawVertex(xWorld+coords[0]+.5 , yWorld-(coords[1]+width/200) , zWorld-coords[2]+1); - } - - } - else - { - - - if(quads.containsKey(i+1)) - { - - drawVertex(xWorld-coords[0]+1, yWorld-(coords[1]-width/2) , zWorld+coords[2]+.5); - drawVertex(xWorld-coords[0]+1, yWorld-(coords[1]+width/2) , zWorld+coords[2]+.5); - - } - else - { - drawVertex(xWorld-coords[0]+1, yWorld-(coords[1]+width/200) , zWorld+coords[2]+.5); - drawVertex(xWorld-coords[0]+1, yWorld-(coords[1]-width/200), zWorld+coords[2]+.5); - } - - } - } - - GL11.glEnd(); - } - - public void testDraw(HashMap quads,double xWorld,double yWorld,double zWorld) - { - GL11.glBegin(GL11.GL_QUADS); - for(int i = 0;;i++) - { - - if(!quads.containsKey(i)) - { - break; - } - double[] coords = quads.get(i); - drawVertex(xWorld-coords[0], yWorld , zWorld+.1); - drawVertex(xWorld-coords[0], yWorld+.1 , zWorld+.1); - drawVertex(xWorld-coords[0], yWorld +.1, zWorld); - drawVertex(xWorld-coords[0], yWorld , zWorld); - - - } - GL11.glEnd(); - - } - public void drawVertex(double x, double y, double z) - { - GL11.glVertex3f((float)x,(float)y,(float)z); - } - public double[] rotateCoords(int rotation, double[] coords) - { - double[] rotatedCoords = new double[4]; - if(rotation == 180) - { - - - rotatedCoords[0]=-coords[0]; - rotatedCoords[1]=-coords[1]; - - rotatedCoords[2]=-coords[2]; - rotatedCoords[3]=-coords[3]; - //return rotatedCoords; - } - return coords; - - } -} \ No newline at end of file