Skip to content

Commit

Permalink
refactor: datagen everything
Browse files Browse the repository at this point in the history
This also fixes recipes that didn't appear in the recipe book, such as
module upgrades. There's still a few small hiccups (for example if you
have all the requirements for a laser, it won't automatically move the
book into the recipe slot), but most of the recipes are working now.
  • Loading branch information
Lemmmy committed Sep 18, 2022
1 parent 7c7c5c2 commit d1b363f
Show file tree
Hide file tree
Showing 68 changed files with 725 additions and 1,093 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ root = true
end_of_line = lf
insert_final_newline = true

[*.{java,kt,kts}]
[*.{java,kt,kts,json,lua}]
indent_style = space
indent_size = 2
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Plethora-Fabric

Plethora-Fabric is a port of [Plethora](https://github.com/SquidDev-CC/plethora) for Fabric 1.18+. The port is still
Plethora-Fabric is a port of [Plethora](https://github.com/SquidDev-CC/plethora) for Fabric 1.19+. The port is still
ongoing.

## Port status
Expand All @@ -16,8 +16,7 @@ ongoing.

### Peripheral modules
- [x] Manipulator
- [ ] Chat recorder
- [ ] Overlay glasses
- [x] Overlay glasses
- [x] Introspection nodule
- [x] Inventory methods
- [x] Kinetic augment
Expand All @@ -34,7 +33,6 @@ ongoing.
- [x] Cost system
- [ ] Config
- [ ] Module blacklist & method configuration
- [ ] Recipe book advancements

### Integration
- [x] API
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ configurateVersion = 4.1.2

trinketsVersion = 3.4.0

scLibraryVersion = 1.0.12
scLibraryVersion = 1.0.17
8 changes: 8 additions & 0 deletions src/main/java/pw/switchcraft/plethora/PlethoraKt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pw.switchcraft.plethora

import net.minecraft.util.Identifier

object PlethoraKt {
internal const val modId = Plethora.MOD_ID
internal fun ModId(value: String) = Identifier(modId, value)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package pw.switchcraft.plethora.gameplay.data

import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider
import net.minecraft.block.Block
import net.minecraft.data.client.*
import net.minecraft.data.client.TextureKey.*
import net.minecraft.state.property.Properties.FACING
import net.minecraft.util.math.Direction
import pw.switchcraft.plethora.PlethoraKt.ModId
import pw.switchcraft.plethora.gameplay.registry.Registration.ModBlocks.*
import java.util.*

class BlockModelProvider(generator: FabricDataGenerator) : FabricModelProvider(generator) {
override fun generateBlockStateModels(gen: BlockStateModelGenerator) {
gen.registerSimpleCubeAll(REDSTONE_INTEGRATOR)

registerManipulator(gen, MANIPULATOR_MARK_1, 1)
registerManipulator(gen, MANIPULATOR_MARK_2, 2)
}

override fun generateItemModels(gen: ItemModelGenerator) {
}

private fun registerManipulator(gen: BlockStateModelGenerator, block: Block, mark: Int) {
val modelId = manipulatorModel.upload(
block,
TextureMap()
.put(PARTICLE, ModId("block/manipulator_side"))
.put(BOTTOM, ModId("block/manipulator_bottom"))
.put(TOP, ModId("block/manipulator_top$mark"))
.put(SIDE, ModId("block/manipulator_side")),
gen.modelCollector
)

val variants = createDownDefaultFacingVariantMap()

gen.blockStateCollector.accept(VariantsBlockStateSupplier.create(
block,
BlockStateVariant.create().put(VariantSettings.MODEL, modelId)
).coordinate(variants))
}

private fun createDownDefaultFacingVariantMap(): BlockStateVariantMap.SingleProperty<Direction> =
BlockStateVariantMap.create(FACING)
.register(Direction.DOWN, BlockStateVariant.create())
.register(Direction.UP, BlockStateVariant.create()
.put(VariantSettings.X, VariantSettings.Rotation.R180))
.register(Direction.NORTH, BlockStateVariant.create()
.put(VariantSettings.X, VariantSettings.Rotation.R90)
.put(VariantSettings.Y, VariantSettings.Rotation.R180))
.register(Direction.SOUTH, BlockStateVariant.create()
.put(VariantSettings.X, VariantSettings.Rotation.R90))
.register(Direction.EAST, BlockStateVariant.create()
.put(VariantSettings.X, VariantSettings.Rotation.R90)
.put(VariantSettings.Y, VariantSettings.Rotation.R270))
.register(Direction.WEST, BlockStateVariant.create()
.put(VariantSettings.X, VariantSettings.Rotation.R90)
.put(VariantSettings.Y, VariantSettings.Rotation.R90))

companion object {
val manipulatorModel = Model(
Optional.of(ModId("block/manipulator_base")), Optional.empty(),
PARTICLE, BOTTOM, TOP, SIDE
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package pw.switchcraft.plethora.gameplay.data

import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider
import net.minecraft.data.client.BlockStateModelGenerator
import net.minecraft.data.client.ItemModelGenerator
import net.minecraft.data.client.Models.GENERATED
import pw.switchcraft.plethora.gameplay.registry.Registration.ModItems

class ItemModelProvider(generator: FabricDataGenerator) : FabricModelProvider(generator) {
override fun generateBlockStateModels(gen: BlockStateModelGenerator) {
}

override fun generateItemModels(gen: ItemModelGenerator) {
gen.register(ModItems.GLASSES_MODULE, GENERATED)
gen.register(ModItems.INTROSPECTION_MODULE, GENERATED)
gen.register(ModItems.KEYBOARD_MODULE, GENERATED)
gen.register(ModItems.KINETIC_MODULE, GENERATED)
// Laser provided in JSON for custom rotations
gen.register(ModItems.SCANNER_MODULE, GENERATED)
gen.register(ModItems.SENSOR_MODULE, GENERATED)
gen.register(ModItems.NEURAL_CONNECTOR, GENERATED)
gen.register(ModItems.NEURAL_INTERFACE, GENERATED)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pw.switchcraft.plethora.gameplay.data

import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator
import org.slf4j.LoggerFactory
import pw.switchcraft.plethora.gameplay.data.recipes.RecipeGenerator

object PlethoraDatagen : DataGeneratorEntrypoint {
val log = LoggerFactory.getLogger("Plethora/PlethoraDatagen")!!

override fun onInitializeDataGenerator(generator: FabricDataGenerator) {
log.info("Plethora datagen initializing")

generator.addProvider(BlockModelProvider(generator))
generator.addProvider(ItemModelProvider(generator))
generator.addProvider(RecipeGenerator(generator))
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package pw.switchcraft.plethora.gameplay.data.recipes

import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags.GOLD_INGOTS
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalItemTags.REDSTONE_DUSTS
import net.minecraft.entity.effect.StatusEffects
import net.minecraft.item.ItemStack
import net.minecraft.item.Items.PISTON
import net.minecraft.potion.Potions
import net.minecraft.recipe.Ingredient.fromTag
import net.minecraft.recipe.Ingredient.ofItems
import net.minecraft.recipe.SpecialRecipeSerializer
import net.minecraft.util.Identifier
import pw.switchcraft.library.recipe.BetterSpecialRecipe
import pw.switchcraft.library.recipe.IngredientBrew
import pw.switchcraft.plethora.gameplay.registry.Registration.ModItems.KINETIC_MODULE

class KineticRecipe(id: Identifier) : BetterSpecialRecipe(id) {
private val brew = IngredientBrew(StatusEffects.JUMP_BOOST, Potions.LEAPING)

override val ingredients = listOf(
fromTag(REDSTONE_DUSTS), fromTag(GOLD_INGOTS), fromTag(REDSTONE_DUSTS),
ofItems(PISTON), brew, ofItems(PISTON),
fromTag(REDSTONE_DUSTS), fromTag(GOLD_INGOTS), fromTag(REDSTONE_DUSTS),
)

override val outputItem = ItemStack(KINETIC_MODULE)

override fun isIgnoredInRecipeBook() = false
override fun getSerializer() = recipeSerializer

companion object {
val recipeSerializer = SpecialRecipeSerializer { KineticRecipe(it) }
}
}
Loading

0 comments on commit d1b363f

Please sign in to comment.