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+ }
0 commit comments