diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java index 24e58dff..063fa44a 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/CraftingManager.java @@ -1,15 +1,21 @@ package StevenDimDoors.mod_pocketDim; import StevenDimDoors.mod_pocketDim.config.DDProperties; +import StevenDimDoors.mod_pocketDim.core.DimLink; +import StevenDimDoors.mod_pocketDim.items.ItemDDKey; import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.registry.GameRegistry; import static StevenDimDoors.mod_pocketDim.mod_pocketDim.*; -public class CraftingManager +public class CraftingManager implements ICraftingHandler { - private CraftingManager() { } + CraftingManager() { } public static void registerRecipes(DDProperties properties) { @@ -86,6 +92,55 @@ public class CraftingManager GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemGoldenDoor, 1), "yy", "yy", "yy", 'y', Item.ingotGold); } + if (properties.CraftingDDKeysAllowed) + { + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemDDKey, 1), + " x ", " x ", "yzy", 'y', Item.ingotGold, 'x', Item.ingotIron, 'z', mod_pocketDim.itemStableFabric); + GameRegistry.addRecipe(new ItemStack(mod_pocketDim.itemDDKey, 1), + "z", "z", 'z', mod_pocketDim.itemDDKey); + } + + } + + @Override + public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) + { + if(item.getItem() instanceof ItemDDKey) + { + ItemDDKey keyItem = (ItemDDKey) item.getItem(); + ItemStack topKey = null; + ItemStack bottomKey = null; + int topKeySlot = 0; + + for(int i = 0; i 0 && neighborID != this.blockID) { this.onNeighborBlockChange(world, x, y - 1, z, neighborID); @@ -358,7 +353,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn this.dropBlockAsItem(world, x, y, z, metadata, 0); } } - else + else if(!this.hasLock(world, x, y, z)) { boolean powered = world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z); if ((powered || neighborID > 0 && Block.blocksList[neighborID].canProvidePower()) && neighborID != this.blockID) @@ -490,7 +485,6 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn return false; } DimLink link = getLink(world, x, y, z); - ItemStack itemStack; for(ItemStack item : player.inventory.mainInventory) { @@ -498,7 +492,7 @@ public abstract class BaseDimDoor extends BlockDoor implements IDimDoor, ITileEn { if(item.getItem() instanceof ItemDDKey) { - if(ItemDDKey.getBoundLink(item)==link) + if(((ItemDDKey) item.getItem()).canKeyOpen(link, item)) { return true; } diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/config/DDProperties.java b/src/main/java/StevenDimDoors/mod_pocketDim/config/DDProperties.java index f86c5144..8cf94ae3 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/config/DDProperties.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/config/DDProperties.java @@ -47,7 +47,6 @@ public class DDProperties public final int WarpDoorItemID; public final int WorldThreadItemID; public final int DDKeyItemID; - public final int DDLockCreatorItemID; /** @@ -77,6 +76,8 @@ public class DDProperties public final boolean CraftingStableFabricAllowed; public final boolean CraftingGoldenDimensionalDoorAllowed; public final boolean CraftingGoldenDoorAllowed; + public final boolean CraftingDDKeysAllowed; + /** * Loot Flags @@ -149,7 +150,8 @@ public class DDProperties CraftingStableFabricAllowed = config.get(CATEGORY_CRAFTING, "Allow Crafting Stable Fabric", true).getBoolean(true); CraftingGoldenDoorAllowed = config.get(CATEGORY_CRAFTING, "Allow Crafting Golden Door", true).getBoolean(true); CraftingGoldenDimensionalDoorAllowed = config.get(CATEGORY_CRAFTING, "Allow Crafting Golden Dimensional Door", true).getBoolean(true); - + CraftingDDKeysAllowed = config.get(CATEGORY_CRAFTING, "Allow Crafting Rift Keys", true).getBoolean(true); + WorldThreadRequirementLevel = config.get(CATEGORY_CRAFTING, "World Thread Requirement Level", 4, "Controls the amount of World Thread needed to craft Stable Fabric. The number must be an " + "integer from 1 to 4. The levels change the recipe to use 1, 2, 4, or 8 threads, respectively. The default level is 4.").getInt(); @@ -207,7 +209,6 @@ public class DDProperties GoldenDimensionalDoorItemID = config.getItem("Gold Dim Door Item ID", 5679).getInt(); WorldThreadItemID = config.getItem("World Thread Item ID", 5680).getInt(); DDKeyItemID = config.getItem("Rift Key Item ID", 5681).getInt(); - DDLockCreatorItemID = config.getItem("Rift Interlock Item ID", 5682).getInt(); LimboBlockID = config.getTerrainBlock("World Generation Block IDs - must be less than 256", "Limbo Block ID", 217, "Blocks used for the terrain in Limbo").getInt(); diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemDDKey.java b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemDDKey.java index 6f645535..7a74d6a0 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemDDKey.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/items/ItemDDKey.java @@ -1,14 +1,22 @@ package StevenDimDoors.mod_pocketDim.items; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; import StevenDimDoors.mod_pocketDim.mod_pocketDim; +import StevenDimDoors.mod_pocketDim.blocks.IDimDoor; import StevenDimDoors.mod_pocketDim.core.DimLink; import StevenDimDoors.mod_pocketDim.core.PocketManager; @@ -18,8 +26,17 @@ public class ItemDDKey extends Item { super(itemID); this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab); + this.setMaxStackSize(1); + } + public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) + { + boolean check = (this.isBound(par1ItemStack) ? par3List.add("Bound") : par3List.add("Unbound")); + return; + } + + @Override public void registerIcons(IconRegister par1IconRegister) { @@ -30,44 +47,185 @@ public class ItemDDKey extends Item @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack par1ItemStack) { - return true; + return !this.isBound(par1ItemStack); } - public static void setBoundDoor(ItemStack itemStack, DimLink link) + public boolean onItemUseFirst(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float playerX, float playerY, + float playerZ) { + if(world.isRemote) + { + return false; + } + int blockID = world.getBlockId(x, y, z); + //make sure we are dealing with a door + if (!(Block.blocksList[blockID] instanceof IDimDoor)) + { + return false; + } + + DimLink link = PocketManager.getLink(x, y, z, world); + //dont do anything to doors without links + if (link == null) + { + return false; + } + //make sure we are not trying to mess with a door thats already locked by someone else + if(!this.canKeyOpen(link, itemStack)&&link.isLocked()) + { + return false; + } + + //see if we can bind this key to this door and lock it + if(setBoundDoor(itemStack, link)) + { + link.setLocked(true); + return false; + } + + //lastly, just see if we can toggle the door's lock state if its locked. + if(this.canKeyOpen(link, itemStack)) + { + link.setLocked(!link.isLocked()); + return false; + } + + return false; + } + + + public boolean setBoundDoor(ItemStack itemStack, DimLink link) + { + //dont bind to a door if we already are bound, or if we dont have permission to lock that door + if(this.isBound(itemStack)|| (!this.canKeyOpen(link, itemStack)&&link.isLocked())) + { + return false; + } + + //dont bind if the door has a lock already on it, but we can still open it. That would waste the key. + if(link.isLocked()) + { + return false; + } + + //init tags + if(!itemStack.hasTagCompound()) + { + this.initNBTTags(itemStack); + } + + //consume this keys ability to create a lock + itemStack.getTagCompound().setBoolean("HasLockedDoor", true); + + //create the tag that binds this door to this key NBTTagCompound tag = new NBTTagCompound(); int x = link.source().getX(); int y = link.source().getY(); int z = link.source().getZ(); - tag.setInteger("linkX", x); - tag.setInteger("linkY", y); - tag.setInteger("linkZ", z); - tag.setInteger("linkDimID", link.source().getDimension()); + tag.setInteger("x", x); + tag.setInteger("y", y); + tag.setInteger("z", z); + tag.setInteger("dim", link.source().getDimension()); - itemStack.setTagCompound(tag); - itemStack.setItemDamage(1); + //add this door's tag to this keys keyring + NBTTagList keyRing = itemStack.getTagCompound().getTagList("DDKeys"); + keyRing.appendTag(tag); + itemStack.getTagCompound().setTag("DDKeys", keyRing); + + return true; + } + + /** + * copies all the tags from the first key onto the second key + * @param givingKey + * @param receivingKey + */ + public void addDoorToKey(ItemStack givingKey, ItemStack receivingKey) + { + //cant copy tags from a key with no tags + if(!givingKey.hasTagCompound()) + { + return; + } + + //initialize the receiving key + if(!receivingKey.hasTagCompound()) + { + this.initNBTTags(receivingKey); + } + + //get the tags + NBTTagCompound recevingTags = receivingKey.getTagCompound(); + NBTTagCompound sendingTags = (NBTTagCompound) givingKey.getTagCompound().copy(); + + //copy over the actual tags + for(int i = 0; i3) + { + return; + } + int rotation = (tile.orientation+3)%4; + + GL11.glPushMatrix(); + GL11.glTranslated(x,y,z); + x= ActiveRenderInfo.objectX; + y = ActiveRenderInfo.objectY; + z = ActiveRenderInfo.objectZ; + + + + + GL11.glRotatef(180.0F - 90*rotation, 0.0F, 1.0F, 0.0F); + //GL11.glRotatef((float)(-90 * rotation), 0.0F, 0.0F, 1.0F); + + switch (rotation) + { + case 0: + GL11.glTranslatef(-0.5F, .24F, -0.03F); + break; + case 1: + GL11.glTranslatef(-.5F, .24F, .97F); + break; + case 2: + GL11.glTranslatef(.5F, .24F, .97F); + break; + case 3: + GL11.glTranslatef(0.5F, .24F, -0.03F); + } + + GL11.glDisable(GL_LIGHTING); + Tessellator tessellator = Tessellator.instance; + GL11.glEnable(GL11.GL_BLEND); + if(i==1) + { + bindTexture(KeyholeLight); + GL11.glColor4d(1, 1, 1, .6); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_COLOR); + + } + else + { + bindTexture(keyPath); + GL11.glColor4d(.0, .7, .1, 1); + + glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); + + } + GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); + GL11.glScalef(0.00860625F, 0.00730625F, 0.0086625F); + GL11.glTranslatef(-65.0F, -107.0F, -3.0F); + GL11.glNormal3f(0.0F, 0.0F, -1.0F); + tessellator.startDrawingQuads(); + byte b0 = 7; + tessellator.addVertexWithUV((double)(0 - b0), (double)(128 + b0), 0.0D, 0.0D, 1.0D); + tessellator.addVertexWithUV((double)(128 + b0), (double)(128 + b0), 0.0D, 1.0D, 1.0D); + tessellator.addVertexWithUV((double)(128 + b0), (double)(0 - b0), 0.0D, 1.0D, 0.0D); + tessellator.addVertexWithUV((double)(0 - b0), (double)(0 - b0), 0.0D, 0.0D, 0.0D); + tessellator.draw(); + GL11.glTranslatef(0.0F, 0.0F, -1.0F); + GL11.glDisable(GL11.GL_BLEND); + + + GL11.glPopMatrix(); + } + + @Override public void renderTileEntityAt(TileEntity par1TileEntity, double par2, double par4, double par6, float par8) { @@ -279,7 +366,13 @@ public class RenderDimDoor extends TileEntitySpecialRenderer if (tile.openOrClosed) { renderDimDoorTileEntity((TileEntityDimDoor) par1TileEntity, par2, par4, par6); + for(int i = 0; i<2; i++ ) + { + this.renderKeyHole(tile, par2, par4, par6, i); + + } } + } } } \ No newline at end of file diff --git a/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderRift.java b/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderRift.java index 07c1cf95..8782e2bc 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderRift.java +++ b/src/main/java/StevenDimDoors/mod_pocketDimClient/RenderRift.java @@ -39,7 +39,7 @@ public class RenderRift extends TileEntitySpecialRenderer GL11.glColor4f(.2F, .2F, .2F, 1F); GL11.glEnable(GL_BLEND); - glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); + glBlendFunc(GL11.GL_SRC_ALPHA_SATURATE,GL_ONE_MINUS_DST_COLOR); /** * just draws the verticies diff --git a/src/main/resources/assets/dimdoors/RIFT.png b/src/main/resources/assets/dimdoors/RIFT.png deleted file mode 100644 index ae24e834..00000000 Binary files a/src/main/resources/assets/dimdoors/RIFT.png and /dev/null differ diff --git a/src/main/resources/assets/dimdoors/WARP.png b/src/main/resources/assets/dimdoors/WARP.png deleted file mode 100644 index fd8efb2c..00000000 Binary files a/src/main/resources/assets/dimdoors/WARP.png and /dev/null differ diff --git a/src/main/resources/assets/dimdoors/textures/other/keyOutline.png b/src/main/resources/assets/dimdoors/textures/other/keyOutline.png new file mode 100644 index 00000000..7cc27136 Binary files /dev/null and b/src/main/resources/assets/dimdoors/textures/other/keyOutline.png differ diff --git a/src/main/resources/assets/dimdoors/textures/other/keyOutlineLight.png b/src/main/resources/assets/dimdoors/textures/other/keyOutlineLight.png new file mode 100644 index 00000000..382c1d05 Binary files /dev/null and b/src/main/resources/assets/dimdoors/textures/other/keyOutlineLight.png differ diff --git a/src/main/resources/assets/dimdoors/textures/other/keyhole.png b/src/main/resources/assets/dimdoors/textures/other/keyhole.png new file mode 100644 index 00000000..262a8e5e Binary files /dev/null and b/src/main/resources/assets/dimdoors/textures/other/keyhole.png differ diff --git a/src/main/resources/assets/dimdoors/textures/other/keyholeLight.png b/src/main/resources/assets/dimdoors/textures/other/keyholeLight.png new file mode 100644 index 00000000..e6fcfc63 Binary files /dev/null and b/src/main/resources/assets/dimdoors/textures/other/keyholeLight.png differ