From 8d1028ccb5077d2935e2cc0cd5721a5a4ab7f394 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 15 May 2014 06:45:26 -0400 Subject: [PATCH 01/17] Changes to CraftingManager * Fixed a mistake in the crafting recipe for Golden Dim Doors * Removed static import of fields from mod_pocketDim. There were already qualified references to those fields in some areas. We should be consistent. --- .../mod_pocketDim/CraftingManager.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java index 24e58dff..508a0416 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java @@ -5,7 +5,6 @@ import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import cpw.mods.fml.common.registry.GameRegistry; -import static StevenDimDoors.mod_pocketDim.mod_pocketDim.*; public class CraftingManager { @@ -18,19 +17,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,37 +37,37 @@ 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), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemWarpDoor, 1), "yxy", 'x', mod_pocketDim.itemStableFabric, 'y', Item.doorWood); } if (properties.CraftingTransTrapdoorAllowed) { - GameRegistry.addRecipe(new ItemStack(transTrapdoor, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.transTrapdoor, 1), "y", "x", "y", 'x', mod_pocketDim.itemStableFabric, 'y', Block.trapdoor); } if (properties.CraftingRiftSignatureAllowed) { - GameRegistry.addRecipe(new ItemStack(itemRiftSignature, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemRiftSignature, 1), " y ", "yxy", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotIron); } if (properties.CraftingRiftRemoverAllowed) { - GameRegistry.addRecipe(new ItemStack(itemRiftRemover, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemRiftRemover, 1), "yyy", "yxy", "yyy", 'x', mod_pocketDim.itemStableFabric, '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) @@ -79,7 +78,7 @@ public class CraftingManager if (properties.CraftingGoldenDimensionalDoorAllowed) { GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldenDimensionalDoor,1), - "yxy", 'x', mod_pocketDim.itemGoldenDoor, 'y', mod_pocketDim.itemStableFabric); + "yxy", 'x', mod_pocketDim.itemStableFabric, 'y', mod_pocketDim.itemGoldenDoor); } if (properties.CraftingGoldenDoorAllowed) { From 4d39d13703490cc62f4a1ef8d0eb9965c69f7af9 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 25 Jun 2014 14:04:08 -0400 Subject: [PATCH 02/17] Changes to Monolith Behavior 1. Stopped Monoliths from teleporting players while in Limbo. This was a serious issue on some modpacks if players got unlucky. 2. Decreased the required Monolith aggro level to start spawning particles around a target player. The required level was so high, combined with the current Monolith speed, that players would hardly see the particles. 3. Disabled Monolith sounds in Limbo. Some of the sounds were really annoying in Limbo. Usually they only get to play for a moment before a player is teleported, but since no teleports occur in Limbo and the area is full of Monoliths, the constant noise is aggravating. It would also drown out the background music. --- .../mod_pocketDim/ticking/MobMonolith.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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; From 660ff4255e7da6b6a36b3e8477ca56a114e11bf2 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 25 Jun 2014 14:33:19 -0400 Subject: [PATCH 03/17] Code Cleaning 1. Cleaned up some spacing and unused imports in EventHookContainer. Also changed an indirect reference to BaseItemDoor.trytoPlaceDoor() to a direct reference seeing as the function is static and should be accessed that way. 2. Renamed getDoortoItemMapping() to getDoorBlock(). The original named had a minor capitalization mistake and implied that it would return a mapping table or would associate doors to items. The function actually associates items to door blocks. --- .../mod_pocketDim/EventHookContainer.java | 10 +++------- .../mod_pocketDim/items/BaseItemDoor.java | 6 +++--- .../mod_pocketDim/items/ItemDimensionalDoor.java | 2 +- .../mod_pocketDim/items/ItemGoldDimDoor.java | 2 +- .../mod_pocketDim/items/ItemUnstableDoor.java | 2 +- .../mod_pocketDim/items/ItemWarpDoor.java | 2 +- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 4e47d8fc..773877bb 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,9 +88,9 @@ public class EventHookContainer ItemStack stack = event.entityPlayer.inventory.getCurrentItem(); if (stack != null && stack.getItem() instanceof ItemDoor) { - if(BaseItemDoor.getDoorToPlace(stack.getItem())!=null) + if (BaseItemDoor.getDoorToPlace(stack.getItem()) != null) { - if (mod_pocketDim.itemDimensionalDoor.tryToPlaceDoor(stack, event.entityPlayer, world, + if (BaseItemDoor.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 diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java index dafcd913..ddd25027 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; @@ -64,7 +65,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,7 +74,6 @@ 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; } @@ -87,7 +87,7 @@ public abstract class BaseItemDoor extends ItemDoor { return null; } - return ((BaseItemDoor) item).getDoortoItemMapping(); + return ((BaseItemDoor) item).getDoorBlock(); } /** 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/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; } From e4e84644acedf54ccae9807391b4a6b8876a0297 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 25 Jun 2014 14:56:59 -0400 Subject: [PATCH 04/17] Changed Door Item Mapping Code 1. Changed EventHookContainer to remove a check against BaseItemDoor.getDoorToPlace(). The checks performed there can be done in BaseItemDoor.tryToPlaceDoor(), which removes the need for callers to know more internal details about how doors are handled. I moved the checks inside. 2. Renamed vanillaDoorMapping to doorItemMapping. It now maps dim door items to themselves to remove the need for various checks we were performing. Updated BaseItemDoor's constructor to reflect this change. 3. Removed BaseItemDoor.getDoorToPlace() and integrated its functionality into BaseItemDoor.tryToPlaceDoor(). 4. Changed BaseItemDoor.tryToPlaceDoor() so that it simply returns false if a given item stack cannot be used to place any doors. We don't need to check if the item is an ItemDoor or anything like that now. --- .../mod_pocketDim/EventHookContainer.java | 11 ++---- .../mod_pocketDim/items/BaseItemDoor.java | 39 ++++++++----------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java index 773877bb..4130aaf8 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/EventHookContainer.java @@ -88,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 (BaseItemDoor.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/items/BaseItemDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java index ddd25027..538d0592 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java @@ -24,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; /** @@ -35,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); @@ -43,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); } } @@ -77,19 +78,6 @@ public abstract class BaseItemDoor extends ItemDoor 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).getDoorBlock(); - } - /** * Tries to place a door block, called in EventHookContainer * @@ -111,15 +99,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); } /** From a4d0f3939099de2926fd1e034439ebfd824b6199 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 25 Jun 2014 15:08:30 -0400 Subject: [PATCH 05/17] Minor Change Cleaned up comments for BaseItemDoor.tryToPlaceDoor() --- .../StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java index 538d0592..3ad3a4b2 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/BaseItemDoor.java @@ -79,9 +79,8 @@ public abstract class BaseItemDoor extends ItemDoor } /** - * 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 @@ -89,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) From 794310bd986cf9a94320a5daa7bceea933493d08 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 25 Jun 2014 15:18:50 -0400 Subject: [PATCH 06/17] Fixed Max Stack Size of ItemGoldDoor Changed the max stack size of ItemGoldDoor to 16 as it is for Vanilla doors on some modpacks. Later versions of Vanilla have door stacking to 64 so this will need to change eventually. --- .../java/StevenDimDoors/mod_pocketDim/items/ItemGoldDoor.java | 1 + 1 file changed, 1 insertion(+) 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 From 0029d9dac02e5b8274cd33fa770f547e63d1cb18 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 25 Jun 2014 19:00:41 -0400 Subject: [PATCH 07/17] Reduced Usage of Stable Fabric 1. Changed the crafting recipes for most DD items to use Ender Pearls instead of Stable Fabric. The items that still use Stable Fabric are Dimensional Doors, Golden Dimensional Doors, Rift Blades, and Stabilized Rift Signatures. Steven had already made this change in another branch but I'd like to push this out with several bug fixes. The SRS recipe is different from his version - it's now just 4 Iron Ingots and a Stable Fabric. 2. Change Stabilized Rift Signatures back to consuming Ender Pearls instead of Stable Fabric. --- .../mod_pocketDim/CraftingManager.java | 14 +++++++------- .../items/ItemStabilizedRiftSignature.java | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java index 508a0416..5f76964d 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java @@ -48,22 +48,22 @@ public class CraftingManager if (properties.CraftingWarpDoorAllowed) { GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemWarpDoor, 1), - "yxy", 'x', mod_pocketDim.itemStableFabric, 'y', Item.doorWood); + "yxy", 'x', Item.enderPearl, 'y', Item.doorWood); } if (properties.CraftingTransTrapdoorAllowed) { GameRegistry.addRecipe(new ItemStack(mod_pocketDim.transTrapdoor, 1), - "y", "x", "y", 'x', mod_pocketDim.itemStableFabric, 'y', Block.trapdoor); + "y", "x", "y", 'x', Item.enderPearl, 'y', Block.trapdoor); } if (properties.CraftingRiftSignatureAllowed) { GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemRiftSignature, 1), - " y ", "yxy", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotIron); + " y ", "yxy", " y ", 'x', Item.enderPearl, 'y', Item.ingotIron); } if (properties.CraftingRiftRemoverAllowed) { GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemRiftRemover, 1), - "yyy", "yxy", "yyy", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotGold); + "yyy", "yxy", "yyy", 'x', Item.enderPearl, 'y', Item.ingotGold); } if (properties.CraftingRiftBladeAllowed) { @@ -72,12 +72,12 @@ public class CraftingManager } 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.itemStabilizedLinkSignature, 1), + " y ", "yxy", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotIron); } if (properties.CraftingGoldenDimensionalDoorAllowed) { - GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldenDimensionalDoor,1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldenDimensionalDoor, 1), "yxy", 'x', mod_pocketDim.itemStableFabric, 'y', mod_pocketDim.itemGoldenDoor); } if (properties.CraftingGoldenDoorAllowed) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index 4d1cf840..e04afdff 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -54,10 +54,10 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature 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)) + // or if the player can pay with an Ender Pearl to create a rift. + if (!player.capabilities.isCreativeMode && !player.inventory.hasItem(Item.enderPearl.itemID)) { - mod_pocketDim.sendChat(player, "You don't have any Stable Fabric!"); + 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 @@ -88,7 +88,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature if (!player.capabilities.isCreativeMode) { - player.inventory.consumeInventoryItem(mod_pocketDim.itemStableFabric.itemID); + player.inventory.consumeInventoryItem(Item.enderPearl.itemID); } mod_pocketDim.sendChat(player,"Rift Created"); world.playSoundAtEntity(player,"mods.DimDoors.sfx.riftEnd", 0.6f, 1); From 4192270ef34540db112e11c2c89d1b0fc2af2953 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 25 Jun 2014 20:13:03 -0400 Subject: [PATCH 08/17] Changes and Fixes to Rift Signature Variants 1. Changed hasEffect() override since we were overriding a deprecated version. 2. Fixed a bug where we checked if a block could be edited before deciding whether to change the Y coordinate of the rift to be placed. Sometimes we would place the rift in a different block. This is the result of sticking in support for special blocks like grass and snow without considering the impact on surrounding code. It also contradicted comments that specifically said special blocks were ignored... 3. Cleaned up the code for checking for special blocks. 4. Fixed a bug in loading NBT data. There were no null checks on orientation data. If a Rift Signature or Stabilized Rift Signature had been created in a version of DD before orientations were set up, then it cause an exception when so much as looked at in later versions of DD. 5. Partially implemented free redirects for Stabilized Rift Signatures. The check to determine if a redirect is being done is missing. --- .../items/ItemRiftSignature.java | 41 ++++++---- .../items/ItemStabilizedRiftSignature.java | 82 +++++++++++-------- 2 files changed, 71 insertions(+), 52 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index a20bc468..14cf0819 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. @@ -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; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index e04afdff..043cc270 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); // 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; if (source != null) { - // Yes, it's initialized. Check if the player is in creative - // or if the player can pay with an Ender Pearl to create a rift. - if (!player.capabilities.isCreativeMode && !player.inventory.hasItem(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; - } - - //The link was used before and already has an endpoint stored. Create links connecting the two endpoints. + // Yes, it's initialized. + DimLink link; + DimLink reverse; 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)) + + // 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 (false) //TODO Add proper check! { - 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.setDestination(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.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)) + { + 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(Item.enderPearl.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); From fe035f6677767c9180278c6e8171be84bd175121 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Wed, 25 Jun 2014 20:15:43 -0400 Subject: [PATCH 09/17] Renamed Function in NewDimData Renamed NewDimData.setDestination() to setLinkDestination(). I realized that the name was a little confusing at first sight - it confused me! --- .../StevenDimDoors/mod_pocketDim/core/DDTeleporter.java | 6 +++--- .../java/StevenDimDoors/mod_pocketDim/core/NewDimData.java | 6 +++--- .../mod_pocketDim/dungeon/DungeonSchematic.java | 2 +- .../mod_pocketDim/items/ItemRiftSignature.java | 4 ++-- .../mod_pocketDim/items/ItemStabilizedRiftSignature.java | 6 +++--- .../StevenDimDoors/mod_pocketDim/saving/DDSaveHandler.java | 2 +- .../StevenDimDoors/mod_pocketDim/world/PocketBuilder.java | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) 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/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/ItemRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index 14cf0819..b4b52e43 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -76,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)) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index 043cc270..488227cd 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -67,7 +67,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature { // Only the source-to-destination link is needed. link = sourceDimension.createLink(source.getX(), source.getY(), source.getZ(), LinkTypes.NORMAL, source.getOrientation()); - destinationDimension.setDestination(link, x, adjustedY, z); + destinationDimension.setLinkDestination(link, x, adjustedY, z); } else { @@ -86,8 +86,8 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature // 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.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)) 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/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); From 448890207f17315f6bb55d867f6ba7fd818c9e53 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 26 Jun 2014 04:52:03 -0400 Subject: [PATCH 10/17] Completed Changes to Stabilized Rift Signature Completed the change to Stabilized Rift Signatures so that overwriting links that already belonged to an SRS is done for free. --- .../mod_pocketDim/items/ItemRiftSignature.java | 11 +++++++++-- .../items/ItemStabilizedRiftSignature.java | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java index b4b52e43..9cc5053f 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemRiftSignature.java @@ -219,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() @@ -244,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 488227cd..66ee5fdd 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -52,10 +52,10 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature if (source != null) { // Yes, it's initialized. - DimLink link; - DimLink reverse; 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 @@ -63,7 +63,7 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature // intention of overwriting the source-side link to point there. // Those benign redirection operations will be handled for free. - if (false) //TODO Add proper check! + 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()); From 96238d6b53ee064c649cc1f6a2be305f21390bb8 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 26 Jun 2014 04:52:32 -0400 Subject: [PATCH 11/17] Minor Change Minor spacing and annotation changes. --- .../java/StevenDimDoors/mod_pocketDim/core/DimLink.java | 3 +++ .../java/StevenDimDoors/mod_pocketDim/util/Point4D.java | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) 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/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) From 364ba11f811002da3939a77db6c038ee6209b809 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 26 Jun 2014 05:40:35 -0400 Subject: [PATCH 12/17] Updates to TileEntityRift 1. Fixed the bug where the setting that controls whether Endermen can spawn from rifts was being ignored. It was never checked at all. 2. Cleaned up some formatting and annotations. 3. Removed call to World.removeBlockTileEntity() following a call to World.setBlockToAir(). The latter function already handles removing the tile entity. --- .../tileentities/TileEntityRift.java | 44 ++++++------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java index d6e781b6..5b0dea3c 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java @@ -1,17 +1,10 @@ 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 +12,8 @@ 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; @@ -61,22 +50,21 @@ public class TileEntityRift extends DDTileEntityBase public DimLink nearestRiftData; public int spawnedEndermenID = 0; public HashMap renderingCenters = new HashMap(); - + @Override public void updateEntity() { - //Determines if rift should render white closing particles and spread closing effect to other rifts nearby + // Determines if rift should render white closing particles and spread closing effect to other rifts nearby if (this.shouldClose) { closeRift(); } - else if( PocketManager.getLink(xCoord, yCoord, zCoord, worldObj.provider.dimensionId) == null) + 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; } @@ -101,21 +89,19 @@ public class TileEntityRift extends DDTileEntityBase **/ //This code should execute once every 10 seconds - if (updateTimer > 200) + if (updateTimer >= 200) { - this.spawnEndermen(); + this.spawnEndermen(mod_pocketDim.properties); this.grow(mod_pocketDim.properties); updateTimer = 0; } - else if(updateTimer==0) + else if (updateTimer == 0) { this.calculateOldParticleOffset(); //this also calculates the distance for the particle stuff. } updateTimer++; } - - private void clearBlocksOnRift() { //clears blocks for the new rending effect @@ -138,25 +124,23 @@ public class TileEntityRift extends DDTileEntityBase } } - private void spawnEndermen() + private void spawnEndermen(DDProperties properties) { - 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, @@ -210,10 +194,10 @@ public class TileEntityRift extends DDTileEntityBase if (riftCloseTimer > 40) { 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); } @@ -228,8 +212,7 @@ public class TileEntityRift extends DDTileEntityBase private void calculateOldParticleOffset() { - updateNearestRift(); - if (nearestRiftData != null) + if (updateNearestRift()) { Point4D location = nearestRiftData.source(); this.xOffset = this.xCoord - location.getX(); @@ -371,6 +354,7 @@ public class TileEntityRift extends DDTileEntityBase nbt.setInteger("spawnedEndermenID", this.spawnedEndermenID); } + @Override public Packet getDescriptionPacket() { if (PocketManager.getLink(xCoord, yCoord, zCoord, worldObj) != null) From a0629b51a369104f0b2c9b785fc8d337c07c8b92 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 26 Jun 2014 07:06:17 -0400 Subject: [PATCH 13/17] Improvements to TileEntityRift 1. Removed several fields and functions referring to the newer rendering code. The functions were just cluttering up the code and the fields were consuming additional memory that was never being used for anything. 2. Updated NBT reading and writing functions to give some tags proper names and to remove references to unused fields. Removed the tag for riftCloseTimer because it was unnecessary alongside the shouldClose flag. If a server reboots while a rift is closing, the rift can start over upon reloading. 3. Renamed some fields and functions to have better names. 4. Changed the various checks for closing rifts. There were a few redundant parts. We don't have to put calls to "this.invalidate()" everywhere on top of explicitly removing the tile entity and destroying its block. 5. Rewrote update timing checks. The rift spread and Enderman spawning calls have been separated to distribute the impact of updating a rift. Also, a flaw in the timing logic meant that the calculations for particle offsets would only run when a rift was first created. That's been fixed. --- .../tileentities/TileEntityRift.java | 184 +++++------------- 1 file changed, 47 insertions(+), 137 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java index 5b0dea3c..0effc8bf 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java @@ -1,7 +1,6 @@ package StevenDimDoors.mod_pocketDim.tileentities; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Random; @@ -13,7 +12,6 @@ import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet132TileEntityData; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.MathHelper; import StevenDimDoors.mod_pocketDim.ServerPacketHandler; import StevenDimDoors.mod_pocketDim.mod_pocketDim; import StevenDimDoors.mod_pocketDim.config.DDProperties; @@ -33,97 +31,71 @@ 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); - 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) + { + closeRift(); + return; + } + + if (updateTimer >= UPDATE_PERIOD) { this.spawnEndermen(mod_pocketDim.properties); - this.grow(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() - { - //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(DDProperties properties) { if (worldObj.isRemote || !properties.RiftsSpawnEndermenEnabled) @@ -174,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) { @@ -191,9 +163,8 @@ public class TileEntityRift extends DDTileEntityBase } } } - if (riftCloseTimer > 40) + if (closeTimer >= CLOSING_PERIOD) { - this.invalidate(); if (!this.worldObj.isRemote) { DimLink link = PocketManager.getLink(this.xCoord, this.yCoord, this.zCoord, worldObj); @@ -204,13 +175,12 @@ public class TileEntityRift extends DDTileEntityBase } 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; } - riftCloseTimer++; + closeTimer++; } - private void calculateOldParticleOffset() + private void calculateParticleOffsets() { if (updateNearestRift()) { @@ -218,68 +188,16 @@ public class TileEntityRift extends DDTileEntityBase 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) { @@ -292,13 +210,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) @@ -329,13 +244,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"); } @@ -344,9 +256,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); From 444b862b12e9d51c289c57b341a52838339b8467 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 26 Jun 2014 09:19:04 -0400 Subject: [PATCH 14/17] Minor Change Renamed the field mod_pocketDim.itemStabilizedLinkSignature to itemStabilizedRiftSignature to follow the item's actual name. --- .../java/StevenDimDoors/mod_pocketDim/CraftingManager.java | 2 +- .../java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java index 5f76964d..6ff7121e 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java @@ -72,7 +72,7 @@ public class CraftingManager } if (properties.CraftingStabilizedRiftSignatureAllowed) { - GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemStabilizedLinkSignature, 1), + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemStabilizedRiftSignature, 1), " y ", "yxy", " y ", 'x', mod_pocketDim.itemStableFabric, 'y', Item.ingotIron); } if (properties.CraftingGoldenDimensionalDoorAllowed) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java index 239b1370..267f644e 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"); From 59f335ac8c7bdf37de0925748ee896540e05769a Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 26 Jun 2014 12:11:51 -0400 Subject: [PATCH 15/17] Added Dispenser Support for SRS Added support for using Stabilized Rift Signatures from dispensers under specific conditions. Everything works except for playing the sound that occurs when an SRS is used. Not sure why that's not working. --- .../mod_pocketDim/CraftingManager.java | 9 +++- .../items/ItemStabilizedRiftSignature.java | 52 ++++++++++++++++++- .../DispenserBehaviorStabilizedRS.java | 42 +++++++++++++++ .../mod_pocketDim/mod_pocketDim.java | 1 + 4 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/main/java/StevenDimDoors/mod_pocketDim/items/behaviors/DispenserBehaviorStabilizedRS.java diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java index 6ff7121e..7cc635d8 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java @@ -1,9 +1,11 @@ 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; public class CraftingManager @@ -87,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/items/ItemStabilizedRiftSignature.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java index 66ee5fdd..b47bff6b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemStabilizedRiftSignature.java @@ -45,10 +45,10 @@ public class ItemStabilizedRiftSignature extends ItemRiftSignature { return true; } - Point4DOrientation source = getSource(stack); + 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. @@ -117,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/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 267f644e..6554a6a0 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/mod_pocketDim.java @@ -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); From e40168954f17b6832c4f3cea997c59641cd790f2 Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 26 Jun 2014 12:17:59 -0400 Subject: [PATCH 16/17] Minor Change to TileEntityRift Changed the function call for playing the rift-closing sound to match other similar calls in Minecraft - the sound should target the center of the block. I also switched the last flag argument. It seems to determine whether distance between the player and the source should be checked when playing back the sound, although documentation is lacking so I can't be sure. Other blocks that use that function use "false", while things involving sounds that should be heard uniformly, such as rainfall, use "true". --- I noticed that this code runs on the client and server. Some parts modify link data and rifts on the client side. We should really stop this from happening as it could lead to inconsistencies. --- .../mod_pocketDim/tileentities/TileEntityRift.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java index 0effc8bf..13f9f96a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/tileentities/TileEntityRift.java @@ -174,8 +174,7 @@ public class TileEntityRift extends DDTileEntityBase } } worldObj.setBlockToAir(xCoord, yCoord, zCoord); - worldObj.playSound(xCoord, yCoord, zCoord, "mods.DimDoors.sfx.riftClose", (float) .7, 1, true); - return; + worldObj.playSound(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, "mods.DimDoors.sfx.riftClose", 0.7f, 1, false); } closeTimer++; } From 42568a1864a5416eedf78b708c2a509754f3229d Mon Sep 17 00:00:00 2001 From: SenseiKiwi Date: Thu, 26 Jun 2014 12:20:19 -0400 Subject: [PATCH 17/17] Removed RenderRift Removed the RenderRift class since it relates to unused functionality and references fields that I removed from TileEntityRift. --- .../mod_pocketDimClient/RenderRift.java | 218 ------------------ 1 file changed, 218 deletions(-) delete mode 100644 src/main/java/StevenDimDoors/mod_pocketDimClient/RenderRift.java 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