Skip to content

Commit

Permalink
Added VS Creative Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
StewStrong committed Jun 15, 2023
1 parent 555b6f2 commit baf2e17
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package org.valkyrienskies.mod.common

import net.minecraft.core.Registry
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.core.registries.Registries
import net.minecraft.network.chat.Component
import net.minecraft.resources.ResourceKey
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.MinecraftServer
import net.minecraft.world.entity.EntityType
import net.minecraft.world.item.CreativeModeTab
import net.minecraft.world.item.Item
import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.entity.BlockEntityType
import org.valkyrienskies.core.api.ships.setAttachment
import org.valkyrienskies.core.apigame.VSCore
Expand All @@ -21,15 +30,21 @@ object ValkyrienSkiesMod {
const val MOD_ID = "valkyrienskies"

lateinit var TEST_CHAIR: Block
lateinit var TEST_CHAIR_ITEM: Item
lateinit var TEST_HINGE: Block
lateinit var TEST_HINGE_ITEM: Item
lateinit var TEST_FLAP: Block
lateinit var TEST_FLAP_ITEM: Item
lateinit var TEST_WING: Block
lateinit var TEST_WING_ITEM: Item
lateinit var SHIP_CREATOR_ITEM: Item
lateinit var SHIP_ASSEMBLER_ITEM: Item
lateinit var SHIP_CREATOR_ITEM_SMALLER: Item
lateinit var SHIP_MOUNTING_ENTITY_TYPE: EntityType<ShipMountingEntity>
lateinit var TEST_HINGE_BLOCK_ENTITY_TYPE: BlockEntityType<TestHingeBlockEntity>

val VS_CREATIVE_TAB = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation("valkyrienskies"))

@JvmStatic
var currentServer: MinecraftServer? = null

Expand All @@ -52,4 +67,24 @@ object ValkyrienSkiesMod {
event.ship.setAttachment(GameTickForceApplier())
}
}

fun registerCreativeTab() {
Registry.register(
BuiltInRegistries.CREATIVE_MODE_TAB,
VS_CREATIVE_TAB,
CreativeModeTab.builder(CreativeModeTab.Row.TOP, 0)
.title(Component.translatable("itemGroup.valkyrienSkies"))
.icon { ItemStack(SHIP_CREATOR_ITEM) }
.displayItems { _, output ->
output.accept(TEST_CHAIR_ITEM)
output.accept(TEST_HINGE_ITEM)
output.accept(TEST_FLAP_ITEM)
output.accept(TEST_WING_ITEM)
output.accept(SHIP_CREATOR_ITEM)
output.accept(SHIP_ASSEMBLER_ITEM)
output.accept(SHIP_CREATOR_ITEM_SMALLER)
}
.build()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"block.valkyrienskies.test_wing": "Debug Wing",
"item.valkyrienskies.ship_creator": "Ship Creator",
"item.valkyrienskies.ship_creator_smaller": "Mini Ship Creator",
"itemGroup.valkyrienSkies": "Valkyrien Skies",
"argument.valkyrienskies.ship.no_found": "Ship not found",
"argument.valkyrienskies.ship.multiple_found": "Multiple ships found",
"command.valkyrienskies.delete.success": "Deleted %d ships!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import net.minecraft.util.profiling.ProfilerFiller
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.MobCategory
import net.minecraft.world.item.BlockItem
import net.minecraft.world.item.CreativeModeTab
import net.minecraft.world.item.Item
import net.minecraft.world.item.Item.Properties
import net.minecraft.world.level.block.Block
import org.valkyrienskies.core.apigame.VSCoreFactory
Expand All @@ -38,7 +38,6 @@ import org.valkyrienskies.mod.common.config.VSEntityHandlerDataLoader
import org.valkyrienskies.mod.common.config.VSGameConfig
import org.valkyrienskies.mod.common.config.VSKeyBindings
import org.valkyrienskies.mod.common.entity.ShipMountingEntity
import org.valkyrienskies.mod.common.entity.handling.VSEntityManager
import org.valkyrienskies.mod.common.hooks.VSGameEvents
import org.valkyrienskies.mod.common.item.ShipAssemblerItem
import org.valkyrienskies.mod.common.item.ShipCreatorItem
Expand Down Expand Up @@ -95,10 +94,10 @@ class ValkyrienSkiesModFabric : ModInitializer {
ValkyrienSkiesMod.init(vsCore)
// VSEntityManager.registerContraptionHandler(ContraptionShipyardEntityHandlerFabric)

registerBlockAndItem("test_chair", ValkyrienSkiesMod.TEST_CHAIR)
registerBlockAndItem("test_hinge", ValkyrienSkiesMod.TEST_HINGE)
registerBlockAndItem("test_flap", ValkyrienSkiesMod.TEST_FLAP)
registerBlockAndItem("test_wing", ValkyrienSkiesMod.TEST_WING)
ValkyrienSkiesMod.TEST_CHAIR_ITEM = registerBlockAndItem("test_chair", ValkyrienSkiesMod.TEST_CHAIR)
ValkyrienSkiesMod.TEST_HINGE_ITEM =registerBlockAndItem("test_hinge", ValkyrienSkiesMod.TEST_HINGE)
ValkyrienSkiesMod.TEST_FLAP_ITEM = registerBlockAndItem("test_flap", ValkyrienSkiesMod.TEST_FLAP)
ValkyrienSkiesMod.TEST_WING_ITEM = registerBlockAndItem("test_wing", ValkyrienSkiesMod.TEST_WING)
Registry.register(
BuiltInRegistries.ITEM, ResourceLocation(ValkyrienSkiesMod.MOD_ID, "ship_assembler"),
ValkyrienSkiesMod.SHIP_ASSEMBLER_ITEM
Expand All @@ -120,6 +119,8 @@ class ValkyrienSkiesModFabric : ModInitializer {
ValkyrienSkiesMod.TEST_HINGE_BLOCK_ENTITY_TYPE
)

ValkyrienSkiesMod.registerCreativeTab()

CommandRegistrationCallback.EVENT.register { dispatcher, _, _ ->
VSCommands.registerServerCommands(dispatcher)
}
Expand Down Expand Up @@ -175,14 +176,13 @@ class ValkyrienSkiesModFabric : ModInitializer {
}
}

private fun registerBlockAndItem(registryName: String, block: Block) {
private fun registerBlockAndItem(registryName: String, block: Block): Item {
Registry.register(
BuiltInRegistries.BLOCK, ResourceLocation(ValkyrienSkiesMod.MOD_ID, registryName),
block
)
Registry.register(
BuiltInRegistries.ITEM, ResourceLocation(ValkyrienSkiesMod.MOD_ID, registryName),
BlockItem(block, Properties())
)
val item = BlockItem(block, Properties())
Registry.register(BuiltInRegistries.ITEM, ResourceLocation(ValkyrienSkiesMod.MOD_ID, registryName), item)
return item
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import org.valkyrienskies.mod.common.config.VSEntityHandlerDataLoader
import org.valkyrienskies.mod.common.config.VSGameConfig
import org.valkyrienskies.mod.common.config.VSKeyBindings
import org.valkyrienskies.mod.common.entity.ShipMountingEntity
import org.valkyrienskies.mod.common.entity.handling.VSEntityManager
import org.valkyrienskies.mod.common.hooks.VSGameEvents
import org.valkyrienskies.mod.common.item.ShipAssemblerItem
import org.valkyrienskies.mod.common.item.ShipCreatorItem
Expand All @@ -52,9 +51,13 @@ class ValkyrienSkiesModForge {
private val ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, ValkyrienSkiesMod.MOD_ID)
private val BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, ValkyrienSkiesMod.MOD_ID)
private val TEST_CHAIR_REGISTRY: RegistryObject<Block>
private val TEST_CHAIR_REGISTRY_ITEM: RegistryObject<BlockItem>
private val TEST_HINGE_REGISTRY: RegistryObject<Block>
private val TEST_HINGE_REGISTRY_ITEM: RegistryObject<BlockItem>
private val TEST_FLAP_REGISTRY: RegistryObject<Block>
private val TEST_FLAP_REGISTRY_ITEM: RegistryObject<BlockItem>
private val TEST_WING_REGISTRY: RegistryObject<Block>
private val TEST_WING_REGISTRY_ITEM: RegistryObject<BlockItem>
private val SHIP_CREATOR_ITEM_REGISTRY: RegistryObject<Item>
private val SHIP_CREATOR_SMALLER_ITEM_REGISTRY: RegistryObject<Item>
private val SHIP_MOUNTING_ENTITY_REGISTRY: RegistryObject<EntityType<ShipMountingEntity>>
Expand Down Expand Up @@ -104,10 +107,22 @@ class ValkyrienSkiesModForge {
}
}

TEST_CHAIR_REGISTRY = registerBlockAndItem("test_chair") { TestChairBlock }
TEST_HINGE_REGISTRY = registerBlockAndItem("test_hinge") { TestHingeBlock }
TEST_FLAP_REGISTRY = registerBlockAndItem("test_flap") { TestFlapBlock }
TEST_WING_REGISTRY = registerBlockAndItem("test_wing") { TestWingBlock }
val testChairPair = registerBlockAndItem("test_chair") { TestChairBlock }
TEST_CHAIR_REGISTRY = testChairPair.first
TEST_CHAIR_REGISTRY_ITEM = testChairPair.second

val testHingePair = registerBlockAndItem("test_hinge") { TestHingeBlock }
TEST_HINGE_REGISTRY = testHingePair.first
TEST_HINGE_REGISTRY_ITEM = testHingePair.second

val testFlapPair = registerBlockAndItem("test_flap") { TestFlapBlock }
TEST_FLAP_REGISTRY = testFlapPair.first
TEST_FLAP_REGISTRY_ITEM = testFlapPair.second

val testWingPair = registerBlockAndItem("test_wing") { TestWingBlock }
TEST_WING_REGISTRY = testWingPair.first
TEST_WING_REGISTRY_ITEM = testWingPair.second

SHIP_CREATOR_ITEM_REGISTRY =
ITEMS.register("ship_creator") {
ShipCreatorItem(Properties(),
Expand Down Expand Up @@ -151,10 +166,10 @@ class ValkyrienSkiesModForge {
event.registerEntityRenderer(SHIP_MOUNTING_ENTITY_REGISTRY.get(), ::EmptyRenderer)
}

private fun registerBlockAndItem(registryName: String, blockSupplier: () -> Block): RegistryObject<Block> {
private fun registerBlockAndItem(registryName: String, blockSupplier: () -> Block): Pair<RegistryObject<Block>, RegistryObject<BlockItem>> {
val blockRegistry = BLOCKS.register(registryName, blockSupplier)
ITEMS.register(registryName) { BlockItem(blockRegistry.get(), Properties()) }
return blockRegistry
val itemRegister = ITEMS.register(registryName) { BlockItem(blockRegistry.get(), Properties()) }
return Pair(blockRegistry, itemRegister)
}

private fun registerCommands(event: RegisterCommandsEvent) {
Expand All @@ -171,13 +186,19 @@ class ValkyrienSkiesModForge {

private fun loadComplete(event: FMLLoadCompleteEvent) {
ValkyrienSkiesMod.TEST_CHAIR = TEST_CHAIR_REGISTRY.get()
ValkyrienSkiesMod.TEST_CHAIR_ITEM = TEST_CHAIR_REGISTRY_ITEM.get()
ValkyrienSkiesMod.TEST_HINGE = TEST_HINGE_REGISTRY.get()
ValkyrienSkiesMod.TEST_HINGE_ITEM = TEST_HINGE_REGISTRY_ITEM.get()
ValkyrienSkiesMod.TEST_FLAP = TEST_FLAP_REGISTRY.get()
ValkyrienSkiesMod.TEST_FLAP_ITEM = TEST_FLAP_REGISTRY_ITEM.get()
ValkyrienSkiesMod.TEST_WING = TEST_WING_REGISTRY.get()
ValkyrienSkiesMod.TEST_WING_ITEM = TEST_WING_REGISTRY_ITEM.get()
ValkyrienSkiesMod.SHIP_CREATOR_ITEM = SHIP_CREATOR_ITEM_REGISTRY.get()
ValkyrienSkiesMod.SHIP_CREATOR_ITEM_SMALLER = SHIP_CREATOR_SMALLER_ITEM_REGISTRY.get()
ValkyrienSkiesMod.SHIP_MOUNTING_ENTITY_TYPE = SHIP_MOUNTING_ENTITY_REGISTRY.get()
ValkyrienSkiesMod.SHIP_ASSEMBLER_ITEM = SHIP_ASSEMBLER_ITEM_REGISTRY.get()
ValkyrienSkiesMod.TEST_HINGE_BLOCK_ENTITY_TYPE = TEST_HINGE_BLOCK_ENTITY_TYPE_REGISTRY.get()

ValkyrienSkiesMod.registerCreativeTab()
}
}

0 comments on commit baf2e17

Please sign in to comment.