Skip to content

Commit 318387f

Browse files
committed
general code cleanup
1 parent e1af1f8 commit 318387f

File tree

13 files changed

+200
-47
lines changed

13 files changed

+200
-47
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies {
3636
api("space.impact:Packet-Network:1.1.8")
3737
api("space.impact:Impact-API:0.0.4:dev")
3838
api("space.impact:WAILAPlugins:0.3.1:dev")
39-
api("space.impact:VirtualWorld:1.4.2:dev")
39+
api("space.impact:VirtualWorld:1.5.0:dev")
4040
api("space.impact:gregtech-impact:5.09.35.25:dev") { isTransitive = false }
4141
api("com.github.GTNewHorizons:ModularUI:1.1.24:dev") { isTransitive = false }
4242
api("com.github.GTNewHorizons:NotEnoughItems:2.3.+:dev") { isChanging = true }

src/main/java/com/impact/addon/vw/VirtualWorldScan.kt

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@ package com.impact.addon.vw
22

33
import gregtech.api.interfaces.tileentity.IGregTechTileEntity
44
import net.minecraft.entity.player.EntityPlayer
5-
import net.minecraft.entity.player.EntityPlayerMP
65
import net.minecraft.world.chunk.Chunk
76
import space.gtimpact.virtual_world.api.OreVeinCount
87
import space.gtimpact.virtual_world.api.VirtualAPI
9-
import space.gtimpact.virtual_world.api.prospect.scanFluids
10-
import space.gtimpact.virtual_world.api.prospect.scanOres
11-
import space.gtimpact.virtual_world.common.items.ScannerTool.Companion.TYPE_FLUIDS
12-
import space.gtimpact.virtual_world.common.items.ScannerTool.Companion.TYPE_ORES
13-
import space.gtimpact.virtual_world.extras.send
14-
import space.gtimpact.virtual_world.extras.toTranslate
158

169
object VirtualWorldScan {
1710

@@ -25,14 +18,14 @@ object VirtualWorldScan {
2518
else -> 7
2619
}
2720

28-
scanOres(te.world, 0, player as EntityPlayerMP, radius)
29-
scanOres(te.world, 1, player, radius)
30-
scanFluids(te.world, player, radius)
21+
VirtualAPI.scanOres(te.world, 0, player, radius, true)
22+
VirtualAPI.scanOres(te.world, 1, player, radius, true)
23+
VirtualAPI.scanFluids(te.world, player, radius, true)
3124
}
3225

3326
@JvmStatic
3427
fun scanVeinOre(chunk: Chunk, layer: Int, player: EntityPlayer, needScanSize: Boolean = false): OreVeinCount? {
35-
scanOres(chunk.worldObj, layer, player, 4, needScanSize = needScanSize)
28+
VirtualAPI.scanOres(chunk.worldObj, layer, player, 4, needScanSize = needScanSize)
3629
val list = arrayListOf<OreVeinCount?>()
3730
VirtualAPI.getVeinChunks(chunk).forEach {
3831
chunk.worldObj.getChunkFromChunkCoords(it.chunkXPos, it.chunkZPos)?.also { ch ->
@@ -43,17 +36,4 @@ object VirtualWorldScan {
4336
count.copy(size = list.sumOf { it?.size ?: 0 })
4437
}
4538
}
46-
47-
@JvmStatic
48-
fun sendChatChangeType(player: EntityPlayer, type: Int) {
49-
when (type) {
50-
TYPE_ORES -> player.send("scanner.change_mode.0".toTranslate())
51-
TYPE_FLUIDS -> player.send("scanner.change_mode.1".toTranslate())
52-
}
53-
}
54-
55-
@JvmStatic
56-
fun sendChatChangeLayer(player: EntityPlayer, layer: Int) {
57-
player.send("scanner.change_layer".toTranslate() + layer)
58-
}
5939
}

src/main/java/com/impact/mods/gregtech/GT_ItemList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public enum GT_ItemList implements IItemContainer {
2626
packOberon, packPhobos, packPluto, packTCetiE, packTitan, packTriton, packVegaB, packVenus, packMars,
2727
packProteus, packAsteroids, spacebox1, spacebox2, spacebox3, spacebox4, spacebox5, spacebox6, spacebox7,
2828
spacebox8, Aerostat, ConstructLaser, DebugOreGen, OreProbe,
29-
29+
30+
HandProspectorEV, HandProspectorIV, HandProspectorLuV, HandProspectorZPM,
31+
3032
ULVMotor, ULVPiston, ULVRobotArm, ULVConveyorModule, ULVPump,
3133

3234
//BASIC

src/main/java/com/impact/mods/gregtech/GT_ItemRegister.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.impact.mods.gregtech;
2+
import com.impact.mods.gregtech.items.tools.behaviour.BehaviourProspector;
23
import com.impact.mods.gregtech.items.tools.behaviour.Behaviour_Aerostat;
34
import com.impact.mods.gregtech.items.tools.behaviour.BehaviourOreProbe;
5+
import gregtech.api.enums.GT_Values;
46
import gregtech.common.items.GT_MetaGenerated_Item_04;
57

68
public class GT_ItemRegister {
@@ -15,7 +17,16 @@ public void run() {
1517
private void registerItems() {
1618
GT_ItemList.Aerostat.set(GT.addItem(6, "Aerostat", "", Behaviour_Aerostat.INSTANCE));
1719
GT_ItemList.OreProbe.set(GT.addItem(8, "Ore Sampling Tool", "Ore sampling tool in current Chunk (Only Layer 0)", BehaviourOreProbe.INSTANCE));
18-
20+
21+
GT_ItemList.HandProspectorEV.set(GT.addItem(100, "Underground Resource Scanner (EV)", "", new BehaviourProspector(4, 8)));
22+
GT.setElectricStats(32100, 6_400_000, GT_Values.V[4], 4, -1L, false);
23+
GT_ItemList.HandProspectorIV.set(GT.addItem(101, "Underground Resource Scanner (IV)", "", new BehaviourProspector(5, 12)));
24+
GT.setElectricStats(32101, 25_600_000, GT_Values.V[5], 5, -1L, false);
25+
GT_ItemList.HandProspectorLuV.set(GT.addItem(102, "Underground Resource Scanner (LuV)", "", new BehaviourProspector(6, 16)));
26+
GT.setElectricStats(32102, 102_400_000, GT_Values.V[6], 6, -1L, false);
27+
GT_ItemList.HandProspectorZPM.set(GT.addItem(103, "Underground Resource Scanner (ZPM)", "", new BehaviourProspector(7, 20)));
28+
GT.setElectricStats(32103, 409_600_000, GT_Values.V[7], 7, -1L, false);
29+
1930
GT_ItemList.ULVPump.set(GT.addItem(395, "ULV Electric Pump", "640 L/sec"));
2031
GT_ItemList.ULVMotor.set(GT.addItem(396, "ULV Electric Motor", ""));
2132
GT_ItemList.ULVPiston.set(GT.addItem(397, "ULV Electric Piston", ""));

src/main/java/com/impact/mods/gregtech/items/tools/behaviour/BehaviourOreProbe.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import net.minecraft.entity.player.EntityPlayerMP
1111
import net.minecraft.item.ItemStack
1212
import net.minecraft.util.EnumChatFormatting
1313
import net.minecraft.world.World
14-
import space.gtimpact.virtual_world.common.items.ScannerTool
1514

1615
class BehaviourOreProbe : Behaviour_None() {
1716

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package com.impact.mods.gregtech.items.tools.behaviour
2+
3+
import gregtech.api.GregTech_API
4+
import gregtech.api.items.GT_MetaBase_Item
5+
import gregtech.api.util.GT_Utility
6+
import gregtech.common.items.behaviors.Behaviour_None
7+
import net.minecraft.entity.player.EntityPlayer
8+
import net.minecraft.entity.player.EntityPlayerMP
9+
import net.minecraft.item.ItemStack
10+
import net.minecraft.nbt.NBTTagCompound
11+
import net.minecraft.world.World
12+
import space.gtimpact.virtual_world.api.VirtualAPI
13+
import space.gtimpact.virtual_world.api.VirtualAPI.LAYERS_VIRTUAL_ORES
14+
import space.gtimpact.virtual_world.config.Config
15+
import space.gtimpact.virtual_world.extras.send
16+
import space.gtimpact.virtual_world.extras.toTranslate
17+
18+
class BehaviourProspector(
19+
private val tier: Int,
20+
private val radiusWork: Int,
21+
) : Behaviour_None() {
22+
23+
companion object {
24+
internal const val TYPE_ORES_0 = 0
25+
internal const val TYPE_ORES_1 = 1
26+
internal const val TYPE_FLUIDS = 2
27+
28+
internal const val TYPES_COUNT = 3
29+
30+
internal const val NBT_TYPE = "type_mode"
31+
internal const val NBT_LAYER = "layer_id"
32+
}
33+
34+
private fun ItemStack.setNBT(data: Int, key: String) {
35+
val nbt = tagCompound ?: NBTTagCompound().apply { tagCompound = this }
36+
val props = nbt.getTag("props") ?: NBTTagCompound().apply { nbt.setTag("props", this) }
37+
(props as NBTTagCompound).setInteger(key, data)
38+
}
39+
40+
private fun ItemStack.getNBTInt(key: String): Int {
41+
val nbt = tagCompound?.getCompoundTag("props") ?: return 0
42+
return nbt.getInteger(key)
43+
}
44+
45+
fun changeLayer(player: EntityPlayer, stack: ItemStack) {
46+
val type = stack.getNBTInt(NBT_TYPE)
47+
if (type != TYPE_FLUIDS) {
48+
var realLayer = stack.getNBTInt(NBT_LAYER) + 1
49+
if (realLayer >= LAYERS_VIRTUAL_ORES) {
50+
realLayer = 0
51+
}
52+
// Set ore layer #
53+
player.send("scanner.change_layer".toTranslate() + realLayer)
54+
stack.setNBT(realLayer, NBT_LAYER)
55+
}
56+
}
57+
58+
override fun onItemUseFirst(
59+
item: GT_MetaBase_Item, stack: ItemStack, player: EntityPlayer,
60+
world: World, aX: Int, aY: Int, aZ: Int, aSide: Int, hitX: Float,
61+
hitY: Float, hitZ: Float,
62+
): Boolean {
63+
if (player is EntityPlayerMP) {
64+
65+
var type = stack.getNBTInt(NBT_TYPE)
66+
val layer = stack.getNBTInt(NBT_LAYER)
67+
68+
when (stack.stackSize) {
69+
//for debug
70+
2 -> VirtualAPI.addCustomObject(stack, "Test Point ${world.rand.nextInt(99)}", player)
71+
72+
in 3..64 -> if (Config.enableDebug && player.capabilities.isCreativeMode) {
73+
val chunk = world.getChunkFromBlockCoords(player.posX.toInt(), player.posZ.toInt())
74+
75+
when (type) {
76+
TYPE_ORES_0, TYPE_ORES_1 -> VirtualAPI.extractOreFromChunk(chunk, layer, 1000 * stack.stackSize)?.also { data ->
77+
player.send("${data.vein.name}: ${data.size}")
78+
}
79+
80+
TYPE_FLUIDS -> VirtualAPI.extractFluidFromVein(chunk, 1000 * stack.stackSize / 16)?.also { data ->
81+
player.send("${data.vein.name}: ${data.size}")
82+
}
83+
}
84+
}
85+
86+
else -> {
87+
if (player.isSneaking) {
88+
type++
89+
90+
if (type >= TYPES_COUNT) {
91+
type = 0
92+
}
93+
94+
when {
95+
type != TYPE_FLUIDS -> {
96+
player.send("scanner.change_mode.0".toTranslate()) //Set mod: Underground Ores
97+
changeLayer(player, stack)
98+
}
99+
type == TYPE_FLUIDS -> player.send("scanner.change_mode.1".toTranslate()) //Set mod: Underground Fluids
100+
}
101+
stack.setNBT(type, NBT_TYPE)
102+
return true
103+
}
104+
105+
val discharge = item.getMaxCharge(stack) * .1
106+
107+
if (item.canUse(stack, discharge)) {
108+
item.discharge(stack, discharge, tier, true, false, false)
109+
GT_Utility.doSoundAtClient(
110+
GregTech_API.sSoundList[108],
111+
1, 1.0f,
112+
aX.toDouble(), aY.toDouble(), aZ.toDouble()
113+
)
114+
when (type) {
115+
TYPE_ORES_0, TYPE_ORES_1 -> VirtualAPI.scanOres(world, layer, player, radiusWork, true)
116+
TYPE_FLUIDS -> VirtualAPI.scanFluids(world, player, radiusWork, true)
117+
}
118+
}
119+
}
120+
}
121+
122+
return true
123+
}
124+
return false
125+
}
126+
127+
override fun getAdditionalToolTips(item: GT_MetaBase_Item?, tooltip: MutableList<String>, stack: ItemStack): List<String> {
128+
129+
val mode = stack.getNBTInt(NBT_TYPE)
130+
val layer = stack.getNBTInt(NBT_LAYER)
131+
132+
tooltip += "scanner.tooltip.0".toTranslate() // Change scanner mode: SHIFT + Right Click
133+
val modName = when (mode) {
134+
TYPE_ORES_0, TYPE_ORES_1 -> "scanner.tooltip.2".toTranslate() // Virtual Ores
135+
TYPE_FLUIDS -> "scanner.tooltip.4".toTranslate() // Virtual Fluids else
136+
else -> ""
137+
}
138+
// Current scanner mode:
139+
tooltip += "scanner.tooltip.1".toTranslate() + " " + modName
140+
if (mode != TYPE_FLUIDS) {
141+
tooltip += "scanner.tooltip.6".toTranslate() + layer // Current ore layer: #
142+
}
143+
// To scan the area use Right Click
144+
tooltip += "scanner.tooltip.5".toTranslate()
145+
tooltip += ""
146+
tooltip += "scanner.tooltip.7".toTranslate(radiusWork)
147+
tooltip += ""
148+
149+
if (Config.enableDebug)
150+
tooltip += listOf(
151+
"2 stackSize create point item",
152+
"3..64 stackSize extract current chunk stackSize * 1000",
153+
)
154+
155+
return super.getAdditionalToolTips(item, tooltip, stack)
156+
}
157+
}

src/main/java/com/impact/mods/gregtech/tileentities/basic/GTMTE_Prospector.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,6 @@ public void loadNBTData(NBTTagCompound aNBT) {
8686
playerHandler = MinecraftServer.getServer().getConfigurationManager().func_152612_a(name);
8787
}
8888
}
89-
90-
@Override
91-
public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
92-
if (aPlayer.isSneaking()) {
93-
this.type++;
94-
if (this.type > 1) this.type = 0;
95-
this.layer = 0;
96-
VirtualWorldScan.sendChatChangeType(aPlayer, type);
97-
VirtualWorldScan.sendChatChangeLayer(aPlayer, layer);
98-
} else {
99-
this.layer++;
100-
if (type == 0) {
101-
if (this.layer >= VirtualAPI.LAYERS_VIRTUAL_ORES) this.layer = 0;
102-
VirtualWorldScan.sendChatChangeLayer(aPlayer, layer);
103-
}
104-
}
105-
}
10689

10790
@Override
10891
public void inValidate() {
@@ -113,7 +96,6 @@ public void inValidate() {
11396
@Override
11497
public void onPostTick(IGregTechTileEntity te, long aTick) {
11598
super.onPostTick(te, aTick);
116-
11799
if (te.isServerSide() && aTick % 20 == 0) {
118100
if (ready && mMaxProgresstime == 0) {
119101
if (playerHandler != null) {
@@ -135,7 +117,7 @@ public boolean onRightclick(IGregTechTileEntity te, EntityPlayer aPlayer) {
135117
|| GT_Utility.consumeItems(aPlayer, aStack, ItemList.Block_Powderbarrel.getItem(), 2))) {
136118

137119
this.ready = true;
138-
this.mMaxProgresstime = (aPlayer.capabilities.isCreativeMode ? 20 : 800);
120+
this.mMaxProgresstime = (aPlayer.capabilities.isCreativeMode ? 20 : 1200);
139121
playerHandler = aPlayer;
140122
}
141123
}
1.75 KB
Loading
308 Bytes
Loading
313 Bytes
Loading

0 commit comments

Comments
 (0)