mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Fix modded PointOfInterestType's not populating blockstate map when registered (#7503)
This commit is contained in:
1 parent
b64f4780c5
commit
545723dc8c
2 files changed
+74
-5
No files matched your search
@@ -51,10 +51,7 @@ import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.stats.StatType;
|
||||
import net.minecraft.tags.TagRegistryManager;
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
import net.minecraft.util.ObjectIntIdentityMap;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.registry.DefaultedRegistry;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.SimpleRegistry;
|
||||
@@ -115,6 +112,7 @@ public class GameData
|
||||
|
||||
private static final ResourceLocation BLOCK_TO_ITEM = new ResourceLocation("minecraft:blocktoitemmap");
|
||||
private static final ResourceLocation BLOCKSTATE_TO_ID = new ResourceLocation("minecraft:blockstatetoid");
|
||||
private static final ResourceLocation BLOCKSTATE_TO_POINT_OF_INTEREST_TYPE = new ResourceLocation("minecraft:blockstatetopointofinteresttype");
|
||||
private static final ResourceLocation SERIALIZER_TO_ENTRY = new ResourceLocation("forge:serializer_to_entry");
|
||||
private static final ResourceLocation STRUCTURES = new ResourceLocation("minecraft:structures");
|
||||
|
||||
@@ -157,7 +155,7 @@ public class GameData
|
||||
|
||||
// Villagers
|
||||
makeRegistry(VILLAGER_PROFESSIONS, VillagerProfession.class, "none").create();
|
||||
makeRegistry(POI_TYPES, PointOfInterestType.class, "unemployed").disableSync().create();
|
||||
makeRegistry(POI_TYPES, PointOfInterestType.class, "unemployed").addCallback(PointOfInterestTypeCallbacks.INSTANCE).disableSync().create();
|
||||
makeRegistry(MEMORY_MODULE_TYPES, c(MemoryModuleType.class), "dummy").disableSync().create();
|
||||
makeRegistry(SENSOR_TYPES, c(SensorType.class), "dummy").disableSaving().disableSync().create();
|
||||
makeRegistry(SCHEDULES, Schedule.class).disableSaving().disableSync().create();
|
||||
@@ -230,6 +228,12 @@ public class GameData
|
||||
{
|
||||
return RegistryManager.ACTIVE.getRegistry(Block.class).getSlaveMap(BLOCKSTATE_TO_ID, ObjectIntIdentityMap.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<BlockState, PointOfInterestType> getBlockStatePointOfInterestTypeMap()
|
||||
{
|
||||
return RegistryManager.ACTIVE.getRegistry(PointOfInterestType.class).getSlaveMap(BLOCKSTATE_TO_POINT_OF_INTEREST_TYPE, Map.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<IDataSerializer<?>, DataSerializerEntry> getSerializerMap()
|
||||
@@ -615,6 +619,41 @@ public class GameData
|
||||
}
|
||||
}
|
||||
|
||||
private static class PointOfInterestTypeCallbacks implements IForgeRegistry.AddCallback<PointOfInterestType> , IForgeRegistry.ClearCallback<PointOfInterestType>, IForgeRegistry.CreateCallback<PointOfInterestType>
|
||||
{
|
||||
static final PointOfInterestTypeCallbacks INSTANCE = new PointOfInterestTypeCallbacks();
|
||||
|
||||
@Override
|
||||
public void onAdd(IForgeRegistryInternal<PointOfInterestType> owner, RegistryManager stage, int id, PointOfInterestType obj, @Nullable PointOfInterestType oldObj)
|
||||
{
|
||||
Map<BlockState, PointOfInterestType> map = owner.getSlaveMap(BLOCKSTATE_TO_POINT_OF_INTEREST_TYPE, Map.class);
|
||||
if (oldObj != null)
|
||||
{
|
||||
oldObj.getBlockStates().forEach(map::remove);
|
||||
}
|
||||
obj.getBlockStates().forEach((state) ->
|
||||
{
|
||||
PointOfInterestType oldType = map.put(state, obj);
|
||||
if (oldType != null)
|
||||
{
|
||||
throw new IllegalStateException(String.format("Point of interest types %s and %s both list %s in their blockstates, this is not allowed. Blockstates can only have one point of interest type each.", oldType, obj, state));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClear(IForgeRegistryInternal<PointOfInterestType> owner, RegistryManager stage)
|
||||
{
|
||||
owner.getSlaveMap(BLOCKSTATE_TO_POINT_OF_INTEREST_TYPE, Map.class).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(IForgeRegistryInternal<PointOfInterestType> owner, RegistryManager stage)
|
||||
{
|
||||
owner.setSlaveMap(BLOCKSTATE_TO_POINT_OF_INTEREST_TYPE, new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
||||
private static <T extends IForgeRegistryEntry<T>> void loadRegistry(final ResourceLocation registryName, final RegistryManager from, final RegistryManager to, final Class<T> regType, boolean freeze)
|
||||
{
|
||||
ForgeRegistry<T> fromRegistry = from.getRegistry(registryName);
|
||||
|
||||
Reference in new issue
Block a user