diff --git a/src/main/java/dev/tilera/auracore/EventHandler.java b/src/main/java/dev/tilera/auracore/EventHandler.java index aa28d39..08f1d17 100644 --- a/src/main/java/dev/tilera/auracore/EventHandler.java +++ b/src/main/java/dev/tilera/auracore/EventHandler.java @@ -29,6 +29,7 @@ public class EventHandler { nodeNBT.setInteger("key", node.key); nodeNBT.setShort("level", node.level); nodeNBT.setShort("baseLevel", node.baseLevel); + nodeNBT.setShort("taint", node.taint); nodeNBT.setByte("type", (byte)node.type.ordinal()); nodeNBT.setDouble("xPos", node.xPos); nodeNBT.setDouble("yPos", node.yPos); @@ -67,6 +68,8 @@ public class EventHandler { node.level = nodeData.getShort("level"); node.baseLevel = nodeData.getShort("baseLevel"); node.locked = nodeData.getBoolean("locked"); + if(nodeData.hasKey("taint")) + node.taint = nodeData.getShort("taint"); if(nodeData.hasKey("isVirtual")) node.isVirtual = nodeData.getBoolean("isVirtual"); node.type = EnumNodeType.getType(nodeData.getByte("type")); diff --git a/src/main/java/dev/tilera/auracore/api/AuraNode.java b/src/main/java/dev/tilera/auracore/api/AuraNode.java index b91ad60..8c1c655 100644 --- a/src/main/java/dev/tilera/auracore/api/AuraNode.java +++ b/src/main/java/dev/tilera/auracore/api/AuraNode.java @@ -8,6 +8,7 @@ public class AuraNode implements Serializable { public int key; public short level; public short baseLevel; + public short taint; public AspectList flux = new AspectList(); public EnumNodeType type; public int dimension; @@ -26,6 +27,7 @@ public class AuraNode implements Serializable { this.xPos = (double)x + 0.5; this.yPos = (double)y + 0.5; this.zPos = (double)z + 0.5; + this.taint = 0; this.isVirtual = false; } diff --git a/src/main/java/dev/tilera/auracore/api/machine/IConnection.java b/src/main/java/dev/tilera/auracore/api/machine/IConnection.java new file mode 100644 index 0000000..76912ee --- /dev/null +++ b/src/main/java/dev/tilera/auracore/api/machine/IConnection.java @@ -0,0 +1,36 @@ +package dev.tilera.auracore.api.machine; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IConnection +{ + boolean getConnectable(ForgeDirection side); + + boolean isVisSource(); + + boolean isVisConduit(); + + float[] subtractVis(float amount); + + float getPureVis(); + + void setPureVis(float vis); + + float getTaintedVis(); + + void setTaintedVis(float taint); + + float getMaxVis(); + + int getVisSuction(int x, int y, int z); + + void setVisSuction(int suction); + + int getTaintSuction(int x, int y, int z); + + void setTaintSuction(int suction); + + void setSuction(int suction); + + int getSuction(int x, int y, int z); +} \ No newline at end of file diff --git a/src/main/java/dev/tilera/auracore/api/machine/IUpgradable.java b/src/main/java/dev/tilera/auracore/api/machine/IUpgradable.java new file mode 100644 index 0000000..e6ea7cb --- /dev/null +++ b/src/main/java/dev/tilera/auracore/api/machine/IUpgradable.java @@ -0,0 +1,16 @@ +package dev.tilera.auracore.api.machine; + +public interface IUpgradable +{ + boolean canAcceptUpgrade(byte p0); + + boolean hasUpgrade(byte p0); + + int getUpgradeLimit(); + + byte[] getUpgrades(); + + boolean setUpgrade(byte p0); + + boolean clearUpgrade(int p0); +} diff --git a/src/main/java/dev/tilera/auracore/api/machine/TileVisUser.java b/src/main/java/dev/tilera/auracore/api/machine/TileVisUser.java new file mode 100644 index 0000000..c371015 --- /dev/null +++ b/src/main/java/dev/tilera/auracore/api/machine/TileVisUser.java @@ -0,0 +1,178 @@ +package dev.tilera.auracore.api.machine; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileVisUser extends TileEntity implements IConnection +{ + public int visSuction; + public int taintSuction; + + public TileVisUser() { + this.visSuction = 0; + this.taintSuction = 0; + } + + @Override + public void updateEntity() { + super.updateEntity(); + this.setSuction(0); + } + + public boolean getExactPureVis(float amount) { + this.setVisSuction(50); + int x = super.xCoord; + int y = super.yCoord; + int z = super.zCoord; + for (ForgeDirection side : ForgeDirection.values()) { + int offX = x + side.offsetX; + int offY = y + side.offsetY; + int offZ = z + side.offsetZ; + if (this.getConnectable(side)) { + TileEntity te = worldObj.getTileEntity(offX, offY, offZ); + IConnection ic = te instanceof IConnection ? (IConnection) te : null; + if (ic != null && (ic.isVisConduit() || ic.isVisSource()) && ic.getPureVis() >= amount) { + ic.setPureVis(ic.getPureVis() - amount); + return true; + } + } + } + return false; + } + + public float getAvailablePureVis(float amount) { + this.setVisSuction(50); + int x = super.xCoord; + int y = super.yCoord; + int z = super.zCoord; + float gatheredVis = 0.0f; + for (ForgeDirection side : ForgeDirection.values()) { + int offX = x + side.offsetX; + int offY = y + side.offsetY; + int offZ = z + side.offsetZ; + if (this.getConnectable(side)) { + TileEntity te = worldObj.getTileEntity(offX, offY, offZ); + IConnection ic = te instanceof IConnection ? (IConnection) te : null; + if (ic != null && (ic.isVisConduit() || ic.isVisSource())) { + float sucked = Math.min(amount - gatheredVis, ic.getPureVis()); + if (sucked < 0.001f) { + sucked = 0.0f; + } + gatheredVis += sucked; + ic.setPureVis(ic.getPureVis() - sucked); + } + if (gatheredVis >= amount) { + break; + } + } + } + return Math.min(gatheredVis, amount); + } + + public float getAvailableTaintedVis(float amount) { + this.setTaintSuction(50); + int x = super.xCoord; + int y = super.yCoord; + int z = super.zCoord; + float gatheredVis = 0.0f; + for (ForgeDirection side : ForgeDirection.values()) { + int offX = x + side.offsetX; + int offY = y + side.offsetY; + int offZ = z + side.offsetZ; + if (this.getConnectable(side)) { + TileEntity te = worldObj.getTileEntity(offX, offY, offZ); + IConnection ic = te instanceof IConnection ? (IConnection) te : null; + if (ic != null && (ic.isVisConduit() || ic.isVisSource())) { + float sucked = Math.min(amount - gatheredVis, ic.getTaintedVis()); + if (sucked < 0.001f) { + sucked = 0.0f; + } + gatheredVis += sucked; + ic.setTaintedVis(ic.getTaintedVis() - sucked); + } + if (gatheredVis >= amount) { + break; + } + } + } + return Math.min(gatheredVis, amount); + } + + protected boolean gettingPower() { + return super.worldObj.isBlockIndirectlyGettingPowered(super.xCoord, super.yCoord, super.zCoord) || super.worldObj.isBlockIndirectlyGettingPowered(super.xCoord, super.yCoord + 1, super.zCoord); + } + + @Override + public boolean getConnectable(ForgeDirection face) { + return false; + } + + @Override + public boolean isVisSource() { + return false; + } + + @Override + public boolean isVisConduit() { + return false; + } + + @Override + public float[] subtractVis(float amount) { + return new float[] { 0.0f, 0.0f }; + } + + @Override + public float getPureVis() { + return 0.0f; + } + + @Override + public void setPureVis(float amount) { + } + + @Override + public float getTaintedVis() { + return 0.0f; + } + + @Override + public float getMaxVis() { + return 0.0f; + } + + @Override + public void setTaintedVis(float amount) { + } + + @Override + public int getVisSuction(int x, int y, int z) { + return this.visSuction; + } + + @Override + public void setVisSuction(int suction) { + this.visSuction = suction; + } + + @Override + public int getTaintSuction(int x, int y, int z) { + return this.taintSuction; + } + + @Override + public void setTaintSuction(int suction) { + this.taintSuction = suction; + } + + @Override + public void setSuction(int suction) { + this.visSuction = suction; + this.taintSuction = suction; + } + + @Override + public int getSuction(int x, int y, int z) { + return Math.max(this.visSuction, this.taintSuction); + } +} diff --git a/src/main/java/dev/tilera/auracore/aura/AuraManager.java b/src/main/java/dev/tilera/auracore/aura/AuraManager.java index ba8e838..92460f4 100644 --- a/src/main/java/dev/tilera/auracore/aura/AuraManager.java +++ b/src/main/java/dev/tilera/auracore/aura/AuraManager.java @@ -779,16 +779,30 @@ public class AuraManager { } public static void queueNodeChanges(int key, int levelMod, int baseMod, boolean toggleLock, AspectList flx, float x, float y, float z) { - NodeChanges nc = new NodeChanges(key, levelMod, baseMod, toggleLock, flx, x, y, z); + NodeChanges nc = new NodeChanges(key, levelMod, baseMod, 0, toggleLock, flx, x, y, z); auraUpdateQueue.add(nc); } + public static void queueNodeChanges(int key, int levelMod, int baseMod, int taint, boolean toggleLock, AspectList flx, float x, float y, float z) { + NodeChanges nc = new NodeChanges(key, levelMod, baseMod, taint, toggleLock, flx, x, y, z); + auraUpdateQueue.add(nc); + } + + public static void addTaintToClosest(World world, int x, int y, int z, int taint) { + int key = getClosestAuraWithinRange(world, x, y, z, 64); + if (key < 0) { + key = registerAuraNode(world, (short)(world.rand.nextInt(50) + 50), EnumNodeType.DARK, world.provider.dimensionId, x, y, z); + } + queueNodeChanges(key, 0, 0, taint, false, null, x, y, z); + } + public static AuraNode copyNode(AuraNode in) { try { AuraNode out = new AuraNode(); out.key = in.key; out.level = in.level; out.baseLevel = in.baseLevel; + out.taint = in.taint; out.type = in.type; AspectList outflux = new AspectList(); for (Aspect tag : in.flux.getAspects()) { @@ -812,6 +826,7 @@ public class AuraManager { out.key = in.key; out.level = in.level; out.baseLevel = in.baseLevel; + out.taint = in.taint; out.type = in.type; out.flux = in.flux; out.dimension = in.dimension; @@ -826,16 +841,18 @@ public class AuraManager { int key = 0; int levelMod = 0; int baseMod = 0; + int taintMod = 0; boolean lock = false; AspectList flux = null; float motionX; float motionY; float motionZ; - NodeChanges(int k, int l, int b, boolean lo, AspectList ot, float x, float y, float z) { + NodeChanges(int k, int l, int b, int t, boolean lo, AspectList ot, float x, float y, float z) { this.key = k; this.levelMod = l; this.baseMod = b; + this.taintMod = t; this.lock = lo; this.flux = ot; this.motionX = x; diff --git a/src/main/java/dev/tilera/auracore/aura/AuraUpdateThread.java b/src/main/java/dev/tilera/auracore/aura/AuraUpdateThread.java index 49e8120..897d8e9 100644 --- a/src/main/java/dev/tilera/auracore/aura/AuraUpdateThread.java +++ b/src/main/java/dev/tilera/auracore/aura/AuraUpdateThread.java @@ -29,6 +29,7 @@ public class AuraUpdateThread continue; node.level = (short) (node.level + nc.levelMod); node.baseLevel = (short) (node.baseLevel + nc.baseMod); + node.taint = (short) (node.taint + nc.taintMod); if (nc.lock) { node.locked = !node.locked; } @@ -38,6 +39,9 @@ public class AuraUpdateThread if (node.baseLevel < 0) { node.baseLevel = 0; } + if (node.taint < 0) { + node.taint = 0; + } if (nc.flux != null) { for (Aspect tag : nc.flux.getAspects()) { if (nc.flux.getAmount(tag) > 0) { diff --git a/src/main/java/dev/tilera/auracore/client/AuraManagerClient.java b/src/main/java/dev/tilera/auracore/client/AuraManagerClient.java index 9172a61..0e47535 100644 --- a/src/main/java/dev/tilera/auracore/client/AuraManagerClient.java +++ b/src/main/java/dev/tilera/auracore/client/AuraManagerClient.java @@ -28,6 +28,7 @@ public class AuraManagerClient { public double z; public short level; public short base; + public short taint; public int flux; public boolean lock; public byte type; @@ -40,6 +41,7 @@ public class AuraManagerClient { z = packet.z; level = packet.level; base = packet.base; + taint = packet.taint; flux = packet.flux; lock = packet.lock; type = packet.type; @@ -51,17 +53,20 @@ public class AuraManagerClient { public static class NodeHistoryStats { public short level; + public short taint; public int flux; - public NodeHistoryStats(short level, int flux) { + public NodeHistoryStats(short level, int flux, short taint) { this.level = level; this.flux = flux; + this.taint = taint; } public NodeHistoryStats(NodeStats stats) { if (stats != null) { this.level = stats.level; this.flux = stats.flux; + this.taint = stats.taint; } } diff --git a/src/main/java/dev/tilera/auracore/network/AuraPacket.java b/src/main/java/dev/tilera/auracore/network/AuraPacket.java index 540ca07..8029bf2 100644 --- a/src/main/java/dev/tilera/auracore/network/AuraPacket.java +++ b/src/main/java/dev/tilera/auracore/network/AuraPacket.java @@ -12,6 +12,7 @@ public class AuraPacket implements IMessage { public double z; public short level; public short base; + public short taint; public int flux; public boolean lock; public byte type; @@ -25,6 +26,7 @@ public class AuraPacket implements IMessage { this.z = node.zPos; this.level = node.level; this.base = node.baseLevel; + this.taint = node.taint; this.flux = node.flux.visSize(); this.lock = node.locked; this.type = (byte) node.type.ordinal(); @@ -38,6 +40,7 @@ public class AuraPacket implements IMessage { this.z = buf.readDouble(); this.level = buf.readShort(); this.base = buf.readShort(); + this.taint = buf.readShort(); this.flux = buf.readInt(); this.lock = buf.readBoolean(); this.type = buf.readByte(); @@ -51,6 +54,7 @@ public class AuraPacket implements IMessage { buf.writeDouble(z); buf.writeShort(level); buf.writeShort(base); + buf.writeShort(taint); buf.writeInt(flux); buf.writeBoolean(lock); buf.writeByte(type); diff --git a/src/main/java/dev/tilera/auracore/network/AuraPacketHandler.java b/src/main/java/dev/tilera/auracore/network/AuraPacketHandler.java index 9cd70f8..78d9d56 100644 --- a/src/main/java/dev/tilera/auracore/network/AuraPacketHandler.java +++ b/src/main/java/dev/tilera/auracore/network/AuraPacketHandler.java @@ -19,7 +19,7 @@ public class AuraPacketHandler implements IMessageHandler } AuraManagerClient.auraClientList.put(message.key, new NodeStats(message, world.provider.dimensionId)); if (AuraManagerClient.auraClientHistory.get(message.key) == null) { - AuraManagerClient.auraClientHistory.put(message.key, new NodeHistoryStats(message.level, message.flux)); + AuraManagerClient.auraClientHistory.put(message.key, new NodeHistoryStats(message.level, message.flux, message.taint)); } return null; }