Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App prospector #104

Merged
merged 2 commits into from
Aug 22, 2021
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 5 additions & 4 deletions src/main/java/gregtech/api/gui/widgets/SlotWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ protected Slot createSlot(IItemHandler itemHandler, int index) {
@Override
@SideOnly(Side.CLIENT)
public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
if (isEnabled() && backgroundTexture != null) {
if (isEnabled()) {
Position pos = getPosition();
Size size = getSize();
for (IGuiTexture backgroundTexture : this.backgroundTexture) {
backgroundTexture.draw(pos.x, pos.y, size.width, size.height);
if (backgroundTexture != null) {
for (IGuiTexture backgroundTexture : this.backgroundTexture) {
backgroundTexture.draw(pos.x, pos.y, size.width, size.height);
}
}

RenderHelper.enableGUIStandardItemLighting();
GlStateManager.pushMatrix();
RenderItem itemRender = Minecraft.getMinecraft().getRenderItem();
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/gregtech/api/net/SProspectingPacket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package gregtech.api.net;

import net.minecraft.network.PacketBuffer;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class SProspectingPacket {
public int chunkX;
public int chunkZ;
public int posX;
public int posZ;
public int mode;
public HashMap<Byte, String>[][] map;
public Set<String> ores;

public SProspectingPacket(int chunkX, int chunkZ, int posX, int posZ, int mode) {
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.posX = posX;
this.posZ = posZ;
this.mode = mode;
if (mode == 1)
map = new HashMap[1][1];
else
map = new HashMap[16][16];

ores = new HashSet<>();
}

public static SProspectingPacket readPacketData(PacketBuffer buffer) {
SProspectingPacket packet = new SProspectingPacket(buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt(), buffer.readInt());
int aSize = 0;
if (packet.mode == 0)
aSize = 16;
else if (packet.mode == 1)
aSize = 1;
int checkOut = 0;
for (int i = 0; i < aSize; i++)
for (int j = 0; j < aSize; j++) {
byte kSize = buffer.readByte();
if (kSize == 0) continue;
packet.map[i][j] = new HashMap<>();
for (int k = 0; k < kSize; k++) {
byte y = buffer.readByte();
String name = buffer.readString(1000);
packet.map[i][j].put(y, name);
if (packet.mode != 1 || y == 1)
packet.ores.add(name);
checkOut++;
}
}
int checkOut2 = buffer.readInt();
if (checkOut != checkOut2) {
return null;
}
return packet;
}

public void writePacketData(PacketBuffer buffer) {
buffer.writeInt(chunkX);
buffer.writeInt(chunkZ);
buffer.writeInt(posX);
buffer.writeInt(posZ);
buffer.writeInt(mode);
int aSize = 0;
if (this.mode == 0)
aSize = 16;
else if (this.mode == 1)
aSize = 1;
int checkOut = 0;
for (int i = 0; i < aSize; i++)
for (int j = 0; j < aSize; j++) {
if (map[i][j] == null)
buffer.writeByte(0);
else {
buffer.writeByte(map[i][j].keySet().size());
for (byte key : map[i][j].keySet()) {
buffer.writeByte(key);
buffer.writeString(map[i][j].get(key));
checkOut++;
}
}
}
buffer.writeInt(checkOut);
}

public void addBlock(int x, int y, int z, String orePrefix) {
if (this.mode == 0) {
if (map[x][z] == null)
map[x][z] = new HashMap<>();
map[x][z].put((byte) y, orePrefix);
ores.add(orePrefix);
} else if (this.mode == 1) {
if (map[x][z] == null)
map[x][z] = new HashMap<>();
map[x][z].put((byte) y, orePrefix);
if (y == 1) {
ores.add(orePrefix);
}
}
}

}
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/terminal/TerminalRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import gregtech.common.terminal.app.guide.SimpleMachineGuideApp;
import gregtech.common.terminal.app.guide.TutorialGuideApp;
import gregtech.common.terminal.app.guideeditor.GuideEditorApp;
import gregtech.common.terminal.app.prospector.OreProspectorApp;
import gregtech.common.terminal.app.recipechart.RecipeChartApp;

import java.util.*;
Expand All @@ -23,6 +24,7 @@ public static void init() {
registerApp(new TutorialGuideApp(), true);
registerApp(new GuideEditorApp(), true);
registerApp(new ThemeSettingApp(), true);
registerApp(new OreProspectorApp(), true);
if (GTValues.isModLoaded(GTValues.MODID_JEI)) {
registerApp(new RecipeChartApp(), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ else if (yBarWidth > 0 && isOnYScrollPane(mouseX, mouseY)) {
return false;
}

private boolean checkClickedDragged(int mouseX, int mouseY, int button) {
protected boolean checkClickedDragged(int mouseX, int mouseY, int button) {
draggedWidget = null;
for (int i = widgets.size() - 1; i >= 0; i--) {
Widget widget = widgets.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public TerminalDesktopWidget(Position position, Size size, TerminalOSWidget os)
public void installApplication(AbstractApplication application){
int r = 12;
int index = appDiv.widgets.size();
int x = this.getSize().width / 2 + (3 * r) * (index - 3);
int x = this.getSize().width / 2 + (3 * r) * (index % 7 - 3);
int y = (index / 7) * (3 * r) + 40;
CircleButtonWidget button = new CircleButtonWidget(x,y)
.setColors(TerminalTheme.COLOR_B_2.getColor(),
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/gregtech/api/unification/OreDictUnifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gregtech.api.unification.stack.*;
import gregtech.api.util.CustomModPriorityComparator;
import gregtech.common.ConfigHolder;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.MinecraftForge;
Expand Down Expand Up @@ -200,6 +201,10 @@ public static OrePrefix getPrefix(ItemStack itemStack) {
return null;
}

public static OrePrefix getPrefix(Block block) {
return getPrefix(new ItemStack(block));
}

@Nullable
public static UnificationEntry getUnificationEntry(ItemStack itemStack) {
if (itemStack.isEmpty()) return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package gregtech.common.terminal.app.prospector;

import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.widgets.ImageWidget;
import gregtech.api.terminal.app.AbstractApplication;
import gregtech.api.terminal.os.TerminalOSWidget;
import gregtech.api.terminal.os.TerminalTheme;
import gregtech.api.terminal.os.menu.IMenuComponent;
import gregtech.common.terminal.app.prospector.widget.WidgetOreList;
import gregtech.common.terminal.app.prospector.widget.WidgetProspectingMap;
import gregtech.common.terminal.component.ClickComponent;
import gregtech.common.terminal.component.SearchComponent;
import net.minecraft.nbt.NBTTagCompound;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public class OreProspectorApp extends AbstractApplication implements
SearchComponent.IWidgetSearch<String> {
WidgetOreList widgetOreList;
WidgetProspectingMap widgetProspectingMap;

public OreProspectorApp() {
super("ore_prospector", GuiTextures.SCANNER_OVERLAY);
}

@Override
public AbstractApplication createApp(TerminalOSWidget os, boolean isClient, NBTTagCompound nbt) { //333, 232
OreProspectorApp app = new OreProspectorApp();
app.addWidget(new ImageWidget(0, 0, 333, 232, TerminalTheme.COLOR_B_2));
int chunkRadius = 7;
int offset = (232 - 32 * 7 + 16) / 2;
if (isClient) {
app.widgetOreList = new WidgetOreList(32 * chunkRadius - 16, offset, 333 - 32 * chunkRadius + 16, 232 - 2 * offset);
app.addWidget(app.widgetOreList);
}
app.widgetProspectingMap = new WidgetProspectingMap(0, offset, chunkRadius, app.widgetOreList, 0, 1);
app.addWidget(1, app.widgetProspectingMap);
return app;
}

@Override
public List<IMenuComponent> getMenuComponents() {
ClickComponent darkMode = new ClickComponent().setIcon(GuiTextures.ICON_VISIBLE).setHoverText("terminal.prospector.vis_mode").setClickConsumer(cd->{
if (cd.isClient) {
widgetProspectingMap.setDarkMode(!widgetProspectingMap.getDarkMode());
}
});
return Arrays.asList(darkMode, new SearchComponent<>(this));
}

@Override
public String resultDisplay(String result) {
if (widgetOreList != null) {
return widgetOreList.ores.get(result);
}
return "";
}

@Override
public void selectResult(String result) {
if (widgetOreList != null) {
widgetOreList.setSelected(result);
}
}

@Override
public void search(String word, Consumer<String> find) {
if (widgetOreList != null) {
word = word.toLowerCase();
for (Map.Entry<String, String> entry : widgetOreList.ores.entrySet()) {
if (entry.getKey().toLowerCase().contains(word) || entry.getValue().toLowerCase().contains(word)) {
find.accept(entry.getKey());
}
}
}
}
}
Loading