diff --git a/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java b/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java index 20c110c13..afc1ae70d 100644 --- a/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java +++ b/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java @@ -1,5 +1,7 @@ package com.unlikepaladin.pfm; +import com.google.common.collect.ImmutableSet; +import com.unlikepaladin.pfm.blocks.SimpleBedBlock; import com.unlikepaladin.pfm.blocks.behavior.BathtubBehavior; import com.unlikepaladin.pfm.blocks.behavior.SinkBehavior; import com.unlikepaladin.pfm.compat.PFMModCompatibility; @@ -10,17 +12,30 @@ import com.unlikepaladin.pfm.data.materials.DynamicBlockRegistry; import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry; +import com.unlikepaladin.pfm.mixin.PFMPointOfInterestTypesAccessor; import com.unlikepaladin.pfm.registry.dynamic.FurnitureEntry; +import com.unlikepaladin.pfm.mixin.PFMPointOfInterestTypeAccessor; +import com.unlikepaladin.pfm.registry.BlockEntityRegistry; +import com.unlikepaladin.pfm.registry.PaladinFurnitureModBlocksItems; +import com.unlikepaladin.pfm.registry.dynamic.LateBlockRegistry; import dev.architectury.injectables.annotations.ExpectPlatform; import net.minecraft.block.Block; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import net.minecraft.block.BlockState; +import net.minecraft.block.enums.BedPart; import net.minecraft.item.ItemGroup; +import net.minecraft.registry.Registries; import net.minecraft.sound.SoundEvent; import net.minecraft.util.Identifier; import net.minecraft.util.Pair; import net.minecraft.util.StringIdentifiable; +import net.minecraft.world.poi.PointOfInterestType; +import net.minecraft.world.poi.PointOfInterestTypes; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.*; +import java.lang.reflect.InvocationTargetException; import java.util.*; public class PaladinFurnitureMod { @@ -32,7 +47,6 @@ public class PaladinFurnitureMod { public static final Logger GENERAL_LOGGER = LogManager.getLogger(); public static Pair FURNITURE_GROUP = new Pair<>("furniture", null); - public static Pair DYE_KITS = new Pair<>("dye_kits", null);; private static PaladinFurnitureModUpdateChecker updateChecker; public static boolean isClient = false; @@ -54,6 +68,17 @@ public void commonInit() { pfmModCompatibilities.add(PFMImmersivePortals.getInstance()); } + public static void replaceHomePOIStates() { + PointOfInterestType homePOI = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME); + Set originalBedStates = ((PFMPointOfInterestTypeAccessor)(Object)homePOI).getBlockStates(); + Set addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet()); + Set newBedStates = new HashSet<>(); + newBedStates.addAll(originalBedStates); + newBedStates.addAll(addedBedStates); + ((PFMPointOfInterestTypeAccessor) (Object)homePOI).setBlockStates(ImmutableSet.copyOf(newBedStates)); + addedBedStates.forEach(state -> PFMPointOfInterestTypesAccessor.getBlockStateToPointOfInterestType().put(state, Registries.POINT_OF_INTEREST_TYPE.entryOf(PointOfInterestTypes.HOME))); + } + @ExpectPlatform public static PaladinFurnitureModConfig getPFMConfig() { throw new AssertionError(); diff --git a/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMPointOfInterestTypeAccessor.java b/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMPointOfInterestTypeAccessor.java new file mode 100644 index 000000000..587fa2d0d --- /dev/null +++ b/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMPointOfInterestTypeAccessor.java @@ -0,0 +1,20 @@ +package com.unlikepaladin.pfm.mixin; + +import net.minecraft.block.BlockState; +import net.minecraft.world.poi.PointOfInterestType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; +import java.util.Set; + +@Mixin(PointOfInterestType.class) +public interface PFMPointOfInterestTypeAccessor { + @Accessor("blockStates") + Set getBlockStates(); + + @Mutable + @Accessor("blockStates") + void setBlockStates(Set states); +} diff --git a/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMPointOfInterestTypesAccessor.java b/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMPointOfInterestTypesAccessor.java new file mode 100644 index 000000000..14e47f225 --- /dev/null +++ b/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMPointOfInterestTypesAccessor.java @@ -0,0 +1,29 @@ +package com.unlikepaladin.pfm.mixin; + +import net.minecraft.block.BlockState; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.world.poi.PointOfInterestType; +import net.minecraft.world.poi.PointOfInterestTypes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; +import java.util.Set; + +@Mixin(PointOfInterestTypes.class) +public interface PFMPointOfInterestTypesAccessor { + @Accessor("POI_STATES_TO_TYPE") + static Map> getBlockStateToPointOfInterestType() { + throw new AssertionError(); + } + + + @Mutable + @Accessor("HOME") + static void setHome(RegistryKey home) { + throw new AssertionError(); + } + +} diff --git a/common/src/main/resources/pfm-common.mixins.json b/common/src/main/resources/pfm-common.mixins.json index d55c769f0..dbe862bd5 100644 --- a/common/src/main/resources/pfm-common.mixins.json +++ b/common/src/main/resources/pfm-common.mixins.json @@ -7,6 +7,8 @@ "PFMDataCache$CachedDataMixin", "PFMFeatureFlagFactory", "PFMPlayerInventoryMixin", + "PFMPointOfInterestTypeAccessor", + "PFMPointOfInterestTypesAccessor", "PFMTextureKeyFactory" ], "server": [ diff --git a/common/src/main/resources/pfm.accesswidener b/common/src/main/resources/pfm.accesswidener index 82154f44d..8775e0cd5 100644 --- a/common/src/main/resources/pfm.accesswidener +++ b/common/src/main/resources/pfm.accesswidener @@ -1,8 +1,6 @@ accessWidener v1 named accessible class net/minecraft/recipe/CookingRecipeSerializer$RecipeFactory -accessible field net/minecraft/world/poi/PointOfInterestTypes BED_HEADS Ljava/util/Set; -mutable field net/minecraft/world/poi/PointOfInterestTypes HOME Lnet/minecraft/registry/RegistryKey; accessible class net/minecraft/block/entity/BlockEntityType$BlockEntityFactory accessible method net/minecraft/data/server/loottable/BlockLootTableGenerator drops (Lnet/minecraft/item/ItemConvertible;)Lnet/minecraft/loot/LootTable$Builder; accessible method net/minecraft/data/server/loottable/BlockLootTableGenerator dropsWithProperty (Lnet/minecraft/block/Block;Lnet/minecraft/state/property/Property;Ljava/lang/Comparable;)Lnet/minecraft/loot/LootTable$Builder; @@ -14,6 +12,4 @@ accessible field net/minecraft/resource/featuretoggle/FeatureSet universe Lnet/m accessible field net/minecraft/resource/featuretoggle/FeatureSet featuresMask J mutable field net/minecraft/resource/featuretoggle/FeatureFlag mask J accessible field net/minecraft/resource/featuretoggle/FeatureFlag mask J -accessible class net/minecraft/data/server/tag/TagProvider$ProvidedTagBuilder -accessible field net/minecraft/world/poi/PointOfInterestType blockStates Ljava/util/Set; -mutable field net/minecraft/world/poi/PointOfInterestType blockStates Ljava/util/Set; \ No newline at end of file +accessible class net/minecraft/data/server/tag/TagProvider$ProvidedTagBuilder \ No newline at end of file diff --git a/fabric/src/main/java/com/unlikepaladin/pfm/blocks/models/basicTable/fabric/FabricBasicTableModel.java b/fabric/src/main/java/com/unlikepaladin/pfm/blocks/models/basicTable/fabric/FabricBasicTableModel.java index b8b778a1b..2cca4fb69 100644 --- a/fabric/src/main/java/com/unlikepaladin/pfm/blocks/models/basicTable/fabric/FabricBasicTableModel.java +++ b/fabric/src/main/java/com/unlikepaladin/pfm/blocks/models/basicTable/fabric/FabricBasicTableModel.java @@ -142,7 +142,7 @@ public void emitBlockQuads(BlockRenderView world, BlockState state, BlockPos pos } if (north && south && !east) { - ((FabricBakedModel) getTemplateBakedModels().get(2)).emitBlockQuads(world, state, pos, randomSupplier, context); + ((FabricBakedModel) getTemplateBakedModels().get(12)).emitBlockQuads(world, state, pos, randomSupplier, context); } if (north && south && !west) { ((FabricBakedModel) getTemplateBakedModels().get(11)).emitBlockQuads(world, state, pos, randomSupplier, context); diff --git a/fabric/src/main/java/com/unlikepaladin/pfm/client/fabric/PaladinFurnitureModClientFabric.java b/fabric/src/main/java/com/unlikepaladin/pfm/client/fabric/PaladinFurnitureModClientFabric.java index 4bf2fae77..93765fc02 100644 --- a/fabric/src/main/java/com/unlikepaladin/pfm/client/fabric/PaladinFurnitureModClientFabric.java +++ b/fabric/src/main/java/com/unlikepaladin/pfm/client/fabric/PaladinFurnitureModClientFabric.java @@ -28,7 +28,7 @@ public class PaladinFurnitureModClientFabric implements ClientModInitializer { public void onInitializeClient() { PaladinFurnitureMod.isClient = true; PaladinFurnitureModFabric.registerLateEntries(); - PaladinFurnitureModFabric.replaceHomePOI(); + PaladinFurnitureModFabric.replaceHomePOIStates(); ColorRegistryFabric.registerAll(); NetworkRegistryFabric.registerClientPackets(); diff --git a/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java b/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java index a2a9be844..3c6846c1a 100644 --- a/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java +++ b/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java @@ -25,9 +25,6 @@ import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.block.BlockState; -import net.minecraft.block.enums.BedPart; -import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; import net.minecraft.registry.*; @@ -46,6 +43,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.*; +import java.util.Collection; import java.util.ArrayList; public class PaladinFurnitureModFabric extends PaladinFurnitureMod implements ModInitializer, DedicatedServerModInitializer { @@ -132,20 +130,11 @@ public static void initializeItemGroup() { ).build())); } - public static void replaceHomePOI() { - Set originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME).blockStates(); - Set addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet()); - Set newBedStates = new HashSet<>(); - newBedStates.addAll(originalBedStates); - newBedStates.addAll(addedBedStates); - PointOfInterestType homePOI = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME); - homePOI.blockStates = ImmutableSet.copyOf(newBedStates); - } @Override public void onInitializeServer() { PaladinFurnitureMod.isClient = false; registerLateEntries(); - replaceHomePOI(); + replaceHomePOIStates(); } public static void registerLateEntries() { diff --git a/fabric/src/main/java/com/unlikepaladin/pfm/mixin/fabric/PFMMixinPointOfInterestType.java b/fabric/src/main/java/com/unlikepaladin/pfm/mixin/fabric/PFMMixinPointOfInterestType.java deleted file mode 100644 index dae4765e0..000000000 --- a/fabric/src/main/java/com/unlikepaladin/pfm/mixin/fabric/PFMMixinPointOfInterestType.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.unlikepaladin.pfm.mixin.fabric; - -import com.unlikepaladin.pfm.registry.PaladinFurnitureModBlocksItems; -import net.minecraft.block.BlockState; -import net.minecraft.registry.RegistryKey; -import net.minecraft.world.poi.PointOfInterestType; -import net.minecraft.world.poi.PointOfInterestTypes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.Slice; - -import java.util.Set; - -@Mixin(PointOfInterestTypes.class) -public abstract class PFMMixinPointOfInterestType { - @ModifyArg( - method = "registerAndGetDefault(Lnet/minecraft/registry/Registry;)Lnet/minecraft/world/poi/PointOfInterestType;", - slice = @Slice(from = @At( - value = "FIELD", - target = "Lnet/minecraft/world/poi/PointOfInterestTypes;HOME:Lnet/minecraft/registry/RegistryKey;" - )), - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/poi/PointOfInterestTypes;register(Lnet/minecraft/registry/Registry;Lnet/minecraft/registry/RegistryKey;Ljava/util/Set;II)Lnet/minecraft/world/poi/PointOfInterestType;", - ordinal = 0 - ), index = 2 - ) - private static Set appendBeds(Set states) { - PaladinFurnitureModBlocksItems.originalHomePOIBedStates.addAll(states); - return states; - } -} \ No newline at end of file diff --git a/fabric/src/main/resources/pfm.mixins.json b/fabric/src/main/resources/pfm.mixins.json index 631669bcc..7bebf7f9b 100755 --- a/fabric/src/main/resources/pfm.mixins.json +++ b/fabric/src/main/resources/pfm.mixins.json @@ -11,7 +11,6 @@ "PFMAbstractTagProvider$ObjectBuilderMixin", "PFMCookingPotBlockEntityMixin", "PFMMinecraftServerMixin", - "PFMMixinPointOfInterestType", "PFMReloadableResourceManagerImplMixin", "PFMSaveLoaderMixin", "PFMModResourcePackCreatorMixin" diff --git a/forge/src/main/java/com/unlikepaladin/pfm/registry/dynamic/forge/LateBlockRegistryImpl.java b/forge/src/main/java/com/unlikepaladin/pfm/registry/dynamic/forge/LateBlockRegistryImpl.java index 760cfbdaf..39051fe83 100644 --- a/forge/src/main/java/com/unlikepaladin/pfm/registry/dynamic/forge/LateBlockRegistryImpl.java +++ b/forge/src/main/java/com/unlikepaladin/pfm/registry/dynamic/forge/LateBlockRegistryImpl.java @@ -4,6 +4,8 @@ import com.unlikepaladin.pfm.PaladinFurnitureMod; import com.unlikepaladin.pfm.blocks.AbstractSittableBlock; import com.unlikepaladin.pfm.blocks.SimpleBedBlock; +import com.unlikepaladin.pfm.forge.PaladinFurnitureModForge; +import com.unlikepaladin.pfm.mixin.PFMPointOfInterestTypesAccessor; import com.unlikepaladin.pfm.registry.PaladinFurnitureModBlocksItems; import com.unlikepaladin.pfm.registry.dynamic.LateBlockRegistry; import com.unlikepaladin.pfm.registry.forge.BlockItemRegistryImpl; @@ -20,14 +22,18 @@ import net.minecraft.util.Pair; import net.minecraft.world.poi.PointOfInterestType; import net.minecraft.world.poi.PointOfInterestTypes; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.IForgeRegistry; +import net.minecraftforge.registries.RegisterEvent; import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.function.Supplier; +@Mod.EventBusSubscriber(modid = "pfm", bus = Mod.EventBusSubscriber.Bus.MOD) public class LateBlockRegistryImpl { public static Map blocks = new LinkedHashMap<>(); @@ -68,14 +74,6 @@ public static void registerBlocks(IForgeRegistry blockRegisterEvent) { throw new RuntimeException(ex); } blocks.forEach(blockRegisterEvent::register); - - Set originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME).blockStates(); - Set addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet()); - Set newBedStates = new HashSet<>(); - newBedStates.addAll(originalBedStates); - newBedStates.addAll(addedBedStates); - PointOfInterestType homePOI = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME); - homePOI.blockStates = ImmutableSet.copyOf(newBedStates); } public static void registerItems(IForgeRegistry itemIForgeRegistry) { @@ -97,4 +95,19 @@ public static T registerLateBlockClassic(String blockId, T blo blocks.put(blockId, block); return block; } + + @SubscribeEvent + public static void registerPOI(RegisterEvent event) { + event.register(ForgeRegistries.Keys.POI_TYPES, pointOfInterestTypeRegisterHelper -> { + Set originalBedStates = ForgeRegistries.POI_TYPES.getValue(PointOfInterestTypes.HOME.getValue()).blockStates(); + Set addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet()); + Set newBedStates = new HashSet<>(); + newBedStates.addAll(originalBedStates); + newBedStates.addAll(addedBedStates); + PointOfInterestType pointOfInterestType = new PointOfInterestType(newBedStates, 1, 1); + ForgeRegistries.POI_TYPES.register("minecraft:home", pointOfInterestType); + PFMPointOfInterestTypesAccessor.setHome(ForgeRegistries.POI_TYPES.getHolder(pointOfInterestType).get().getKey().get()); + // PaladinFurnitureModForge.replaceHomePOIStates(); + }); + } } diff --git a/neoforge/src/main/java/com/unlikepaladin/pfm/registry/dynamic/neoforge/LateBlockRegistryImpl.java b/neoforge/src/main/java/com/unlikepaladin/pfm/registry/dynamic/neoforge/LateBlockRegistryImpl.java index 0661edfb9..a22474c5f 100644 --- a/neoforge/src/main/java/com/unlikepaladin/pfm/registry/dynamic/neoforge/LateBlockRegistryImpl.java +++ b/neoforge/src/main/java/com/unlikepaladin/pfm/registry/dynamic/neoforge/LateBlockRegistryImpl.java @@ -5,6 +5,7 @@ import com.unlikepaladin.pfm.PaladinFurnitureMod; import com.unlikepaladin.pfm.blocks.AbstractSittableBlock; import com.unlikepaladin.pfm.blocks.SimpleBedBlock; +import com.unlikepaladin.pfm.neoforge.PaladinFurnitureModNeoForge; import com.unlikepaladin.pfm.registry.PaladinFurnitureModBlocksItems; import com.unlikepaladin.pfm.registry.dynamic.LateBlockRegistry; import com.unlikepaladin.pfm.registry.neoforge.BlockItemRegistryImpl; @@ -24,12 +25,16 @@ import net.minecraft.util.Pair; import net.minecraft.world.poi.PointOfInterestType; import net.minecraft.world.poi.PointOfInterestTypes; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.registries.RegisterEvent; import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.function.Supplier; +@Mod.EventBusSubscriber(modid = "pfm", bus = Mod.EventBusSubscriber.Bus.MOD) public class LateBlockRegistryImpl { public static Map blocks = new LinkedHashMap<>(); @@ -70,14 +75,6 @@ public static void registerBlocks(Registry blockRegisterEvent) { throw new RuntimeException(ex); } blocks.forEach((blockName, block) -> Registry.register(Registries.BLOCK, new Identifier(PaladinFurnitureMod.MOD_ID, blockName), block)); - - Set originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME).blockStates(); - Set addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet()); - Set newBedStates = new HashSet<>(); - newBedStates.addAll(originalBedStates); - newBedStates.addAll(addedBedStates); - PointOfInterestType homePOI = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME); - homePOI.blockStates = ImmutableSet.copyOf(newBedStates); } public static void registerItems(Registry itemIForgeRegistry) { @@ -99,4 +96,11 @@ public static T registerLateBlockClassic(String blockId, T blo blocks.put(blockId, block); return block; } + + @SubscribeEvent + public static void registerPOI(RegisterEvent event) { + event.register(Registries.POINT_OF_INTEREST_TYPE.getKey(), pointOfInterestTypeRegisterHelper -> { + PaladinFurnitureModNeoForge.replaceHomePOIStates(); + }); + } }