Skip to content

Commit

Permalink
replace deprecated methods in neoforge and jei
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Oct 1, 2024
1 parent 31c7870 commit 45e573c
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public ItemStack finishUsingItem(@NotNull ItemStack stack, @NotNull Level worldI
if (!(entityLiving instanceof Player player)) return stack;
VampirePlayer vampire = VampirePlayer.get(player);
int amount = (vampire.getRefinementHandler().isRefinementEquipped(ModRefinements.BLOOD_CHARGE_SPEED) ? VampirismConfig.BALANCE.vrBloodChargeSpeedMod.get() : 2);
if (((Player) entityLiving).isCreative() || vampire.useBlood(amount, false)) {
if (player.isCreative() || vampire.useBlood(amount, false)) {
this.charge(stack, amount * VReference.FOOD_TO_FLUID_BLOOD);
}
if (getChargePercentage(stack) == 1) {
Expand Down Expand Up @@ -174,7 +174,7 @@ public boolean isFullyCharged(@NotNull ItemStack stack) {
}

@Override
public boolean onEntitySwing(ItemStack stack, LivingEntity entity) {
public boolean onEntitySwing(ItemStack stack, LivingEntity entity, InteractionHand hand) {
return !Helper.isVampire(entity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ public class AlchemicalCauldronRecipeCategory implements IRecipeCategory<RecipeH
this.bubbles = guiHelper.createAnimatedDrawable(bubblesDrawable, 200, IDrawableAnimated.StartDirection.BOTTOM, false);
}

private static ResourceLocation fixSprite(ResourceLocation spriteLoc) {
public static ResourceLocation fixSprite(ResourceLocation spriteLoc) {
return spriteLoc.withPrefix("textures/gui/sprites/").withSuffix(".png");
}

@Override
public void draw(@NotNull RecipeHolder<AlchemicalCauldronRecipe> holder, @NotNull IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics graphics, double mouseX, double mouseY) {
this.background.draw(graphics);
graphics.pose().pushPose();
AlchemicalCauldronRecipe recipe = holder.value();
this.flame.draw(graphics, 19, 27);
this.arrow.draw(graphics, 41, 25);
Expand All @@ -79,13 +81,17 @@ public void draw(@NotNull RecipeHolder<AlchemicalCauldronRecipe> holder, @NotNul
}
y += UtilLib.renderMultiLine(minecraft.font, graphics, skillText, 132, x, y, Color.GRAY.getRGB());
}
graphics.pose().popPose();
}

@Override
public int getHeight() {
return 103;
}

@NotNull
@Override
public IDrawable getBackground() {
return this.background;
public int getWidth() {
return 120;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package de.teamlapen.vampirism.modcompat.jei;

import de.teamlapen.lib.lib.util.UtilLib;
import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.api.entity.player.skills.ISkill;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.core.ModBlocks;
import de.teamlapen.vampirism.items.component.OilContent;
import de.teamlapen.vampirism.recipes.AlchemyTableRecipe;
import de.teamlapen.vampirism.util.OilUtils;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
Expand Down Expand Up @@ -63,10 +61,14 @@ public Component getTitle() {
return this.localizedName;
}

@NotNull
@Override
public IDrawable getBackground() {
return this.background;
public int getWidth() {
return 149;
}

@Override
public int getHeight() {
return 110;
}

@NotNull
Expand All @@ -88,6 +90,8 @@ public void setRecipe(@NotNull IRecipeLayoutBuilder builder, @NotNull RecipeHold

@Override
public void draw(@NotNull RecipeHolder<AlchemyTableRecipe> holder, IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics graphics, double mouseX, double mouseY) {
this.background.draw(graphics);
graphics.pose().pushPose();
AlchemyTableRecipe recipe = holder.value();
this.blazeHeat.draw(graphics, 33 - 9 - 2, 60 - 10 - 2);
this.arrow.draw(graphics, 73 - 9 - 2, 57 - 10 - 2);
Expand All @@ -112,5 +116,7 @@ public void draw(@NotNull RecipeHolder<AlchemyTableRecipe> holder, IRecipeSlotsV
y += UtilLib.renderMultiLine(minecraft.font, graphics, skillText, 132, x, y, Color.gray.getRGB());

}

graphics.pose().popPose();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.teamlapen.vampirism.modcompat.jei;

import de.teamlapen.vampirism.REFERENCE;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.core.ModBlocks;
import de.teamlapen.vampirism.entity.player.hunter.skills.HunterSkills;
Expand All @@ -17,7 +16,6 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

Expand All @@ -44,9 +42,15 @@ public BlessingRecipeCategory(@NotNull IGuiHelper guiHelper) {
return Component.translatable("text.vampirism.blessing");
}


@Override
public int getWidth() {
return 123;
}

@Override
public IDrawable getBackground() {
return background;
public int getHeight() {
return 79;
}

@Override
Expand All @@ -56,11 +60,14 @@ public IDrawable getIcon() {

@Override
public void draw(BlessableItem.@NotNull Recipe recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics graphics, double mouseX, double mouseY) {
background.draw(graphics);
graphics.pose().pushPose();
if (recipe.enhanced()) {
Minecraft minecraft = Minecraft.getInstance();
graphics.drawString(minecraft.font, Component.translatable("gui.vampirism.skill_required"), 15, 52, Color.gray.getRGB(), false);
graphics.drawString(minecraft.font, HunterSkills.ENHANCED_BLESSING.get().getName(), 15, 52 + minecraft.font.lineHeight + 2, Color.gray.getRGB(), false);
}
graphics.pose().popPose();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package de.teamlapen.vampirism.modcompat.jei;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import de.teamlapen.vampirism.api.util.VResourceLocation;
import de.teamlapen.vampirism.client.gui.screens.AlchemicalCauldronScreen;
import de.teamlapen.vampirism.core.ModBlocks;
import de.teamlapen.vampirism.core.ModFluids;
import de.teamlapen.vampirism.modcompat.jei.recipes.BloodSieveRecipe;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
Expand All @@ -22,8 +21,9 @@
import net.neoforged.neoforge.fluids.FluidType;
import org.jetbrains.annotations.NotNull;

import static de.teamlapen.vampirism.modcompat.jei.AlchemicalCauldronRecipeCategory.fixSprite;

public class BloodSieveRecipeCategory implements IRecipeCategory<BloodSieveRecipe> {
private static final ResourceLocation PROGRESS = VResourceLocation.loc("jei", "textures/jei/gui/gui_vanilla.png");
private static final ResourceLocation BACKGROUND = VResourceLocation.mod("textures/gui/container/blood_grinder_jei.png");
public static final int width = 78;
public static final int height = 18;
Expand All @@ -32,22 +32,15 @@ public class BloodSieveRecipeCategory implements IRecipeCategory<BloodSieveRecip
private final IDrawable slot;
private final IDrawable icon;
private final Component localizedName;
private final LoadingCache<Integer, IDrawableAnimated> cachedArrows;
private final @NotNull IDrawableAnimated arrow;

public BloodSieveRecipeCategory(IGuiHelper guiHelper) {
this.background = guiHelper.drawableBuilder(BACKGROUND, 0, 0, width, height).setTextureSize(width, height).build();
this.slot = guiHelper.getSlotDrawable();
this.icon = guiHelper.createDrawableItemStack(ModBlocks.BLOOD_SIEVE.toStack());
this.localizedName = Component.translatable("block.vampirism.blood_grinder");
this.cachedArrows = CacheBuilder.newBuilder()
.maximumSize(25)
.build(new CacheLoader<>() {
@Override
public @NotNull IDrawableAnimated load(@NotNull Integer cookTime) {
return guiHelper.drawableBuilder(PROGRESS, 82, 128, 24, 17)
.buildAnimated(cookTime, IDrawableAnimated.StartDirection.LEFT, false);
}
});
this.localizedName = Component.translatable("block.vampirism.blood_sieve");
IDrawableStatic arrowDrawable = guiHelper.drawableBuilder(fixSprite(AlchemicalCauldronScreen.BURN_PROGRESS_SPRITE), 0, 0, 24, 16).setTextureSize(24, 16).build();
this.arrow = guiHelper.createAnimatedDrawable(arrowDrawable, 200, IDrawableAnimated.StartDirection.LEFT, false);
}

@Override
Expand All @@ -61,8 +54,13 @@ public BloodSieveRecipeCategory(IGuiHelper guiHelper) {
}

@Override
public @NotNull IDrawable getBackground() {
return this.background;
public int getHeight() {
return height;
}

@Override
public int getWidth() {
return width;
}

@Override
Expand All @@ -81,7 +79,10 @@ public void setRecipe(IRecipeLayoutBuilder builder, BloodSieveRecipe recipe, @No

@Override
public void draw(@NotNull BloodSieveRecipe recipe, @NotNull IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics guiGraphics, double mouseX, double mouseY) {
this.background.draw(guiGraphics);
guiGraphics.pose().pushPose();
this.slot.draw(guiGraphics);
this.cachedArrows.getUnchecked(50).draw(guiGraphics, 26, 1);
this.arrow.draw(guiGraphics, 26, 1);
guiGraphics.pose().popPose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ public GrinderRecipeCategory(IGuiHelper guiHelper) {
}

@Override
public @NotNull IDrawable getBackground() {
return this.background;
public int getHeight() {
return height;
}

@Override
public int getWidth() {
return width;
}

@Override
Expand All @@ -61,12 +66,15 @@ public void setRecipe(IRecipeLayoutBuilder builder, GrinderRecipe recipe, @NotNu

@Override
public void draw(GrinderRecipe recipe, @NotNull IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics guiGraphics, double mouseX, double mouseY) {
this.background.draw(guiGraphics);
guiGraphics.pose().pushPose();
this.slot.draw(guiGraphics);

int blood = recipe.itemBlood().blood();

MutableComponent text = Component.translatable("gui.vampirism.jei.category.grinder.blood", blood);

guiGraphics.drawString(Minecraft.getInstance().font, text, 24, 5, 0xFF808080, false);
guiGraphics.pose().popPose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import de.teamlapen.vampirism.core.ModBlocks;
import de.teamlapen.vampirism.entity.player.hunter.skills.HunterSkills;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.ITickTimer;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
Expand Down Expand Up @@ -56,6 +55,8 @@ private static ResourceLocation fixSprite(ResourceLocation spriteLoc) {

@Override
public void draw(@NotNull JEIPotionMix recipe, @NotNull IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics graphics, double mouseX, double mouseY) {
this.background.draw(graphics);
graphics.pose().pushPose();
this.blazeHeat.draw(graphics, 1, 35);
this.bubbles.draw(graphics, 3, 4);
this.arrow.draw(graphics, 80, 10);
Expand All @@ -81,12 +82,17 @@ public void draw(@NotNull JEIPotionMix recipe, @NotNull IRecipeSlotsView recipeS
graphics.drawString(minecraft.font, HunterSkills.EFFICIENT_BREWING.get().getName(), x, y, Color.GRAY.getRGB(), false);
y += minecraft.font.lineHeight;
}
graphics.pose().popPose();
}

@Override
public int getWidth() {
return 128;
}

@NotNull
@Override
public IDrawable getBackground() {
return background;
public int getHeight() {
return 106;
}

@NotNull
Expand Down Expand Up @@ -116,21 +122,4 @@ public void setRecipe(@NotNull IRecipeLayoutBuilder builder, @NotNull JEIPotionM
builder.addSlot(RecipeIngredientRole.OUTPUT, 105, 15).addItemStack(recipe.getPotionOutput()).setBackground(this.slotDrawable, -1, -1);
}

private static class BrewingBubblesTickTimer implements ITickTimer {
private static final int[] BUBBLE_LENGTHS = new int[] {29, 23, 18, 13, 9, 5, 0};
private final @NotNull ITickTimer internalTimer;

public BrewingBubblesTickTimer(@NotNull IGuiHelper guiHelper) {
this.internalTimer = guiHelper.createTickTimer(14, BUBBLE_LENGTHS.length - 1, false);
}

public int getMaxValue() {
return BUBBLE_LENGTHS[0];
}

public int getValue() {
int timerValue = this.internalTimer.getValue();
return BUBBLE_LENGTHS[timerValue];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public TaskRecipeCategory(@NotNull IGuiHelper guiHelper) {

@Override
public void draw(@NotNull Task task, @NotNull IRecipeSlotsView recipeSlotsView, @NotNull GuiGraphics graphics, double mouseX, double mouseY) {

this.background.draw(graphics);
graphics.pose().pushPose();
Minecraft minecraft = Minecraft.getInstance();
int x = 4;
int y = 40;
Expand All @@ -66,13 +69,17 @@ public void draw(@NotNull Task task, @NotNull IRecipeSlotsView recipeSlotsView,
prerequisites.append(Component.translatable("text.vampirism.task.prerequisites.none"));
}
y += UtilLib.renderMultiLine(minecraft.font, graphics, prerequisites, 160, x, y, Color.GRAY.getRGB());
graphics.pose().popPose();
}

@Override
public int getHeight() {
return 122;
}

@NotNull
@Override
public IDrawable getBackground() {
return background;
public int getWidth() {
return 168;
}

@NotNull
Expand Down
Loading

0 comments on commit 45e573c

Please sign in to comment.