Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,6 +49,37 @@ public boolean canProvidePower() {
@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) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public String getItemStackDisplayName(ItemStack stack) {
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
par3List.add(StatCollector.translateToLocal("tooltip.attunedcrystal.desc1"));
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)) {
Reagent reagent = this.getReagent(par1ItemStack);
Expand Down Expand Up @@ -142,6 +145,10 @@ public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer
if (movingobjectposition == null) {
if (player.isSneaking()) {
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"));
}

Expand All @@ -161,35 +168,101 @@ public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer
IReagentHandler relay = (IReagentHandler) tile;

if (player.isSneaking()) {
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);
}
}
if (this.getHasSavedCoordinates(itemStack)) {
Int3 coords = this.getCoordinates(itemStack);
int dimension = this.getDimension(itemStack);

if (coords == null) {
return itemStack;
}

// 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;
}

Reagent pastReagent = this.getReagent(itemStack);
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 (reagentList.size() <= 0) {
TileEntity pastTile = world.getTileEntity(coords.xCoord, coords.yCoord, coords.zCoord);
if (!(pastTile instanceof TEReagentConduit)) {
player.addChatComponentMessage(
new ChatComponentTranslation("message.attunedcrystal.error.cannotfind"));
return itemStack;
}

int reagentLocation;
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);
}
}
}
}

reagentLocation = reagentList.indexOf(pastReagent);
Reagent pastReagent = this.getReagent(itemStack);

if (reagentLocation == -1 || reagentLocation + 1 >= reagentList.size()) {
this.setReagentWithNotification(itemStack, reagentList.get(0), player);
} else {
this.setReagentWithNotification(itemStack, reagentList.get(reagentLocation + 1), player);
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 {
Expand Down Expand Up @@ -217,25 +290,28 @@ public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer
}

Reagent reagent = this.getReagent(itemStack);

if (reagent == null) {
player.addChatComponentMessage(
new ChatComponentTranslation("message.attunedcrystal.error.noreagent"));
return itemStack;
}

TEReagentConduit pastRelay = (TEReagentConduit) pastTile;

if (player.isSneaking()) {
pastRelay.removeReagentDestinationViaActual(reagent, x, y, z);
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 {
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"));
}
player.addChatComponentMessage(
new ChatComponentTranslation("message.attunedcrystal.error.noconnections"));
}
world.markBlockForUpdate(coords.xCoord, coords.yCoord, coords.zCoord);
} else {
Expand All @@ -244,7 +320,8 @@ public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer
this.setDimension(itemStack, dimension);
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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,31 @@ public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
readClientNBT(packet.func_148857_g());
}

public boolean addReagentDestinationViaOffset(Reagent reagent, int xOffset, int yOffset, int zOffset) {
int totalConnections = 0;
public int getTotalConnections() {
int total = 0;
for (List<Int3> list : this.reagentTargetList.values()) {
if (list != null) {
total += list.size();
}
}
return total;
}

for (Entry<Reagent, List<Int3>> entry : this.reagentTargetList.entrySet()) {
if (entry.getValue() != null) {
totalConnections += entry.getValue().size();
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<Int3> coords = this.reagentTargetList.get(reagent);
if (coords != null) {
return coords.contains(new Int3(xOffset, yOffset, zOffset));
}
}
return false;
}

if (totalConnections >= this.maxConnextions) {
// Send message that it cannot be done? Maybe add a Player instance
public boolean addReagentDestinationViaOffset(Reagent reagent, int xOffset, int yOffset, int zOffset) {
if (getTotalConnections() >= this.maxConnextions) {
return false;
}

Expand All @@ -444,6 +458,9 @@ public boolean addReagentDestinationViaOffset(Reagent reagent, int xOffset, int
newCoordList.add(newCoord);
this.reagentTargetList.put(reagent, newCoordList);
} else {
if (coordList.contains(newCoord)) {
return false;
}
coordList.add(newCoord);
}

Expand Down
21 changes: 16 additions & 5 deletions src/main/resources/assets/alchemicalwizardry/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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.
Expand Down
Loading