mirror of
https://github.com/GTNewHorizons/BloodMagic.git
synced 2026-11-24 05:44:32 +00:00
Make the Alchemic Router's UX Better (#124)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: koolkrafter5 <[email protected]>
This commit is contained in:
6 files changed
+276
-118
No files matched your search
@@ -96,6 +96,7 @@ public class IMCForNEI {
|
||||
sendInfoPage("AWWayofTime masterStone,blockAlchemicCalcinator", "nei.infopage.reagents.1");
|
||||
sendInfoPage("AWWayofTime masterStone,blockAlchemicCalcinator|<AWWayofTime:terrae>", "nei.infopage.reagents.2");
|
||||
sendInfoPage("AWWayofTime masterStone,blockAlchemicCalcinator,itemAttunedCrystal", "nei.infopage.reagents.3");
|
||||
sendInfoPage("AWWayofTime masterStone,blockAlchemicCalcinator,itemAttunedCrystal", "nei.infopage.reagents.3b");
|
||||
sendInfoPage(
|
||||
"AWWayofTime masterStone,blockAlchemicCalcinator,itemTankSegmenter,itemDestinationClearer",
|
||||
"nei.infopage.reagents.4");
|
||||
|
||||
@@ -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<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.x(),
|
||||
y + offset.y(),
|
||||
z + offset.z()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onBlockActivated(world, x, y, z, player, side, what, these, are);
|
||||
}
|
||||
|
||||
|
||||
+132
-88
@@ -60,6 +60,9 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
|
||||
public void addInformation(ItemStack item, EntityPlayer player, List<String> 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;
|
||||
@@ -131,107 +134,141 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, false);
|
||||
|
||||
if (movingobjectposition == null) {
|
||||
if (player.isSneaking()) {
|
||||
// Sneak wipes the source first, then the reagent — regardless of where the cursor points.
|
||||
if (player.isSneaking()) {
|
||||
if (this.getHasSavedCoordinates(itemStack)) {
|
||||
this.setHasSavedCoordinates(itemStack, false);
|
||||
player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.clearing"));
|
||||
} else if (this.getReagent(itemStack) != null) {
|
||||
this.clearReagent(itemStack);
|
||||
player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.reagentcleared"));
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, false);
|
||||
if (movingobjectposition == null
|
||||
|| movingobjectposition.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
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 (this.getHasSavedCoordinates(itemStack)) {
|
||||
Int3 coords = this.getCoordinates(itemStack);
|
||||
int dimension = this.getDimension(itemStack);
|
||||
if (coords == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
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 (!(tile instanceof IReagentHandler relay)) {
|
||||
// Re-clicking the saved source cycles its reagents, never tries to self-link.
|
||||
if (dimension == world.provider.dimensionId && coords.x() == x && coords.y() == y && coords.z() == z) {
|
||||
List<Reagent> reagentList = collectReagents(relay);
|
||||
if (reagentList.size() <= 1) {
|
||||
player.addChatComponentMessage(
|
||||
new ChatComponentTranslation("message.attunedcrystal.error.cannotlinktoself"));
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
if (player.isSneaking()) {
|
||||
ReagentContainerInfo[] infos = relay.getContainerInfo(ForgeDirection.UNKNOWN);
|
||||
if (infos != null) {
|
||||
List<Reagent> 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);
|
||||
}
|
||||
}
|
||||
} 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"));
|
||||
}
|
||||
}
|
||||
Reagent pastReagent = this.getReagent(itemStack);
|
||||
int reagentLocation = reagentList.indexOf(pastReagent);
|
||||
Reagent next = (reagentLocation == -1 || reagentLocation + 1 >= reagentList.size())
|
||||
? reagentList.getFirst()
|
||||
: reagentList.get(reagentLocation + 1);
|
||||
this.setReagentWithNotification(itemStack, next, player);
|
||||
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)) {
|
||||
// Saved source is gone — clear it so the player can start over without a manual reset.
|
||||
this.setHasSavedCoordinates(itemStack, false);
|
||||
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));
|
||||
// Successful link: clear the source so the next click starts a fresh link, but
|
||||
// keep the reagent so the player can fan out to multiple destinations quickly.
|
||||
this.setHasSavedCoordinates(itemStack, false);
|
||||
} else {
|
||||
player.addChatComponentMessage(
|
||||
new ChatComponentTranslation("message.attunedcrystal.error.noconnections"));
|
||||
}
|
||||
world.markBlockForUpdate(coords.x(), coords.y(), coords.z());
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
// No saved source — this click saves one and (when useful) copies its reagent.
|
||||
if (tile instanceof TEReagentConduit conduit && conduit.getTotalConnections() >= conduit.maxConnextions) {
|
||||
player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.error.sourcefull"));
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
List<Reagent> reagentList = collectReagents(relay);
|
||||
Reagent currentReagent = this.getReagent(itemStack);
|
||||
if (reagentList.isEmpty() && currentReagent == null) {
|
||||
player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.error.nothingtocopy"));
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
// Keep the crystal's existing reagent if the source has it (or if the source is empty);
|
||||
// otherwise replace with the source's first tank.
|
||||
if (!reagentList.isEmpty() && (currentReagent == null || !reagentList.contains(currentReagent))) {
|
||||
this.setReagentWithNotification(itemStack, reagentList.getFirst(), player);
|
||||
}
|
||||
|
||||
this.setDimension(itemStack, world.provider.dimensionId);
|
||||
this.setCoordinates(itemStack, new Int3(x, y, z));
|
||||
player.addChatComponentMessage(new ChatComponentTranslation("message.attunedcrystal.linking", x, y, z));
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private static List<Reagent> collectReagents(IReagentHandler relay) {
|
||||
List<Reagent> reagentList = new LinkedList<>();
|
||||
ReagentContainerInfo[] infos = relay.getContainerInfo(ForgeDirection.UNKNOWN);
|
||||
if (infos == null) {
|
||||
return reagentList;
|
||||
}
|
||||
for (ReagentContainerInfo info : infos) {
|
||||
if (info == null) continue;
|
||||
ReagentStack reagentStack = info.reagent;
|
||||
if (reagentStack == null) continue;
|
||||
Reagent reagent = reagentStack.reagent;
|
||||
if (reagent != null && !reagentList.contains(reagent)) {
|
||||
reagentList.add(reagent);
|
||||
}
|
||||
}
|
||||
return reagentList;
|
||||
}
|
||||
|
||||
public static List<Reagent> getReagents(ReagentContainerInfo[] infos) {
|
||||
List<Reagent> reagentList = new LinkedList<>();
|
||||
for (ReagentContainerInfo info : infos) {
|
||||
@@ -248,6 +285,13 @@ public class ItemAttunedCrystal extends Item implements IReagentManipulator {
|
||||
return reagentList;
|
||||
}
|
||||
|
||||
public void clearReagent(ItemStack stack) {
|
||||
if (!stack.hasTagCompound()) {
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
stack.getTagCompound().setString("reagent", "");
|
||||
}
|
||||
|
||||
public void setCoordinates(ItemStack stack, Int3 coords) {
|
||||
if (!stack.hasTagCompound()) {
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
|
||||
+55
-11
@@ -1,6 +1,8 @@
|
||||
package WayofTime.alchemicalWizardry.common.items.energy;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -13,6 +15,8 @@ import net.minecraft.util.StatCollector;
|
||||
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;
|
||||
@@ -45,26 +49,66 @@ public class ItemDestinationClearer extends Item implements IReagentManipulator
|
||||
}
|
||||
|
||||
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, false);
|
||||
|
||||
if (movingobjectposition == null) {
|
||||
if (movingobjectposition == null
|
||||
|| movingobjectposition.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) {
|
||||
return itemStack;
|
||||
}
|
||||
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);
|
||||
int x = movingobjectposition.blockX;
|
||||
int y = movingobjectposition.blockY;
|
||||
int z = movingobjectposition.blockZ;
|
||||
|
||||
if (!(tile instanceof TEReagentConduit relay)) {
|
||||
return itemStack;
|
||||
}
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (!(tile instanceof TEReagentConduit relay)) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
if (player.isSneaking()) {
|
||||
int removed = clearIncomingConnections(world, x, y, z);
|
||||
player.addChatComponentMessage(
|
||||
new ChatComponentTranslation("message.destinationclearer.incoming.cleared", removed));
|
||||
} else {
|
||||
relay.reagentTargetList.clear();
|
||||
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
player.addChatComponentMessage(new ChatComponentTranslation("message.destinationclearer.cleared"));
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private static int clearIncomingConnections(World world, int x, int y, int z) {
|
||||
int range = ItemAttunedCrystal.maxDistance;
|
||||
int totalRemoved = 0;
|
||||
for (int dx = -range; dx <= range; dx++) {
|
||||
for (int dy = -range; dy <= range; dy++) {
|
||||
for (int dz = -range; dz <= range; dz++) {
|
||||
if (dx == 0 && dy == 0 && dz == 0) continue;
|
||||
TileEntity neighbor = world.getTileEntity(x + dx, y + dy, z + dz);
|
||||
if (!(neighbor instanceof TEReagentConduit src)) continue;
|
||||
|
||||
boolean changed = false;
|
||||
Iterator<Map.Entry<Reagent, List<Int3>>> entries = src.reagentTargetList.entrySet().iterator();
|
||||
while (entries.hasNext()) {
|
||||
Map.Entry<Reagent, List<Int3>> entry = entries.next();
|
||||
List<Int3> coords = entry.getValue();
|
||||
if (coords == null) continue;
|
||||
Iterator<Int3> it = coords.iterator();
|
||||
while (it.hasNext()) {
|
||||
Int3 off = it.next();
|
||||
if (src.xCoord + off.x() == x && src.yCoord + off.y() == y && src.zCoord + off.z() == z) {
|
||||
it.remove();
|
||||
changed = true;
|
||||
totalRemoved++;
|
||||
}
|
||||
}
|
||||
if (coords.isEmpty()) entries.remove();
|
||||
}
|
||||
if (changed) {
|
||||
world.markBlockForUpdate(src.xCoord, src.yCoord, src.zCoord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalRemoved;
|
||||
}
|
||||
}
|
||||
@@ -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<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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user