Added entity attribute setup and creation events

This commit is contained in:
Kovak authored and LexManos committed 2021-02-15 18:40:32 -08:00
1 parent 58f93263e2
commit ba15737fe3
8 files changed
+290 -12

No files matched your search

@@ -30,7 +30,9 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes;
import net.minecraft.entity.ai.brain.memory.MemoryModuleType;
import net.minecraft.entity.ai.brain.schedule.Activity;
@@ -68,13 +70,17 @@ import net.minecraft.world.gen.foliageplacer.FoliagePlacerType;
import net.minecraft.world.gen.placement.Placement;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
import net.minecraft.world.gen.treedecorator.TreeDecoratorType;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.ForgeTagHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.loot.GlobalLootModifierSerializer;
import net.minecraftforge.common.world.ForgeWorldType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.MissingMappings;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
import net.minecraftforge.event.entity.EntityAttributeModificationEvent;
import net.minecraftforge.fml.ModContainer;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.ModLoadingStage;
import net.minecraftforge.fml.common.EnhancedRuntimeException;
@@ -228,7 +234,7 @@ public class GameData
{
return RegistryManager.ACTIVE.getRegistry(Block.class).getSlaveMap(BLOCKSTATE_TO_ID, ObjectIntIdentityMap.class);
}
@SuppressWarnings("unchecked")
public static Map<BlockState, PointOfInterestType> getBlockStatePointOfInterestTypeMap()
{
@@ -379,12 +385,15 @@ public class GameData
}, executor).handle((v, t)->t != null ? Collections.singletonList(t): Collections.emptyList());
}
@SuppressWarnings("deprecation")
public static CompletableFuture<List<Throwable>> checkForRevertToVanilla(final Executor executor, final CompletableFuture<List<Throwable>> listCompletableFuture) {
return listCompletableFuture.whenCompleteAsync((errors, except) -> {
if (except != null) {
LOGGER.fatal("Detected errors during registry event dispatch, rolling back to VANILLA state");
revertTo(RegistryManager.VANILLA, false);
LOGGER.fatal("Detected errors during registry event dispatch, roll back to VANILLA complete");
} else {
net.minecraftforge.common.ForgeHooks.modifyAttributes();
}
}, executor);
}
@@ -622,7 +631,7 @@ 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)
{
@@ -631,7 +640,7 @@ public class GameData
{
oldObj.getBlockStates().forEach(map::remove);
}
obj.getBlockStates().forEach((state) ->
obj.getBlockStates().forEach((state) ->
{
PointOfInterestType oldType = map.put(state, obj);
if (oldType != null)
@@ -653,7 +662,7 @@ public class GameData
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);