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

@@ -0,0 +1,34 @@
--- a/net/minecraft/entity/ai/attributes/AttributeModifierMap.java
+++ b/net/minecraft/entity/ai/attributes/AttributeModifierMap.java
@@ -69,7 +69,23 @@
public static class MutableAttribute {
private final Map<Attribute, ModifiableAttributeInstance> field_233811_a_ = Maps.newHashMap();
private boolean field_233812_b_;
+ private final java.util.List<AttributeModifierMap.MutableAttribute> others = new java.util.ArrayList<>();
+ public MutableAttribute() { }
+
+ public MutableAttribute(AttributeModifierMap attributeMap) {
+ this.field_233811_a_.putAll(attributeMap.field_233802_a_);
+ }
+
+ public void combine(MutableAttribute other) {
+ this.field_233811_a_.putAll(other.field_233811_a_);
+ others.add(other);
+ }
+
+ public boolean hasAttribute(Attribute attribute) {
+ return this.field_233811_a_.containsKey(attribute);
+ }
+
private ModifiableAttributeInstance func_233817_b_(Attribute p_233817_1_) {
ModifiableAttributeInstance modifiableattributeinstance = new ModifiableAttributeInstance(p_233817_1_, (p_233816_2_) -> {
if (this.field_233812_b_) {
@@ -93,6 +109,7 @@
public AttributeModifierMap func_233813_a_() {
this.field_233812_b_ = true;
+ others.forEach(o -> o.field_233812_b_ = true);
return new AttributeModifierMap(this.field_233811_a_);
}
}
@@ -1,19 +1,22 @@
--- a/net/minecraft/entity/ai/attributes/GlobalEntityTypeAttributes.java
+++ b/net/minecraft/entity/ai/attributes/GlobalEntityTypeAttributes.java
@@ -72,13 +72,19 @@
@@ -72,13 +72,22 @@
public class GlobalEntityTypeAttributes {
private static final Logger field_233832_a_ = LogManager.getLogger();
private static final Map<EntityType<? extends LivingEntity>, AttributeModifierMap> field_233833_b_ = ImmutableMap.<EntityType<? extends LivingEntity>, AttributeModifierMap>builder().put(EntityType.field_200789_c, LivingEntity.func_233639_cI_().func_233813_a_()).put(EntityType.field_200791_e, BatEntity.func_234175_m_().func_233813_a_()).put(EntityType.field_226289_e_, BeeEntity.func_234182_eX_().func_233813_a_()).put(EntityType.field_200792_f, BlazeEntity.func_234276_m_().func_233813_a_()).put(EntityType.field_220360_g, CatEntity.func_234184_eY_().func_233813_a_()).put(EntityType.field_200794_h, CaveSpiderEntity.func_234277_m_().func_233813_a_()).put(EntityType.field_200795_i, ChickenEntity.func_234187_eI_().func_233813_a_()).put(EntityType.field_203780_j, AbstractFishEntity.func_234176_m_().func_233813_a_()).put(EntityType.field_200796_j, CowEntity.func_234188_eI_().func_233813_a_()).put(EntityType.field_200797_k, CreeperEntity.func_234278_m_().func_233813_a_()).put(EntityType.field_205137_n, DolphinEntity.func_234190_eK_().func_233813_a_()).put(EntityType.field_200798_l, AbstractChestedHorseEntity.func_234234_eJ_().func_233813_a_()).put(EntityType.field_204724_o, ZombieEntity.func_234342_eQ_().func_233813_a_()).put(EntityType.field_200800_n, ElderGuardianEntity.func_234283_m_().func_233813_a_()).put(EntityType.field_200803_q, EndermanEntity.func_234287_m_().func_233813_a_()).put(EntityType.field_200804_r, EndermiteEntity.func_234288_m_().func_233813_a_()).put(EntityType.field_200802_p, EnderDragonEntity.func_234257_m_().func_233813_a_()).put(EntityType.field_200806_t, EvokerEntity.func_234289_eI_().func_233813_a_()).put(EntityType.field_220356_B, FoxEntity.func_234192_eI_().func_233813_a_()).put(EntityType.field_200811_y, GhastEntity.func_234290_eH_().func_233813_a_()).put(EntityType.field_200812_z, GiantEntity.func_234291_m_().func_233813_a_()).put(EntityType.field_200761_A, GuardianEntity.func_234292_eK_().func_233813_a_()).put(EntityType.field_233588_G_, HoglinEntity.func_234362_eI_().func_233813_a_()).put(EntityType.field_200762_B, AbstractHorseEntity.func_234237_fg_().func_233813_a_()).put(EntityType.field_200763_C, ZombieEntity.func_234342_eQ_().func_233813_a_()).put(EntityType.field_200764_D, IllusionerEntity.func_234293_eI_().func_233813_a_()).put(EntityType.field_200757_aw, IronGolemEntity.func_234200_m_().func_233813_a_()).put(EntityType.field_200769_I, LlamaEntity.func_234244_fu_().func_233813_a_()).put(EntityType.field_200771_K, MagmaCubeEntity.func_234294_m_().func_233813_a_()).put(EntityType.field_200780_T, CowEntity.func_234188_eI_().func_233813_a_()).put(EntityType.field_200779_S, AbstractChestedHorseEntity.func_234234_eJ_().func_233813_a_()).put(EntityType.field_200781_U, OcelotEntity.func_234201_eI_().func_233813_a_()).put(EntityType.field_220353_aa, PandaEntity.func_234204_eW_().func_233813_a_()).put(EntityType.field_200783_W, ParrotEntity.func_234213_eS_().func_233813_a_()).put(EntityType.field_203097_aH, MonsterEntity.func_234295_eP_().func_233813_a_()).put(EntityType.field_200784_X, PigEntity.func_234215_eI_().func_233813_a_()).put(EntityType.field_233591_ai_, PiglinEntity.func_234420_eI_().func_233813_a_()).put(EntityType.field_242287_aj, PiglinBruteEntity.func_242344_eS().func_233813_a_()).put(EntityType.field_220350_aJ, PillagerEntity.func_234296_eI_().func_233813_a_()).put(EntityType.field_200729_aH, PlayerEntity.func_234570_el_().func_233813_a_()).put(EntityType.field_200786_Z, PolarBearEntity.func_234219_eI_().func_233813_a_()).put(EntityType.field_203779_Z, AbstractFishEntity.func_234176_m_().func_233813_a_()).put(EntityType.field_200736_ab, RabbitEntity.func_234224_eJ_().func_233813_a_()).put(EntityType.field_220352_aU, RavagerEntity.func_234297_m_().func_233813_a_()).put(EntityType.field_203778_ae, AbstractFishEntity.func_234176_m_().func_233813_a_()).put(EntityType.field_200737_ac, SheepEntity.func_234225_eI_().func_233813_a_()).put(EntityType.field_200738_ad, ShulkerEntity.func_234300_m_().func_233813_a_()).put(EntityType.field_200740_af, SilverfishEntity.func_234301_m_().func_233813_a_()).put(EntityType.field_200741_ag, AbstractSkeletonEntity.func_234275_m_().func_233813_a_()).put(EntityType.field_200742_ah, SkeletonHorseEntity.func_234250_eJ_().func_233813_a_()).put(EntityType.field_200743_ai, MonsterEntity.func_234295_eP_().func_233813_a_()).put(EntityType.field_200745_ak, SnowGolemEntity.func_234226_m_().func_233813_a_()).put(EntityType.field_200748_an, SpiderEntity.func_234305_eI_().func_233813_a_()).put(EntityType.field_200749_ao, SquidEntity.func_234227_m_().func_233813_a_()).put(EntityType.field_200750_ap, AbstractSkeletonEntity.func_234275_m_().func_233813_a_()).put(EntityType.field_233589_aE_, StriderEntity.func_234317_eK_().func_233813_a_()).put(EntityType.field_220354_ax, LlamaEntity.func_234244_fu_().func_233813_a_()).put(EntityType.field_204262_at, AbstractFishEntity.func_234176_m_().func_233813_a_()).put(EntityType.field_203099_aq, TurtleEntity.func_2342 Line truncated
+ private static final Map<EntityType<? extends LivingEntity>, AttributeModifierMap> FORGE_ATTRIBUTES = new java.util.HashMap<EntityType<? extends LivingEntity>, AttributeModifierMap>();
+
+ public static AttributeModifierMap put(EntityType<? extends LivingEntity> type, AttributeModifierMap map) {
+ return FORGE_ATTRIBUTES.put(type, map);
+ }
+ @Deprecated // Remove in 1.17
+ private static final Map<EntityType<? extends LivingEntity>, AttributeModifierMap> FORGE_ATTRIBUTES = net.minecraftforge.common.ForgeHooks.getAttributesView();
+ /** FORGE: Use net.minecraftforge.event.entity.EntityAttributeCreationEvent#put To be removed in 1.17 */
+ @Deprecated
+ public static AttributeModifierMap put(EntityType<? extends LivingEntity> type, AttributeModifierMap map) {
+ return net.minecraftforge.common.ForgeHooks.putAttributesOld(type, map);
+ }
+
public static AttributeModifierMap func_233835_a_(EntityType<? extends LivingEntity> p_233835_0_) {
- return field_233833_b_.get(p_233835_0_);
+ AttributeModifierMap map = FORGE_ATTRIBUTES.get(p_233835_0_);
+ return map != null ? map : field_233833_b_.get(p_233835_0_);
+ AttributeModifierMap map = FORGE_ATTRIBUTES.get(p_233835_0_);
+ return map != null ? map : field_233833_b_.get(p_233835_0_);
}
public static boolean func_233837_b_(EntityType<?> p_233837_0_) {
@@ -23,6 +23,7 @@ import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
@@ -58,6 +59,8 @@ import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes;
import net.minecraft.fluid.*;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.loot.LootContext;
@@ -70,6 +73,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.MobEntity;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.LivingEntity;
@@ -141,6 +145,8 @@ import net.minecraftforge.event.DifficultyChangeEvent;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.ItemAttributeModifierEvent;
import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
import net.minecraftforge.event.entity.EntityAttributeModificationEvent;
import net.minecraftforge.event.entity.EntityTravelToDimensionEvent;
import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
@@ -166,6 +172,7 @@ import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.NoteBlockEvent;
import net.minecraftforge.eventbus.api.Event.Result;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.minecraftforge.fml.packs.ResourcePackLoader;
import net.minecraftforge.registries.DataSerializerEntry;
@@ -1402,4 +1409,39 @@ public class ForgeHooks
}).result().orElse(dymData);
return data.set(DIMENSIONS_KEY, withInjected);
}
private static final Map<EntityType<? extends LivingEntity>, AttributeModifierMap> FORGE_ATTRIBUTES = new HashMap<>();
/** FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY */
@Deprecated
public static Map<EntityType<? extends LivingEntity>, AttributeModifierMap> getAttributesView()
{
return Collections.unmodifiableMap(FORGE_ATTRIBUTES);
}
/** FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY
* ONLY EXISTS FOR LEGACY REASONS SHOULD BE REMOVED IN 1.17
*/
@Deprecated /// Internal use only, Remove in 1.17
public static AttributeModifierMap putAttributesOld(EntityType<? extends LivingEntity> type, AttributeModifierMap map)
{
LOGGER.warn("Called deprecated GlobalEntityTypeAttributes#put for {}, use EntityAttributeCreationEvent instead.", type.getRegistryName());
return FORGE_ATTRIBUTES.put(type, map);
}
/** FOR INTERNAL USE ONLY, DO NOT CALL DIRECTLY */
@Deprecated
public static void modifyAttributes()
{
ModLoader.get().postEvent(new EntityAttributeCreationEvent(FORGE_ATTRIBUTES));
Map<EntityType<? extends LivingEntity>, AttributeModifierMap.MutableAttribute> finalMap = new HashMap<>();
ModLoader.get().postEvent(new EntityAttributeModificationEvent(finalMap));
finalMap.forEach((k, v) ->
{
AttributeModifierMap modifiers = GlobalEntityTypeAttributes.getAttributesForEntity(k);
AttributeModifierMap.MutableAttribute newMutable = modifiers != null ? new AttributeModifierMap.MutableAttribute(modifiers) : new AttributeModifierMap.MutableAttribute();
newMutable.combine(v);
FORGE_ATTRIBUTES.put(k, newMutable.create());
});
}
}
@@ -0,0 +1,53 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2021.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import java.util.Map;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.event.lifecycle.IModBusEvent;
/**
* EntityAttributeCreationEvent.<br>
* Use this event to register attributes for your own EntityTypes.
* This event is fired after registration and before common setup.
* <br>
* Fired on the Mod bus {@link IModBusEvent}.<br>
**/
public class EntityAttributeCreationEvent extends Event implements IModBusEvent
{
private final Map<EntityType<? extends LivingEntity>, AttributeModifierMap> map;
public EntityAttributeCreationEvent(Map<EntityType<? extends LivingEntity>, AttributeModifierMap> map)
{
this.map = map;
}
public void put(EntityType<? extends LivingEntity> entity, AttributeModifierMap map)
{
if (GlobalEntityTypeAttributes.doesEntityHaveAttributes(entity))
throw new IllegalStateException("Duplicate GlobalEntityTypeAttributes entry: " + entity);
this.map.put(entity, map);
}
}
@@ -0,0 +1,83 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2021.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.event.entity;
import com.google.common.collect.ImmutableList;
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.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.event.lifecycle.IModBusEvent;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* EntityAttributeModificationEvent.<br>
* Use this event to add attributes to existing entity types.
* This event is fired after registration and before common setup, and after {@link EntityAttributeCreationEvent}
* <br>
* Fired on the Mod bus {@link IModBusEvent}.<br>
**/
public class EntityAttributeModificationEvent extends Event implements IModBusEvent
{
private final Map<EntityType<? extends LivingEntity>, AttributeModifierMap.MutableAttribute> entityAttributes;
private final List<EntityType<? extends LivingEntity>> entityTypes;
@SuppressWarnings("unchecked")
public EntityAttributeModificationEvent(Map<EntityType<? extends LivingEntity>, AttributeModifierMap.MutableAttribute> mapIn)
{
this.entityAttributes = mapIn;
this.entityTypes = ImmutableList.copyOf(
ForgeRegistries.ENTITIES.getValues().stream()
.filter(GlobalEntityTypeAttributes::doesEntityHaveAttributes)
.map(entityType -> (EntityType<? extends LivingEntity>) entityType)
.collect(Collectors.toList())
);
}
public void add(EntityType<? extends LivingEntity> entityType, Attribute attribute, double value)
{
AttributeModifierMap.MutableAttribute attributes = entityAttributes.computeIfAbsent(entityType,
(type) -> new AttributeModifierMap.MutableAttribute());
attributes.createMutableAttribute(attribute, value);
}
public void add(EntityType<? extends LivingEntity> entityType, Attribute attribute)
{
add(entityType, attribute, attribute.getDefaultValue());
}
public boolean has(EntityType<? extends LivingEntity> entityType, Attribute attribute)
{
AttributeModifierMap globalMap = GlobalEntityTypeAttributes.getAttributesForEntity(entityType);
return globalMap.hasAttribute(attribute) || (entityAttributes.get(entityType) != null && entityAttributes.get(entityType).hasAttribute(attribute));
}
public List<EntityType<? extends LivingEntity>> getTypes()
{
return entityTypes;
}
}
@@ -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);
@@ -0,0 +1,52 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2021.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.entity;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.RangedAttribute;
import net.minecraftforge.event.entity.EntityAttributeModificationEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
@Mod("add_entity_attribute_test")
public class AddEntityAttributeTest {
public static final boolean ENABLE = true;
private static final DeferredRegister<Attribute> ATTRIBUTES = DeferredRegister.create(Attribute.class, "add_entity_attribute_test");
public static final RegistryObject<Attribute> TEST_ATTR = ATTRIBUTES.register("test_attr", () -> new RangedAttribute("forge.test_attr", 1.0D, 0.0D, 1024.0D).setShouldWatch(true));
public AddEntityAttributeTest() {
if (ENABLE) {
ATTRIBUTES.register(FMLJavaModLoadingContext.get().getModEventBus());
FMLJavaModLoadingContext.get().getModEventBus().register(this);
}
}
@SubscribeEvent
public void entityAttributeSetup(EntityAttributeModificationEvent event) {
event.getTypes().forEach(entityType -> {
if (!event.has(entityType, TEST_ATTR.get())){
event.add(entityType, TEST_ATTR.get());
}
});
}
}
+2
View File
@@ -114,3 +114,5 @@ license="LGPL v2.1"
modId="shader_fix_test"
[[mods]]
modId="worldgen_registry_desync_test"
[[mods]]
modId="add_entity_attribute_test"