Skip to content

Commit

Permalink
json crap
Browse files Browse the repository at this point in the history
  • Loading branch information
ttttdoy committed Aug 5, 2024
1 parent 208753d commit dc3df9b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import breadmod.ModMain.modTranslatable
import breadmod.datagen.tool_gun.BreadModToolGunModeProvider.Companion.TOOL_GUN_DEF
import breadmod.item.tool_gun.mode.creator.*
import breadmod.menu.item.ToolGunCreatorMenu
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.stream.JsonReader
import com.mojang.blaze3d.systems.RenderSystem
import moze_intel.projecte.gameObjs.registries.PEItems
import net.minecraft.ChatFormatting
Expand All @@ -29,8 +31,12 @@ import net.minecraft.world.entity.ai.attributes.Attributes
import net.minecraft.world.entity.player.Inventory
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import net.minecraftforge.fml.loading.FMLPaths
import net.minecraftforge.registries.ForgeRegistries
import java.awt.Color
import java.io.FileReader
import java.nio.file.Files
import java.nio.file.Path

@Suppress("Unused", "MemberVisibilityCanBePrivate")
class ToolGunCreatorScreen(
Expand All @@ -56,7 +62,7 @@ class ToolGunCreatorScreen(
var entitySpeed: Double? = 5.0

// First Int: Duration, Second Int: Amplifier
var entityEffect: List<Triple<MobEffect, Int, Int>>? = listOf(
var entityEffect: MutableList<Triple<MobEffect, Int, Int>>? = mutableListOf(
Triple(MobEffects.HARM, 1000, 10),
Triple(MobEffects.JUMP, 1000, 10)
)
Expand All @@ -71,9 +77,9 @@ class ToolGunCreatorScreen(

val json = JsonObject().also {
it.addProperty("entity", ForgeRegistries.ENTITY_TYPES.getKey(entityType).toString())
if(customEntityName != null) { it.addProperty("customEntityName", customEntityName) }
if(entityHealth != null) { it.addProperty("entityHealth", entityHealth) }
if(entitySpeed != null) { it.addProperty("entitySpeed", entitySpeed) }
if(customEntityName != null) { it.addProperty("custom_entity_name", customEntityName) }
if(entityHealth != null) { it.addProperty("entity_health", entityHealth) }
if(entitySpeed != null) { it.addProperty("entity_speed", entitySpeed) }
if(entityEffect != null) {
it.add("effects", JsonObject().also { effectObject ->
entityEffect?.forEach { (effect, duration, amplifier) ->
Expand Down Expand Up @@ -104,10 +110,33 @@ class ToolGunCreatorScreen(
}
}

val jsonByteArray = json.toString().toByteArray()
val gson = Gson()
val filePath: Path = FMLPaths.GAMEDIR.get().resolve("breadmod/tool_gun/mob.json").toAbsolutePath()

val reader = JsonReader(FileReader(filePath.toFile()))
val data: JsonObject = gson.fromJson(reader, JsonObject::class.java)

init {
imageWidth = 256
imageHeight = 220
println(json)
// println(json)

if(!Files.exists(filePath)) Files.write(filePath, jsonByteArray)

// println(GsonHelper.parse(String(jsonByteArray, StandardCharsets.UTF_8)).get("effects"))

data.getAsJsonObject("effects").asMap().forEach { (key, value) ->
println("key: $key")
value.asJsonObject.asMap().forEach { (effectKey, valueInt) ->
println("key: $effectKey, valueInt: $valueInt")
}
}

// intentionally returns null to test non-existing entries in the object
if(data.getAsJsonObject("stinky") != null) {
println(data.getAsJsonObject("stinky"))
} else println("this is null!")
}

override fun render(pGuiGraphics: GuiGraphics, pMouseX: Int, pMouseY: Int, pPartialTick: Float) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal class ToolGunCreatorMode : IToolGunMode, MenuProvider {
private var entitySpeed: Double? = null

// First Int: Duration, Second Int: Amplifier
private var entityEffect: List<Triple<MobEffect, Int, Int>>? = null
private var entityEffect: MutableList<Triple<MobEffect, Int, Int>>? = null

private var helmetSlot: ItemStack? = null
private var chestplateSlot: ItemStack? = null
Expand Down

0 comments on commit dc3df9b

Please sign in to comment.