Skip to content

Commit

Permalink
Merge branch '1.20.1' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
YoungOnionMC authored Jul 26, 2024
2 parents 8aa98d0 + 6c57c61 commit 4a590cb
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 42 deletions.
2 changes: 2 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -3794,6 +3794,8 @@
"gtceu.tooltip.fluid_pipe_hold_shift": "oɟuI ʇuǝɯuıɐʇuoƆ pınןℲ ʍoɥs oʇ ⟘ℲIHS pןoHㄥ§",
"gtceu.tooltip.hold_ctrl": "oɟuı ǝɹoɯ ɹoɟ Ꞁᴚ⟘Ɔ pןoHㄥ§",
"gtceu.tooltip.hold_shift": "oɟuı ǝɹoɯ ɹoɟ ⟘ℲIHS pןoHㄥ§",
"gtceu.tooltip.potion.each": "buıuǝddɐɥ ɟo ǝɔuɐɥɔ ɹ§%s%%ɐ§ ɐ ɥʇıʍ sʞɔıʇ ɹ§%sɔ§ ɹoɟ ɹ§%s %sǝ§ ",
"gtceu.tooltip.potion.header": ":sʇɔǝɟɟǝ suıɐʇuoƆ9§",
"gtceu.tooltip.tool_fluid_hold_shift": "oɟuI ןoo⟘ puɐ ʇuǝɯuıɐʇuoƆ pınןℲ ʍoɥs oʇ ⟘ℲIHS pןoHㄥ§",
"gtceu.top.allow_output_input": "ʇnduI ʍoןןⱯ",
"gtceu.top.auto_output": "ʇndʇnO oʇnⱯ",
Expand Down
2 changes: 2 additions & 0 deletions src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -3794,6 +3794,8 @@
"gtceu.tooltip.fluid_pipe_hold_shift": "§7Hold SHIFT to show Fluid Containment Info",
"gtceu.tooltip.hold_ctrl": "§7Hold CTRL for more info",
"gtceu.tooltip.hold_shift": "§7Hold SHIFT for more info",
"gtceu.tooltip.potion.each": " §e%s %s§r for §c%s§r ticks with a §a%s%%§r chance of happening",
"gtceu.tooltip.potion.header": "§6Contains effects:",
"gtceu.tooltip.tool_fluid_hold_shift": "§7Hold SHIFT to show Fluid Containment and Tool Info",
"gtceu.top.allow_output_input": "Allow Input",
"gtceu.top.auto_output": "Auto Output",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.gregtechceu.gtceu.api.data.chemical.material.stack.UnificationEntry;
import com.gregtechceu.gtceu.api.data.medicalcondition.MedicalCondition;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.api.item.GTBucketItem;
import com.gregtechceu.gtceu.api.item.TagPrefixItem;
import com.gregtechceu.gtceu.api.item.armor.ArmorComponentItem;
import com.gregtechceu.gtceu.api.item.forge.GTBucketItem;
import com.gregtechceu.gtceu.config.ConfigHolder;
import com.gregtechceu.gtceu.data.recipe.CustomTags;

Expand Down
55 changes: 54 additions & 1 deletion src/main/java/com/gregtechceu/gtceu/api/item/ComponentItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.NonNullList;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
Expand All @@ -23,10 +24,12 @@
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.food.FoodProperties;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.enchantment.Enchantment;
Expand Down Expand Up @@ -212,6 +215,16 @@ public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity livi
return stack;
}

@Override
public UseAnim getUseAnimation(ItemStack stack) {
for (IItemComponent component : components) {
if (component instanceof IInteractionItem interactionItem) {
return interactionItem.getUseAnimation(stack);
}
}
return super.getUseAnimation(stack);
}

@Override
public InteractionResult onItemUseFirst(ItemStack itemStack, UseOnContext context) {
for (IItemComponent component : components) {
Expand Down Expand Up @@ -345,12 +358,52 @@ public int getBurnTime(ItemStack itemStack, @Nullable RecipeType<?> recipeType)
return burnTime;
}

@Override
public @Nullable FoodProperties getFoodProperties(ItemStack stack, @Nullable LivingEntity entity) {
for (IItemComponent component : components) {
if (component instanceof IEdibleItem foodBehavior) {
return foodBehavior.getFoodProperties(stack, entity);
}
}
return super.getFoodProperties(stack, entity);
}

@Override
public boolean isEdible() {
for (IItemComponent component : components) {
if (component instanceof IEdibleItem foodBehavior) {
return foodBehavior.isEdible();
}
}
return super.isEdible();
}

@Override
public SoundEvent getEatingSound() {
for (IItemComponent component : components) {
if (component instanceof IEdibleItem foodBehavior) {
return foodBehavior.getEatingSound();
}
}
return super.getEatingSound();
}

@Override
public SoundEvent getDrinkingSound() {
for (IItemComponent component : components) {
if (component instanceof IEdibleItem foodBehavior) {
return foodBehavior.getDrinkingSound();
}
}
return super.getDrinkingSound();
}

public void burnTime(int burnTime) {
this.burnTime = burnTime;
}

/**
* Attempts to get an fully charged variant of this electric item
* Attempts to get a fully charged variant of this electric item
*
* @param chargeAmount amount of charge
* @return charged electric item stack
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gregtechceu.gtceu.api.item.forge;
package com.gregtechceu.gtceu.api.item;

import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.chemical.material.properties.PropertyKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ public static FilteredFluidContainer create(int capacity, boolean allowPartialFi
@Override
public @NotNull <T> LazyOptional<T> getCapability(ItemStack itemStack, @NotNull Capability<T> cap) {
if (cap == ForgeCapabilities.FLUID_HANDLER_ITEM) {
return ForgeCapabilities.FLUID_HANDLER_ITEM.orEmpty(cap, LazyOptional.of(() -> {
return new FilteredFluidHandlerItemStack(itemStack, capacity, filter);
}));
return ForgeCapabilities.FLUID_HANDLER_ITEM.orEmpty(cap,
LazyOptional.of(() -> new FilteredFluidHandlerItemStack(itemStack, capacity, filter)));
}
return LazyOptional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.gregtechceu.gtceu.api.item.component;

import com.gregtechceu.gtceu.utils.GTUtil;

import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.Level;

import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.function.Supplier;

/**
* Simple {@link IEdibleItem} implementation.
*
* @author GateGuardian
* @date : 2024/7/22
*/
public class FoodStats implements IEdibleItem, IInteractionItem, IAddInformation {

protected final FoodProperties properties;

protected final boolean isDrink;

@Nullable
protected final Supplier<ItemStack> containerItem;

public FoodStats(FoodProperties properties, boolean isDrink, @Nullable Supplier<ItemStack> containerItem) {
this.properties = properties;
this.isDrink = isDrink;
this.containerItem = containerItem;
}

@Override
public FoodProperties getFoodProperties(ItemStack stack, @Nullable LivingEntity entity) {
return properties;
}

@Override
public boolean isEdible() {
return true;
}

@Override
public SoundEvent getEatingSound() {
return isDrink ? getDrinkingSound() : IEdibleItem.super.getEatingSound();
}

@Override
public UseAnim getUseAnimation(ItemStack stack) {
return isDrink ? UseAnim.DRINK : UseAnim.EAT;
}

@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltipComponents,
TooltipFlag isAdvanced) {
GTUtil.addPotionTooltip(properties.getEffects(), tooltipComponents);
}

@Override
public ItemStack finishUsingItem(ItemStack food, Level level, LivingEntity livingEntity) {
Player player = livingEntity instanceof Player ? (Player) livingEntity : null;
var stack = livingEntity.eat(level, food);
if (containerItem != null && (player == null || !player.getAbilities().instabuild)) {
var container = containerItem.get();
if (stack.isEmpty()) {
return container;
}

if (player != null) {
if (!player.getInventory().add(container)) {
player.drop(container, true);
}
}
}
return stack;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.gregtechceu.gtceu.api.item.component;

import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.ItemStack;

import org.jetbrains.annotations.Nullable;

public interface IEdibleItem {

FoodProperties getFoodProperties(ItemStack stack, @Nullable LivingEntity entity);

boolean isEdible();

default SoundEvent getEatingSound() {
return SoundEvents.GENERIC_EAT;
}

default SoundEvent getDrinkingSound() {
return SoundEvents.GENERIC_DRINK;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;

Expand All @@ -17,6 +18,10 @@
*/
public interface IInteractionItem extends IItemComponent {

default InteractionResult onItemUseFirst(ItemStack itemStack, UseOnContext context) {
return InteractionResult.PASS;
}

default InteractionResult useOn(UseOnContext context) {
return InteractionResult.PASS;
}
Expand All @@ -39,8 +44,8 @@ default ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity liv
return stack.isEdible() ? livingEntity.eat(level, stack) : stack;
}

default InteractionResult onItemUseFirst(ItemStack itemStack, UseOnContext context) {
return InteractionResult.PASS;
default UseAnim getUseAnimation(ItemStack stack) {
return stack.getItem().isEdible() ? UseAnim.EAT : UseAnim.NONE;
}

default boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.gregtechceu.gtceu.api.fluids.FluidState;
import com.gregtechceu.gtceu.api.fluids.GTFluid;
import com.gregtechceu.gtceu.api.fluids.forge.GTFluidImpl;
import com.gregtechceu.gtceu.api.item.forge.GTBucketItem;
import com.gregtechceu.gtceu.api.item.GTBucketItem;
import com.gregtechceu.gtceu.api.registry.registrate.IGTFluidBuilder;

import net.minecraft.MethodsReturnNonnullByDefault;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.gregtechceu.gtceu.common.data.forge;
package com.gregtechceu.gtceu.common.data;

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.common.data.GTPlacements;
import com.gregtechceu.gtceu.data.recipe.CustomTags;

import net.minecraft.core.*;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ public static void generateTools() {
.onRegister(compassNode(GTCompassSections.MISC))
.onRegister(materialInfo(new ItemMaterialInfo(new MaterialStack(GTMaterials.Brass, GTValues.M / 4))))
.register();
public static ItemEntry<Item> COIN_CHOCOLATE = REGISTRATE.item("chocolate_coin", Item::new)
public static ItemEntry<ComponentItem> COIN_CHOCOLATE = REGISTRATE.item("chocolate_coin", ComponentItem::create)
.lang("Chocolate Coin")
.properties(p -> p.rarity(Rarity.EPIC).food(GTFoods.CHOCOLATE))
.properties(p -> p.rarity(Rarity.EPIC))
.onRegister(attach(new FoodStats(GTFoods.CHOCOLATE, false,
() -> ChemicalHelper.get(TagPrefix.foil, GTMaterials.Gold))))
.onRegister(compassNode(GTCompassSections.MISC))
.onRegister(materialInfo(new ItemMaterialInfo(new MaterialStack(GTMaterials.Gold, GTValues.M / 4))))
.register();
Expand Down Expand Up @@ -2221,9 +2223,9 @@ public Component getItemName(ItemStack stack) {
public static ItemEntry<Item> GELLED_TOLUENE = REGISTRATE.item("gelled_toluene", Item::new)
.onRegister(compassNode(GTCompassSections.MISC)).register();

public static ItemEntry<Item> BOTTLE_PURPLE_DRINK = REGISTRATE.item("purple_drink", Item::new)
public static ItemEntry<ComponentItem> BOTTLE_PURPLE_DRINK = REGISTRATE.item("purple_drink", ComponentItem::create)
.lang("Purple Drink")
.properties(p -> p.food(GTFoods.DRINK))
.onRegister(attach(new FoodStats(GTFoods.DRINK, true, () -> Items.GLASS_BOTTLE.getDefaultInstance())))
.onRegister(compassNode(GTCompassSections.MISC))
.register();
public static ItemEntry<ComponentItem> PLANT_BALL = REGISTRATE.item("plant_ball", ComponentItem::create)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
public class GTFoods {

public final static FoodProperties CHOCOLATE = new FoodProperties.Builder()
.effect(() -> new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 200, 1), 0.1f)
.effect(() -> new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 200, 1), 0.1F)
.alwaysEat().nutrition(4).saturationMod(0.3F).build();

public final static FoodProperties DRINK = new FoodProperties.Builder()
.effect(() -> new MobEffectInstance(MobEffects.HEAL, 200, 1), 0.1f)
.effect(() -> new MobEffectInstance(MobEffects.DIG_SPEED, 800, 1), 0.9F)
.alwaysEat().nutrition(4).saturationMod(0.3F).build();

public static final FoodProperties ANTIDOTE = new FoodProperties.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.gregtechceu.gtceu.api.registry.registrate.CompassNode;
import com.gregtechceu.gtceu.api.registry.registrate.CompassSection;
import com.gregtechceu.gtceu.api.registry.registrate.SoundEntryBuilder;
import com.gregtechceu.gtceu.common.data.GTBiomeModifiers;
import com.gregtechceu.gtceu.common.data.GTConfiguredFeatures;
import com.gregtechceu.gtceu.common.data.GTDamageTypes;
import com.gregtechceu.gtceu.common.data.GTPlacements;
import com.gregtechceu.gtceu.common.data.GTWorldgen;
import com.gregtechceu.gtceu.common.data.forge.GTBiomeModifiers;
import com.gregtechceu.gtceu.data.tags.BiomeTagsLoader;
import com.gregtechceu.gtceu.data.tags.DamageTagsLoader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,9 @@ public static void init(RegistrateLangProvider provider) {
provider.add("gtceu.subtitle.metal_pipe", "Destruction_Metal_Pole_L_Wave_2_0_0.wav");

provider.add("effect.gtceu.weak_poison", "Weak Poison");

provider.add("gtceu.tooltip.potion.header", "§6Contains effects:");
provider.add("gtceu.tooltip.potion.each", " §e%s %s§r for §c%s§r ticks with a §a%s%%§r chance of happening");
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/utils/GTUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.tags.BiomeTags;
import net.minecraft.util.RandomSource;
import net.minecraft.util.Tuple;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand All @@ -41,6 +42,7 @@

import com.google.common.math.LongMath;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.datafixers.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -506,4 +508,17 @@ public static Tuple<ItemStack, MutableComponent> getMaintenanceText(byte flag) {
Component.translatable("gtceu.top.maintenance.crowbar"));
};
}

public static void addPotionTooltip(List<Pair<MobEffectInstance, Float>> effects, List<Component> list) {
list.add(Component.translatable("gtceu.tooltip.potion.header"));
effects.forEach(pair -> {
var effect = pair.getFirst();
float probability = pair.getSecond();
list.add(Component.translatable("gtceu.tooltip.potion.each",
Component.translatable(effect.getDescriptionId()),
Component.translatable("enchantment.level." + (effect.getAmplifier() + 1)),
effect.getDuration(),
100 * probability));
});
}
}
Loading

0 comments on commit 4a590cb

Please sign in to comment.