diff --git a/src/main/java/tb/common/tile/TileNodeManipulator.java b/src/main/java/tb/common/tile/TileNodeManipulator.java index 2119e09..59a85cb 100644 --- a/src/main/java/tb/common/tile/TileNodeManipulator.java +++ b/src/main/java/tb/common/tile/TileNodeManipulator.java @@ -1,6 +1,6 @@ package tb.common.tile; -import java.util.Hashtable; +import java.util.HashMap; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -9,6 +9,7 @@ import net.minecraft.world.World; import thaumcraft.api.aspects.Aspect; +import thaumcraft.api.aspects.AspectList; import thaumcraft.api.nodes.INode; import thaumcraft.api.nodes.NodeModifier; import thaumcraft.api.nodes.NodeType; @@ -19,72 +20,234 @@ public class TileNodeManipulator extends TileEntity implements IWandable { - public int workTime = 0; - public Hashtable nodeAspects = new Hashtable(); - public Hashtable newNodeAspects = new Hashtable(); - public boolean firstTick = true; - - public void updateEntity() { - INode node = getNode(); - - if (node == null) return; - - newNodeAspects.clear(); - for (int i = 0; i < node.getAspects().size(); ++i) { - newNodeAspects.put( - node.getAspects().getAspects()[i].getTag(), - node.getAspects().getAmount(node.getAspects().getAspects()[i])); + private static final int ticksInWorkCycle = 20; + private int workTime = 0; + private int maxTimeRequired = 0; + private final HashMap previousNodeAspects = new HashMap<>(); + private NodeType nodeType; + private INode node; + + private int getColor(int effect) { + int color; + switch (effect) { + case 1: + color = 0x4e4756; + break; + case 2: + color = 0xd2d200; + break; + case 3: + color = 0xaf7c23; + break; + case 4: + color = 0x0b4d42; + break; + case 5: + color = 0xccc8f7; + break; + case 6: + color = 0x643c5b; + break; + case 7: + color = 0xeaeaea; + break; + case 8: + color = 0xd0e0f8; + break; + case 9: + color = 0x713496; + break; + default: + color = 0xffffff; } + return color; + } - if (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0 || getNode() == null) workTime = 0; + private void stopManipulator() { + workTime = 0; + maxTimeRequired = 0; + node = null; + previousNodeAspects.clear(); + } - if (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != 0 && getNode() != null) { - int color = 0xffffff; - int effect = this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) - 1; + private void applyDestructionEffect() { + NodeModifier nodeModifier = node.getNodeModifier(); - switch (this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) - 1) { - case 0: { - color = 0xffffff; + if (maxTimeRequired == 0) { + switch (nodeModifier) { + case BRIGHT: + maxTimeRequired = 60 * 20; break; - } - case 1: { - color = 0x4e4756; + case PALE: + maxTimeRequired = 3 * 60 * 20; break; - } - case 2: { - color = 0xd2d200; - break; - } - case 3: { - color = 0xaf7c23; + case FADING: + maxTimeRequired = 6 * 60 * 20; break; - } - case 4: { - color = 0x0b4d42; - break; - } - case 5: { - color = 0xccc8f7; + default: + maxTimeRequired = 2 * 60 * 20; break; - } - case 6: { - color = 0x643c5b; + } + } + + if (workTime >= maxTimeRequired) { + stopManipulator(); + + if (nodeModifier == NodeModifier.FADING) { + this.worldObj.setBlockToAir(xCoord, yCoord, zCoord); + return; + } + + NodeModifier newNodeModifier; + switch (nodeModifier) { + case BRIGHT: + newNodeModifier = null; break; - } - case 7: { - color = 0xeaeaea; + case PALE: + newNodeModifier = NodeModifier.FADING; break; + default: + newNodeModifier = NodeModifier.PALE; + } + + node.setNodeModifier(newNodeModifier); + return; + } + increaseWorkTime(); + if (!this.worldObj.isRemote && workTime % 200 == 0) { + Aspect[] aspects = node.getAspects().getAspects(); + Aspect aspect = aspects[this.worldObj.rand.nextInt(aspects.length)]; + EntityAspectOrb aspectOrb = new EntityAspectOrb( + worldObj, + xCoord + 0.5D, + yCoord - 0.5D, + zCoord + 0.5D, + aspect, + 1); + this.worldObj.spawnEntityInWorld(aspectOrb); + } + } + + private void applyEfficiencyEffect() { + if (workTime == 0) workTime = -1; + if (!worldObj.isRemote) { + AspectList aspectList = node.getAspects(); + Aspect[] aspects = aspectList.getAspects(); + + for (Aspect aspect : aspects) { + if (previousNodeAspects.containsKey(aspect)) { + int currentAmount = aspectList.getAmount(aspect); + int previousAmount = previousNodeAspects.get(aspect); + + if (currentAmount < previousAmount && this.worldObj.rand.nextInt(2) == 1) { + node.addToContainer(aspect, previousAmount - currentAmount); + } } - case 8: { - color = 0xd0e0f8; - break; + previousNodeAspects.put(aspect, node.getAspects().getAmount(aspect)); + } + } + } + + private void applySpeedEffect() { + if (workTime == 0) workTime = -1; + + if (!this.worldObj.isRemote && this.worldObj.rand.nextInt(5) == 1) { + boolean isNodeChanged = false; + AspectList aspectList = node.getAspects(); + Aspect[] aspects = aspectList.getAspects(); + + for (Aspect aspect : aspects) { + int maximum = node.getNodeVisBase(aspect); + int currentAmount = aspectList.getAmount(aspect); + + if (currentAmount < maximum) { + node.addToContainer(aspect, 1); + isNodeChanged = true; } - case 9: { - color = 0x713496; - break; + } + + if (isNodeChanged) { + MiscUtils.sendPacketToAllAround( + worldObj, + this.worldObj.getTileEntity(xCoord, yCoord - 1, zCoord).getDescriptionPacket(), + xCoord, + yCoord, + zCoord, + this.worldObj.provider.dimensionId, + 6); + } + } + } + + private void applyStabilityEffect() { + NodeModifier nodeModifier = node.getNodeModifier(); + if (nodeModifier == null) { + changeNodeModifier(null, NodeModifier.BRIGHT, 5 * 60 * 20); + return; + } + + switch (nodeModifier) { + case FADING: + changeNodeModifier(NodeModifier.FADING, NodeModifier.PALE, 5 * 60 * 20); + break; + case PALE: + changeNodeModifier(NodeModifier.PALE, null, 10 * 60 * 20); + break; + default: { + switch (nodeType) { + case DARK: + changeNodeType(NodeType.DARK, NodeType.NORMAL, 2 * 60 * 20); + break; + case HUNGRY: + changeNodeType(NodeType.HUNGRY, NodeType.NORMAL, 30 * 20); + break; + case UNSTABLE: + changeNodeType(NodeType.UNSTABLE, NodeType.NORMAL, 7 * 30 * 20); + break; + case TAINTED: + changeNodeType(NodeType.TAINTED, NodeType.NORMAL, 30 * 30 * 20); + break; + default: + break; } } - if (!firstTick && this.worldObj.isRemote) Thaumcraft.proxy.beam( + } + } + + private void increaseWorkTime() { + workTime += ticksInWorkCycle; + } + + private void changeNodeModifier(NodeModifier fromNodeModifier, NodeModifier toModifierNode, int time) { + if (node.getNodeModifier() == fromNodeModifier) { + if (maxTimeRequired == 0) maxTimeRequired = time; + + if (workTime >= maxTimeRequired) { + node.setNodeModifier(toModifierNode); + stopManipulator(); + } else increaseWorkTime(); + } + } + + private void changeNodeType(NodeType fromNodeType, NodeType toTypeNode, int time) { + if (nodeType == fromNodeType) { + if (maxTimeRequired == 0) maxTimeRequired = time; + + if (workTime >= maxTimeRequired) { + node.setNodeType(toTypeNode); + stopManipulator(); + } else increaseWorkTime(); + } + } + + @Override + public void updateEntity() { + int effect = this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) - 1; + long ticks = worldObj.getWorldTime() + 7; + + // Graphic + if (this.worldObj.isRemote && workTime != 0) { + Thaumcraft.proxy.beam( this.worldObj, xCoord + 0.5D, yCoord + 0.5D, @@ -93,223 +256,79 @@ public void updateEntity() { yCoord - 0.5D, zCoord + 0.5D, 2, - color, + getColor(effect), false, 0.5F, 2); + } - if (!firstTick) { - if (effect == 7) { - if (!this.worldObj.isRemote) { - boolean isNodeChanged = false; - for (int i = 0; i < node.getAspects().size(); ++i) { - Aspect a = node.getAspects().getAspects()[i]; - int max = node.getNodeVisBase(a); - int current = node.getAspects().getAmount(a); - - if (current < max && this.worldObj.rand.nextFloat() < 0.01F) { - node.getAspects().add(a, 1); - isNodeChanged = true; - } - } - if (isNodeChanged) { - MiscUtils.sendPacketToAllAround( - worldObj, - this.worldObj.getTileEntity(xCoord, yCoord - 1, zCoord).getDescriptionPacket(), - xCoord, - yCoord, - zCoord, - this.worldObj.provider.dimensionId, - 6); - } - } - } - if (effect == 1) { - int maxTimeRequired = node.getNodeModifier() == NodeModifier.BRIGHT ? 1 * 60 * 20 - : node.getNodeModifier() == NodeModifier.PALE ? 3 * 60 * 20 - : node.getNodeModifier() == NodeModifier.FADING ? 6 * 60 * 20 : 2 * 60 * 20; - if (workTime >= maxTimeRequired) { - workTime = 0; - if (node.getNodeModifier() == NodeModifier.FADING) { - this.worldObj.setBlockToAir(xCoord, yCoord, zCoord); - return; - } - node.setNodeModifier( - node.getNodeModifier() == NodeModifier.BRIGHT ? null - : node.getNodeModifier() == NodeModifier.PALE ? NodeModifier.FADING - : node.getNodeModifier() == NodeModifier.FADING ? NodeModifier.FADING - : NodeModifier.PALE); - - } else { - ++workTime; - if (this.worldObj.getTotalWorldTime() % 10 == 0) { - Aspect a = node.getAspects().getAspects()[this.worldObj.rand - .nextInt(node.getAspects().getAspects().length)]; - EntityAspectOrb aspect = new EntityAspectOrb( - worldObj, - xCoord + 0.5D, - yCoord - 0.5D, - zCoord + 0.5D, - a, - 1); - if (!this.worldObj.isRemote) { - this.worldObj.spawnEntityInWorld(aspect); - } - } - } - } - if (effect == 2) { - for (int i = 0; i < node.getAspects().size(); ++i) { - Aspect a = node.getAspects().getAspects()[i]; - int current = node.getAspects().getAmount(a); - if (nodeAspects.containsKey(a.getTag())) { - int prev = nodeAspects.get(a.getTag()); - - if (current < prev && this.worldObj.rand.nextFloat() < 0.5F) { - node.getAspects().add(a, 1); - } - } - } - } - if (effect == 3) { - if (node.getNodeType() == NodeType.NORMAL) { - if (workTime > 5 * 60 * 20) { - workTime = 0; - node.setNodeType(NodeType.HUNGRY); - } else { - ++workTime; - } - } - } - if (effect == 4) { - if (node.getNodeType() == NodeType.NORMAL) { - if (workTime > 7 * 60 * 20) { - workTime = 0; - node.setNodeType(NodeType.UNSTABLE); - } else { - ++workTime; - } - } - } - if (effect == 5) { - if (node.getNodeType() == NodeType.NORMAL) { - if (workTime > 3 * 60 * 20) { - workTime = 0; - node.setNodeType(NodeType.PURE); - } else++workTime; - } else if (node.getNodeType() == NodeType.TAINTED) { - if (workTime > 33 * 60 * 20) { - workTime = 0; - node.setNodeType(NodeType.PURE); - } else++workTime; - } - } - if (effect == 6) { - if (node.getNodeType() == NodeType.NORMAL) { - if (workTime > 6 * 60 * 20) { - workTime = 0; - node.setNodeType(NodeType.DARK); - } else { - ++workTime; - } - } - } - if (effect == 8) { - int maxTimeRequired = 0; - - if (node.getNodeModifier() == NodeModifier.FADING) { - maxTimeRequired = 5 * 60 * 20; - } - - if (node.getNodeModifier() == NodeModifier.PALE) { - maxTimeRequired = 10 * 60 * 20; - } - - if (node.getNodeType() == NodeType.DARK) { - maxTimeRequired = 2 * 60 * 20; - } - - if (node.getNodeType() == NodeType.HUNGRY) { - maxTimeRequired = 30 * 20; - } + // Logic + if (ticks % 2 == 0) { + node = getNode(); - if (node.getNodeType() == NodeType.UNSTABLE) { - maxTimeRequired = 7 * 60 * 20; - } + if (node == null || this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0) { + if (workTime != 0) stopManipulator(); + return; + } + nodeType = node.getNodeType(); - if (node.getNodeType() == NodeType.TAINTED || node.getNodeType() == NodeType.PURE) { - maxTimeRequired = 30 * 60 * 20; - } + if (effect == 2) { + applyEfficiencyEffect(); + } - if (workTime >= maxTimeRequired) { - workTime = 0; - if (node.getNodeModifier() == NodeModifier.FADING) { - node.setNodeModifier(NodeModifier.PALE); - return; - } - - if (node.getNodeModifier() == NodeModifier.PALE) { - node.setNodeModifier(null); - return; - } - - if (node.getNodeType() == NodeType.DARK || node.getNodeType() == NodeType.HUNGRY - || node.getNodeType() == NodeType.UNSTABLE - || node.getNodeType() == NodeType.TAINTED - || node.getNodeType() == NodeType.PURE) { - node.setNodeType(NodeType.NORMAL); - return; - } - - } else { - ++workTime; - } - } - if (effect == 0) { - if (node.getNodeModifier() == null) { - if (workTime > 20 * 60 * 20) { - workTime = 0; - node.setNodeModifier(NodeModifier.BRIGHT); - } else { - ++workTime; - } - } - } - if (effect == 9) { - if (node.getNodeType() == NodeType.NORMAL) { - if (workTime > 6 * 60 * 20) { - workTime = 0; - node.setNodeType(NodeType.TAINTED); - } else { - ++workTime; - } - } + if (ticks % ticksInWorkCycle == 0) { + + switch (effect) { + case 0: // Brightness + changeNodeModifier(null, NodeModifier.BRIGHT, 24000); + break; + case 1: // Destruction + applyDestructionEffect(); + break; + case 2: // Efficiency + break; + case 3: // Hunger + changeNodeType(NodeType.NORMAL, NodeType.HUNGRY, 6000); + break; + case 4: // Instability + changeNodeType(NodeType.NORMAL, NodeType.UNSTABLE, 8400); + break; + case 5: // Purity + changeNodeType(NodeType.NORMAL, NodeType.PURE, 3600); + changeNodeType(NodeType.TAINTED, NodeType.NORMAL, 39600); + break; + case 6: // Sinister + changeNodeType(NodeType.NORMAL, NodeType.DARK, 7200); + changeNodeType(NodeType.PURE, NodeType.NORMAL, 18000); + break; + case 7: // Speed + applySpeedEffect(); + break; + case 8: // Stability + applyStabilityEffect(); + break; + case 9: // Taint + changeNodeType(NodeType.NORMAL, NodeType.TAINTED, 7200); + break; } } } - - firstTick = false; - - nodeAspects.clear(); - for (int i = 0; i < node.getAspects().size(); ++i) { - nodeAspects.put( - node.getAspects().getAspects()[i].getTag(), - node.getAspects().getAmount(node.getAspects().getAspects()[i])); - } } public INode getNode() { if (this.worldObj.getTileEntity(xCoord, yCoord - 1, zCoord) instanceof INode) - return INode.class.cast(worldObj.getTileEntity(xCoord, yCoord - 1, zCoord)); + return (INode) worldObj.getTileEntity(xCoord, yCoord - 1, zCoord); return null; } + @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); workTime = tag.getInteger("workTime"); } + @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); tag.setInteger("workTime", workTime); diff --git a/src/main/resources/assets/thaumicbases/lang/en_US.lang b/src/main/resources/assets/thaumicbases/lang/en_US.lang index 945de78..4424b45 100644 --- a/src/main/resources/assets/thaumicbases/lang/en_US.lang +++ b/src/main/resources/assets/thaumicbases/lang/en_US.lang @@ -437,7 +437,7 @@ tb.rec.foci.speed.page.0=Speed foci increases the speed at which node restores i tc.research_name.TB.NodeFoci.Sinister=Manipulator Foci: Sinister tc.research_text.TB.NodeFoci.Sinister=A tiny mob spawner -tb.rec.foci.sinister.page.0=Sinister foci will make the Manipulator slowly turn the node into a Sinister Node. Will only work with normal nodes. Takes 6 minutes to finish. +tb.rec.foci.sinister.page.0=Sinister foci will make the Manipulator slowly turn the node into a Sinister Node. Removing the Pure modifier takes 30 minutes. Takes 6 minutes to turn a normal node into Sinister. tc.research_name.TB.NodeFoci.Unstable=Manipulator Foci: Instability tc.research_text.TB.NodeFoci.Unstable=Shaterring the node @@ -461,15 +461,15 @@ tb.rec.foci.hunger.page.0=Hunger foci will make the Manipulator slowly turn the tc.research_name.TB.NodeFoci.Purity=Manipulator Foci: Purity tc.research_text.TB.NodeFoci.Purity=Node purification -tb.rec.foci.pure.page.0=Purity foci will make the Manipulator slowly turn the node into a Pure Node. Will only work with normal or tainted nodes. Takes 3 minutes to finish with a normal node or 33 minutes with a tainted node. Note, that the node will not recieve aspects that pure nodes usually have in them, but will still turn the biome around to Magical Forest. +tb.rec.foci.pure.page.0=Purity foci will make the Manipulator slowly turn a Tainted node into normal and a normal node into Pure Node. Will only work with normal or tainted nodes. Takes 3 minutes to finish with a normal node or 33 minutes with a tainted node. Note that the node will not recieve aspects that pure nodes usually have in them, but will still turn the biome around to Magical Forest. tc.research_name.TB.NodeFoci.Stability=Manipulator Foci: Stability tc.research_text.TB.NodeFoci.Stability=Saving the dying nodes -tb.rec.foci.stability.page.0=Stability foci will make the Manipulator slowly restore nodes. It will convert nodes into different types, using time. Converting a Fading node into Pale takes 5 minutes. Converting a Pale node into normal takes 10 minutes. Removing the Sinister modifier takes 2 minutes. Removing the Unstable modifier takes 7 minutes. Removing the Hunger modifier takes 30 seconds. Removing the Taint or Pure modifier takes 30 minutes. +tb.rec.foci.stability.page.0=Stability foci will make the Manipulator slowly restore nodes. It will convert nodes into different types, using time. Converting a Fading node into Pale takes 5 minutes. Converting a Pale node into normal takes 10 minutes. Removing the Sinister modifier takes 2 minutes. Removing the Unstable modifier takes 7 minutes. Removing the Hunger modifier takes 30 seconds. Removing the Taint modifier takes 30 minutes. tc.research_name.TB.NodeFoci.Taint=Manipulator Foci: Taint tc.research_text.TB.NodeFoci.Taint=Why make everything worse? -tb.rec.foci.taint.page.0=Taint foci will make the Manipulator slowly turn the node into a tainted node. Will only work with normal nodes. Takes 6 minutes to finish. Note, that the node will not recieve aspects that tainted nodes usually have in them, but will still turn the biome around to tainted Lands. +tb.rec.foci.taint.page.0=Taint foci will make the Manipulator slowly turn the node into a tainted node. Will only work with normal nodes. Takes 6 minutes to finish. Note that the node will not recieve aspects that tainted nodes usually have in them, but will still turn the biome around to tainted Lands. tc.research_name.TB.Enchantments=New Enchantments! tc.research_text.TB.Enchantments=Magic reborn!