Skip to content

Commit

Permalink
Add Disruption's loot table
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligabi1 committed Mar 14, 2024
1 parent 26738dc commit f3650b6
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 9 deletions.
7 changes: 7 additions & 0 deletions base/src/main/kotlin/dev/nathanpb/dml/BaseConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class LootFabricator {
class Misc {
var glitchSword = GlitchSword()
var energyOctahedron = EnergyOctahedron()
var disruption = Disruption()
}

class GlitchSword {
Expand All @@ -151,4 +152,10 @@ class GlitchSword {
class EnergyOctahedron {
var energyCapacity = 50000L
var energyIO = 5000L
}

class Disruption {
var maxDataModelData = 14
var maxPristineMatterStackSize = 3
var maxEnergyOctahedronEnergyPercentage = 0.65F
}
2 changes: 2 additions & 0 deletions base/src/main/kotlin/dev/nathanpb/dml/DeepMobLearning.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import dev.nathanpb.dml.item.registerItems
import dev.nathanpb.dml.itemgroup.registerItemGroup
import dev.nathanpb.dml.listener.CrushingRecipeListener
import dev.nathanpb.dml.listener.DataCollectListener
import dev.nathanpb.dml.misc.lootfunction.registerLootFunctions
import dev.nathanpb.dml.misc.registerSounds
import dev.nathanpb.dml.recipe.registerRecipeSerializers
import dev.nathanpb.dml.recipe.registerRecipeTypes
Expand Down Expand Up @@ -80,6 +81,7 @@ fun init() {
}
TrialAffixRegistry.registerDefaultAffixes()
registerFeatures()
registerLootFunctions()
registerSounds()
CommandRegistrationCallback.EVENT.register(DMLCommand())
LOGGER.info("Deep Mob Learning: Refabricated" + quirkyStartupMessages[Random.nextInt(quirkyStartupMessages.size)])
Expand Down
6 changes: 5 additions & 1 deletion base/src/main/kotlin/dev/nathanpb/dml/misc/Tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package dev.nathanpb.dml.misc

import dev.nathanpb.dml.identifier
import net.minecraft.block.Block
import net.minecraft.item.Item
import net.minecraft.registry.RegistryKeys

import net.minecraft.registry.tag.TagKey


val TRIAL_GRIEF_WHITELIST: TagKey<Block> = TagKey.of(RegistryKeys.BLOCK, identifier("trial_grief_whitelist"))
val TRIAL_GRIEF_WHITELIST: TagKey<Block> = TagKey.of(RegistryKeys.BLOCK, identifier("trial_grief_whitelist"))

val ATTUNED_DATA_MODELS: TagKey<Item> = TagKey.of(RegistryKeys.ITEM, identifier("attuned_data_models"))
val PRISTINE_MATTER: TagKey<Item> = TagKey.of(RegistryKeys.ITEM, identifier("pristine_matter"))
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
}
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)
}
}
}
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)
}
}
}
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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import dev.nathanpb.dml.block.BLOCK_DISRUPTIONS_CORE
import dev.nathanpb.dml.block.BLOCK_FADING_GLITCHED_TILE
import dev.nathanpb.dml.block.BlockDisruptionsCore
import dev.nathanpb.dml.blockEntity.BlockEntityFadingGlitchedTile
import dev.nathanpb.dml.identifier
import net.minecraft.block.Block
import net.minecraft.block.entity.LootableContainerBlockEntity
import net.minecraft.loot.LootTables
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.BlockPos.Mutable
import net.minecraft.util.math.Direction
Expand All @@ -28,7 +28,7 @@ class DisruptionFeature(
val world = context.world


var i = 0
var hasGeneratedAny = false
val radius = config.radius.get(random)

val cx: Int = origin.x
Expand Down Expand Up @@ -61,23 +61,24 @@ class DisruptionFeature(
}

if(canGenerate) {
pos = verticalOffset(pos, offset)
if(pos != origin) { // block below core can never be offset
pos = verticalOffset(pos, offset)
}

val blockState = world.getBlockState(pos)
world.setBlockState(pos, BLOCK_FADING_GLITCHED_TILE.defaultState, Block.NOTIFY_LISTENERS)
(world.getBlockEntity(pos) as? BlockEntityFadingGlitchedTile)?.blockState = blockState
i++
hasGeneratedAny = true
}
}
}

val hasGenerated = i > 0
if(hasGenerated) {
if(hasGeneratedAny) {
world.setBlockState(origin, BLOCK_DISRUPTIONS_CORE.defaultState.with(BlockDisruptionsCore.FADING, true), Block.NOTIFY_LISTENERS)
LootableContainerBlockEntity.setLootTable(world, random, origin, LootTables.WOODLAND_MANSION_CHEST)
LootableContainerBlockEntity.setLootTable(world, random, origin, identifier("chests/disruption"))
}

return hasGenerated
return hasGeneratedAny
}

private fun testPos(pos: BlockPos, direction: Direction, world: StructureWorldAccess): Boolean {
Expand Down
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"
}
]
}
]
}

0 comments on commit f3650b6

Please sign in to comment.