-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
59 additions
and
43 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/vazkii/quark/base/handler/EntityAttributeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package vazkii.quark.base.handler; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.ai.attributes.AttributeModifierMap.MutableAttribute; | ||
import net.minecraftforge.event.entity.EntityAttributeCreationEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber; | ||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; | ||
import vazkii.quark.base.Quark; | ||
|
||
@EventBusSubscriber(modid = Quark.MOD_ID, bus = Bus.MOD) | ||
public final class EntityAttributeHandler { | ||
|
||
private static Map<EntityType<? extends LivingEntity>, Supplier<MutableAttribute>> attributeSuppliers = new HashMap<>(); | ||
|
||
public static void put(EntityType<? extends LivingEntity> type, Supplier<MutableAttribute> attrSupplier) { | ||
attributeSuppliers.put(type, attrSupplier); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void onAttributeCreation(EntityAttributeCreationEvent event) { | ||
for(EntityType<? extends LivingEntity> type : attributeSuppliers.keySet()) { | ||
Supplier<MutableAttribute> supplier = attributeSuppliers.get(type); | ||
event.put(type, supplier.get().create()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters