diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-09-05 20:57:51 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-09-05 21:36:21 -0400 |
| commit | 6706fae4a88b04d0a290e246b33eba313841e338 (patch) | |
| tree | 3bb84fe39505095e071462e573772cf28a3e7379 /src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java | |
| parent | 6e097a5056ad343271e21109f593f7cb77e4667e (diff) | |
Yet more affix work
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java')
| -rwxr-xr-x | src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java | 100 |
1 files changed, 65 insertions, 35 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java index 4cfbbc8..9b4930f 100755 --- a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java +++ b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java @@ -5,9 +5,11 @@ import java.util.ArrayList; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import darkknight.jewelrycraft.affixes.AffixMods;
+import darkknight.jewelrycraft.api.IJewelryItem;
import darkknight.jewelrycraft.block.BlockHandPedestal;
import darkknight.jewelrycraft.block.BlockList;
import darkknight.jewelrycraft.config.ConfigHandler;
+import darkknight.jewelrycraft.item.ItemBaseJewelry;
import darkknight.jewelrycraft.model.ModelShadowEye;
import darkknight.jewelrycraft.util.JewelryNBT;
import darkknight.jewelrycraft.util.JewelrycraftUtil;
@@ -15,6 +17,7 @@ import darkknight.jewelrycraft.util.Variables; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
@@ -64,11 +67,18 @@ public class TileEntityShadowEye extends TileEntity { super.updateEntity();
StringBuilder er = new StringBuilder();
boolean valid = isValidStructure(worldObj, xCoord, yCoord, zCoord, blockMetadata, er);
- boolean centerHasItem = false, hasMods = false, hasAffixes = false;
+ boolean centerHasItem = false, centerIsJewelry = false, hasMods = false, hasAffixes = false;
if (valid) {
TileEntity te = worldObj.getTileEntity(xCoord, yCoord - 3, zCoord);
if (te instanceof TileEntityHandPedestal) {
- centerHasItem = ((TileEntityHandPedestal) te).heldItemStack != null;
+ ItemStack heldItemStack = ((TileEntityHandPedestal) te).heldItemStack;
+
+ centerHasItem = heldItemStack != null;
+ if (centerHasItem) {
+ Item heldItem = heldItemStack.getItem();
+
+ centerIsJewelry = heldItem instanceof IJewelryItem || heldItem instanceof ItemBaseJewelry;
+ }
}
hasMods = getNumberOfItems(worldObj, xCoord, yCoord, zCoord) > 0;
@@ -76,10 +86,10 @@ public class TileEntityShadowEye extends TileEntity { hasAffixes = worldObj.getBlock(xCoord, yCoord + 2, zCoord) == Blocks.enchanting_table;
}
- boolean canStartRitual = valid && centerHasItem && (hasMods || hasAffixes);
+ boolean canStartRitual = valid && (centerHasItem && centerIsJewelry) && (hasMods || hasAffixes);
if (!canStartRitual && valid) {
- if (!centerHasItem) {
- er.append("Center pedestal requires an item");
+ if (!centerHasItem || !centerIsJewelry) {
+ er.append("Center pedestal requires a piece of jewelry");
} else if (!hasMods && !hasAffixes) {
er.append("Need at least one modifier, or an enchanting table for affixes.");
} else {
@@ -110,36 +120,11 @@ public class TileEntityShadowEye extends TileEntity { if (opening == 2 && timer <= 0 && t == 10 && shouldAddData) {
addData(worldObj, xCoord, yCoord, zCoord);
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"));
- }
- }
+ ItemStack centerItem = pedstl == null ? null : pedstl.getHeldItemStack();
+ if (pedstl != null && centerItem != null) {
+ if (!worldObj.isRemote) {
+ modifyJewelry(centerItem);
+ }
}
revertPedestals(worldObj, xCoord, yCoord, zCoord);
@@ -186,6 +171,51 @@ public class TileEntityShadowEye extends TileEntity { }
}
+ private void modifyJewelry(ItemStack centerItem) {
+ Item itm = centerItem.getItem();
+
+ int jewelType = -1;
+
+ if (itm instanceof IJewelryItem) {
+ IJewelryItem jewelryItem = (IJewelryItem) itm;
+
+ jewelType = jewelryItem.type();
+ } else if (itm instanceof ItemBaseJewelry) {
+ ItemBaseJewelry jewelry = (ItemBaseJewelry) itm;
+
+ jewelType = jewelry.type();
+ }
+
+ JewelryNBT.addModifiers(centerItem, pedestalItems);
+
+ if (worldObj.getBlock(xCoord, yCoord + 2, zCoord) == Blocks.enchanting_table) {
+ if (worldObj.rand.nextBoolean()) {
+ JewelryNBT.addPrefix(centerItem, AffixMods.pickPrefix(worldObj.rand, jewelType));
+ target.addChatMessage(
+ new ChatComponentText(EnumChatFormatting.DARK_PURPLE + "The item is infused with a prefix"));
+ } else if (target.experienceLevel > 2) {
+ target.addExperienceLevel(-2);
+ JewelryNBT.addPrefix(centerItem, AffixMods.pickPrefix(worldObj.rand, jewelType));
+ if (!worldObj.isRemote)
+ target.addChatMessage(new ChatComponentText(
+ EnumChatFormatting.DARK_PURPLE + "You infuse the item with a prefix"));
+ }
+
+ if (worldObj.rand.nextBoolean()) {
+ JewelryNBT.addSuffix(centerItem, AffixMods.pickSuffix(worldObj.rand, jewelType));
+ 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(centerItem, AffixMods.pickSuffix(worldObj.rand, jewelType));
+ if (!worldObj.isRemote)
+ target.addChatMessage(new ChatComponentText(
+ EnumChatFormatting.DARK_PURPLE + "You infuse the item with a suffix"));
+ }
+ }
+ }
+
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
|
