Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private static ItemStack lemonadeJugStack(ItemStack stack) {

// Glass
output.accept(ModBlocks.LEMONADE_GLASS);
output.accept(ModBlocks.LEMONADE_JUG_TERRACOTTA);
output.accept(lemonadeJugStack(ModItems.LEMONADE_JUG_TERRACOTTA.toStack()));
output.accept(ModItems.ICE_CUBES);

// Straws
Expand Down
33 changes: 6 additions & 27 deletions src/main/java/net/doppelr/lemonmates/LemonMatesTooltipUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@

public class LemonMatesTooltipUtils {

public static void createCustomTooltip(String id, boolean hasConditionalBehaviour, List<Component> components) {
createShiftText(components);
if (Screen.hasShiftDown()) {
components.add(empty());
components.addAll(getBasicSummary(id));
if (hasConditionalBehaviour) {
createConditionalBehaviourTooltip(id, 1, components);
}
}
}

public static void createCustomTooltip(String id, boolean hasConditionalBehaviour, List<Component> components, Object... args) {
createShiftText(components);
if (Screen.hasShiftDown()) {
Expand Down Expand Up @@ -57,23 +46,17 @@ public static List<Component> createGeneric(MutableComponent component) {
return textComponentIndentHelper(component, FontHelper.Palette.STANDARD_CREATE, 1);
}

public static void createAdditionalConditionalBehaviourTooltip(String id, int sequence, List<Component> components) {
public static void createAdditionalConditionalBehaviourTooltip(String id, int sequence, List<Component> components, Object... args) {
if (Screen.hasShiftDown()) {
components.addAll(getCondition(id, sequence));
components.addAll(getBehaviour(id, sequence));
components.addAll(getCondition(id, sequence, args));
components.addAll(getBehaviour(id, sequence, args));
}
}

public static void createConditionalBehaviourTooltip(String id, int sequence, List<Component> components) {
components.add(empty());
components.addAll(getCondition(id, sequence));
components.addAll(getBehaviour(id, sequence));
}

public static void createConditionalBehaviourTooltip(String id, int sequence, List<Component> components, Object... args) {
components.add(empty());
components.addAll(getCondition(id, sequence, args));
components.addAll(getBehaviour(id, sequence));
components.addAll(getBehaviour(id, sequence, args));
}

public static MutableComponent empty() {
Expand All @@ -84,16 +67,12 @@ public static List<Component> getBasicSummary(String id) {
return FontHelper.cutTextComponent(Component.translatable(id + ".tooltip.summary"), FontHelper.Palette.STANDARD_CREATE);
}

public static List<Component> getCondition(String id, int sequence) {
return FontHelper.cutTextComponent(Component.translatable(id + ".tooltip.condition" + sequence), FontHelper.Palette.GRAY);
}

public static List<Component> getCondition(String id, int sequence, Object... args) {
return FontHelper.cutTextComponent(Component.translatable(id + ".tooltip.condition" + sequence, args), FontHelper.Palette.GRAY);
}

public static List<Component> getBehaviour(String id, int sequence) {
return textComponentIndentHelper(Component.translatable(id + ".tooltip.behaviour" + sequence), FontHelper.Palette.STANDARD_CREATE, 1);
public static List<Component> getBehaviour(String id, int sequence, Object... args) {
return textComponentIndentHelper(Component.translatable(id + ".tooltip.behaviour" + sequence, args), FontHelper.Palette.STANDARD_CREATE, 1);
}

public static List<Component> textComponentIndentHelper(Component component, FontHelper.Palette palette, int indent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
if (state.getValue(FLUID) == ApplicableFluidsToFluidContainer.NONE || state.getValue(DRINK_LEVEL) == 0) {
level.setBlockAndUpdate(pos, state.setValue(FLUID, pouredFluid).setValue(DRINK_LEVEL, blockDrinkLevel));
jugItem.removeFromJugLevel(stack, player, newDrinkLevel);
if (stack.get(AllDataComponents.JUG_LEVEL) > 0)
level.playSound(player, pos, SoundEvents.BOTTLE_EMPTY, SoundSource.BLOCKS, 1.0F, 1.0F);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.food.FoodProperties;
import org.jetbrains.annotations.NotNull;

import java.util.Locale;

Expand Down Expand Up @@ -34,7 +35,7 @@ public FoodProperties getProperties() {
}

@Override
public String getSerializedName() {
public @NotNull String getSerializedName() {
return name().toLowerCase(Locale.ROOT);
}
}
13 changes: 11 additions & 2 deletions src/main/java/net/doppelr/lemonmates/item/ModJugItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.doppelr.lemonmates.block.properties.ApplicableFluidsToFluidContainer;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
Expand All @@ -23,6 +25,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Locale;

public class ModJugItem extends BlockItem {
public ModJugItem(Block block, Properties properties) {
Expand Down Expand Up @@ -57,22 +60,26 @@ public void removeFromJugLevel(ItemStack stack, Player player, int decrement) {
}

public void jugLevelHandling(ItemStack stack, Player player, ApplicableFluidsToFluidContainer fluid) {
Level level = player.level();
if (stack.get(AllDataComponents.APPLICABLE_FLUID_TO_CONTAINER) != fluid)
this.setContainedFluid(stack, fluid);

if (stack.get(AllDataComponents.JUG_LEVEL) == null || stack.get(AllDataComponents.JUG_LEVEL) == 0) {
this.setJugLevel(stack, 4);
level.playSound(player, player.blockPosition(), SoundEvents.BOTTLE_FILL, SoundSource.PLAYERS, 1.0F, 1.0F);
if (!player.getAbilities().instabuild)
player.setItemInHand(InteractionHand.OFF_HAND, ModItems.BOTTLE_EMPTY.toStack());
} else if (stack.get(AllDataComponents.JUG_LEVEL) <= 4) {
this.addToJugLevel(stack, 4);
level.playSound(player, player.blockPosition(), SoundEvents.BOTTLE_FILL, SoundSource.PLAYERS, 1.0F, 1.0F);
if (!player.getAbilities().instabuild)
player.setItemInHand(InteractionHand.OFF_HAND, ModItems.BOTTLE_EMPTY.toStack());
} else if (stack.get(AllDataComponents.JUG_LEVEL) < 8) {
int incrementJugLevel = 4;
if (stack.get(AllDataComponents.JUG_LEVEL) > 4)
incrementJugLevel = 8 - stack.get(AllDataComponents.JUG_LEVEL);
this.addToJugLevel(stack, incrementJugLevel);
level.playSound(player, player.blockPosition(), SoundEvents.BOTTLE_FILL, SoundSource.PLAYERS, 1.0F, 1.0F);
if (!player.getAbilities().instabuild)
player.setItemInHand(InteractionHand.OFF_HAND, ModItems.BOTTLE_EMPTY.toStack());
}
Expand Down Expand Up @@ -134,8 +141,10 @@ public InteractionResult useOn(UseOnContext context) {
public void appendHoverText(ItemStack stack, @NotNull TooltipContext context, @NotNull List<Component> tooltipComponents, @NotNull TooltipFlag tooltipFlag) {
String id = "block.lemonmates.lemonade_jug_terracotta";
boolean pour = stack.get(AllDataComponents.CAN_POUR) != null ? stack.get(AllDataComponents.CAN_POUR) : false;
//String currentfluid = stack.get(AllDataComponents.APPLICABLE_FLUID_TO_CONTAINER) != ApplicableFluidsToFluidContainer.NONE ? stack.get(AllDataComponents.APPLICABLE_FLUID_TO_CONTAINER) : ApplicableFluidsToFluidContainer.NONE ;
LemonMatesTooltipUtils.createCustomTooltip(id, true, tooltipComponents, pour );// , currentfluid);
ApplicableFluidsToFluidContainer applicableFluid = stack.get(AllDataComponents.APPLICABLE_FLUID_TO_CONTAINER) != null ? stack.get(AllDataComponents.APPLICABLE_FLUID_TO_CONTAINER) : ApplicableFluidsToFluidContainer.NONE;
Component fluid = Component.translatable("jugFluid.lemonmates." + applicableFluid.getSerializedName());
LemonMatesTooltipUtils.createCustomTooltip(id, true, tooltipComponents, pour, fluid);
LemonMatesTooltipUtils.createAdditionalConditionalBehaviourTooltip(id, 2, tooltipComponents);
LemonMatesTooltipUtils.createAdditionalConditionalBehaviourTooltip(id, 3, tooltipComponents, fluid);
}
}
Loading
Loading