Merge remote-tracking branch 'origin/alchemic-router-not-bad' into dev

This commit is contained in:
Martin Robertz committed 2026-05-03 12:15:09 +02:00
commit 801c1c9eb5
4 files changed
+194 -50

No files matched your search

@@ -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,37 @@ 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) {
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);
}
@@ -60,6 +60,9 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
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);
@@ -142,6 +145,10 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
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"));
}
@@ -161,35 +168,101 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
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);
Reagent pastReagent = this.getReagent(itemStack);
if (reagentList.size() <= 0) {
if (coords == null) {
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()) {
this.setReagentWithNotification(itemStack, reagentList.get(0), player);
} else {
this.setReagentWithNotification(itemStack, reagentList.get(reagentLocation + 1), player);
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;
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 {
@@ -217,25 +290,28 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
}
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 {
@@ -244,7 +320,8 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
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));
}
}
}
@@ -417,17 +417,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<Reagent, List<Int3>> entry : this.reagentTargetList.entrySet()) {
if (entry.getValue() != null) {
totalConnections += entry.getValue().size();
public int getTotalConnections() {
int total = 0;
for (List<Int3> 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<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;
}
@@ -444,6 +458,9 @@ public class TEReagentConduit extends TileSegmentedReagentHandler {
newCoordList.add(newCoord);
this.reagentTargetList.put(reagent, newCoordList);
} else {
if (coordList.contains(newCoord)) {
return false;
}
coordList.add(newCoord);
}
@@ -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.