Skip to content

Commit

Permalink
Why is gson dumber outside my dev environment?
Browse files Browse the repository at this point in the history
  • Loading branch information
SirLyle committed Nov 18, 2019
1 parent 81750dd commit d44c662
Show file tree
Hide file tree
Showing 37 changed files with 202 additions and 75 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
minecraft = 1.14.4
yarn_mappings=1.14.4+build.12
loader_version=0.6.1+build.164
loader_version=0.6.4+build.169
fabric_version=0.6.7+build.218-1.14
fabric_api = 0.4.1+build.245-1.14
fabric_kotlin = 1.3.50+build.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import net.minecraft.tag.Tag
import java.util.function.Predicate


abstract class AbstractIngredient<T>(val tags: MutableCollection<Tag<T>>, val matches: MutableSet<T>): Predicate<T> {
abstract class AbstractIngredient<T>(val tags: MutableCollection<Tag<T>> = mutableListOf(), val matches: MutableSet<T> = mutableSetOf()): Predicate<T> {

constructor(vararg matches: T): this(mutableListOf(), matches.toMutableSet())

Expand Down
10 changes: 0 additions & 10 deletions src/main/kotlin/exnihilofabrico/api/recipes/LeakingRecipe.kt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exnihilofabrico.api.recipes
package exnihilofabrico.api.recipes.barrel

import alexiil.mc.lib.attributes.fluid.volume.FluidVolume
import exnihilofabrico.api.crafting.EntityStack
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exnihilofabrico.api.recipes
package exnihilofabrico.api.recipes.barrel

import exnihilofabrico.api.crafting.ItemIngredient
import exnihilofabrico.util.Color
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package exnihilofabrico.api.recipes.barrel

import exnihilofabrico.api.crafting.FluidIngredient
import exnihilofabrico.api.crafting.ItemIngredient
import net.minecraft.block.Block
import net.minecraft.block.Blocks

data class LeakingRecipe(val target: ItemIngredient = ItemIngredient.EMPTY,
val fluid: FluidIngredient = FluidIngredient.EMPTY,
val loss: Int = 0,
val result: Block = Blocks.AIR)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exnihilofabrico.api.recipes
package exnihilofabrico.api.recipes.barrel

import alexiil.mc.lib.attributes.fluid.volume.FluidVolume
import exnihilofabrico.api.crafting.EntityTypeIngredient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exnihilofabrico.api.recipes
package exnihilofabrico.api.recipes.crucible

import exnihilofabrico.api.crafting.FluidIngredient
import exnihilofabrico.api.crafting.ItemIngredient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exnihilofabrico.api.recipes
package exnihilofabrico.api.recipes.crucible

import alexiil.mc.lib.attributes.fluid.volume.FluidVolume
import exnihilofabrico.api.crafting.ItemIngredient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package exnihilofabrico.api.recipes
package exnihilofabrico.api.recipes.witchwater

import exnihilofabrico.api.crafting.EntityTypeIngredient
import net.minecraft.entity.Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package exnihilofabrico.api.recipes.witchwater

import exnihilofabrico.api.crafting.FluidIngredient
import exnihilofabrico.api.crafting.WeightedList

data class WitchWaterWorldRecipe(val fluid: FluidIngredient = FluidIngredient.EMPTY,
val results: WeightedList = WeightedList())
35 changes: 31 additions & 4 deletions src/main/kotlin/exnihilofabrico/api/registry/IAlchemyRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import exnihilofabrico.api.crafting.EntityStack
import exnihilofabrico.api.crafting.FluidIngredient
import exnihilofabrico.api.crafting.ItemIngredient
import exnihilofabrico.api.crafting.Lootable
import exnihilofabrico.api.recipes.AlchemyRecipe
import exnihilofabrico.api.recipes.barrel.AlchemyRecipe
import exnihilofabrico.modules.barrels.modes.EmptyMode
import exnihilofabrico.modules.barrels.modes.FluidMode
import exnihilofabrico.modules.barrels.modes.ItemMode
Expand All @@ -25,11 +25,38 @@ interface IAlchemyRegistry {


fun register(reactant: FluidIngredient, catalyst: ItemIngredient, byproduct: Lootable, delay: Int, spawn: EntityStack) =
register(AlchemyRecipe(reactant, catalyst, EmptyMode(), byproduct, delay, spawn))
register(
AlchemyRecipe(
reactant,
catalyst,
EmptyMode(),
byproduct,
delay,
spawn
)
)
fun register(reactant: FluidIngredient, catalyst: ItemIngredient, product: ItemStack, byproduct: Lootable, delay: Int, spawn: EntityStack) =
register(AlchemyRecipe(reactant, catalyst, ItemMode(product), byproduct, delay, spawn))
register(
AlchemyRecipe(
reactant,
catalyst,
ItemMode(product),
byproduct,
delay,
spawn
)
)
fun register(reactant: FluidIngredient, catalyst: ItemIngredient, product: FluidVolume, byproduct: Lootable, delay: Int, spawn: EntityStack) =
register(AlchemyRecipe(reactant, catalyst, FluidMode(product), byproduct, delay, spawn))
register(
AlchemyRecipe(
reactant,
catalyst,
FluidMode(product),
byproduct,
delay,
spawn
)
)

fun register(reactant: FluidIngredient, catalyst: ItemIngredient, product: FluidVolume) =
register(AlchemyRecipe(reactant, catalyst, FluidMode(product)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package exnihilofabrico.api.registry

import exnihilofabrico.api.crafting.ItemIngredient
import exnihilofabrico.api.recipes.CompostRecipe
import exnihilofabrico.api.recipes.barrel.CompostRecipe
import exnihilofabrico.util.Color
import exnihilofabrico.util.asStack
import net.minecraft.item.Item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exnihilofabrico.api.registry

import exnihilofabrico.api.crafting.FluidIngredient
import exnihilofabrico.api.crafting.ItemIngredient
import exnihilofabrico.api.recipes.CrucibleHeatRecipe
import exnihilofabrico.api.recipes.crucible.CrucibleHeatRecipe
import net.minecraft.block.Block
import net.minecraft.fluid.Fluid
import net.minecraft.item.Item
Expand All @@ -13,7 +13,13 @@ interface ICrucibleHeatRegistry {
fun clear()
fun register(recipe: CrucibleHeatRecipe): Boolean

fun register(blocks: ItemIngredient, fluids: FluidIngredient, heat: Int) = register(CrucibleHeatRecipe(blocks, fluids, heat))
fun register(blocks: ItemIngredient, fluids: FluidIngredient, heat: Int) = register(
CrucibleHeatRecipe(
blocks,
fluids,
heat
)
)

fun registerFluidTag(tag: Tag<Fluid>, heat: Int) = register(ItemIngredient.EMPTY, FluidIngredient(tag), heat)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exnihilofabrico.api.registry

import alexiil.mc.lib.attributes.fluid.volume.FluidVolume
import exnihilofabrico.api.crafting.ItemIngredient
import exnihilofabrico.api.recipes.CrucibleRecipe
import exnihilofabrico.api.recipes.crucible.CrucibleRecipe
import net.minecraft.fluid.Fluid
import net.minecraft.item.Item
import net.minecraft.item.ItemConvertible
Expand All @@ -12,12 +12,17 @@ interface ICrucibleRegistry {
fun clear()
fun register(recipe: CrucibleRecipe): Boolean

fun register(input: ItemIngredient, output: FluidVolume) = register(CrucibleRecipe(input, output))
fun register(input: ItemIngredient, output: FluidVolume) = register(
CrucibleRecipe(
input,
output
)
)
fun register(input: ItemConvertible, output: FluidVolume) = register(ItemIngredient(input), output)
fun register(input: Tag<Item>, output: FluidVolume) = register(ItemIngredient(input), output)
fun register(input: ItemIngredient, fluid: Fluid, amount: Int) = register(input, FluidVolume.create(fluid, amount))
fun register(input: ItemConvertible, fluid: Fluid, amount: Int) = register(input, FluidVolume.create(fluid, amount))
fun register(input: Tag<Item>, fluid: Fluid, amount: Int) = register(input, FluidVolume.create(fluid, amount))
fun register(input: ItemConvertible, fluid: Fluid, amount: Int) = register(ItemIngredient(input), FluidVolume.create(fluid, amount))
fun register(input: Tag<Item>, fluid: Fluid, amount: Int) = register(ItemIngredient(input), FluidVolume.create(fluid, amount))

fun getResult(item: Item): FluidVolume?
}
20 changes: 17 additions & 3 deletions src/main/kotlin/exnihilofabrico/api/registry/ILeakingRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package exnihilofabrico.api.registry
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume
import exnihilofabrico.api.crafting.FluidIngredient
import exnihilofabrico.api.crafting.ItemIngredient
import exnihilofabrico.api.recipes.LeakingRecipe
import exnihilofabrico.api.recipes.barrel.LeakingRecipe
import net.minecraft.block.Block
import net.minecraft.fluid.Fluid
import net.minecraft.item.Item
Expand All @@ -22,9 +22,23 @@ interface ILeakingRegistry {
register(LeakingRecipe(target, FluidIngredient(fluid), fluid.amount, result))

fun register(target: ItemConvertible, fluid: Fluid, amount: Int, result: Block) =
register(LeakingRecipe(ItemIngredient(target), FluidIngredient(fluid), amount, result))
register(
LeakingRecipe(
ItemIngredient(target),
FluidIngredient(fluid),
amount,
result
)
)
fun register(target: Tag<Item>, fluid: Fluid, amount: Int, result: Block) =
register(LeakingRecipe(ItemIngredient(target), FluidIngredient(fluid), amount, result))
register(
LeakingRecipe(
ItemIngredient(target),
FluidIngredient(fluid),
amount,
result
)
)

/**
* Returns the block to transform the input block into, and the amount to drain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exnihilofabrico.api.registry

import alexiil.mc.lib.attributes.fluid.volume.FluidVolume
import exnihilofabrico.api.crafting.EntityTypeIngredient
import exnihilofabrico.api.recipes.MilkingRecipe
import exnihilofabrico.api.recipes.barrel.MilkingRecipe
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityType
import net.minecraft.fluid.Fluid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package exnihilofabrico.api.registry

import exnihilofabrico.api.crafting.EntityTypeIngredient
import exnihilofabrico.api.recipes.WitchWaterEntityRecipe
import exnihilofabrico.api.recipes.witchwater.WitchWaterEntityRecipe
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityType
import net.minecraft.village.VillagerProfession
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/exnihilofabrico/json/AlchemyRecipeJson.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import exnihilofabrico.api.crafting.EntityStack
import exnihilofabrico.api.crafting.FluidIngredient
import exnihilofabrico.api.crafting.ItemIngredient
import exnihilofabrico.api.crafting.Lootable
import exnihilofabrico.api.recipes.AlchemyRecipe
import exnihilofabrico.api.recipes.barrel.AlchemyRecipe
import exnihilofabrico.modules.barrels.modes.EmptyMode
import exnihilofabrico.modules.barrels.modes.barrelModeFactory
import java.lang.reflect.Type
Expand All @@ -17,19 +17,19 @@ object AlchemyRecipeJson: JsonDeserializer<AlchemyRecipe>, JsonSerializer<Alchem
return AlchemyRecipe(
FluidIngredient.fromJson(obj.get("reactant"), context),
ItemIngredient.fromJson(obj.get("catalyst"), context),
if(!obj.has("product"))
if (!obj.has("product"))
EmptyMode()
else
barrelModeFactory(obj.get("product"), context),
if(!obj.has("byproduct"))
if (!obj.has("byproduct"))
Lootable.EMPTY
else
context.deserialize<Lootable>(obj["byproduct"], object: TypeToken<Lootable>(){}.type),
context.deserialize<Lootable>(obj["byproduct"], object : TypeToken<Lootable>() {}.type),
obj["delay"].asInt,
if(!obj.has("toSpawn"))
if (!obj.has("toSpawn"))
EntityStack.EMPTY
else
context.deserialize(obj["toSpawn"], object: TypeToken<EntityStack>(){}.type)
context.deserialize(obj["toSpawn"], object : TypeToken<EntityStack>() {}.type)
)
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/exnihilofabrico/json/BasicJson.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ object ItemJson: JsonDeserializer<Item>, JsonSerializer<Item> {
Registry.ITEM[context.deserialize<Identifier>(json, IdentifierJson.TYPE_TOKEN)]

override fun serialize(src: Item, typeOfSrc: Type, context: JsonSerializationContext): JsonElement =
context.serialize(src.getId())
JsonPrimitive(src.getId().toString())
}

object BlockJson: JsonDeserializer<Block>, JsonSerializer<Block> {
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext) =
Registry.BLOCK[context.deserialize<Identifier>(json, IdentifierJson.TYPE_TOKEN)]

override fun serialize(src: Block, typeOfSrc: Type, context: JsonSerializationContext): JsonElement =
context.serialize(src.getId())
JsonPrimitive(src.getId().toString())

}

Expand All @@ -36,7 +36,7 @@ object FluidJson: JsonDeserializer<Fluid>, JsonSerializer<Fluid> {
Registry.FLUID[context.deserialize<Identifier>(json, IdentifierJson.TYPE_TOKEN)]

override fun serialize(src: Fluid, typeOfSrc: Type, context: JsonSerializationContext): JsonElement =
context.serialize(src.getId())
JsonPrimitive(src.getId().toString())
}

object EntityTypeJson: JsonDeserializer<EntityType<*>>, JsonSerializer<EntityType<*>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package exnihilofabrico.json
import com.google.gson.*
import exnihilofabrico.api.crafting.FluidIngredient
import exnihilofabrico.api.crafting.ItemIngredient
import exnihilofabrico.api.recipes.CrucibleHeatRecipe
import exnihilofabrico.api.recipes.crucible.CrucibleHeatRecipe
import java.lang.reflect.Type

object CrucibleHeatRecipeJson: JsonDeserializer<CrucibleHeatRecipe>, JsonSerializer<CrucibleHeatRecipe> {
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): CrucibleHeatRecipe {
val obj = json.asJsonObject
return CrucibleHeatRecipe(
if(obj.has("block"))
if (obj.has("block"))
ItemIngredient.fromJson(obj.get("block"), context)
else
ItemIngredient.EMPTY,
if(obj.has("fluid"))
if (obj.has("fluid"))
FluidIngredient.fromJson(obj.get("fluid"), context)
else
FluidIngredient.EMPTY,
Expand Down
25 changes: 25 additions & 0 deletions src/main/kotlin/exnihilofabrico/json/CrucibleRecipeJson.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package exnihilofabrico.json

import com.google.gson.*
import exnihilofabrico.api.crafting.ItemIngredient
import exnihilofabrico.api.recipes.crucible.CrucibleRecipe
import exnihilofabrico.json.FluidVolumeJson.TYPE_TOKEN
import java.lang.reflect.Type

object CrucibleRecipeJson: JsonDeserializer<CrucibleRecipe>, JsonSerializer<CrucibleRecipe> {
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): CrucibleRecipe {
val obj = json.asJsonObject
return CrucibleRecipe(
ItemIngredient.fromJson(obj.get("input"), context),
FluidVolumeJson.deserialize(obj.get("output"), TYPE_TOKEN, context)
)
}

override fun serialize(src: CrucibleRecipe, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
val obj = JsonObject()
obj.add("input", src.input.toJson(context))
obj.add("output", FluidVolumeJson.serialize(src.output, TYPE_TOKEN, context))
return obj
}

}
2 changes: 2 additions & 0 deletions src/main/kotlin/exnihilofabrico/json/FluidVolumeJson.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package exnihilofabrico.json
import alexiil.mc.lib.attributes.fluid.volume.FluidKeys
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume
import com.google.gson.*
import com.google.gson.reflect.TypeToken
import exnihilofabrico.util.getId
import net.minecraft.util.Identifier
import net.minecraft.util.registry.Registry
import java.lang.reflect.Type


object FluidVolumeJson: JsonDeserializer<FluidVolume>, JsonSerializer<FluidVolume> {
val TYPE_TOKEN: Type = object: TypeToken<FluidVolume>() {}.type
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): FluidVolume {
val splits = json.asString.split(" x ")
val amount = splits[0].toInt()
Expand Down
Loading

0 comments on commit d44c662

Please sign in to comment.