mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 19:46:42 +01:00
Implement seapony diets
This commit is contained in:
parent
e49828fea1
commit
38422bda42
14 changed files with 61 additions and 45 deletions
|
@ -31,7 +31,7 @@ public class ChangeFormAbility implements Ability<Hit> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUse(Race.Composite race) {
|
public boolean canUse(Race.Composite race) {
|
||||||
return race.potential() != null;
|
return race.potential() != null && race.potential() != race.physical();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,11 +2,8 @@ package com.minelittlepony.unicopia.item;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
|
|
||||||
|
|
||||||
import net.minecraft.advancement.criterion.Criteria;
|
import net.minecraft.advancement.criterion.Criteria;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
@ -21,18 +18,13 @@ public class DrinkableItem extends Item {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
|
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
|
||||||
|
super.finishUsing(stack, world, user);
|
||||||
if (user instanceof ServerPlayerEntity) {
|
if (user instanceof ServerPlayerEntity) {
|
||||||
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)user;
|
ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)user;
|
||||||
Criteria.CONSUME_ITEM.trigger(serverPlayerEntity, stack);
|
Criteria.CONSUME_ITEM.trigger(serverPlayerEntity, stack);
|
||||||
serverPlayerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
|
serverPlayerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
((ToxicHolder)this).getToxic(stack).finishUsing(stack, world, user);
|
|
||||||
|
|
||||||
if (user instanceof PlayerEntity && !((PlayerEntity)user).getAbilities().creativeMode) {
|
|
||||||
stack.decrement(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stack.isEmpty() ? Optional.ofNullable(getRecipeRemainder()).map(Item::getDefaultStack).orElse(ItemStack.EMPTY) : stack;
|
return stack.isEmpty() ? Optional.ofNullable(getRecipeRemainder()).map(Item::getDefaultStack).orElse(ItemStack.EMPTY) : stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class ZapAppleItem extends Item implements ChameleonItem, ToxicHolder, Mu
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Toxic getToxic(ItemStack stack) {
|
public Toxic getToxic(ItemStack stack, LivingEntity entity) {
|
||||||
return hasAppearance(stack) ? Toxics.SEVERE_INNERT : Toxics.FORAGE_EDIBLE;
|
return hasAppearance(stack) ? Toxics.SEVERE_INNERT : Toxics.FORAGE_EDIBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,6 @@ public record Ailment (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity entity) {
|
|
||||||
effect().afflict((PlayerEntity)entity, stack);
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||||
if (!Pony.of(player).getObservedSpecies().hasIronGut()) {
|
if (!Pony.of(player).getObservedSpecies().hasIronGut()) {
|
||||||
return TypedActionResult.fail(player.getStackInHand(hand));
|
return TypedActionResult.fail(player.getStackInHand(hand));
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.minelittlepony.unicopia.item.toxin;
|
package com.minelittlepony.unicopia.item.toxin;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
|
|
||||||
import net.minecraft.client.item.TooltipContext;
|
import net.minecraft.client.item.TooltipContext;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
@ -14,7 +17,7 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
public record Toxic (
|
public record Toxic (
|
||||||
Optional<UseAction> useAction,
|
Optional<UseAction> useAction,
|
||||||
Optional<FoodComponent> component,
|
Function<LivingEntity, Optional<FoodComponent>> food,
|
||||||
Ailment.Set ailment
|
Ailment.Set ailment
|
||||||
) {
|
) {
|
||||||
public void appendTooltip(PlayerEntity player, List<Text> tooltip, TooltipContext context) {
|
public void appendTooltip(PlayerEntity player, List<Text> tooltip, TooltipContext context) {
|
||||||
|
@ -36,6 +39,7 @@ public record Toxic (
|
||||||
private final Ailment def;
|
private final Ailment def;
|
||||||
private final Map<Race, Ailment> overrides = new HashMap<>();
|
private final Map<Race, Ailment> overrides = new HashMap<>();
|
||||||
private Optional<UseAction> action = Optional.of(UseAction.EAT);
|
private Optional<UseAction> action = Optional.of(UseAction.EAT);
|
||||||
|
private final Map<Race, FoodComponent> components = new HashMap<>();
|
||||||
private Optional<FoodComponent> component = Optional.empty();
|
private Optional<FoodComponent> component = Optional.empty();
|
||||||
|
|
||||||
public Builder(Ailment def) {
|
public Builder(Ailment def) {
|
||||||
|
@ -52,13 +56,23 @@ public record Toxic (
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder food(Race race, FoodComponent food) {
|
||||||
|
components.put(race, food);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder with(Race race, Ailment ailment) {
|
public Builder with(Race race, Ailment ailment) {
|
||||||
overrides.put(race, ailment);
|
overrides.put(race, ailment);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Toxic build() {
|
public Toxic build() {
|
||||||
return new Toxic(action, component, Ailment.Set.of(def, overrides));
|
return new Toxic(action, entity -> {
|
||||||
|
if (entity instanceof PlayerEntity player) {
|
||||||
|
return Optional.ofNullable(components.get(Pony.of(player).getObservedSpecies())).or(() -> component);
|
||||||
|
}
|
||||||
|
return component;
|
||||||
|
}, Ailment.Set.of(def, overrides));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Toxic> buildOptional() {
|
public Optional<Toxic> buildOptional() {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.minelittlepony.unicopia.item.toxin;
|
package com.minelittlepony.unicopia.item.toxin;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.item.*;
|
import net.minecraft.item.*;
|
||||||
|
|
||||||
public interface ToxicHolder {
|
public interface ToxicHolder {
|
||||||
Toxic getToxic(ItemStack stack);
|
Toxic getToxic(ItemStack stack, @Nullable LivingEntity entity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.item.toxin;
|
||||||
import com.minelittlepony.unicopia.*;
|
import com.minelittlepony.unicopia.*;
|
||||||
import com.minelittlepony.unicopia.util.RegistryUtils;
|
import com.minelittlepony.unicopia.util.RegistryUtils;
|
||||||
|
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.item.FoodComponent;
|
import net.minecraft.item.FoodComponent;
|
||||||
import net.minecraft.registry.Registry;
|
import net.minecraft.registry.Registry;
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
public interface Toxics {
|
public interface Toxics {
|
||||||
Registry<ToxicRegistryEntry> REGISTRY = RegistryUtils.createSimple(Unicopia.id("toxic"));
|
Registry<ToxicRegistryEntry> REGISTRY = RegistryUtils.createSimple(Unicopia.id("toxic"));
|
||||||
|
|
||||||
Toxic EMPTY = new Toxic(Optional.empty(), Optional.empty(), Ailment.Set.EMPTY);
|
Toxic EMPTY = new Toxic(Optional.empty(), entity -> Optional.empty(), Ailment.Set.EMPTY);
|
||||||
|
|
||||||
Toxic SEVERE_INNERT = Toxic.innert(Toxicity.SEVERE);
|
Toxic SEVERE_INNERT = Toxic.innert(Toxicity.SEVERE);
|
||||||
|
|
||||||
|
@ -144,20 +145,28 @@ public interface Toxics {
|
||||||
.with(Race.BAT, of(Toxicity.SAFE, Toxin.BAT_PONY_INTOXICATION))
|
.with(Race.BAT, of(Toxicity.SAFE, Toxin.BAT_PONY_INTOXICATION))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Toxic RAW_SEA_VEGITABLES = register("raw_sea_vegitable", new Toxic.Builder(Ailment.INNERT)
|
||||||
|
.food(Race.SEAPONY, UFoodComponents.RANDOM_FOLIAGE)
|
||||||
|
);
|
||||||
|
|
||||||
|
Toxic COOKED_SEA_VEGITABLES = register("cooked_sea_vegitable", new Toxic.Builder(Ailment.INNERT)
|
||||||
|
.food(Race.SEAPONY, UFoodComponents.RANDOM_FOLIAGE_FILLING)
|
||||||
|
);
|
||||||
|
|
||||||
static void bootstrap() {}
|
static void bootstrap() {}
|
||||||
|
|
||||||
static Toxic register(String name, Toxic.Builder builder) {
|
static Toxic register(String name, Toxic.Builder builder) {
|
||||||
return Registry.register(REGISTRY, Unicopia.id(name), new ToxicRegistryEntry(builder.build(), UTags.item("food_types/" + name))).value();
|
return Registry.register(REGISTRY, Unicopia.id(name), new ToxicRegistryEntry(builder.build(), UTags.item("food_types/" + name))).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Toxic lookup(ItemDuck item) {
|
static Toxic lookup(ItemDuck item, @Nullable LivingEntity entity) {
|
||||||
@Nullable FoodComponent food = item.asItem().getFoodComponent();
|
@Nullable FoodComponent food = item.asItem().getFoodComponent();
|
||||||
return REGISTRY.stream()
|
return REGISTRY.stream()
|
||||||
.filter(i -> i.matches(item.asItem()))
|
.filter(i -> i.matches(item.asItem()))
|
||||||
.map(ToxicRegistryEntry::value)
|
.map(ToxicRegistryEntry::value)
|
||||||
.map(t -> {
|
.map(t -> {
|
||||||
if (food == null) {
|
if (food == null) {
|
||||||
t.component().ifPresent(item::setFoodComponent);
|
t.food().apply(entity).ifPresent(item::setFoodComponent);
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}).findFirst().orElse(food == null ? Toxics.EMPTY : Toxics.EDIBLE);
|
}).findFirst().orElse(food == null ? Toxics.EMPTY : Toxics.EDIBLE);
|
||||||
|
|
|
@ -25,12 +25,14 @@ abstract class MixinBlockItem extends Item implements ToxicHolder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UseAction getUseAction(ItemStack stack) {
|
public UseAction getUseAction(ItemStack stack) {
|
||||||
return getToxic(stack).useAction().orElseGet(() -> super.getUseAction(stack));
|
return getToxic(stack, null).useAction().orElseGet(() -> super.getUseAction(stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||||
return getToxic(player.getStackInHand(hand)).ailment().get(player)
|
return getToxic(player.getStackInHand(hand), player)
|
||||||
|
.ailment()
|
||||||
|
.get(player)
|
||||||
.map(t -> t.use(world, player, hand))
|
.map(t -> t.use(world, player, hand))
|
||||||
.orElseGet(() -> super.use(world, player, hand));
|
.orElseGet(() -> super.use(world, player, hand));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Mutable;
|
import org.spongepowered.asm.mixin.Mutable;
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
@ -43,14 +44,16 @@ abstract class MixinItem implements ItemDuck {
|
||||||
public abstract void setFoodComponent(FoodComponent food);
|
public abstract void setFoodComponent(FoodComponent food);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Toxic getToxic(ItemStack stack) {
|
public Toxic getToxic(ItemStack stack, @Nullable LivingEntity entity) {
|
||||||
|
if (entity != null) {
|
||||||
setFoodComponent(originalFoodComponent.get());
|
setFoodComponent(originalFoodComponent.get());
|
||||||
return Toxics.lookup(this);
|
}
|
||||||
|
return Toxics.lookup(this, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "finishUsing", at = @At("HEAD"))
|
||||||
private void finishUsing(ItemStack stack, World world, LivingEntity entity, CallbackInfoReturnable<ItemStack> info) {
|
private void finishUsing(ItemStack stack, World world, LivingEntity entity, CallbackInfoReturnable<ItemStack> info) {
|
||||||
getToxic(stack).finishUsing(stack, world, entity);
|
getToxic(stack, entity).finishUsing(stack, world, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "use", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "use", at = @At("HEAD"), cancellable = true)
|
||||||
|
|
|
@ -21,6 +21,6 @@ import net.minecraft.world.World;
|
||||||
abstract class MixinItem implements ToxicHolder {
|
abstract class MixinItem implements ToxicHolder {
|
||||||
@Inject(method = "appendTooltip", at = @At("RETURN"))
|
@Inject(method = "appendTooltip", at = @At("RETURN"))
|
||||||
private void onAppendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context, CallbackInfo into) {
|
private void onAppendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context, CallbackInfo into) {
|
||||||
getToxic(stack).appendTooltip(MinecraftClient.getInstance().player, tooltip, context);
|
getToxic(stack, MinecraftClient.getInstance().player).appendTooltip(MinecraftClient.getInstance().player, tooltip, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"replace": false,
|
|
||||||
"values": [
|
|
||||||
"unicopia:mango",
|
|
||||||
"unicopia:banana",
|
|
||||||
"unicopia:pineapple"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"replace": false,
|
|
||||||
"values": [
|
|
||||||
"unicopia:pineapple"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"replace": false,
|
"replace": false,
|
||||||
"values": [
|
"values": [
|
||||||
"unicopia:banana"
|
"minecraft:dried_kelp_block"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"replace": false,
|
||||||
|
"values": [
|
||||||
|
"minecraft:kelp",
|
||||||
|
"minecraft:dried_kelp",
|
||||||
|
"minecraft:seagrass",
|
||||||
|
"minecraft:sea_pickle",
|
||||||
|
{ "id": "farmersdelight:melon_popsicle", "required": false },
|
||||||
|
{ "id": "farmersdelight:kelp_roll", "required": false },
|
||||||
|
{ "id": "farmersdelight:kelp_roll_slice", "required": false }
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in a new issue