Last active
January 10, 2022 13:12
-
-
Save Lanse505/102da0f05160d50f448034aa6ed38eb8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.teamacronymcoders.essence.api.modifier.rewrite; | |
import com.teamacronymcoders.essence.api.modifier.legacy.core.ModifierInstance; | |
import com.teamacronymcoders.essence.common.util.helper.EssenceUtilHelper; | |
import net.minecraft.ChatFormatting; | |
import net.minecraft.nbt.CompoundTag; | |
import net.minecraft.network.chat.Component; | |
import net.minecraft.network.chat.TextComponent; | |
import net.minecraft.network.chat.TranslatableComponent; | |
import net.minecraft.resources.ResourceLocation; | |
import net.minecraftforge.registries.IForgeRegistryEntry; | |
import java.util.ArrayList; | |
import java.util.List; | |
public interface IModifier<T> extends IForgeRegistryEntry<IModifier<?>> { | |
// Core Modifier Methods | |
/** | |
* Used to get the Min level of the Modifier. | |
* | |
* @return Returns the minimum level of the Modifier. | |
*/ | |
int getMinLevel(T target); | |
/** | |
* Used to get the Max level of the Modifier. | |
* | |
* @return Returns the maximum level of the Modifier. | |
*/ | |
int getMaxLevel(T target); | |
/** | |
* Used to dictate if the modifier counts towards the maximum modifier count of the storage object. | |
* | |
* @param level The current level of the modifier to check against. | |
* @return Returns whether the modifier counts towards the tool maximum modifier slots. | |
*/ | |
boolean countsTowardsLimit(T target, int level); | |
/** | |
* Used to get how many Modifier points the Modifier will take from the storage objects point pool. | |
* | |
* @param level The current level of the modifier to check against. | |
* @return Returns how many Modifier points the modifier currently takes up. | |
*/ | |
int getModifierCountValue(T target, int level); | |
/** | |
* Used to check whether the current level is within the allowed range of levels for the Modifier. | |
* | |
* @param level The level to check against. | |
* @return Returns whether the checked level is within the min-max span of allowed levels. | |
*/ | |
default int getLevelInRange(T target, int level) { | |
return Math.max(Math.min(level, this.getMaxLevel(target)), this.getMinLevel(target)); | |
} | |
// Conflict Checking Methods | |
/** | |
* This returns a boolean check against the provided modifier. | |
* | |
* @param modifier Modifier to check against. | |
* @return Returns if this modifier can be applied together with the provided Modifier. | |
*/ | |
boolean canApplyTogether(T target, IModifier<T> modifier); | |
/** | |
* This returns a boolean check against both Modifiers not just this Modifier. | |
* | |
* @param modifier Modifier to check against. | |
* @return Returns the final value if this can be applied together with the other Modifier. | |
*/ | |
default boolean isCompatibleWith(T target, IModifier<T> modifier) { | |
return this.canApplyTogether(target, modifier) && modifier.canApplyTogether(target, this); | |
} | |
/** | |
* Used to check if the modifier can be applied on the provided target object. | |
* | |
* @param target Target T object. | |
* @return Returns whether this modifier can be applied on the provided T object. | |
*/ | |
boolean canApplyOnObject(T target); | |
// Resolution Methods | |
/** | |
* Used to handle merging the existing modifier data with new modifier data. | |
* | |
* @param target The T target instance. | |
* @param originalTag The original ModifierInstance's CompoundTag. | |
* @param mergeTag The mergable CompoundTag. | |
*/ | |
void mergeData(T target, CompoundTag originalTag, CompoundTag mergeTag); | |
/** | |
* Used to handle merging the existing ModifierInstance with the new ModifierInstance | |
* | |
* @param target The T target instance. | |
* @param originalInstance The original stored ModifierInstance. | |
* @param mergeInstance The mergable ModifierInstance. | |
*/ | |
void mergeInstance(T target, ModifierInstance originalInstance, ModifierInstance mergeInstance); | |
/** | |
* Used to update a modifier whenever the Tag data gets updated. | |
* @param data The Instanced Modifier Data. | |
*/ | |
void update(CompoundTag data); | |
// Translation and Component Methods | |
/** | |
* Used to get the translatable string value for the modifier name. | |
* Example: 'modifier.namespace.path' = 'modifier.essence.soaked' | |
* | |
* @return Returns the translation id for the Modifier | |
*/ | |
default String getTranslationName() { | |
final ResourceLocation id = this.getRegistryName(); | |
return "modifier." + id.getNamespace() + "." + id.getPath(); | |
} | |
/** | |
* Override this and use Level -1 as a dump value! | |
* | |
* @param level Level of the Modifier | |
* @return Returns the formatted TextComponent | |
*/ | |
default Component getTextComponentName(int level) { | |
if (level == -1) { | |
return new TranslatableComponent(getTranslationName()).withStyle(ChatFormatting.GRAY); | |
} | |
if (level == 1) { | |
return new TextComponent(" ").append(new TranslatableComponent(getTranslationName()).withStyle(ChatFormatting.GRAY)); | |
} | |
return new TextComponent(" ").append(new TranslatableComponent(getTranslationName()).append(" " + EssenceUtilHelper.toRoman(level)).withStyle(ChatFormatting.GRAY)); | |
} | |
/** | |
* @return Gets the ITextComponent that should be rendered in it's Information-Box on the ItemStack. | |
*/ | |
default List<Component> getRenderedText(ModifierInstance instance) { | |
List<Component> textComponents = new ArrayList<>(); | |
if (instance == null) { | |
return textComponents; | |
} | |
textComponents.add(getTextComponentName(instance.getLevel())); | |
return textComponents; | |
} | |
} |
This file contains hidden or 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
package com.teamacronymcoders.essence.api.modifier.rewrite; | |
import com.teamacronymcoders.essence.api.modifier.legacy.core.ModifierInstance; | |
import net.minecraft.nbt.CompoundTag; | |
import net.minecraftforge.registries.ForgeRegistryEntry; | |
public class Modifier<T> extends ForgeRegistryEntry<IModifier<?>> implements IModifier<T>{ | |
private final int maxLevel; | |
private final int minLevel; | |
public Modifier() { | |
this.maxLevel = 1; | |
this.minLevel = 0; | |
} | |
public Modifier(int maxLevel) { | |
this.maxLevel = maxLevel; | |
this.minLevel = 0; | |
} | |
public Modifier(int minLevel, int maxLevel) { | |
this.minLevel = minLevel; | |
this.maxLevel = maxLevel; | |
} | |
@Override | |
public int getMinLevel(T target) { | |
return minLevel; | |
} | |
@Override | |
public int getMaxLevel(T target) { | |
return maxLevel; | |
} | |
@Override | |
public boolean countsTowardsLimit(T target, int level) { | |
return true; | |
} | |
@Override | |
public int getModifierCountValue(T target, int level) { | |
return 1; | |
} | |
@Override | |
public boolean canApplyTogether(T target, IModifier<T> modifier) { | |
return this != modifier; | |
} | |
@Override | |
public boolean canApplyOnObject(T target) { | |
return true; | |
} | |
@Override | |
public void mergeData(T target, CompoundTag originalTag, CompoundTag mergeTag) {} | |
@Override | |
public void mergeInstance(T target, ModifierInstance originalInstance, ModifierInstance mergeInstance) {} | |
@Override | |
public void update(CompoundTag data) {} | |
} |
This file contains hidden or 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
package com.teamacronymcoders.essence.api.modifier.rewrite.item; | |
import com.google.common.collect.HashMultimap; | |
import com.google.common.collect.Multimap; | |
import com.teamacronymcoders.essence.api.modifier.legacy.core.ModifierInstance; | |
import com.teamacronymcoders.essence.api.modifier.rewrite.Modifier; | |
import net.minecraft.world.entity.LivingEntity; | |
import net.minecraft.world.entity.ai.attributes.Attribute; | |
import net.minecraft.world.entity.ai.attributes.AttributeModifier; | |
import net.minecraft.world.item.ItemStack; | |
import net.minecraft.world.item.enchantment.Enchantment; | |
import net.minecraft.world.level.block.state.BlockState; | |
import javax.annotation.Nullable; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.UUID; | |
public class ItemCoreModifier extends Modifier<ItemStack> { | |
private static final Multimap<Attribute, AttributeModifier> DEFAULT_IMMUTABLE_MAP = HashMultimap.create(0, 0); | |
private static final List<Multimap<Attribute, AttributeModifier>> MODIFIERS = new ArrayList<>(); | |
public ItemCoreModifier() { | |
this(0, 1); | |
} | |
public ItemCoreModifier(int minLevel) { | |
this(minLevel, 1); | |
} | |
public ItemCoreModifier(int minLevel, int maxLevel) { | |
super(minLevel, maxLevel); | |
for (int i = 1; i <= maxLevel; i++) { | |
final Multimap<Attribute, AttributeModifier> levelModifiers = HashMultimap.create(0, 0); | |
MODIFIERS.add(levelModifiers); | |
} | |
} | |
public ItemCoreModifier(Attribute attribute, String identifier, UUID uuid, double amount, AttributeModifier.Operation operation) { | |
this(attribute, identifier, uuid, amount, 0, 1, operation); | |
} | |
public ItemCoreModifier(Attribute attribute, String identifier, UUID uuid, double amount, int maxLevel, AttributeModifier.Operation operation) { | |
this(attribute, identifier, uuid, amount, 0, maxLevel, operation); | |
} | |
public ItemCoreModifier(Attribute attribute, String identifier, UUID uuid, double amount, int minLevel, int maxLevel, AttributeModifier.Operation operation) { | |
super(minLevel, maxLevel); | |
for (int i = 1; i <= maxLevel; i++) { | |
final Multimap<Attribute, AttributeModifier> levelModifiers = HashMultimap.create(); | |
levelModifiers.put(attribute, new AttributeModifier(uuid, identifier, amount * i, operation)); | |
MODIFIERS.add(levelModifiers); | |
} | |
} | |
/** | |
* Used to get the Attribute -> Modifiers list for the Modifier. | |
* | |
* @param stack The currently held tool. | |
* @param wielder The current wielder of the tool. | |
* @param instance The current instance object for this modifier. | |
* @return Returns the AttributeModifier MultiMap. | |
*/ | |
public Multimap<Attribute, AttributeModifier> getAttributeModifiers(ItemStack stack, LivingEntity wielder, ModifierInstance instance) { | |
return DEFAULT_IMMUTABLE_MAP; | |
} | |
/** | |
* Gets the modified max-durability of the tool. | |
* | |
* @param stack The currently held tool. | |
* @param instance The current instance object for this modifier. | |
* @param base The base durability of the tool item. | |
* @return Returns the modified durability. | |
*/ | |
public int getModifiedDurability(ItemStack stack, ModifierInstance instance, int base) { | |
return 0; | |
} | |
/** | |
* Gets the modified destroy speed of the tool. | |
* | |
* @param stack The currently held tool. | |
* @param state The currently mining BlockState. | |
* @param original The original destroy speed. | |
* @param instance The current instance object for this modifier. | |
* @return | |
*/ | |
public float getDestroySpeed(ItemStack stack, BlockState state, float original, ModifierInstance instance) { | |
return original; | |
} | |
/** | |
* Used to have the modified have an associated Enchantment linked to it. | |
* | |
* @param stack The currently held tool. | |
* @return Returns the associated Enchantment. | |
*/ | |
@Nullable | |
public Enchantment getLinkedEnchantment(ItemStack stack) { return null; }; | |
} |
This file contains hidden or 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
package com.teamacronymcoders.essence.api.modifier.rewrite.item; | |
import com.teamacronymcoders.essence.api.modifier.legacy.core.ModifierInstance; | |
import net.minecraft.core.BlockPos; | |
import net.minecraft.world.InteractionHand; | |
import net.minecraft.world.InteractionResult; | |
import net.minecraft.world.entity.Entity; | |
import net.minecraft.world.entity.LivingEntity; | |
import net.minecraft.world.entity.ai.attributes.Attribute; | |
import net.minecraft.world.entity.ai.attributes.AttributeModifier; | |
import net.minecraft.world.entity.player.Player; | |
import net.minecraft.world.item.AxeItem; | |
import net.minecraft.world.item.ItemStack; | |
import net.minecraft.world.item.context.UseOnContext; | |
import net.minecraft.world.level.Level; | |
import net.minecraft.world.level.block.state.BlockState; | |
import net.minecraft.world.phys.AABB; | |
import net.minecraftforge.common.ToolAction; | |
import net.minecraftforge.common.ToolActions; | |
import javax.annotation.Nonnull; | |
import javax.annotation.Nullable; | |
import java.util.List; | |
import java.util.UUID; | |
public abstract class ItemInteractionModifier extends ItemCoreModifier { | |
public ItemInteractionModifier() { | |
this(0, 1); | |
} | |
public ItemInteractionModifier(int minLevel) { | |
this(minLevel, 1); | |
} | |
public ItemInteractionModifier(int minLevel, int maxLevel) { | |
super(minLevel, maxLevel); | |
} | |
public ItemInteractionModifier(Attribute attribute, String identifier, UUID uuid, double amount, AttributeModifier.Operation operation) { | |
this(attribute, identifier, uuid, amount, 0, 1, operation); | |
} | |
public ItemInteractionModifier(Attribute attribute, String identifier, UUID uuid, double amount, int maxLevel, AttributeModifier.Operation operation) { | |
this(attribute, identifier, uuid, amount, 0, maxLevel, operation); | |
} | |
public ItemInteractionModifier(Attribute attribute, String identifier, UUID uuid, double amount, int minLevel, int maxLevel, AttributeModifier.Operation operation) { | |
super(attribute, identifier, uuid, amount, minLevel, maxLevel, operation); | |
} | |
/** | |
* Used to modify "useOn" method behaviour. | |
* | |
* @param context The provided UseOnContext. | |
* @param instance The current instance of the Modifier. | |
* @return Returns the InteractionResult of the method. | |
*/ | |
public InteractionResult useOn(UseOnContext context, ModifierInstance instance) { | |
return InteractionResult.PASS; | |
} | |
/** | |
* Used to modify "hurtEnemy" method behaviour. | |
* | |
* @param stack The currently held stack. | |
* @param attacked The attacked entity. | |
* @param attacker The attacking entity. | |
* @param instance The current instance of the modifier. | |
* @return Returns true if it successfully hurt the attacked entity. | |
*/ | |
public boolean hurtEnemy(ItemStack stack, LivingEntity attacked, LivingEntity attacker, ModifierInstance instance) { | |
return false; | |
} | |
/** | |
* Used to modify "mineBlock" method behaviour. | |
* | |
* @param stack The currently held stack. | |
* @param level The Level where the mining is occurring. | |
* @param state The BlockState of the block being mined. | |
* @param pos The BlockPos where the mined block is. | |
* @param miner The LivingEntity miner. | |
* @param instance The current instance of the modifier. | |
* @return Returns whether it successfully mined the block. | |
*/ | |
public boolean mineBlock(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity miner, ModifierInstance instance) { | |
return false; | |
} | |
/** | |
* Used to modify "inventoryTick" method behaviour. | |
* | |
* @param stack The currently held stack. | |
* @param level The Level where the entity whose inventory is ticking is occurring. | |
* @param entity The entity whose inventory is ticking. | |
* @param inventorySlot The slot where the item is located in the inventory. | |
* @param isCurrentItem If the item is the currently selected item. | |
* @param instance The current instance of the modifier. | |
*/ | |
public void inventoryTick(ItemStack stack, Level level, Entity entity, int inventorySlot, boolean isCurrentItem, ModifierInstance instance) {} | |
/** | |
* Used to modify "onSheared" method behaviour. | |
* | |
* @param stack The currently held stack. | |
* @param player The Player doing the shearing. | |
* @param sheared The sheared LivingEntity. | |
* @param hand The InteractionHand being used for the shearing interaction. | |
* @param stackList The list to add drops to. | |
* @param instance The current instance of the modifier. | |
* @return Returns an updated and filled list of Drops. | |
*/ | |
public List<ItemStack> onSheared(ItemStack stack, @Nullable Player player, LivingEntity sheared, InteractionHand hand, List<ItemStack> stackList, ModifierInstance instance) { | |
return stackList; | |
} | |
/** | |
* Can this Item disable a shield | |
* | |
* @param stack The ItemStack | |
* @param shield The shield in question | |
* @param entity The LivingEntity holding the shield | |
* @param attacker The LivingEntity holding the ItemStack | |
* @param instance The current instance of the modifier. | |
* @return True if this ItemStack can disable the shield in question. | |
*/ | |
public boolean canDisableShield(ItemStack stack, ItemStack shield, LivingEntity entity, LivingEntity attacker, ModifierInstance instance) | |
{ | |
return false; | |
} | |
/** | |
* Queries if an item can perform the given action. | |
* See {@link ToolActions} for a description of each stock action. | |
* | |
* @param toolAction The action being queried. | |
* @param instance The current instance of the modifier. | |
* @return True if the stack can perform the action. | |
*/ | |
public boolean canPerformAction(ItemStack stack, ToolAction toolAction, ModifierInstance instance) { | |
return false; | |
} | |
/** | |
* Get a bounding box ({@link AABB}) of a sweep attack. | |
* | |
* @param player The player performing the attack. | |
* @param target The entity targeted by the attack. | |
* @param stack The currently used ItemStack. | |
* @param instance The current instance of the modifier. | |
* @return the bounding box. | |
*/ | |
@Nonnull | |
public AABB getSweepHitBox(@Nonnull Player player, @Nonnull Entity target, ItemStack stack, ModifierInstance instance) | |
{ | |
return stack.getItem().getSweepHitBox(stack, player, target); | |
} | |
} |
This file contains hidden or 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
package com.teamacronymcoders.essence.api.modifier.rewrite.item; | |
import com.teamacronymcoders.essence.api.modifier.legacy.core.ModifierInstance; | |
import com.teamacronymcoders.essence.common.entity.ModifiableArrowEntity; | |
import net.minecraft.world.entity.player.Player; | |
import net.minecraft.world.item.ItemStack; | |
import net.minecraft.world.phys.BlockHitResult; | |
public abstract class ItemArrowModifier extends ItemCoreModifier { | |
public ItemArrowModifier() { | |
this(0, 1); | |
} | |
public ItemArrowModifier(int minLevel) { | |
this(minLevel, 1); | |
} | |
public ItemArrowModifier(int minLevel, int maxLevel) { | |
super(minLevel, maxLevel); | |
} | |
/** | |
* Used to modify "onCollide" method behaviour. | |
* | |
* @param bowStack The bow as an ItemStack. | |
* @param abstractArrowEntity The ModifiableArrowEntity being shot. | |
* @param shooter The shooting Player. | |
* @param result The BlockHitResult of the entity on collision. | |
* @param instance The instance of the modifier. | |
*/ | |
public abstract void onCollide(ItemStack bowStack, ModifiableArrowEntity abstractArrowEntity, Player shooter, BlockHitResult result, ModifierInstance instance); | |
/** | |
* Used to modify "alterArrowEntity" method behaviour. | |
* | |
* @param abstractArrowEntity The ModifiableArrowEntity being shot. | |
* @param shooter The shooting Player. | |
* @param velocity The current velocity of the arrow entity when shot. | |
* @param instance The instance of the modifier. | |
*/ | |
public abstract void alterArrowEntity(ModifiableArrowEntity abstractArrowEntity, Player shooter, float velocity, ModifierInstance instance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment