From 6e097a5056ad343271e21109f593f7cb77e4667e Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 5 Sep 2019 20:11:13 -0400 Subject: More affix work, and some other cleanups --- .../tileentity/TileEntityShadowEye.java | 284 ++++++++++++++++----- 1 file changed, 217 insertions(+), 67 deletions(-) (limited to 'src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java') diff --git a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java index 65be5cb..4cfbbc8 100755 --- a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java +++ b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.affixes.AffixMods; import darkknight.jewelrycraft.block.BlockHandPedestal; import darkknight.jewelrycraft.block.BlockList; import darkknight.jewelrycraft.config.ConfigHandler; @@ -61,10 +62,30 @@ public class TileEntityShadowEye extends TileEntity { @Override public void updateEntity() { super.updateEntity(); - boolean valid = isValidStructure(worldObj, xCoord, yCoord, zCoord, blockMetadata); - boolean canStartRitual = valid - && ((TileEntityHandPedestal) worldObj.getTileEntity(xCoord, yCoord - 3, zCoord)).heldItemStack != null - && getNumberOfItems(worldObj, xCoord, yCoord, zCoord) > 0; + StringBuilder er = new StringBuilder(); + boolean valid = isValidStructure(worldObj, xCoord, yCoord, zCoord, blockMetadata, er); + boolean centerHasItem = false, hasMods = false, hasAffixes = false; + if (valid) { + TileEntity te = worldObj.getTileEntity(xCoord, yCoord - 3, zCoord); + if (te instanceof TileEntityHandPedestal) { + centerHasItem = ((TileEntityHandPedestal) te).heldItemStack != null; + } + + hasMods = getNumberOfItems(worldObj, xCoord, yCoord, zCoord) > 0; + + hasAffixes = worldObj.getBlock(xCoord, yCoord + 2, zCoord) == Blocks.enchanting_table; + } + + boolean canStartRitual = valid && centerHasItem && (hasMods || hasAffixes); + if (!canStartRitual && valid) { + if (!centerHasItem) { + er.append("Center pedestal requires an item"); + } else if (!hasMods && !hasAffixes) { + er.append("Need at least one modifier, or an enchanting table for affixes."); + } else { + er.append("Unknown issue"); + } + } if (active) { timer--; if (canStartRitual && canChangePedestals(worldObj, xCoord, yCoord, zCoord) && opening == 4) @@ -88,9 +109,39 @@ public class TileEntityShadowEye extends TileEntity { } if (opening == 2 && timer <= 0 && t == 10 && shouldAddData) { addData(worldObj, xCoord, yCoord, zCoord); - TileEntityHandPedestal target = (TileEntityHandPedestal) worldObj.getTileEntity(xCoord, yCoord - 3, zCoord); - if (target != null && target.getHeldItemStack() != null) - JewelryNBT.addModifiers(target.getHeldItemStack(), pedestalItems); + TileEntityHandPedestal pedstl = (TileEntityHandPedestal) worldObj.getTileEntity(xCoord, yCoord - 3, zCoord); + if (pedstl != null && pedstl.getHeldItemStack() != null) { + JewelryNBT.addModifiers(pedstl.getHeldItemStack(), pedestalItems); + + if (!worldObj.isRemote) + if (worldObj.getBlock(xCoord, yCoord + 2, zCoord) == Blocks.enchanting_table) { + if (worldObj.rand.nextBoolean()) { + JewelryNBT.addPrefix(pedstl.getHeldItemStack(), AffixMods.pickPrefix(worldObj.rand)); + target.addChatMessage(new ChatComponentText( + EnumChatFormatting.DARK_PURPLE + "The item is infused with a prefix")); + } else if (target.experienceLevel > 2) { + target.addExperienceLevel(-2); + JewelryNBT.addPrefix(pedstl.getHeldItemStack(), AffixMods.pickPrefix(worldObj.rand)); + if (!worldObj.isRemote) + target.addChatMessage(new ChatComponentText( + EnumChatFormatting.DARK_PURPLE + "You infuse the item with a prefix")); + } + + if (worldObj.rand.nextBoolean()) { + JewelryNBT.addSuffix(pedstl.getHeldItemStack(), AffixMods.pickSuffix(worldObj.rand)); + if (!worldObj.isRemote) + target.addChatMessage(new ChatComponentText( + EnumChatFormatting.DARK_PURPLE + "The item is infused with a suffix")); + } else if (target.experienceLevel > 2) { + target.addExperienceLevel(-2); + JewelryNBT.addSuffix(pedstl.getHeldItemStack(), AffixMods.pickSuffix(worldObj.rand)); + if (!worldObj.isRemote) + target.addChatMessage(new ChatComponentText( + EnumChatFormatting.DARK_PURPLE + "You infuse the item with a suffix")); + } + } + } + revertPedestals(worldObj, xCoord, yCoord, zCoord); } if (active && timer <= 0) { @@ -109,6 +160,11 @@ public class TileEntityShadowEye extends TileEntity { JewelrycraftUtil.addCursePoints(target, 50); target.addChatMessage(new ChatComponentText( EnumChatFormatting.BLACK + "The Shadows don't like to be disturbed for no reason!")); + String str = er.toString(); + if (!str.equals("")) { + target.addChatMessage( + new ChatComponentText(EnumChatFormatting.DARK_PURPLE + "Check the following: " + er)); + } target.addChatMessage(new ChatComponentText( EnumChatFormatting.DARK_PURPLE + "You feel a strange aura encumbering you.")); } @@ -130,137 +186,231 @@ public class TileEntityShadowEye extends TileEntity { } } - public boolean isValidStructure(World world, int x, int y, int z, int metadata) { + public boolean isValidStructure(World world, int x, int y, int z, int metadata, StringBuilder err) { if (world.getBlockMetadata(x, y, z) == 0 || world.getBlockMetadata(x, y, z) == 2) { // Layers from top to bottom // 1st Layer - if (world.getBlock(x, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z) != 5) + if (world.getBlock(x, y + 1, z) != Blocks.stone_slab) { + err.append(String.format("Missing stone slab at <%d, %d, %d>", x, y + 1, z)); return false; - if (world.getBlock(x + 1, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x + 1, y + 1, z) != 5) + } + if (world.getBlock(x + 1, y + 1, z) != Blocks.stone_slab) { + err.append(String.format("Missing stone slab at <%d, %d, %d>", x + 1, y + 1, z)); return false; - if (world.getBlock(x - 1, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x - 1, y + 1, z) != 5) + } + if (world.getBlock(x - 1, y + 1, z) != Blocks.stone_slab) { + err.append(String.format("Missing stone slab at <%d, %d, %d>", x - 1, y + 1, z)); return false; + } // 2nd Layer - if (world.getBlock(x + 2, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x + 2, y, z) != 1) + if (world.getBlock(x + 2, y, z) != Blocks.stone_brick_stairs) { + err.append(String.format("Missing stone brick stairs at <%d, %d, %d>", x + 2, y, z)); return false; - if (world.getBlock(x + 1, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x + 1, y, z) != 4) + } + if (world.getBlock(x + 1, y, z) != Blocks.stone_brick_stairs) { + err.append(String.format("Missing stone brick stairs at <%d, %d, %d>", x + 1, y, z)); return false; - if (world.getBlock(x - 1, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x - 1, y, z) != 5) + } + if (world.getBlock(x - 1, y, z) != Blocks.stone_brick_stairs) { + err.append(String.format("Missing stone brick stairs at <%d, %d, %d>", x - 1, y, z)); return false; - if (world.getBlock(x - 2, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x - 2, y, z) != 0) + } + if (world.getBlock(x - 2, y, z) != Blocks.stone_brick_stairs) { + err.append(String.format("Missing stone brick stairs at <%d, %d, %d>", x - 2, y, z)); return false; + } // 3rd Layer - if (world.getBlock(x + 2, y - 1, z) != Blocks.stonebrick) + if (world.getBlock(x + 2, y - 1, z) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x + 2, y - 1, z)); return false; - if (world.getBlock(x - 2, y - 1, z) != Blocks.stonebrick) + } + if (world.getBlock(x - 2, y - 1, z) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x - 2, y - 1, z)); return false; + } // 4th Layer - if (world.getBlock(x + 2, y - 2, z) != Blocks.stonebrick) + if (world.getBlock(x + 2, y - 2, z) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x + 2, y - 2, z)); return false; - if (world.getBlock(x - 2, y - 2, z) != Blocks.stonebrick) + } + if (world.getBlock(x - 2, y - 2, z) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x - 2, y - 2, z)); return false; + } // 5th Layer - if (world.getBlock(x + 2, y - 3, z) != Blocks.stonebrick) + if (world.getBlock(x + 2, y - 3, z) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x + 2, y - 3, z)); return false; - if (world.getBlock(x - 2, y - 3, z) != Blocks.stonebrick) + } + if (world.getBlock(x - 2, y - 3, z) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x - 2, y - 3, z)); return false; + } } else if (world.getBlockMetadata(x, y, z) == 1 || world.getBlockMetadata(x, y, z) == 3) { // Layers from top to bottom // 1st Layer - if (world.getBlock(x, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z) != 5) + if (world.getBlock(x, y + 1, z) != Blocks.stone_slab) { + err.append(String.format("Missing stone brick slab at <%d, %d, %d>", x, y + 1, z)); return false; - if (world.getBlock(x, y + 1, z + 1) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z + 1) != 5) + } + if (world.getBlock(x, y + 1, z + 1) != Blocks.stone_slab) { + err.append(String.format("Missing stone brick slab at <%d, %d, %d>", x, y + 1, z + 1)); return false; - if (world.getBlock(x, y + 1, z - 1) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z - 1) != 5) + } + if (world.getBlock(x, y + 1, z - 1) != Blocks.stone_slab) { + err.append(String.format("Missing stone brick slab at <%d, %d, %d>", x, y + 1, z - 1)); return false; + } // 2nd Layer - if (world.getBlock(x, y, z + 2) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z + 2) != 3) + if (world.getBlock(x, y, z + 2) != Blocks.stone_brick_stairs) { + err.append(String.format("Missing stone brick stairs at <%d, %d, %d>", x, y, z + 2)); return false; - if (world.getBlock(x, y, z + 1) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z + 1) != 6) + } + if (world.getBlock(x, y, z + 1) != Blocks.stone_brick_stairs) { + err.append(String.format("Missing stone brick stairs at <%d, %d, %d>", x, y, z + 1)); return false; - if (world.getBlock(x, y, z - 1) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z - 1) != 7) + } + if (world.getBlock(x, y, z - 1) != Blocks.stone_brick_stairs) { + err.append(String.format("Missing stone brick stairs at <%d, %d, %d>", x, y, z - 1)); return false; - if (world.getBlock(x, y, z - 2) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z - 2) != 2) + } + if (world.getBlock(x, y, z - 2) != Blocks.stone_brick_stairs) { + err.append(String.format("Missing stone brick stairs at <%d, %d, %d>", x, y, z - 2)); return false; + } // 3rd Layer - if (world.getBlock(x, y - 1, z + 2) != Blocks.stonebrick) + if (world.getBlock(x, y - 1, z + 2) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x, y - 1, z + 2)); return false; - if (world.getBlock(x, y - 1, z - 2) != Blocks.stonebrick) + } + if (world.getBlock(x, y - 1, z - 2) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x, y - 1, z - 2)); return false; + } // 4th Layer - if (world.getBlock(x, y - 2, z + 2) != Blocks.stonebrick) + if (world.getBlock(x, y - 2, z + 2) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x, y - 2, z + 2)); return false; - if (world.getBlock(x, y - 2, z - 2) != Blocks.stonebrick) + } + if (world.getBlock(x, y - 2, z - 2) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x, y - 2, z - 2)); return false; + } // 5th Layer - if (world.getBlock(x, y - 3, z + 2) != Blocks.stonebrick) + if (world.getBlock(x, y - 3, z + 2) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x, y - 3, z + 2)); return false; - if (world.getBlock(x, y - 3, z - 2) != Blocks.stonebrick) + } + if (world.getBlock(x, y - 3, z - 2) != Blocks.stonebrick) { + err.append(String.format("Missing stone bricks at <%d, %d, %d>", x, y - 3, z - 2)); return false; + } } // 3rd Layer - if (world.getBlock(x - 4, y - 1, z - 4) != BlockList.shadowBlock) + if (world.getBlock(x - 4, y - 1, z - 4) != BlockList.shadowBlock) { + err.append(String.format("Missing shadow block at <%d, %d, %d>", x - 4, y - 1, z - 4)); return false; - if (world.getBlock(x - 4, y - 1, z + 4) != BlockList.shadowBlock) + } + if (world.getBlock(x - 4, y - 1, z + 4) != BlockList.shadowBlock) { + err.append(String.format("Missing shadow block at <%d, %d, %d>", x - 4, y - 1, z + 4)); return false; - if (world.getBlock(x + 4, y - 1, z - 4) != BlockList.shadowBlock) + } + if (world.getBlock(x + 4, y - 1, z - 4) != BlockList.shadowBlock) { + err.append(String.format("Missing shadow block at <%d, %d, %d>", x + 4, y - 1, z - 4)); return false; - if (world.getBlock(x + 4, y - 1, z + 4) != BlockList.shadowBlock) + } + if (world.getBlock(x + 4, y - 1, z + 4) != BlockList.shadowBlock) { + err.append(String.format("Missing shadow block at <%d, %d, %d>", x + 4, y - 1, z + 4)); return false; + } // 4th Layer - if (world.getBlock(x - 4, y - 2, z - 4) != Blocks.stonebrick) + if (world.getBlock(x - 4, y - 2, z - 4) != Blocks.stonebrick) { + err.append(String.format("Missing stone brick at <%d, %d, %d>", x - 4, y - 2, z - 4)); return false; - if (world.getBlock(x - 4, y - 2, z + 4) != Blocks.stonebrick) + } + if (world.getBlock(x - 4, y - 2, z + 4) != Blocks.stonebrick) { + err.append(String.format("Missing stone brick at <%d, %d, %d>", x - 4, y - 2, z + 4)); return false; - if (world.getBlock(x + 4, y - 2, z - 4) != Blocks.stonebrick) + } + if (world.getBlock(x + 4, y - 2, z - 4) != Blocks.stonebrick) { + err.append(String.format("Missing stone brick at <%d, %d, %d>", x + 4, y - 2, z - 4)); return false; - if (world.getBlock(x + 4, y - 2, z + 4) != Blocks.stonebrick) + } + if (world.getBlock(x + 4, y - 2, z + 4) != Blocks.stonebrick) { + err.append(String.format("Missing stone brick at <%d, %d, %d>", x + 4, y - 2, z + 4)); return false; + } // 5th Layer // Pillars - if (world.getBlock(x - 4, y - 3, z - 4) != Blocks.stonebrick) + if (world.getBlock(x - 4, y - 3, z - 4) != Blocks.stonebrick) { + err.append(String.format("Missing stone brick at <%d, %d, %d>", x - 4, y - 3, z - 4)); return false; - if (world.getBlock(x - 4, y - 3, z + 4) != Blocks.stonebrick) + } + if (world.getBlock(x - 4, y - 3, z + 4) != Blocks.stonebrick) { + err.append(String.format("Missing stone brick at <%d, %d, %d>", x - 4, y - 3, z + 4)); return false; - if (world.getBlock(x + 4, y - 3, z - 4) != Blocks.stonebrick) + } + if (world.getBlock(x + 4, y - 3, z - 4) != Blocks.stonebrick) { + err.append(String.format("Missing stone brick at <%d, %d, %d>", x + 4, y - 3, z - 4)); return false; - if (world.getBlock(x + 4, y - 3, z + 4) != Blocks.stonebrick) + } + if (world.getBlock(x + 4, y - 3, z + 4) != Blocks.stonebrick) { + err.append(String.format("Missing stone brick at <%d, %d, %d>", x + 4, y - 3, z + 4)); return false; + } // Pedestals - if (!(world.getBlock(x, y - 3, z) instanceof BlockHandPedestal)) + if (world.getBlock(x, y - 3, z) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x, y - 3, z)); return false; - if (world.getBlock(x - 4, y - 3, z + 2) != BlockList.handPedestal - || world.getBlockMetadata(x - 4, y - 3, z + 2) != 1) + } + if (world.getBlock(x - 4, y - 3, z + 2) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x - 4, y - 3, z + 2)); return false; - if (world.getBlock(x - 5, y - 3, z) != BlockList.handPedestal || world.getBlockMetadata(x - 5, y - 3, z) != 2) + } + if (world.getBlock(x - 5, y - 3, z) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x - 5, y - 3, z)); return false; - if (world.getBlock(x - 4, y - 3, z - 2) != BlockList.handPedestal - || world.getBlockMetadata(x - 4, y - 3, z - 2) != 3) + } + if (world.getBlock(x - 4, y - 3, z - 2) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x - 4, y - 3, z - 2)); return false; - if (world.getBlock(x - 2, y - 3, z - 4) != BlockList.handPedestal - || world.getBlockMetadata(x - 2, y - 3, z - 4) != 3) + } + if (world.getBlock(x - 2, y - 3, z - 4) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x - 2, y - 3, z - 4)); return false; - if (world.getBlock(x, y - 3, z - 5) != BlockList.handPedestal || world.getBlockMetadata(x, y - 3, z - 5) != 4) + } + if (world.getBlock(x, y - 3, z - 5) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x, y - 3, z - 5)); return false; - if (world.getBlock(x + 2, y - 3, z - 4) != BlockList.handPedestal - || world.getBlockMetadata(x + 2, y - 3, z - 4) != 5) + } + if (world.getBlock(x + 2, y - 3, z - 4) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x + 2, y - 3, z - 4)); return false; - if (world.getBlock(x + 4, y - 3, z - 2) != BlockList.handPedestal - || world.getBlockMetadata(x + 4, y - 3, z - 2) != 5) + } + if (world.getBlock(x + 4, y - 3, z - 2) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x + 4, y - 3, z - 2)); return false; - if (world.getBlock(x + 5, y - 3, z) != BlockList.handPedestal || world.getBlockMetadata(x + 5, y - 3, z) != 6) + } + if (world.getBlock(x + 5, y - 3, z) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x + 5, y - 3, z)); return false; - if (world.getBlock(x + 4, y - 3, z + 2) != BlockList.handPedestal - || world.getBlockMetadata(x + 4, y - 3, z + 2) != 7) + } + if (world.getBlock(x + 4, y - 3, z + 2) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x + 4, y - 3, z + 2)); return false; - if (world.getBlock(x + 2, y - 3, z + 4) != BlockList.handPedestal - || world.getBlockMetadata(x + 2, y - 3, z + 4) != 7) + } + if (world.getBlock(x + 2, y - 3, z + 4) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x + 2, y - 3, z + 4)); return false; - if (world.getBlock(x, y - 3, z + 5) != BlockList.handPedestal || world.getBlockMetadata(x, y - 3, z + 5) != 0) + } + if (world.getBlock(x, y - 3, z + 5) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x, y - 3, z + 5)); return false; - if (world.getBlock(x - 2, y - 3, z + 4) != BlockList.handPedestal - || world.getBlockMetadata(x - 2, y - 3, z + 4) != 1) + } + if (world.getBlock(x - 2, y - 3, z + 4) != BlockList.handPedestal) { + err.append(String.format("Missing hand pedestal at <%d, %d, %d>", x - 2, y - 3, z + 4)); return false; + } return true; } -- cgit v1.2.3