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,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());
}
});
}
}