diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/block/BlockReagentConduit.java b/src/main/java/WayofTime/alchemicalWizardry/common/block/BlockReagentConduit.java index c8680e3b..32255160 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/block/BlockReagentConduit.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/block/BlockReagentConduit.java @@ -1,13 +1,21 @@ package WayofTime.alchemicalWizardry.common.block; +import java.util.List; +import java.util.Map; + import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; import WayofTime.alchemicalWizardry.AlchemicalWizardry; +import WayofTime.alchemicalWizardry.api.Int3; +import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent; +import WayofTime.alchemicalWizardry.api.items.interfaces.IReagentManipulator; import WayofTime.alchemicalWizardry.common.tileEntity.TEReagentConduit; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -41,6 +49,36 @@ public class BlockReagentConduit extends BlockContainer { @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float what, float these, float are) { + if (!world.isRemote) { + ItemStack held = player.getHeldItem(); + if (held == null || !(held.getItem() instanceof IReagentManipulator)) { + TileEntity tile = world.getTileEntity(x, y, z); + if (tile instanceof TEReagentConduit relay) { + if (relay.reagentTargetList.isEmpty()) { + player.addChatComponentMessage( + new ChatComponentTranslation("message.reagentconduit.noconnections")); + } else { + player.addChatComponentMessage( + new ChatComponentTranslation("message.reagentconduit.connections")); + for (Map.Entry> entry : relay.reagentTargetList.entrySet()) { + Reagent reagent = entry.getKey(); + List offsets = entry.getValue(); + if (offsets == null) continue; + for (Int3 offset : offsets) { + player.addChatComponentMessage( + new ChatComponentTranslation( + "message.reagentconduit.connection.entry", + reagent.name(), + x + offset.x(), + y + offset.y(), + z + offset.z())); + } + } + } + return true; + } + } + } return super.onBlockActivated(world, x, y, z, player, side, what, these, are); } diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/items/energy/ItemAttunedCrystal.java b/src/main/java/WayofTime/alchemicalWizardry/common/items/energy/ItemAttunedCrystal.java index 12bb3b58..90d99c49 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/items/energy/ItemAttunedCrystal.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/items/energy/ItemAttunedCrystal.java @@ -60,6 +60,9 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator { public void addInformation(ItemStack item, EntityPlayer player, List tooltip, boolean adv) { tooltip.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc1")); tooltip.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc2")); + tooltip.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc3")); + tooltip.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc4")); + tooltip.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc5")); if (item.getTagCompound() == null) { return; @@ -136,97 +139,159 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator { if (movingobjectposition == null) { if (player.isSneaking()) { this.setHasSavedCoordinates(itemStack, false); + if (!itemStack.hasTagCompound()) { + itemStack.setTagCompound(new NBTTagCompound()); + } + itemStack.getTagCompound().setString("reagent", ""); player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.clearing")); } return itemStack; - } else { - if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { - int x = movingobjectposition.blockX; - int y = movingobjectposition.blockY; - int z = movingobjectposition.blockZ; + } - TileEntity tile = world.getTileEntity(x, y, z); + if (movingobjectposition.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) { + return itemStack; + } - if (!(tile instanceof IReagentHandler relay)) { + int x = movingobjectposition.blockX; + int y = movingobjectposition.blockY; + int z = movingobjectposition.blockZ; + + TileEntity tile = world.getTileEntity(x, y, z); + if (!(tile instanceof IReagentHandler relay)) { + return itemStack; + } + + if (player.isSneaking()) { + if (this.getHasSavedCoordinates(itemStack)) { + Int3 coords = this.getCoordinates(itemStack); + int dimension = this.getDimension(itemStack); + + if (coords == null) { return itemStack; } - if (player.isSneaking()) { - ReagentContainerInfo[] infos = relay.getContainerInfo(ForgeDirection.UNKNOWN); - if (infos != null) { - List reagentList = getReagents(infos); - - Reagent pastReagent = this.getReagent(itemStack); - - if (reagentList.isEmpty()) { - return itemStack; - } - - int reagentLocation; - - reagentLocation = reagentList.indexOf(pastReagent); - - if (reagentLocation == -1 || reagentLocation + 1 >= reagentList.size()) { - this.setReagentWithNotification(itemStack, reagentList.getFirst(), player); - } else { - this.setReagentWithNotification(itemStack, reagentList.get(reagentLocation + 1), player); - } + // Sneak+right-click saved source block again -> clear all of reagent's connections + if (coords.x() == x && coords.y() == y && coords.z() == z) { + TileEntity pastTile = world.getTileEntity(coords.x(), coords.y(), coords.z()); + if (!(pastTile instanceof TEReagentConduit pastRelay)) { + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.error.cannotfind")); + return itemStack; } + Reagent reagent = this.getReagent(itemStack); + if (reagent == null) { + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.error.noreagent")); + return itemStack; + } + pastRelay.reagentTargetList.remove(reagent); + this.setHasSavedCoordinates(itemStack, false); + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.clearedreagent", reagent.name())); + world.markBlockForUpdate(coords.x(), coords.y(), coords.z()); + return itemStack; + } + + if (dimension != world.provider.dimensionId || Math.abs(coords.x() - x) > maxDistance + || Math.abs(coords.y() - y) > maxDistance + || Math.abs(coords.z() - z) > maxDistance) { + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.error.toofar")); + return itemStack; + } + + TileEntity pastTile = world.getTileEntity(coords.x(), coords.y(), coords.z()); + if (!(pastTile instanceof TEReagentConduit pastRelay)) { + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.error.cannotfind")); + return itemStack; + } + + Reagent reagent = this.getReagent(itemStack); + if (reagent == null) { + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.error.noreagent")); + return itemStack; + } + + boolean removed = pastRelay.removeReagentDestinationViaActual(reagent, x, y, z); + player.addChatComponentMessage( + new ChatComponentTranslation( + removed ? "message.attunedcrystal.removed" + : "message.attunedcrystal.error.notremoved")); + world.markBlockForUpdate(coords.x(), coords.y(), coords.z()); + return itemStack; + } + + // No saved coords -> cycle reagent selection + ReagentContainerInfo[] infos = relay.getContainerInfo(ForgeDirection.UNKNOWN); + if (infos != null) { + List reagentList = getReagents(infos); + if (reagentList.isEmpty()) { + return itemStack; + } + Reagent pastReagent = this.getReagent(itemStack); + int reagentLocation = reagentList.indexOf(pastReagent); + if (reagentLocation == -1 || reagentLocation + 1 >= reagentList.size()) { + this.setReagentWithNotification(itemStack, reagentList.getFirst(), player); } else { - if (this.getHasSavedCoordinates(itemStack)) { - Int3 coords = this.getCoordinates(itemStack); - int dimension = this.getDimension(itemStack); - - if (coords == null) { - return itemStack; - } - - if (dimension != world.provider.dimensionId || Math.abs(coords.x() - x) > maxDistance - || Math.abs(coords.y() - y) > maxDistance - || Math.abs(coords.z() - z) > maxDistance) { - player.addChatComponentMessage( - new ChatComponentTranslation("message.attunedcrystal.error.toofar")); - return itemStack; - } - - TileEntity pastTile = world.getTileEntity(coords.x(), coords.y(), coords.z()); - if (!(pastTile instanceof TEReagentConduit pastRelay)) { - player.addChatComponentMessage( - new ChatComponentTranslation("message.attunedcrystal.error.cannotfind")); - return itemStack; - } - - Reagent reagent = this.getReagent(itemStack); - - if (reagent == null) { - return itemStack; - } - - if (player.isSneaking()) { - pastRelay.removeReagentDestinationViaActual(reagent, x, y, z); - } else { - if (pastRelay.addReagentDestinationViaActual(reagent, x, y, z)) { - player.addChatComponentMessage( - new ChatComponentText( - StatCollector.translateToLocal("message.attunedcrystal.linked") + " " - + reagent.name())); - } else { - player.addChatComponentMessage( - new ChatComponentTranslation("message.attunedcrystal.error.noconnections")); - } - } - world.markBlockForUpdate(coords.x(), coords.y(), coords.z()); - } else { - int dimension = world.provider.dimensionId; - - this.setDimension(itemStack, dimension); - this.setCoordinates(itemStack, new Int3(x, y, z)); - - player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.linking")); - } + this.setReagentWithNotification(itemStack, reagentList.get(reagentLocation + 1), player); } } + return itemStack; + } + + // Not sneaking + if (this.getHasSavedCoordinates(itemStack)) { + Int3 coords = this.getCoordinates(itemStack); + int dimension = this.getDimension(itemStack); + + if (coords == null) { + return itemStack; + } + + if (dimension != world.provider.dimensionId || Math.abs(coords.x() - x) > maxDistance + || Math.abs(coords.y() - y) > maxDistance + || Math.abs(coords.z() - z) > maxDistance) { + player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.error.toofar")); + return itemStack; + } + + TileEntity pastTile = world.getTileEntity(coords.x(), coords.y(), coords.z()); + if (!(pastTile instanceof TEReagentConduit pastRelay)) { + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.error.cannotfind")); + return itemStack; + } + + Reagent reagent = this.getReagent(itemStack); + if (reagent == null) { + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.error.noreagent")); + return itemStack; + } + + if (pastRelay.hasReagentDestination(reagent, x, y, z)) { + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.error.duplicate")); + } else if (pastRelay.addReagentDestinationViaActual(reagent, x, y, z)) { + int used = pastRelay.getTotalConnections(); + int max = pastRelay.maxConnextions; + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.linked", reagent.name(), used, max)); + } else { + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.error.noconnections")); + } + world.markBlockForUpdate(coords.x(), coords.y(), coords.z()); + } else { + int dimension = world.provider.dimensionId; + this.setDimension(itemStack, dimension); + this.setCoordinates(itemStack, new Int3(x, y, z)); + + player.addChatComponentMessage( + new ChatComponentTranslation("message.attunedcrystal.linking", x, y, z)); } return itemStack; diff --git a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEReagentConduit.java b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEReagentConduit.java index 4a204a9e..644828a1 100644 --- a/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEReagentConduit.java +++ b/src/main/java/WayofTime/alchemicalWizardry/common/tileEntity/TEReagentConduit.java @@ -415,17 +415,31 @@ public class TEReagentConduit extends TileSegmentedReagentHandler { readClientNBT(packet.func_148857_g()); } - public boolean addReagentDestinationViaOffset(Reagent reagent, int xOffset, int yOffset, int zOffset) { - int totalConnections = 0; - - for (Entry> entry : this.reagentTargetList.entrySet()) { - if (entry.getValue() != null) { - totalConnections += entry.getValue().size(); + public int getTotalConnections() { + int total = 0; + for (List list : this.reagentTargetList.values()) { + if (list != null) { + total += list.size(); } } + return total; + } - if (totalConnections >= this.maxConnextions) { - // Send message that it cannot be done? Maybe add a Player instance + public boolean hasReagentDestination(Reagent reagent, int x, int y, int z) { + int xOffset = x - this.xCoord; + int yOffset = y - this.yCoord; + int zOffset = z - this.zCoord; + if (this.reagentTargetList.containsKey(reagent)) { + List coords = this.reagentTargetList.get(reagent); + if (coords != null) { + return coords.contains(new Int3(xOffset, yOffset, zOffset)); + } + } + return false; + } + + public boolean addReagentDestinationViaOffset(Reagent reagent, int xOffset, int yOffset, int zOffset) { + if (getTotalConnections() >= this.maxConnextions) { return false; } @@ -442,6 +456,9 @@ public class TEReagentConduit extends TileSegmentedReagentHandler { newCoordList.add(newCoord); this.reagentTargetList.put(reagent, newCoordList); } else { + if (coordList.contains(newCoord)) { + return false; + } coordList.add(newCoord); } diff --git a/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang b/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang index dd3f62ec..04b57c94 100644 --- a/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang +++ b/src/main/resources/assets/alchemicalwizardry/lang/en_US.lang @@ -434,8 +434,11 @@ tooltip.alchemyflask.caution=CAUTION: Contents are throwable tooltip.alchemyflask.swigsleft=Swigs Left: tooltip.armorinhibitor.desc1=Used to suppress a soul's tooltip.armorinhibitor.desc2=unnatural abilities. -tooltip.attunedcrystal.desc1=A tool to tune alchemy -tooltip.attunedcrystal.desc2=reagent transmission +tooltip.attunedcrystal.desc1=1) Sneak+right-click relay to select reagent +tooltip.attunedcrystal.desc2=2) Right-click source relay +tooltip.attunedcrystal.desc3=3) Right-click destination relay to link +tooltip.attunedcrystal.desc4=Sneak+right-click air to clear selection. +tooltip.attunedcrystal.desc5=Sneak+right-click relay to remove/clear links. tooltip.blankspell.desc=Crystal of infinite possibilities. tooltip.bloodframe.desc=Stirs bees into a frenzy. tooltip.bloodletterpack.desc=This pack really chafes... @@ -548,13 +551,21 @@ message.altar.progress=Altar's Progress: %,d LP / %,d LP message.altar.inputtank= Input Tank: %,d LP message.altar.outputtank= Output Tank: %,d LP message.altar.hunger=[BM] Your high regeneration rate has caused you to become hungry... -message.attunedcrystal.clearing=Clearing saved container... +message.attunedcrystal.clearing=Cleared saved source and reagent selection. message.attunedcrystal.error.cannotfind=Can no longer find linked container. message.attunedcrystal.error.noconnections=Linked container has no connections remaining! message.attunedcrystal.error.toofar=Linked container is either too far or is in a different dimension. -message.attunedcrystal.linked=Container is now linked. Transmitting: -message.attunedcrystal.linking=Linking to selected container. +message.attunedcrystal.error.noreagent=No reagent selected! Sneak+right-click a relay to select one. +message.attunedcrystal.error.duplicate=Already connected to that destination! +message.attunedcrystal.error.notremoved=No matching connection found to remove. +message.attunedcrystal.removed=Connection removed successfully. +message.attunedcrystal.clearedreagent=Cleared all %s connections from this relay. +message.attunedcrystal.linked=Linked! Transmitting %s. (%s/%s connections used) +message.attunedcrystal.linking=Source relay saved at %s, %s, %s. Right-click a destination to link. message.attunedcrystal.setto=Attuned Crystal now set to: +message.reagentconduit.noconnections=This relay has no routing connections. +message.reagentconduit.connections=Routing connections: +message.reagentconduit.connection.entry= %s -> (%s, %s, %s) message.demon.shallfollow=I shall follow and protect you! message.demon.willstay=I will stay here for now, Master. message.destinationclearer.cleared=Destination list now cleared.