Compare commits

...
3 Commits
4 changed files with 194 additions and 50 deletions

No files matched your search

@@ -1,13 +1,21 @@
package WayofTime.alchemicalWizardry.common.block; package WayofTime.alchemicalWizardry.common.block;
import java.util.List;
import java.util.Map;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World; import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.AlchemicalWizardry; 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 WayofTime.alchemicalWizardry.common.tileEntity.TEReagentConduit;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@@ -41,6 +49,37 @@ public class BlockReagentConduit extends BlockContainer {
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float what, public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float what,
float these, float are) { 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) {
TEReagentConduit relay = (TEReagentConduit) tile;
if (relay.reagentTargetList.isEmpty()) {
player.addChatComponentMessage(
new ChatComponentTranslation("message.reagentconduit.noconnections"));
} else {
player.addChatComponentMessage(
new ChatComponentTranslation("message.reagentconduit.connections"));
for (Map.Entry<Reagent, List<Int3>> entry : relay.reagentTargetList.entrySet()) {
Reagent reagent = entry.getKey();
List<Int3> offsets = entry.getValue();
if (offsets == null) continue;
for (Int3 offset : offsets) {
player.addChatComponentMessage(
new ChatComponentTranslation(
"message.reagentconduit.connection.entry",
reagent.name,
x + offset.xCoord,
y + offset.yCoord,
z + offset.zCoord));
}
}
}
return true;
}
}
}
return super.onBlockActivated(world, x, y, z, player, side, what, these, are); return super.onBlockActivated(world, x, y, z, player, side, what, these, are);
} }
@@ -60,6 +60,9 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
par3List.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc1")); par3List.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc1"));
par3List.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc2")); par3List.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc2"));
par3List.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc3"));
par3List.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc4"));
par3List.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc5"));
if (!(par1ItemStack.getTagCompound() == null)) { if (!(par1ItemStack.getTagCompound() == null)) {
Reagent reagent = this.getReagent(par1ItemStack); Reagent reagent = this.getReagent(par1ItemStack);
@@ -142,6 +145,10 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
if (movingobjectposition == null) { if (movingobjectposition == null) {
if (player.isSneaking()) { if (player.isSneaking()) {
this.setHasSavedCoordinates(itemStack, false); this.setHasSavedCoordinates(itemStack, false);
if (!itemStack.hasTagCompound()) {
itemStack.setTagCompound(new net.minecraft.nbt.NBTTagCompound());
}
itemStack.getTagCompound().setString("reagent", "");
player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.clearing")); player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.clearing"));
} }
@@ -161,35 +168,101 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
IReagentHandler relay = (IReagentHandler) tile; IReagentHandler relay = (IReagentHandler) tile;
if (player.isSneaking()) { if (player.isSneaking()) {
ReagentContainerInfo[] infos = relay.getContainerInfo(ForgeDirection.UNKNOWN); if (this.getHasSavedCoordinates(itemStack)) {
if (infos != null) { Int3 coords = this.getCoordinates(itemStack);
List<Reagent> reagentList = new LinkedList(); int dimension = this.getDimension(itemStack);
for (ReagentContainerInfo info : infos) {
if (info != null) {
ReagentStack reagentStack = info.reagent;
if (reagentStack != null) {
Reagent reagent = reagentStack.reagent;
if (reagent != null) {
reagentList.add(reagent);
}
}
}
}
Reagent pastReagent = this.getReagent(itemStack); if (coords == null) {
if (reagentList.size() <= 0) {
return itemStack; return itemStack;
} }
int reagentLocation; // Sneak+right-click saved source block again → clear all of reagent's connections
if (coords.xCoord == x && coords.yCoord == y && coords.zCoord == z) {
TileEntity pastTile = world.getTileEntity(coords.xCoord, coords.yCoord, coords.zCoord);
if (!(pastTile instanceof TEReagentConduit)) {
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;
}
TEReagentConduit pastRelay = (TEReagentConduit) pastTile;
pastRelay.reagentTargetList.remove(reagent);
this.setHasSavedCoordinates(itemStack, false);
player.addChatComponentMessage(
new ChatComponentTranslation(
"message.attunedcrystal.clearedreagent",
reagent.name));
world.markBlockForUpdate(coords.xCoord, coords.yCoord, coords.zCoord);
return itemStack;
}
reagentLocation = reagentList.indexOf(pastReagent); if (dimension != world.provider.dimensionId || Math.abs(coords.xCoord - x) > maxDistance
|| Math.abs(coords.yCoord - y) > maxDistance
|| Math.abs(coords.zCoord - z) > maxDistance) {
player.addChatComponentMessage(
new ChatComponentTranslation("message.attunedcrystal.error.toofar"));
return itemStack;
}
if (reagentLocation == -1 || reagentLocation + 1 >= reagentList.size()) { TileEntity pastTile = world.getTileEntity(coords.xCoord, coords.yCoord, coords.zCoord);
this.setReagentWithNotification(itemStack, reagentList.get(0), player); if (!(pastTile instanceof TEReagentConduit)) {
} else { player.addChatComponentMessage(
this.setReagentWithNotification(itemStack, reagentList.get(reagentLocation + 1), player); 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;
}
TEReagentConduit pastRelay = (TEReagentConduit) pastTile;
boolean removed = pastRelay.removeReagentDestinationViaActual(reagent, x, y, z);
player.addChatComponentMessage(
new ChatComponentTranslation(
removed ? "message.attunedcrystal.removed"
: "message.attunedcrystal.error.notremoved"));
world.markBlockForUpdate(coords.xCoord, coords.yCoord, coords.zCoord);
} else {
// No saved coords → cycle reagent selection
ReagentContainerInfo[] infos = relay.getContainerInfo(ForgeDirection.UNKNOWN);
if (infos != null) {
List<Reagent> reagentList = new LinkedList();
for (ReagentContainerInfo info : infos) {
if (info != null) {
ReagentStack reagentStack = info.reagent;
if (reagentStack != null) {
Reagent reagent = reagentStack.reagent;
if (reagent != null) {
reagentList.add(reagent);
}
}
}
}
Reagent pastReagent = this.getReagent(itemStack);
if (reagentList.size() <= 0) {
return itemStack;
}
int reagentLocation = reagentList.indexOf(pastReagent);
if (reagentLocation == -1 || reagentLocation + 1 >= reagentList.size()) {
this.setReagentWithNotification(itemStack, reagentList.get(0), player);
} else {
this.setReagentWithNotification(
itemStack,
reagentList.get(reagentLocation + 1),
player);
}
} }
} }
} else { } else {
@@ -217,25 +290,28 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
} }
Reagent reagent = this.getReagent(itemStack); Reagent reagent = this.getReagent(itemStack);
if (reagent == null) { if (reagent == null) {
player.addChatComponentMessage(
new ChatComponentTranslation("message.attunedcrystal.error.noreagent"));
return itemStack; return itemStack;
} }
TEReagentConduit pastRelay = (TEReagentConduit) pastTile; TEReagentConduit pastRelay = (TEReagentConduit) pastTile;
if (pastRelay.hasReagentDestination(reagent, x, y, z)) {
if (player.isSneaking()) { player.addChatComponentMessage(
pastRelay.removeReagentDestinationViaActual(reagent, x, y, z); 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 { } else {
if (pastRelay.addReagentDestinationViaActual(reagent, x, y, z)) { player.addChatComponentMessage(
player.addChatComponentMessage( new ChatComponentTranslation("message.attunedcrystal.error.noconnections"));
new ChatComponentText(
StatCollector.translateToLocal("message.attunedcrystal.linked") + " "
+ reagent.name));
} else {
player.addChatComponentMessage(
new ChatComponentTranslation("message.attunedcrystal.error.noconnections"));
}
} }
world.markBlockForUpdate(coords.xCoord, coords.yCoord, coords.zCoord); world.markBlockForUpdate(coords.xCoord, coords.yCoord, coords.zCoord);
} else { } else {
@@ -244,7 +320,8 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
this.setDimension(itemStack, dimension); this.setDimension(itemStack, dimension);
this.setCoordinates(itemStack, new Int3(x, y, z)); this.setCoordinates(itemStack, new Int3(x, y, z));
player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.linking")); player.addChatComponentMessage(
new ChatComponentTranslation("message.attunedcrystal.linking", x, y, z));
} }
} }
} }
@@ -417,17 +417,31 @@ public class TEReagentConduit extends TileSegmentedReagentHandler {
readClientNBT(packet.func_148857_g()); readClientNBT(packet.func_148857_g());
} }
public boolean addReagentDestinationViaOffset(Reagent reagent, int xOffset, int yOffset, int zOffset) { public int getTotalConnections() {
int totalConnections = 0; int total = 0;
for (List<Int3> list : this.reagentTargetList.values()) {
for (Entry<Reagent, List<Int3>> entry : this.reagentTargetList.entrySet()) { if (list != null) {
if (entry.getValue() != null) { total += list.size();
totalConnections += entry.getValue().size();
} }
} }
return total;
}
if (totalConnections >= this.maxConnextions) { public boolean hasReagentDestination(Reagent reagent, int x, int y, int z) {
// Send message that it cannot be done? Maybe add a Player instance int xOffset = x - this.xCoord;
int yOffset = y - this.yCoord;
int zOffset = z - this.zCoord;
if (this.reagentTargetList.containsKey(reagent)) {
List<Int3> 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; return false;
} }
@@ -444,6 +458,9 @@ public class TEReagentConduit extends TileSegmentedReagentHandler {
newCoordList.add(newCoord); newCoordList.add(newCoord);
this.reagentTargetList.put(reagent, newCoordList); this.reagentTargetList.put(reagent, newCoordList);
} else { } else {
if (coordList.contains(newCoord)) {
return false;
}
coordList.add(newCoord); coordList.add(newCoord);
} }
@@ -434,8 +434,11 @@ tooltip.alchemyflask.caution=CAUTION: Contents are throwable
tooltip.alchemyflask.swigsleft=Swigs Left: tooltip.alchemyflask.swigsleft=Swigs Left:
tooltip.armorinhibitor.desc1=Used to suppress a soul's tooltip.armorinhibitor.desc1=Used to suppress a soul's
tooltip.armorinhibitor.desc2=unnatural abilities. tooltip.armorinhibitor.desc2=unnatural abilities.
tooltip.attunedcrystal.desc1=A tool to tune alchemy tooltip.attunedcrystal.desc1=1) Sneak+right-click relay to select reagent
tooltip.attunedcrystal.desc2=reagent transmission 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.blankspell.desc=Crystal of infinite possibilities.
tooltip.bloodframe.desc=Stirs bees into a frenzy. tooltip.bloodframe.desc=Stirs bees into a frenzy.
tooltip.bloodletterpack.desc=This pack really chafes... 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.inputtank= Input Tank: %,d LP
message.altar.outputtank= Output 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.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.cannotfind=Can no longer find linked container.
message.attunedcrystal.error.noconnections=Linked container has no connections remaining! 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.error.toofar=Linked container is either too far or is in a different dimension.
message.attunedcrystal.linked=Container is now linked. Transmitting: message.attunedcrystal.error.noreagent=No reagent selected! Sneak+right-click a relay to select one.
message.attunedcrystal.linking=Linking to selected container. 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.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.shallfollow=I shall follow and protect you!
message.demon.willstay=I will stay here for now, Master. message.demon.willstay=I will stay here for now, Master.
message.destinationclearer.cleared=Destination list now cleared. message.destinationclearer.cleared=Destination list now cleared.