Skip to content

Commit

Permalink
Merge branch 'architectury-1.19.3' into architectury-1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Jan 2, 2024
2 parents 5410fd3 + 6186494 commit 3554c35
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 62 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
2 changes: 0 additions & 2 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 Down
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 @@ -26,9 +26,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.Registries;
Expand All @@ -50,6 +47,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 @@ -136,20 +134,11 @@ public static void initializeItemGroup() {
).build());
}

public static void replaceHomePOI() {
Set<BlockState> addedBedStates = PaladinFurnitureModBlocksItems.beds.stream().flatMap(block -> block.getStateManager().getStates().stream().filter(state -> state.get(SimpleBedBlock.PART) == BedPart.HEAD)).collect(ImmutableSet.toImmutableSet());
Set<BlockState> newBedStates = new HashSet<>();
newBedStates.addAll(PaladinFurnitureModBlocksItems.originalHomePOIBedStates);
newBedStates.addAll(addedBedStates);
newBedStates = newBedStates.stream().collect(ImmutableSet.toImmutableSet());
PointOfInterestType pointOfInterestType = new PointOfInterestType(newBedStates, 1, 1);
PointOfInterestTypes.HOME = (RegistryKey<PointOfInterestType>) ((MutableRegistry)Registries.POINT_OF_INTEREST_TYPE).set(Registries.POINT_OF_INTEREST_TYPE.getRawId(Registries.POINT_OF_INTEREST_TYPE.get(PointOfInterestTypes.HOME)), PointOfInterestTypes.HOME, pointOfInterestType, Lifecycle.stable()).getKey().get();
}
@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 @@ -3,6 +3,8 @@
import com.google.common.collect.ImmutableSet;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
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 @@ -19,14 +21,17 @@
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 @@ -67,15 +72,6 @@ public static void registerBlocks(IForgeRegistry<Block> blockRegisterEvent) {
throw new RuntimeException(ex);
}
blocks.forEach(blockRegisterEvent::register);

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);
PointOfInterestTypes.HOME = ForgeRegistries.POI_TYPES.getHolder(pointOfInterestType).get().getKey().get();
}

public static void registerItems(IForgeRegistry<Item> itemIForgeRegistry) {
Expand All @@ -97,4 +93,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();
});
}
}

0 comments on commit 3554c35

Please sign in to comment.