Skip to content

Commit

Permalink
Merge branch 'architectury-1.20' into architectury-1.20.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	fabric/src/main/java/com/unlikepaladin/pfm/fabric/PaladinFurnitureModFabric.java
#	forge/src/main/java/com/unlikepaladin/pfm/registry/dynamic/forge/LateBlockRegistryImpl.java
  • Loading branch information
UnlikePaladin committed Jan 2, 2024
2 parents a4b4a80 + d9d2de2 commit 69ccd2b
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -32,7 +47,6 @@ public class PaladinFurnitureMod {

public static final Logger GENERAL_LOGGER = LogManager.getLogger();
public static Pair<String, ItemGroup> FURNITURE_GROUP = new Pair<>("furniture", null);

public static Pair<String, ItemGroup> DYE_KITS = new Pair<>("dye_kits", null);;
private static PaladinFurnitureModUpdateChecker updateChecker;
public static boolean isClient = false;
Expand All @@ -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<BlockState> originalBedStates = ((PFMPointOfInterestTypeAccessor)(Object)homePOI).getBlockStates();
Set<BlockState> addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BlockState> getBlockStates();

@Mutable
@Accessor("blockStates")
void setBlockStates(Set<BlockState> states);
}
Original file line number Diff line number Diff line change
@@ -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<BlockState, RegistryEntry<PointOfInterestType>> getBlockStateToPointOfInterestType() {
throw new AssertionError();
}


@Mutable
@Accessor("HOME")
static void setHome(RegistryKey<PointOfInterestType> home) {
throw new AssertionError();
}

}
2 changes: 2 additions & 0 deletions common/src/main/resources/pfm-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"PFMDataCache$CachedDataMixin",
"PFMFeatureFlagFactory",
"PFMPlayerInventoryMixin",
"PFMPointOfInterestTypeAccessor",
"PFMPointOfInterestTypesAccessor",
"PFMTextureKeyFactory"
],
"server": [
Expand Down
6 changes: 1 addition & 5 deletions common/src/main/resources/pfm.accesswidener
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
accessible class net/minecraft/data/server/tag/TagProvider$ProvidedTagBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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 {
Expand Down Expand Up @@ -132,20 +130,11 @@ public static void initializeItemGroup() {
).build()));
}

public static void replaceHomePOI() {
Set<BlockState> originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME).blockStates();
Set<BlockState> addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> 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() {
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion fabric/src/main/resources/pfm.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"PFMAbstractTagProvider$ObjectBuilderMixin",
"PFMCookingPotBlockEntityMixin",
"PFMMinecraftServerMixin",
"PFMMixinPointOfInterestType",
"PFMReloadableResourceManagerImplMixin",
"PFMSaveLoaderMixin",
"PFMModResourcePackCreatorMixin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, Block> blocks = new LinkedHashMap<>();
Expand Down Expand Up @@ -68,14 +74,6 @@ public static void registerBlocks(IForgeRegistry<Block> blockRegisterEvent) {
throw new RuntimeException(ex);
}
blocks.forEach(blockRegisterEvent::register);

Set<BlockState> originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME).blockStates();
Set<BlockState> addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> 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<Item> itemIForgeRegistry) {
Expand All @@ -97,4 +95,19 @@ public static <T extends Block> 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<BlockState> originalBedStates = ForgeRegistries.POI_TYPES.getValue(PointOfInterestTypes.HOME.getValue()).blockStates();
Set<BlockState> addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> 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();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, Block> blocks = new LinkedHashMap<>();
Expand Down Expand Up @@ -70,14 +75,6 @@ public static void registerBlocks(Registry<Block> blockRegisterEvent) {
throw new RuntimeException(ex);
}
blocks.forEach((blockName, block) -> Registry.register(Registries.BLOCK, new Identifier(PaladinFurnitureMod.MOD_ID, blockName), block));

Set<BlockState> originalBedStates = Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME).blockStates();
Set<BlockState> addedBedStates = Arrays.stream(PaladinFurnitureModBlocksItems.getBeds()).flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> 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<Item> itemIForgeRegistry) {
Expand All @@ -99,4 +96,11 @@ public static <T extends Block> 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();
});
}
}

0 comments on commit 69ccd2b

Please sign in to comment.