generated from natanfudge/fabric-example-mod-kotlin
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
268 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
base/src/main/kotlin/dev/nathanpb/dml/misc/lootfunction/LootFunctions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dev.nathanpb.dml.misc.lootfunction | ||
|
||
import dev.nathanpb.dml.identifier | ||
import net.minecraft.loot.function.LootFunction | ||
import net.minecraft.loot.function.LootFunctionType | ||
import net.minecraft.registry.Registries | ||
import net.minecraft.registry.Registry | ||
import net.minecraft.util.JsonSerializer | ||
|
||
|
||
val RANDOM_ENERGY: LootFunctionType = registerLootFunction("random_energy", RandomEnergyLootFunction.RandomEnergyLootFunctionSerializer()) | ||
val RANDOM_DATA_MODEL: LootFunctionType = registerLootFunction("random_data_model", RandomDataModelLootFunction.RandomDataModelLootFunctionSerializer()) | ||
val RANDOM_PRISTINE_MATTER: LootFunctionType = registerLootFunction("random_pristine_matter", RandomPristineMatterLootFunction.RandomPristineMatterLootFunctionSerializer()) | ||
|
||
|
||
private fun registerLootFunction(id: String, serializer: JsonSerializer<out LootFunction>): LootFunctionType { | ||
return Registry.register(Registries.LOOT_FUNCTION_TYPE, identifier(id), LootFunctionType(serializer)) | ||
} | ||
|
||
fun registerLootFunctions() { | ||
RANDOM_ENERGY | ||
RANDOM_DATA_MODEL | ||
RANDOM_PRISTINE_MATTER | ||
} |
43 changes: 43 additions & 0 deletions
43
base/src/main/kotlin/dev/nathanpb/dml/misc/lootfunction/RandomDataModelLootFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dev.nathanpb.dml.misc.lootfunction | ||
|
||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonObject | ||
import dev.nathanpb.dml.baseConfig | ||
import dev.nathanpb.dml.data.dataModel | ||
import dev.nathanpb.dml.item.ItemDataModel | ||
import dev.nathanpb.dml.misc.ATTUNED_DATA_MODELS | ||
import net.minecraft.item.ItemStack | ||
import net.minecraft.loot.condition.LootCondition | ||
import net.minecraft.loot.context.LootContext | ||
import net.minecraft.loot.function.ConditionalLootFunction | ||
import net.minecraft.loot.function.LootFunctionType | ||
import net.minecraft.registry.Registries | ||
|
||
class RandomDataModelLootFunction(conditions: Array<out LootCondition>): ConditionalLootFunction(conditions) { | ||
|
||
|
||
override fun process(stack: ItemStack, ctx: LootContext): ItemStack { | ||
val dataModelStack = ItemStack( | ||
Registries.ITEM.iterateEntries(ATTUNED_DATA_MODELS).iterator() | ||
.asSequence() | ||
.toList() | ||
.random() | ||
) | ||
|
||
if(dataModelStack.item is ItemDataModel) { | ||
val maxData = baseConfig.misc.disruption.maxDataModelData | ||
dataModelStack.dataModel.dataAmount = ctx.random.nextInt(maxData + 1).coerceIn(0, baseConfig.dataModel.selfAwareDataRequired) | ||
} | ||
|
||
return dataModelStack | ||
} | ||
|
||
override fun getType(): LootFunctionType = RANDOM_DATA_MODEL | ||
|
||
class RandomDataModelLootFunctionSerializer: Serializer<RandomDataModelLootFunction>() { | ||
|
||
override fun fromJson(json: JsonObject, context: JsonDeserializationContext, conditions: Array<out LootCondition>): RandomDataModelLootFunction { | ||
return RandomDataModelLootFunction(conditions) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
base/src/main/kotlin/dev/nathanpb/dml/misc/lootfunction/RandomEnergyLootFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.nathanpb.dml.misc.lootfunction | ||
|
||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonObject | ||
import dev.nathanpb.dml.baseConfig | ||
import net.minecraft.item.ItemStack | ||
import net.minecraft.loot.condition.LootCondition | ||
import net.minecraft.loot.context.LootContext | ||
import net.minecraft.loot.function.ConditionalLootFunction | ||
import net.minecraft.loot.function.LootFunctionType | ||
import team.reborn.energy.api.base.SimpleEnergyItem | ||
|
||
class RandomEnergyLootFunction(conditions: Array<out LootCondition>): ConditionalLootFunction(conditions) { | ||
|
||
|
||
override fun process(stack: ItemStack, ctx: LootContext): ItemStack { | ||
if(stack.item is SimpleEnergyItem) { | ||
val capacity = (stack.item as SimpleEnergyItem).getEnergyCapacity(stack) | ||
val percentage = ctx.random.nextFloat().coerceIn(0F, baseConfig.misc.disruption.maxEnergyOctahedronEnergyPercentage) | ||
stack.orCreateNbt.putLong(SimpleEnergyItem.ENERGY_KEY, (capacity * percentage).toLong()) | ||
} | ||
return stack | ||
} | ||
|
||
override fun getType(): LootFunctionType = RANDOM_ENERGY | ||
|
||
class RandomEnergyLootFunctionSerializer: Serializer<RandomEnergyLootFunction>() { | ||
|
||
override fun fromJson(json: JsonObject, context: JsonDeserializationContext, conditions: Array<out LootCondition>): RandomEnergyLootFunction { | ||
return RandomEnergyLootFunction(conditions) | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
base/src/main/kotlin/dev/nathanpb/dml/misc/lootfunction/RandomPristineMatterLootFunction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package dev.nathanpb.dml.misc.lootfunction | ||
|
||
import com.google.gson.JsonDeserializationContext | ||
import com.google.gson.JsonObject | ||
import dev.nathanpb.dml.baseConfig | ||
import dev.nathanpb.dml.misc.PRISTINE_MATTER | ||
import net.minecraft.item.ItemStack | ||
import net.minecraft.loot.condition.LootCondition | ||
import net.minecraft.loot.context.LootContext | ||
import net.minecraft.loot.function.ConditionalLootFunction | ||
import net.minecraft.loot.function.LootFunctionType | ||
import net.minecraft.registry.Registries | ||
|
||
class RandomPristineMatterLootFunction(conditions: Array<out LootCondition>): ConditionalLootFunction(conditions) { | ||
|
||
|
||
override fun process(stack: ItemStack, ctx: LootContext): ItemStack { | ||
val pristineMatterStack = ItemStack( | ||
Registries.ITEM.iterateEntries(PRISTINE_MATTER).iterator() | ||
.asSequence() | ||
.toList() | ||
.random() | ||
) | ||
val maxStackSize = baseConfig.misc.disruption.maxPristineMatterStackSize | ||
pristineMatterStack.count = ctx.random.nextInt(maxStackSize + 1).coerceIn(0, 64) | ||
|
||
return pristineMatterStack | ||
} | ||
|
||
override fun getType(): LootFunctionType = RANDOM_PRISTINE_MATTER | ||
|
||
class RandomPristineMatterLootFunctionSerializer: Serializer<RandomPristineMatterLootFunction>() { | ||
|
||
override fun fromJson(json: JsonObject, context: JsonDeserializationContext, conditions: Array<out LootCondition>): RandomPristineMatterLootFunction { | ||
return RandomPristineMatterLootFunction(conditions) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
base/src/main/resources/data/dml-refabricated/loot_tables/chests/disruption.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"type": "minecraft:chest", | ||
"pools": [ | ||
{ | ||
"rolls": { | ||
"type": "minecraft:uniform", | ||
"min": 2, | ||
"max": 5 | ||
}, | ||
"bonus_rolls": 0, | ||
"entries": [ | ||
{ | ||
"type": "minecraft:item", | ||
"weight": 10, | ||
"name": "dml-refabricated:soot_redstone", | ||
"functions": [ | ||
{ | ||
"function": "minecraft:set_count", | ||
"count": { | ||
"type": "minecraft:uniform", | ||
"min": 1, | ||
"max": 4 | ||
}, | ||
"add": false | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "minecraft:item", | ||
"weight": 6, | ||
"name": "dml-refabricated:soot_plate", | ||
"functions": [ | ||
{ | ||
"function": "minecraft:set_count", | ||
"count": { | ||
"type": "minecraft:uniform", | ||
"min": 1, | ||
"max": 3 | ||
}, | ||
"add": false | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "minecraft:item", | ||
"weight": 5, | ||
"name": "dml-refabricated:machine_casing" | ||
}, | ||
{ | ||
"type": "minecraft:item", | ||
"weight": 2, | ||
"name": "dml-refabricated:energy_octahedron", | ||
"functions": [ | ||
{ | ||
"function": "dml-refabricated:random_energy" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "minecraft:item", | ||
"name": "dml-refabricated:data_model_overworld", | ||
"functions": [ | ||
{ | ||
"function": "dml-refabricated:random_data_model" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"rolls": 1, | ||
"bonus_rolls": 0, | ||
"entries": [ | ||
{ | ||
"type": "minecraft:item", | ||
"name": "dml-refabricated:physically_condensed_matrix_fragment", | ||
"functions": [ | ||
{ | ||
"function": "minecraft:set_count", | ||
"count": { | ||
"type": "minecraft:uniform", | ||
"min": 2, | ||
"max": 5 | ||
}, | ||
"add": false | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "minecraft:item", | ||
"weight": 3, | ||
"name": "dml-refabricated:pristine_matter_overworld", | ||
"functions": [ | ||
{ | ||
"function": "dml-refabricated:random_pristine_matter" | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "minecraft:item", | ||
"weight": 5, | ||
"name": "dml-refabricated:glitch_upgrade_smithing_template" | ||
} | ||
] | ||
} | ||
] | ||
} |