aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/drone/DroneConnection.java44
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_DroneCentre.java108
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_Hatch_DroneDownLink.java15
-rw-r--r--src/main/resources/assets/gregtech/lang/en_US.lang4
4 files changed, 143 insertions, 28 deletions
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/drone/DroneConnection.java b/src/main/java/gregtech/common/tileentities/machines/multi/drone/DroneConnection.java
index 57a8bea352..92b1c65032 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/drone/DroneConnection.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/drone/DroneConnection.java
@@ -13,13 +13,15 @@ import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
-import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
+import gregtech.api.util.GT_LanguageManager;
import gregtech.api.util.GT_Util;
+import gregtech.api.util.GT_Utility;
public class DroneConnection {
String customName;
+ String unlocalizedName;
GT_MetaTileEntity_MultiBlockBase machine;
ItemStack machineItem;
ChunkCoordinates machineCoord;
@@ -37,6 +39,7 @@ public class DroneConnection {
.getCoords();
this.world = centre.getBaseMetaTileEntity()
.getWorld();
+ unlocalizedName = machine.mName;
customName = Optional.ofNullable(centre.tempNameList.remove(machineCoord.toString()))
.orElse(machine.getLocalName());
}
@@ -61,6 +64,7 @@ public class DroneConnection {
centreTag.getInteger("z"));
this.centre = (GT_MetaTileEntity_DroneCentre) getLoadedGT_BaseMachineAt(centreCoord, world, true);
this.customName = aNBT.getString("name");
+ this.unlocalizedName = aNBT.getString("unlocalizedName");
}
public GT_MetaTileEntity_MultiBlockBase getMachine() {
@@ -79,25 +83,42 @@ public class DroneConnection {
return isValid();
}
- public String getCustomName() {
+ public String getCustomName(boolean localized) {
+ if (localized) return GT_LanguageManager.getTranslation("gt.blockmachines." + unlocalizedName + ".name");
return customName;
}
+ public float getDistanceSquared() {
+ return centreCoord.getDistanceSquaredToChunkCoordinates(machineCoord);
+ }
+
public void setCustomName(String name) {
customName = name;
}
+ public boolean isMachineShutdown() {
+ return machine != null && machine.shouldDisplayShutDownReason()
+ && !machine.getBaseMetaTileEntity()
+ .isActive()
+ && GT_Utility.isStringValid(
+ machine.getBaseMetaTileEntity()
+ .getLastShutDownReason()
+ .getDisplayString())
+ && machine.getBaseMetaTileEntity()
+ .wasShutdown();
+ }
+
public NBTTagCompound transConnectionToNBT() {
NBTTagCompound aNBT = new NBTTagCompound();
- if (!this.isValid()) return aNBT;
- aNBT.setTag("machine", transGT_BaseMachineToNBT(machine));
- aNBT.setTag("centre", transGT_BaseMachineToNBT(centre));
+ aNBT.setTag("machine", transCoordsToNBT(machineCoord));
+ aNBT.setTag("centre", transCoordsToNBT(centreCoord));
aNBT.setTag("item", machineItem.writeToNBT(new NBTTagCompound()));
aNBT.setInteger(
"worldID",
- machine.getBaseMetaTileEntity()
+ centre.getBaseMetaTileEntity()
.getWorld().provider.dimensionId);
- aNBT.setString("name", getCustomName());
+ aNBT.setString("name", getCustomName(false));
+ aNBT.setString("unlocalizedName", unlocalizedName);
return aNBT;
}
@@ -108,12 +129,11 @@ public class DroneConnection {
return (GT_MetaTileEntity_MultiBlockBase) ((IGregTechTileEntity) te).getMetaTileEntity();
}
- private NBTTagCompound transGT_BaseMachineToNBT(GT_MetaTileEntity_MultiBlockBase machine) {
- IHasWorldObjectAndCoords baseCoord = machine.getBaseMetaTileEntity();
+ private NBTTagCompound transCoordsToNBT(ChunkCoordinates coord) {
NBTTagCompound tag = new NBTTagCompound();
- tag.setInteger("x", baseCoord.getXCoord());
- tag.setInteger("y", baseCoord.getYCoord());
- tag.setInteger("z", baseCoord.getZCoord());
+ tag.setInteger("x", coord.posX);
+ tag.setInteger("y", coord.posY);
+ tag.setInteger("z", coord.posZ);
return tag;
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_DroneCentre.java b/src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_DroneCentre.java
index c989ff536e..fe2f3cceb4 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_DroneCentre.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_DroneCentre.java
@@ -9,12 +9,15 @@ import static gregtech.api.objects.XSTR.XSTR_INSTANCE;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import java.io.IOException;
+import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
-import java.util.Objects;
+import java.util.Locale;
import java.util.Optional;
+import java.util.stream.Collectors;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.item.EntityItem;
@@ -98,7 +101,9 @@ public class GT_MetaTileEntity_DroneCentre extends
private int buttonID;
private String searchFilter = "";
private boolean useRender = true;
- private final List<DroneConnection> connectionList = new ArrayList<>();
+ private boolean showLocalizedName = false;
+ private String sort = "distance";
+ private List<DroneConnection> connectionList = new ArrayList<>();
public HashMap<String, String> tempNameList = new HashMap<>();
// Save centre by dimID
private static final HashMultimap<Integer, GT_MetaTileEntity_DroneCentre> droneMap = HashMultimap.create();
@@ -178,7 +183,7 @@ public class GT_MetaTileEntity_DroneCentre extends
.addInfo("Monitors multiblock machines in range.")
.addInfo("Replace maintenance hatch on other multi with drone downlink module.")
.addInfo("Provides maintenance, power control, monitoring and etc.")
- .addInfo("Range is determined by drone tier: T1-32, T2-128, T3-512")
+ .addInfo("Range is determined by drone tier: T1-128, T2-512, T3-4096")
.addInfo("Place drones in input bus; only one needed to operate.")
.addInfo("Automatically upgrade based on the drone level in the input bus.")
.addInfo("There is a chance per second that the drone will crash.")
@@ -282,6 +287,7 @@ public class GT_MetaTileEntity_DroneCentre extends
super.loadNBTData(aNBT);
droneLevel = aNBT.getInteger("drone");
useRender = aNBT.getBoolean("useRender");
+ sort = aNBT.getString("sort");
NBTTagCompound nameList = aNBT.getCompoundTag("conList");
for (String s : nameList.func_150296_c()) {
tempNameList.put(s, nameList.getString(s));
@@ -293,9 +299,10 @@ public class GT_MetaTileEntity_DroneCentre extends
super.saveNBTData(aNBT);
aNBT.setInteger("drone", droneLevel);
aNBT.setBoolean("useRender", useRender);
+ aNBT.setString("sort", sort);
NBTTagCompound conList = new NBTTagCompound();
for (DroneConnection con : connectionList) {
- if (!Objects.equals(con.customName, con.machine.getLocalName()))
+ if (!con.customName.equals(con.machine.getLocalName()))
conList.setString(con.machineCoord.toString(), con.customName);
}
aNBT.setTag("conList", conList);
@@ -390,9 +397,9 @@ public class GT_MetaTileEntity_DroneCentre extends
public int getRange() {
return switch (droneLevel) {
- case 1 -> 32;
- case 2 -> 128;
- case 3 -> 512;
+ case 1 -> 128;
+ case 2 -> 512;
+ case 3 -> 4096;
default -> 0;
};
}
@@ -611,8 +618,87 @@ public class GT_MetaTileEntity_DroneCentre extends
.setFocusOnGuiOpen(false)
.setBackground(GT_UITextures.BACKGROUND_TEXT_FIELD_LIGHT_GRAY.withOffset(-1, -1, 2, 2))
.addTooltip(StatCollector.translateToLocal("GT5U.gui.text.drone_search"))
- .setPos(10, 30)
- .setSize(240, 16));
+ .setPos(50, 30)
+ .setSize(200, 16))
+ // Sort button
+ .widget(new ButtonWidget() {
+
+ @Override
+ public ClickResult onClick(int buttonId, boolean doubleClick) {
+ ClickResult result = super.onClick(buttonId, doubleClick);
+ syncToServer(2, buffer -> {});
+ return result;
+ }
+
+ @Override
+ public void readOnServer(int id, PacketBuffer buf) {
+ switch (id) {
+ case 1 -> super.readOnServer(id, buf);
+ case 2 -> {
+ getContext().closeWindow(MACHINE_LIST_WINDOW_ID);
+ getContext().openSyncedWindow(MACHINE_LIST_WINDOW_ID);
+ }
+ }
+ }
+ }.setOnClick((clickData, widget) -> {
+ switch (sort) {
+ case "name" -> sort = "distance";
+ case "distance" -> sort = "error";
+ case "error" -> sort = "name";
+ }
+ })
+ .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.drone_" + sort))
+ .setBackground(
+ () -> new IDrawable[] { GT_UITextures.BUTTON_STANDARD, GT_UITextures.OVERLAY_BUTTON_SORTING_MODE })
+ .setPos(10, 30)
+ .setSize(16, 16))
+ .widget(new FakeSyncWidget.StringSyncer(() -> sort, var1 -> sort = var1))
+ // Localized Button
+ .widget(new ButtonWidget() {
+
+ @Override
+ public ClickResult onClick(int buttonId, boolean doubleClick) {
+ ClickResult result = super.onClick(buttonId, doubleClick);
+ syncToServer(2, buffer -> {});
+ return result;
+ }
+
+ @Override
+ public void readOnServer(int id, PacketBuffer buf) {
+ switch (id) {
+ case 1 -> super.readOnServer(id, buf);
+ case 2 -> {
+ getContext().closeWindow(MACHINE_LIST_WINDOW_ID);
+ getContext().openSyncedWindow(MACHINE_LIST_WINDOW_ID);
+ }
+ }
+ }
+ }.setOnClick((clickData, widget) -> showLocalizedName = !showLocalizedName)
+ .addTooltip(StatCollector.translateToLocal("GT5U.gui.button.drone_showLocalName"))
+ .setBackground(
+ () -> new IDrawable[] {
+ showLocalizedName ? GT_UITextures.BUTTON_STANDARD_PRESSED : GT_UITextures.BUTTON_STANDARD,
+ GT_UITextures.OVERLAY_BUTTON_CYCLIC })
+ .setPos(30, 30)
+ .setSize(16, 16));
+ // Sort first
+ switch (sort) {
+ case "name" -> connectionList = connectionList.stream()
+ .sorted(
+ (o1, o2) -> Collator.getInstance(Locale.UK)
+ .compare(o1.getCustomName(false), o2.getCustomName(false)))
+ .collect(Collectors.toList());
+ case "distance" -> connectionList = connectionList.stream()
+ .sorted(Comparator.comparing(DroneConnection::getDistanceSquared))
+ .collect(Collectors.toList());
+ case "error" -> connectionList = connectionList.stream()
+ .sorted(
+ Comparator.comparing(DroneConnection::isMachineShutdown)
+ .reversed()
+ .thenComparing(DroneConnection::getDistanceSquared))
+ .collect(Collectors.toList());
+ }
+
Scrollable MachineContainer = new Scrollable().setVerticalScroll();
int posY = 0;
for (int i = 0; i < connectionList.size(); i++) {
@@ -741,7 +827,7 @@ public class GT_MetaTileEntity_DroneCentre extends
row.widget(
new TextWidget(
connectionList.get(i)
- .getCustomName()).setTextAlignment(Alignment.CenterLeft)
+ .getCustomName(showLocalizedName)).setTextAlignment(Alignment.CenterLeft)
.setPos(0, 4));
MachineContainer.widget(
row.setAlignment(MainAxisAlignment.SPACE_BETWEEN)
@@ -778,7 +864,7 @@ public class GT_MetaTileEntity_DroneCentre extends
}
}.setGetter(
() -> connectionList.get(buttonID)
- .getCustomName())
+ .getCustomName(false))
.setSetter(
var -> connectionList.get(buttonID)
.setCustomName(var))
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_Hatch_DroneDownLink.java b/src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_Hatch_DroneDownLink.java
index 243f846333..959b6874ba 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_Hatch_DroneDownLink.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_Hatch_DroneDownLink.java
@@ -7,6 +7,7 @@ import java.util.Queue;
import java.util.Set;
import java.util.stream.Collectors;
+import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -225,10 +226,14 @@ public class GT_MetaTileEntity_Hatch_DroneDownLink extends GT_MetaTileEntity_Hat
final TileEntity tTileEntity;
final boolean isMachineBlock;
tTileEntity = world.getTileEntity(aCoords.posX, aCoords.posY, aCoords.posZ);
- isMachineBlock = GregTech_API.isMachineBlock(
- world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ),
- world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ));
-
+ Block block = world.getBlock(aCoords.posX, aCoords.posY, aCoords.posZ);
+ // Plascrete block isn't registered as machineBlock, therefore we have to check it manually so that drone
+ // can work with cleanroom.
+ // Todo: loading cleanroom's config for other blocks
+ isMachineBlock = GregTech_API
+ .isMachineBlock(block, world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ))
+ || (block == GregTech_API.sBlockReinforced
+ && world.getBlockMetadata(aCoords.posX, aCoords.posY, aCoords.posZ) == 2);
// See if the block itself is MultiBlock, also the one we need.
if (tTileEntity instanceof IGregTechTileEntity te
&& te.getMetaTileEntity() instanceof GT_MetaTileEntity_MultiBlockBase mte)
@@ -289,7 +294,7 @@ public class GT_MetaTileEntity_Hatch_DroneDownLink extends GT_MetaTileEntity_Hat
.setPos(0, 5)
.setSize(150, 8))
.widget(
- new TextFieldWidget().setGetter(() -> connection == null ? "" : connection.getCustomName())
+ new TextFieldWidget().setGetter(() -> connection == null ? "" : connection.getCustomName(false))
.setSetter(var -> { if (connection != null) connection.setCustomName(var); })
.setTextAlignment(Alignment.CenterLeft)
.setTextColor(Color.WHITE.dark(1))
diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang
index 6158732ac6..f32219580e 100644
--- a/src/main/resources/assets/gregtech/lang/en_US.lang
+++ b/src/main/resources/assets/gregtech/lang/en_US.lang
@@ -432,6 +432,10 @@ GT5U.gui.button.drone_outofrange=§4Machine is too far, drone control system not
GT5U.gui.button.drone_open_list=Open Machine List
GT5U.gui.button.drone_poweron_all=Turn ON ALL machines, no matter how remote
GT5U.gui.button.drone_poweroff_all=Turn OFF ALL machines, no matter how remote
+GT5U.gui.button.drone_name=Sort by §3name
+GT5U.gui.button.drone_distance=Sort by §3distance
+GT5U.gui.button.drone_error=Sort by §3shutdown status
+GT5U.gui.button.drone_showLocalName=Show localized name
GT5U.gui.text.success=§aProcessing recipe
GT5U.gui.text.generating=§aGenerating power
GT5U.gui.text.no_recipe=§7No valid recipe found