Updates for global registry

This commit is contained in:
DBotThePony 2024-08-24 12:15:42 +07:00
parent 12b59ed785
commit cb85689ea9
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -6,7 +6,9 @@ import com.google.common.collect.Streams
import net.minecraft.advancements.CriteriaTriggers import net.minecraft.advancements.CriteriaTriggers
import net.minecraft.client.renderer.item.ItemProperties import net.minecraft.client.renderer.item.ItemProperties
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.core.Registry
import net.minecraft.core.cauldron.CauldronInteraction import net.minecraft.core.cauldron.CauldronInteraction
import net.minecraft.core.component.DataComponents
import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.core.registries.Registries import net.minecraft.core.registries.Registries
import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.CompoundTag
@ -15,9 +17,10 @@ import net.minecraft.world.entity.ai.village.poi.PoiType
import net.minecraft.world.entity.ai.village.poi.PoiTypes import net.minecraft.world.entity.ai.village.poi.PoiTypes
import net.minecraft.world.item.BlockItem import net.minecraft.world.item.BlockItem
import net.minecraft.world.item.DyeColor import net.minecraft.world.item.DyeColor
import net.minecraft.world.item.DyeableArmorItem
import net.minecraft.world.item.Item import net.minecraft.world.item.Item
import net.minecraft.world.item.ShieldItem import net.minecraft.world.item.ShieldItem
import net.minecraft.world.item.component.CustomData
import net.minecraft.world.item.component.DyedItemColor
import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.BlockGetter
import net.minecraft.world.level.block.* import net.minecraft.world.level.block.*
import net.minecraft.world.level.block.state.BlockBehaviour import net.minecraft.world.level.block.state.BlockBehaviour
@ -143,7 +146,7 @@ object MRegistry : IBlockItemRegistryAcceptor {
val TRITANIUM_STAIRS = DecorativeBlock(MNames.TRITANIUM_STAIRS) { val TRITANIUM_STAIRS = DecorativeBlock(MNames.TRITANIUM_STAIRS) {
StairBlock( StairBlock(
{ TRITANIUM_BLOCK.allBlocks[it]!!.defaultBlockState() }, TRITANIUM_BLOCK.allBlocks[it]!!.defaultBlockState(),
BlockBehaviour.Properties.ofFullCopy(TRITANIUM_BLOCK.allBlocks[it]!!) BlockBehaviour.Properties.ofFullCopy(TRITANIUM_BLOCK.allBlocks[it]!!)
) )
}.also { decorativeBlocks.add(it) } }.also { decorativeBlocks.add(it) }
@ -186,13 +189,13 @@ object MRegistry : IBlockItemRegistryAcceptor {
val FLOOR_TILES_STAIRS = ColoredDecorativeBlock(MNames.FLOOR_TILES_STAIRS) { val FLOOR_TILES_STAIRS = ColoredDecorativeBlock(MNames.FLOOR_TILES_STAIRS) {
StairBlock( StairBlock(
{ FLOOR_TILES.blocks[it]!!.defaultBlockState() }, FLOOR_TILES.blocks[it]!!.defaultBlockState(),
BlockBehaviour.Properties.copy(FLOOR_TILES.blocks[it]!!) BlockBehaviour.Properties.ofLegacyCopy(FLOOR_TILES.blocks[it]!!)
) )
}.also { decorativeBlocks.add(it) } }.also { decorativeBlocks.add(it) }
val FLOOR_TILES_SLAB = ColoredDecorativeBlock(MNames.FLOOR_TILES_SLAB) { val FLOOR_TILES_SLAB = ColoredDecorativeBlock(MNames.FLOOR_TILES_SLAB) {
SlabBlock(BlockBehaviour.Properties.copy(FLOOR_TILES.blocks[it]!!)) SlabBlock(BlockBehaviour.Properties.ofLegacyCopy(FLOOR_TILES.blocks[it]!!))
}.also { decorativeBlocks.add(it) } }.also { decorativeBlocks.add(it) }
val UNREFINED_FLOOR_TILES = ColoredDecorativeBlock.simple(MNames.UNREFINED_FLOOR_TILES) { val UNREFINED_FLOOR_TILES = ColoredDecorativeBlock.simple(MNames.UNREFINED_FLOOR_TILES) {
@ -221,7 +224,7 @@ object MRegistry : IBlockItemRegistryAcceptor {
return@DecorativeBlock StainedGlassBlock(color, properties) return@DecorativeBlock StainedGlassBlock(color, properties)
} }
return@DecorativeBlock GlassBlock(properties) return@DecorativeBlock TransparentBlock(properties)
}.also { decorativeBlocks.add(it) } }.also { decorativeBlocks.add(it) }
val INDUSTRIAL_GLASS_PANE = DecorativeBlock(MNames.INDUSTRIAL_GLASS_PANE) { color -> val INDUSTRIAL_GLASS_PANE = DecorativeBlock(MNames.INDUSTRIAL_GLASS_PANE) { color ->
@ -266,7 +269,7 @@ object MRegistry : IBlockItemRegistryAcceptor {
// mojang moment // mojang moment
if (event.registryKey == Registries.POINT_OF_INTEREST_TYPE) { if (event.registryKey == Registries.POINT_OF_INTEREST_TYPE) {
val reg = event.getVanillaRegistry<PoiType>() ?: throw IllegalStateException("POI registry is not a vanilla registry") val reg = event.registry as Registry<PoiType>
event.register(Registries.POINT_OF_INTEREST_TYPE, PoiTypes.BUTCHER.location()) { event.register(Registries.POINT_OF_INTEREST_TYPE, PoiTypes.BUTCHER.location()) {
val old = reg[PoiTypes.BUTCHER] ?: throw IllegalStateException("POI with type ${PoiTypes.ARMORER} does not exist") val old = reg[PoiTypes.BUTCHER] ?: throw IllegalStateException("POI with type ${PoiTypes.ARMORER} does not exist")
@ -353,7 +356,7 @@ object MRegistry : IBlockItemRegistryAcceptor {
for (item in MItems.ESSENCE_STORAGE.values) { for (item in MItems.ESSENCE_STORAGE.values) {
ItemProperties.register(item, ResourceLocation(OverdriveThatMatters.MOD_ID, "is_filled")) { stack, _, _, _ -> ItemProperties.register(item, ResourceLocation(OverdriveThatMatters.MOD_ID, "is_filled")) { stack, _, _, _ ->
val tag = (stack.tag?.get(BlockItem.BLOCK_ENTITY_TAG) as? CompoundTag)?: return@register 0f val tag = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY).unsafe ?: return@register 0f
if (tag.contains("experienceStored") && tag.getLong("experienceStored") > 0.0) { if (tag.contains("experienceStored") && tag.getLong("experienceStored") > 0.0) {
1f 1f
@ -366,14 +369,16 @@ object MRegistry : IBlockItemRegistryAcceptor {
} }
private fun registerCauldronHandlers() { private fun registerCauldronHandlers() {
MItems.TRITANIUM_ARMOR.forEach { CauldronInteraction.WATER[it] = CauldronInteraction.DYED_ITEM } MItems.TRITANIUM_ARMOR.forEach { CauldronInteraction.WATER.map()[it] = CauldronInteraction.DYED_ITEM }
} }
private fun registerItemColorHandlers(event: RegisterColorHandlersEvent.Item) { private fun registerItemColorHandlers(event: RegisterColorHandlersEvent.Item) {
event.register(DynamicFluidContainerModel.Colors(), MItems.FLUID_CAPSULE) event.register(DynamicFluidContainerModel.Colors(), MItems.FLUID_CAPSULE)
event.register({ stack, layer -> if (layer == 0) (stack.item as DyeableArmorItem).getColor(stack) else -1 },
event.register({ stack, layer -> if (layer == 0) DyedItemColor.getOrDefault(stack, -1) else -1 },
*MItems.TRITANIUM_ARMOR.toTypedArray() *MItems.TRITANIUM_ARMOR.toTypedArray()
) )
event.register({ _, layer -> if (layer == 1) RGBAColor.AQUA.toBGRA() else -1 }, event.register({ _, layer -> if (layer == 1) RGBAColor.AQUA.toBGRA() else -1 },
*MItems.MachineUpgrades.Creative.LIST.toTypedArray()) *MItems.MachineUpgrades.Creative.LIST.toTypedArray())
} }