Created
February 15, 2019 09:02
-
-
Save Daomephsta/194c17d1678b60e752c445d01c15dca3 to your computer and use it in GitHub Desktop.
Bach
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 daomephsta.bach.common; | |
| import java.util.HashSet; | |
| import java.util.Set; | |
| import daomephsta.bach.common.component.ComponentProvider; | |
| import daomephsta.bach.common.component.IComponent; | |
| import net.minecraft.item.Item; | |
| public abstract class BachItem extends Item | |
| { | |
| private final ComponentProvider componentProvider; | |
| public BachItem(Settings settings) | |
| { | |
| super(settings); | |
| Set<? extends IComponent<?>> components = new HashSet<>(); | |
| initComponents(components); | |
| this.componentProvider = new ComponentProvider(components); | |
| } | |
| protected abstract void initComponents(Set<? extends IComponent<?>> components); | |
| } |
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 daomephsta.bach.common.component.food; | |
| import daomephsta.bach.common.component.IComponent; | |
| import net.minecraft.item.ItemStack; | |
| public interface IEdible extends IComponent<IEdible> | |
| { | |
| public default Class<IEdible> getComponentType() | |
| { | |
| return IEdible.class; | |
| } | |
| public int getHungerRestored(ItemStack itemStack); | |
| public float getSaturationModifier(ItemStack itemStack); | |
| public boolean isWolfFood(); | |
| public boolean isAlwaysConsumable(); | |
| public boolean consumeQuickly(); | |
| } |
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 daomephsta.bach.common.component.food; | |
| import java.util.function.*; | |
| import net.minecraft.item.ItemStack; | |
| public class SimpleEdible implements IEdible | |
| { | |
| private ToIntFunction<ItemStack> hungerFunction; | |
| private ToDoubleFunction<ItemStack> saturationModifierFunction; | |
| private boolean wolfFood, | |
| alwaysConsumable, | |
| consumeQuickly; | |
| public SimpleEdible setHungerRestored(int hunger) | |
| { | |
| setHungerFunction(stack -> hunger); | |
| return this; | |
| } | |
| public SimpleEdible setHungerFunction(ToIntFunction<ItemStack> hungerFunction) | |
| { | |
| this.hungerFunction = hungerFunction; | |
| return this; | |
| } | |
| @Override | |
| public int getHungerRestored(ItemStack itemStack) | |
| { | |
| return hungerFunction.applyAsInt(itemStack); | |
| } | |
| public SimpleEdible setSaturationModifier(float saturationModifier) | |
| { | |
| setSaturationModifierFunction(stack -> saturationModifier); | |
| return this; | |
| } | |
| public SimpleEdible setSaturationModifierFunction(ToDoubleFunction<ItemStack> saturationModifierFunction) | |
| { | |
| this.saturationModifierFunction = saturationModifierFunction; | |
| return this; | |
| } | |
| @Override | |
| public float getSaturationModifier(ItemStack itemStack) | |
| { | |
| return (float) saturationModifierFunction.applyAsDouble(itemStack); | |
| } | |
| public SimpleEdible setWolfFood(boolean wolfFood) | |
| { | |
| this.wolfFood = wolfFood; | |
| return this; | |
| } | |
| @Override | |
| public boolean isWolfFood() | |
| { | |
| return wolfFood; | |
| } | |
| public SimpleEdible setAlwaysConsumable(boolean alwaysConsumable) | |
| { | |
| this.alwaysConsumable = alwaysConsumable; | |
| return this; | |
| } | |
| @Override | |
| public boolean isAlwaysConsumable() | |
| { | |
| return alwaysConsumable; | |
| } | |
| public SimpleEdible setConsumeQuickly(boolean consumeQuickly) | |
| { | |
| this.consumeQuickly = consumeQuickly; | |
| return this; | |
| } | |
| @Override | |
| public boolean consumeQuickly() | |
| { | |
| return consumeQuickly; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment