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

Handheld Prospectors #314

Merged
merged 4 commits into from
Dec 9, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/main/java/gregtech/common/items/MetaItem1.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,24 +379,26 @@ public void registerSubItems() {
DYNAMITE = addItem(460, "dynamite").addComponents(new DynamiteBehaviour()).setMaxStackSize(16);
INTEGRATED_CIRCUIT = addItem(461, "circuit.integrated").addComponents(new IntCircuitBehaviour()).setModelAmount(33);
FOAM_SPRAYER = addItem(462, "foam_sprayer").addComponents(new FoamSprayerBehavior()).setMaxStackSize(1);
NANO_SABER = addItem(463, "nano_saber").addComponents(ElectricStats.createElectricItem(4000000L, GTValues.HV)).addComponents(new NanoSaberBehavior()).setMaxStackSize(1);
// Free ID 464
SCANNER = addItem(465, "scanner").addComponents(ElectricStats.createElectricItem(200_000L, GTValues.LV), new ScannerBehavior(50));
CLIPBOARD = addItem(466, "clipboard").addComponents(new ClipboardBehavior()).setMaxStackSize(1);
TERMINAL = addItem(467, "terminal").addComponents(new HardwareProvider(), new TerminalBehaviour()).setMaxStackSize(1);
WIRELESS = addItem(468, "wireless");
CAMERA = addItem(469, "camera");
NANO_SABER = addItem(463, "nano_saber").addComponents(ElectricStats.createElectricItem(4_000_000L, GTValues.HV)).addComponents(new NanoSaberBehavior()).setMaxStackSize(1);
SCANNER = addItem(464, "scanner").addComponents(ElectricStats.createElectricItem(200_000L, GTValues.LV), new ScannerBehavior(50));
CLIPBOARD = addItem(465, "clipboard").addComponents(new ClipboardBehavior()).setMaxStackSize(1);
TERMINAL = addItem(466, "terminal").addComponents(new HardwareProvider(), new TerminalBehaviour()).setMaxStackSize(1);
PROSPECTOR_LV = addItem(467, "prospector.lv").addComponents(ElectricStats.createElectricItem(100_000L, GTValues.LV), new ProspectorScannerBehavior(2, GTValues.LV));
PROSPECTOR_HV = addItem(468, "prospector.hv").addComponents(ElectricStats.createElectricItem(1_600_000L, GTValues.HV), new ProspectorScannerBehavior(3, GTValues.HV));
PROSPECTOR_LUV = addItem(469, "prospector.luv").addComponents(ElectricStats.createElectricItem(1_000_000_000L, GTValues.LuV), new ProspectorScannerBehavior(5, GTValues.LuV));

// Misc Crafting Items: ID 491-515
//Free ID: 493, 494, 495, 496
ENERGIUM_DUST = addItem(491, "energium_dust");
ENGRAVED_LAPOTRON_CHIP = addItem(492, "engraved.lapotron_chip");
//Free ID: 493, 494, 495, 496
NEUTRON_REFLECTOR = addItem(497, "neutron_reflector");
GELLED_TOLUENE = addItem(498, "gelled_toluene");
CARBON_FIBERS = addItem(499, "carbon.fibers");
CARBON_MESH = addItem(500, "carbon.mesh");
CARBON_PLATE = addItem(501, "carbon.plate");
DUCT_TAPE = addItem(502, "duct_tape");
WIRELESS = addItem(503, "wireless");
CAMERA = addItem(504, "camera");

// Circuit Components: ID 516-565
VACUUM_TUBE = addItem(516, "circuit.vacuum_tube").setUnificationData(OrePrefix.circuit, Tier.Primitive);
Expand Down Expand Up @@ -559,7 +561,7 @@ public void registerSubItems() {
BATTERY_UV_NAQUADRIA = addItem(747, "battery.uv.naquadria").addComponents(ElectricStats.createRechargeableBattery(2621440000L, GTValues.UV)).setUnificationData(OrePrefix.battery, Tier.Super).setModelAmount(8);

ENERGY_LAPOTRONIC_ORB = addItem(748, "energy.lapotronicorb").addComponents(ElectricStats.createRechargeableBattery(100000000L, GTValues.IV)).setUnificationData(OrePrefix.battery, Tier.Elite).setModelAmount(8);
ENERGY_LAPOTRONIC_ORB2 = addItem(749, "energy.lapotronicorb2").addComponents(ElectricStats.createRechargeableBattery(1000000000L, GTValues.LuV)).setUnificationData(OrePrefix.battery, Tier.Master).setModelAmount(8);
ENERGY_LAPOTRONIC_ORB_CLUSTER = addItem(749, "energy.lapotronicorb2").addComponents(ElectricStats.createRechargeableBattery(1000000000L, GTValues.LuV)).setUnificationData(OrePrefix.battery, Tier.Master).setModelAmount(8);

ENERGY_LAPOTRONIC_MODULE = addItem(750, "energy.module").addComponents(new IItemComponent[]{ElectricStats.createRechargeableBattery(10000000000L, GTValues.ZPM)}).setUnificationData(OrePrefix.battery, Tier.Ultimate).setModelAmount(8);
ENERGY_LAPOTRONIC_CLUSTER = addItem(751, "energy.cluster").addComponents(new IItemComponent[]{ElectricStats.createRechargeableBattery(100000000000L, GTValues.UV)}).setUnificationData(OrePrefix.battery, Tier.Super).setModelAmount(8);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/gregtech/common/items/MetaItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private MetaItems() {
public static MetaItem<?>.MetaValueItem BATTERY_UV_NAQUADRIA;

public static MetaItem<?>.MetaValueItem ENERGY_LAPOTRONIC_ORB;
public static MetaItem<?>.MetaValueItem ENERGY_LAPOTRONIC_ORB2;
public static MetaItem<?>.MetaValueItem ENERGY_LAPOTRONIC_ORB_CLUSTER;
public static MetaItem<?>.MetaValueItem ZERO_POINT_MODULE;
public static MetaItem<?>.MetaValueItem ULTIMATE_BATTERY;

Expand Down Expand Up @@ -441,6 +441,9 @@ private MetaItems() {

public static MetaItem<?>.MetaValueItem NANO_SABER;
public static MetaItem<?>.MetaValueItem SCANNER;
public static MetaItem<?>.MetaValueItem PROSPECTOR_LV;
public static MetaItem<?>.MetaValueItem PROSPECTOR_HV;
public static MetaItem<?>.MetaValueItem PROSPECTOR_LUV;
public static MetaItem<?>.MetaValueItem WIRELESS;
public static MetaItem<?>.MetaValueItem CAMERA;
public static MetaItem<?>.MetaValueItem TERMINAL;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package gregtech.common.items.behaviors;

import gregtech.api.GTValues;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IElectricItem;
import gregtech.api.gui.GuiTextures;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.impl.ModularUIContainer;
import gregtech.api.items.gui.ItemUIFactory;
import gregtech.api.items.gui.PlayerInventoryHolder;
import gregtech.api.items.metaitem.stats.IItemBehaviour;
import gregtech.common.terminal.app.prospector.widget.WidgetOreList;
import gregtech.common.terminal.app.prospector.widget.WidgetProspectingMap;
import gregtech.common.terminal.component.SearchComponent;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;

public class ProspectorScannerBehavior implements IItemBehaviour, ItemUIFactory, SearchComponent.IWidgetSearch<String> {

private static final long VOLTAGE_FACTOR = 16L;
private static final int FLUID_PROSPECTION_THRESHOLD = GTValues.HV;

private final int radius;
private final int tier;
private int mode;

private WidgetOreList widgetOreList;

public ProspectorScannerBehavior(int radius, int tier) {
this.radius = radius + 1;
this.tier = tier;
this.mode = 0;
}

@Override
public ActionResult<ItemStack> onItemRightClick(@Nonnull World world, @Nonnull EntityPlayer player, EnumHand hand) {
ItemStack heldItem = player.getHeldItem(hand);
if (!world.isRemote) {
if (player.isSneaking()) {
if (getNextMode() == WidgetProspectingMap.ORE_PROSPECTING_MODE) {
if (this.tier >= FLUID_PROSPECTION_THRESHOLD)
incrementMode();
player.sendMessage(new TextComponentTranslation("metaitem.prospector.mode.ores"));
} else if (getNextMode() == WidgetProspectingMap.FLUID_PROSPECTING_MODE && this.tier >= FLUID_PROSPECTION_THRESHOLD) {
incrementMode();
player.sendMessage(new TextComponentTranslation("metaitem.prospector.mode.fluid"));
}
} else if (checkCanUseScanner(heldItem, player, true)) {
PlayerInventoryHolder holder = new PlayerInventoryHolder(player, hand);
holder.openUI();
} else {
player.sendMessage(new TextComponentTranslation("behavior.scanner.not_enough_energy"));
}
}
return ActionResult.newResult(EnumActionResult.SUCCESS, heldItem);
}

private int getNextMode() {
return (this.mode + 1) % 2;
}

private void incrementMode() {
this.mode = getNextMode();
}

private boolean checkCanUseScanner(ItemStack stack, @Nonnull EntityPlayer player, boolean simulate) {
return player.isCreative() || drainEnergy(stack, GTValues.V[tier] / VOLTAGE_FACTOR, simulate);
}

private boolean drainEnergy(@Nonnull ItemStack stack, long amount, boolean simulate) {
IElectricItem electricItem = stack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (electricItem == null)
return false;

return electricItem.discharge(amount, Integer.MAX_VALUE, true, false, simulate) >= amount;
}

@Override
public ModularUI createUI(PlayerInventoryHolder holder, @Nonnull EntityPlayer entityPlayer) {
ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 332, 200);
this.widgetOreList = new WidgetOreList(32 * radius - 6, 18, 332 - 32 * radius, 176);
builder.widget(this.widgetOreList);
builder.widget(new WidgetProspectingMap(6, 18, radius, this.widgetOreList, mode, 1));
return builder.label(6, 6, getTranslationKey()).build(holder, entityPlayer);
}

private String getTranslationKey() {
return String.format("metaitem.prospector.%s.name", GTValues.VN[tier].toLowerCase(Locale.ROOT));
}

@Override
public void addInformation(ItemStack itemStack, List<String> lines) {
IItemBehaviour.super.addInformation(itemStack, lines);
if (tier >= GTValues.HV) lines.add(I18n.format("metaitem.prospector.tooltip.fluids", radius));
else lines.add(I18n.format("metaitem.prospector.tooltip.ores", radius));
}

@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());
}
}
}
}

@Override
public void onUpdate(ItemStack itemStack, Entity entity) {
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
if (player.openContainer instanceof ModularUIContainer) {
ModularUIContainer modularUIContainer = (ModularUIContainer) player.openContainer;
if (modularUIContainer.getModularUI().holder instanceof PlayerInventoryHolder) {
if (((PlayerInventoryHolder) (modularUIContainer).getModularUI().holder).getCurrentItem() == itemStack) {
if (!player.isCreative()) {
if (checkCanUseScanner(itemStack, player, true))
drainEnergy(itemStack, GTValues.V[tier] / VOLTAGE_FACTOR, false);
else
player.closeScreen();
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import gregtech.api.gui.Widget;
import gregtech.api.net.SProspectingPacket;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.info.MaterialIconType;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.util.GTUtility;
import gregtech.api.util.Position;
import gregtech.api.util.Size;
import gregtech.api.worldgen.bedrockFluids.BedrockFluidVeinHandler;
Expand Down Expand Up @@ -39,6 +38,9 @@ public class WidgetProspectingMap extends Widget {
@SideOnly(Side.CLIENT)
private ProspectingTexture texture;

public static final int ORE_PROSPECTING_MODE = 0;
public static final int FLUID_PROSPECTING_MODE = 1;

public WidgetProspectingMap(int xPosition, int yPosition, int chunkRadius, WidgetOreList widgetOreList, int mode, int scanTick) {
super(new Position(xPosition, yPosition), new Size(16 * (chunkRadius * 2 - 1), 16 * (chunkRadius * 2 - 1)));
this.chunkRadius = chunkRadius;
Expand Down Expand Up @@ -88,21 +90,20 @@ public void detectAndSendChanges() {
SProspectingPacket packet = new SProspectingPacket(cX + ox, cZ + oz, (int) player.posX, (int) player.posZ, this.mode);

switch (mode) {
case 0:
case ORE_PROSPECTING_MODE:
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
int ySize = chunk.getHeightValue(x, z);
for (int y = 1; y < ySize; y++) {
Block block = chunk.getBlockState(x, y, z).getBlock();
OrePrefix orePrefix = OreDictUnifier.getPrefix(block);
if (orePrefix != null && orePrefix.materialIconType == MaterialIconType.ore) {
if (GTUtility.isOre(block)) {
packet.addBlock(x, y, z, OreDictUnifier.getOreDictionaryNames(new ItemStack(block)).stream().findFirst().get());
}
}
}
}
break;
case 1:
case FLUID_PROSPECTING_MODE:
BedrockFluidVeinHandler.FluidVeinWorldEntry fStack = BedrockFluidVeinHandler.getFluidVeinWorldEntry(world, chunk.x, chunk.z);
if (fStack != null && fStack.getVein() != null) {
packet.addBlock(0, 2, 0, fStack.getCurrentFluidAmount() + "");
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/gregtech/integration/jei/GTJeiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public void register(IModRegistry registry) {
String oreSpawnID = GTValues.MODID + ":" + "ore_spawn_location";
registry.addRecipes(oreInfoList, oreSpawnID);
registry.addRecipeCatalyst(MetaItems.SCANNER.getStackForm(), oreSpawnID);
registry.addRecipeCatalyst(MetaItems.PROSPECTOR_LV.getStackForm(), oreSpawnID);
registry.addRecipeCatalyst(MetaItems.PROSPECTOR_HV.getStackForm(), oreSpawnID);
registry.addRecipeCatalyst(MetaItems.PROSPECTOR_LUV.getStackForm(), oreSpawnID);
//Ore Veins End


Expand Down
Loading