diff --git a/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java b/common/src/main/java/com/unlikepaladin/pfm/PaladinFurnitureMod.java index 15e54de5a..26e198ee3 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,22 +12,26 @@ import com.unlikepaladin.pfm.data.materials.DynamicBlockRegistry; import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry; +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 com.unlikepaladin.pfm.runtime.PFMRuntimeResources; import com.unlikepaladin.pfm.utilities.Version; import dev.architectury.injectables.annotations.ExpectPlatform; +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.sound.SoundEvent; import net.minecraft.util.Identifier; import net.minecraft.util.StringIdentifiable; +import net.minecraft.world.poi.PointOfInterestType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; public class PaladinFurnitureMod { @@ -35,7 +41,6 @@ public class PaladinFurnitureMod { public static final Logger GENERAL_LOGGER = LogManager.getLogger(); public static ItemGroup FURNITURE_GROUP; - public static ItemGroup DYE_KITS; private static PaladinFurnitureModUpdateChecker updateChecker; public static boolean isClient = false; @@ -71,6 +76,18 @@ public static void registerLateEntries() { } BlockEntityRegistry.registerBlockEntities(); } + + public static void replaceHomePOI() { + Set originalBedStates = PointOfInterestType.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.HOME.blockStates = ImmutableSet.copyOf(newBedStates); + addedBedStates.forEach(state -> PFMPointOfInterestTypeAccessor.getBlockStateToPointOfInterestType().put(state, PointOfInterestType.HOME)); + PFMPointOfInterestTypeAccessor.setRegisteredStates(new ObjectOpenHashSet<>(PFMPointOfInterestTypeAccessor.getBlockStateToPointOfInterestType().keySet())); + } + @ExpectPlatform public static PaladinFurnitureModConfig getPFMConfig() { throw new AssertionError(); diff --git a/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMMixinPointOfInterestType.java b/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMMixinPointOfInterestType.java deleted file mode 100644 index 788e387d4..000000000 --- a/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMMixinPointOfInterestType.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.unlikepaladin.pfm.mixin; - -import com.unlikepaladin.pfm.registry.PaladinFurnitureModBlocksItems; -import net.minecraft.block.BlockState; -import net.minecraft.world.poi.PointOfInterestType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.gen.Accessor; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.Slice; - -import java.util.HashSet; -import java.util.Set; - -@Mixin(value = PointOfInterestType.class, priority = 3000) -public class PFMMixinPointOfInterestType { - @ModifyArg( - method = "", - slice = @Slice(from = @At( - value = "CONSTANT", - args = "stringValue=home") - ), - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/poi/PointOfInterestType;register(Ljava/lang/String;Ljava/util/Set;II)Lnet/minecraft/world/poi/PointOfInterestType;", - ordinal = 0 - ), - index = 1 - ) - private static Set appendBeds(Set workStationStates) { - PaladinFurnitureModBlocksItems.originalHomePOIBedStates.addAll(workStationStates); - return new HashSet<>(); - } -} \ No newline at end of file diff --git a/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMMixinPointOfInterestTypeFactory.java b/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMMixinPointOfInterestTypeFactory.java deleted file mode 100644 index c8864842f..000000000 --- a/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMMixinPointOfInterestTypeFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -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.gen.Invoker; - -import java.util.Set; - - -@Mixin(value = PointOfInterestType.class) -public interface PFMMixinPointOfInterestTypeFactory { - @Invoker("") - static PointOfInterestType newPoi(String id, Set blockStates, int ticketCount, int searchDistance) { - throw new AssertionError(); - } -} \ No newline at end of file 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..72503ed7f --- /dev/null +++ b/common/src/main/java/com/unlikepaladin/pfm/mixin/PFMPointOfInterestTypeAccessor.java @@ -0,0 +1,24 @@ +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("BLOCK_STATE_TO_POINT_OF_INTEREST_TYPE") + static Map getBlockStateToPointOfInterestType() { + throw new AssertionError(); + } + + @Mutable + @Accessor("REGISTERED_STATES") + static void setRegisteredStates(Set states) { + throw new AssertionError(); + } +} diff --git a/common/src/main/resources/pfm-common.mixins.json b/common/src/main/resources/pfm-common.mixins.json index 4a3643c84..713eaa5e8 100644 --- a/common/src/main/resources/pfm-common.mixins.json +++ b/common/src/main/resources/pfm-common.mixins.json @@ -5,9 +5,8 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "PFMAbstractTagProvider$ObjectBuilderMixin", - "PFMMixinPointOfInterestType", - "PFMMixinPointOfInterestTypeFactory", "PFMPlayerInventoryMixin", + "PFMPointOfInterestTypeAccessor", "PFMTextureKeyFactory" ], "server": [ diff --git a/common/src/main/resources/pfm.accesswidener b/common/src/main/resources/pfm.accesswidener index ddf35c6e8..7f0aba7bc 100644 --- a/common/src/main/resources/pfm.accesswidener +++ b/common/src/main/resources/pfm.accesswidener @@ -2,10 +2,11 @@ accessWidener v1 named accessible class net/minecraft/recipe/CookingRecipeSerializer$RecipeFactory accessible class net/minecraft/block/entity/BlockEntityType$BlockEntityFactory -accessible field net/minecraft/world/poi/PointOfInterestType BED_STATES Ljava/util/Set; -accessible method net/minecraft/world/poi/PointOfInterestType setup (Lnet/minecraft/world/poi/PointOfInterestType;)Lnet/minecraft/world/poi/PointOfInterestType; -mutable field net/minecraft/world/poi/PointOfInterestType HOME Lnet/minecraft/world/poi/PointOfInterestType; accessible method net/minecraft/data/server/BlockLootTableGenerator drops (Lnet/minecraft/item/ItemConvertible;)Lnet/minecraft/loot/LootTable$Builder; accessible method net/minecraft/data/server/BlockLootTableGenerator dropsWithProperty (Lnet/minecraft/block/Block;Lnet/minecraft/state/property/Property;Ljava/lang/Comparable;)Lnet/minecraft/loot/LootTable$Builder; accessible class net/minecraft/data/server/AbstractTagProvider$ObjectBuilder -accessible method net/minecraft/client/render/item/ItemRenderer renderBakedItemModel (Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/item/ItemStack;IILnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;)V \ No newline at end of file +accessible method net/minecraft/client/render/item/ItemRenderer renderBakedItemModel (Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/item/ItemStack;IILnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;)V +accessible field net/minecraft/client/resource/language/LanguageManager field_25291 Lnet/minecraft/client/resource/language/LanguageDefinition; +accessible field net/minecraft/block/AbstractBlock$Settings material Lnet/minecraft/block/Material; +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 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 87d0bfda7..b22b9783a 100644 --- a/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java +++ b/fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java @@ -10,7 +10,6 @@ import com.unlikepaladin.pfm.config.option.AbstractConfigOption; import com.unlikepaladin.pfm.data.materials.DynamicBlockRegistry; import com.unlikepaladin.pfm.data.materials.WoodVariantRegistry; -import com.unlikepaladin.pfm.mixin.PFMMixinPointOfInterestTypeFactory; import com.unlikepaladin.pfm.registry.*; import com.unlikepaladin.pfm.registry.dynamic.LateBlockRegistry; import com.unlikepaladin.pfm.registry.fabric.*; @@ -39,6 +38,7 @@ import org.apache.logging.log4j.Logger; import java.io.IOException; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -123,14 +123,6 @@ public static void initializeItemGroup() { () -> PaladinFurnitureModBlocksItems.furnitureEntryMap.get(BasicChairBlock.class).getVariantToBlockMap().get(WoodVariantRegistry.OAK).asItem().getDefaultStack()); } - public static void replaceHomePOI() { - Set addedBedStates = PaladinFurnitureModBlocksItems.beds.stream().flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet()); - Set newBedStates = new HashSet<>(); - newBedStates.addAll(PaladinFurnitureModBlocksItems.originalHomePOIBedStates); - newBedStates.addAll(addedBedStates); - newBedStates = newBedStates.stream().collect(ImmutableSet.toImmutableSet()); - PointOfInterestType.HOME = PointOfInterestType.setup(Registry.register(Registry.POINT_OF_INTEREST_TYPE, Registry.POINT_OF_INTEREST_TYPE.getRawId(PointOfInterestType.HOME), "home", PFMMixinPointOfInterestTypeFactory.newPoi("home", newBedStates, 1, 1))); - } @Override public void onInitializeServer() { PaladinFurnitureMod.isClient = false; 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 2a7e8345b..047cd463a 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 @@ -1,6 +1,8 @@ package com.unlikepaladin.pfm.registry.dynamic.forge; +import com.unlikepaladin.pfm.forge.PaladinFurnitureModForge; import com.unlikepaladin.pfm.registry.PaladinFurnitureModBlocksItems; +import com.unlikepaladin.pfm.registry.dynamic.LateBlockRegistry; import com.unlikepaladin.pfm.registry.forge.BlockItemRegistryImpl; import com.unlikepaladin.pfm.runtime.PFMRuntimeResources; import net.minecraft.block.Block; @@ -56,6 +58,7 @@ public int getBurnTime(ItemStack itemStack, @Nullable RecipeType recipeType) public static void registerBlocks(RegistryEvent.Register blockRegisterEvent) { blockRegisterEvent.getRegistry().registerAll(blocks.toArray(new Block[0])); + PaladinFurnitureModForge.replaceHomePOI(); } public static void registerItems(RegistryEvent.Register blockRegisterEvent) {