Skip to content

Commit

Permalink
[wip] 1.20 port begins
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamefrede committed Dec 12, 2023
1 parent 0298dfb commit 85ef344
Show file tree
Hide file tree
Showing 51 changed files with 502 additions and 466 deletions.
12 changes: 6 additions & 6 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#Sun Apr 09 14:41:44 WEST 2023
mapping_channel=parchment
mod_id=psi
forge_version=43.3.0
jei_version=11.6.0.1013
forge_version=47.1.3
jei_version=15.2.0.27
build_number=101
patchy_version=1.19.2-77
patchy_version=1.20.1-83-FORGE
dir_output=../Build Output/Psi/
version=1.19
mapping_version=2022.11.27-1.19.2
version=1.20
mapping_version=2023.09.03-1.20.1
mod_name=Psi
mc_version=1.19.2
mc_version=1.20.1
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 6 additions & 4 deletions src/main/java/vazkii/psi/api/PsiAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.registries.ForgeRegistries;

import org.apache.logging.log4j.LogManager;

Expand Down Expand Up @@ -72,15 +73,16 @@ public final class PsiAPI {

public static final String MOD_ID = "psi";

public static final ResourceKey<Registry<Class<? extends SpellPiece>>> SPELL_PIECE_REGISTRY_TYPE_KEY = Registry.createRegistryKey("spell_piece_registry_type_key");
public static final ResourceKey<Registry<Class<? extends SpellPiece>>> SPELL_PIECE_REGISTRY_TYPE_KEY = ResourceKey.createRegistryKey(new ResourceLocation(MOD_ID, "spell_piece_registry_type_key"));

//private static final MappedRegistry<Class<? extends SpellPiece>> spellPieceRegistry = (MappedRegistry<Class<? extends SpellPiece>>) Registry.registerSimple(SPELL_PIECE_REGISTRY_TYPE_KEY, Lifecycle.stable(), () -> PieceTrickDebug.class);
private static final MappedRegistry<Class<? extends SpellPiece>> spellPieceRegistry = new MappedRegistry<>(SPELL_PIECE_REGISTRY_TYPE_KEY, Lifecycle.stable(), null); //TODO (circa 1.18.2): un-duct-tape this
private static final MappedRegistry<Class<? extends SpellPiece>> spellPieceRegistry = new MappedRegistry<>(SPELL_PIECE_REGISTRY_TYPE_KEY, Lifecycle.stable()); //TODO (circa 1.18.2): un-duct-tape this
private static final Multimap<ResourceLocation, Class<? extends SpellPiece>> advancementGroups = HashMultimap.create();
private static final Map<Class<? extends SpellPiece>, ResourceLocation> advancementGroupsInverse = new HashMap<>();
private static final Map<ResourceLocation, Class<? extends SpellPiece>> mainPieceForGroup = new HashMap<>();

public static final PsimetalArmorMaterial PSIMETAL_ARMOR_MATERIAL = new PsimetalArmorMaterial("psimetal", 18, new int[] { 2, 5, 6, 2 },
12, SoundEvents.ARMOR_EQUIP_IRON, 0F, () -> Ingredient.of(Registry.ITEM.get(new ResourceLocation(MOD_ID, "psimetal"))), 0.0f);
12, SoundEvents.ARMOR_EQUIP_IRON, 0F, () -> Ingredient.of(ForgeRegistries.ITEMS.getValue(new ResourceLocation(MOD_ID, "psimetal"))), 0.0f);
public static final PsimetalToolMaterial PSIMETAL_TOOL_MATERIAL = new PsimetalToolMaterial();

/**
Expand All @@ -104,7 +106,7 @@ public static void registerSpellPiece(ResourceLocation resourceLocation, Class<?
*/
public static void registerSpellPieceAndTexture(ResourceLocation id, Class<? extends SpellPiece> clazz) {
registerSpellPiece(id, clazz);
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ClientPsiAPI.registerPieceTexture(id, new ResourceLocation(id.getNamespace(), "spell/" + id.getPath())));
DistExecutor.safeRunWhenOn(Dist.CLIENT, () -> () -> ClientPsiAPI.registerPieceTexture(id, new ResourceLocation(id.getNamespace(), "spell/" + id.getPath())));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/vazkii/psi/api/internal/MathHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static LinkedHashSet<BlockPos> getBlocksAlongRay(Vec3 origin, Vec3 end, i
return positions;
}
if(origin.equals(end)) {
positions.add(new BlockPos(origin.x, origin.y, origin.z));
positions.add(new BlockPos((int) origin.x, (int) origin.y, (int) origin.z));
} else {
double endX = end.x;
double endY = end.y;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/vazkii/psi/api/internal/Vector3.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.AABB;
Expand Down Expand Up @@ -249,8 +250,10 @@ public Vec3 toVec3D() {
return new Vec3(x, y, z);
}

public Vec3i toVec3i() { return new Vec3i((int) x, (int) y, (int) z); }

public BlockPos toBlockPos() {
return new BlockPos(toVec3D());
return new BlockPos(toVec3i());
}

public double angle(Vector3 vec) {
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/vazkii/psi/api/material/PsimetalArmorMaterial.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.api.distmarker.Dist;
Expand Down Expand Up @@ -40,14 +41,15 @@ public PsimetalArmorMaterial(String nameIn, int maxDamageFactorIn, int[] damageR
this.knockbackResistance = knockbackResistance;
}


@Override
public int getDurabilityForSlot(EquipmentSlot slotIn) {
return MAX_DAMAGE_ARRAY[slotIn.getIndex()] * this.maxDamageFactor;
public int getDurabilityForType(ArmorItem.Type pType) {
return MAX_DAMAGE_ARRAY[pType.ordinal()] * this.maxDamageFactor;
}

@Override
public int getDefenseForSlot(EquipmentSlot slotIn) {
return this.damageReductionAmountArray[slotIn.getIndex()];
public int getDefenseForType(ArmorItem.Type pType) {
return this.damageReductionAmountArray[pType.ordinal()];
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.registries.ForgeRegistries;

import vazkii.psi.api.PsiAPI;

public class PsimetalToolMaterial implements Tier {
private static final LazyLoadedValue<Ingredient> REPAIR_MATERIAL = new LazyLoadedValue<>(
() -> Ingredient.of(Registry.ITEM.get(new ResourceLocation(PsiAPI.MOD_ID, "psimetal"))));
() -> Ingredient.of(ForgeRegistries.ITEMS.getValue(new ResourceLocation(PsiAPI.MOD_ID, "psimetal"))));

@Override
public int getUses() {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/vazkii/psi/api/recipe/ITrickRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

import net.minecraft.core.NonNullList;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.items.wrapper.RecipeWrapper;
import net.minecraftforge.registries.ForgeRegistries;

import vazkii.psi.api.PsiAPI;
import vazkii.psi.api.spell.piece.PieceCraftingTrick;
Expand All @@ -42,8 +44,7 @@ public interface ITrickRecipe extends Recipe<RecipeWrapper> {
Ingredient getInput();

@Override
@Nonnull
ItemStack getResultItem();
ItemStack getResultItem(RegistryAccess pRegistryAccess);

/**
* @return a recommended minimum CAD assembly that can craft this recipe, for JEI display purposes.
Expand All @@ -53,7 +54,7 @@ public interface ITrickRecipe extends Recipe<RecipeWrapper> {
@Nonnull
@Override
default RecipeType<?> getType() {
return Registry.RECIPE_TYPE.get(TYPE_ID);
return ForgeRegistries.RECIPE_TYPES.getValue(TYPE_ID);
}

@Nonnull
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/vazkii/psi/api/spell/SpellPiece.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.math.Matrix4f;

import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.screens.Screen;
Expand All @@ -32,6 +31,8 @@
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.ModList;

import org.joml.Matrix4f;

import vazkii.psi.api.ClientPsiAPI;
import vazkii.psi.api.PsiAPI;
import vazkii.psi.api.internal.PsiRenderHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void clientTick(TickEvent.ClientTickEvent event) {
if(event.phase == TickEvent.Phase.START) {

boolean pressed = mc.options.keyJump.consumeClick();
if(mc.player != null && pressed && (!lastJumpKeyState && !mc.player.isOnGround())) {
if(mc.player != null && pressed && (!lastJumpKeyState && !mc.player.onGround())) {
PsiArmorEvent.post(new PsiArmorEvent(mc.player, PsiArmorEvent.JUMP));
MessageRegister.HANDLER.sendToServer(new MessageTriggerJumpSpell());
}
Expand Down
73 changes: 36 additions & 37 deletions src/main/java/vazkii/psi/client/core/handler/HUDHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -108,7 +108,7 @@ private static boolean showsBar(PlayerData data, ItemStack stack) {
}

@OnlyIn(Dist.CLIENT)
public static void drawPsiBar(PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) {
public static void drawPsiBar(GuiGraphics graphics, float partialTick, int screenWidth, int screenHeight) {
Minecraft mc = Minecraft.getInstance();
ItemStack cadStack = PsiAPI.getPlayerCAD(mc.player);

Expand All @@ -128,7 +128,7 @@ public static void drawPsiBar(PoseStack poseStack, float partialTick, int screen
return;
}

poseStack.pushPose();
graphics.pose().pushPose();

boolean right = ConfigHandler.CLIENT.psiBarOnRight.get();

Expand All @@ -149,8 +149,7 @@ public static void drawPsiBar(PoseStack poseStack, float partialTick, int screen
}

RenderSystem.enableBlend();
RenderSystem.setShaderTexture(0, psiBar);
GuiComponent.blit(poseStack, x, y, 0, 0, width, height, 64, 256);
graphics.blit(psiBar, x, y, 0, 0, width, height, 64, 256);

x += 8;
y += 26;
Expand Down Expand Up @@ -184,7 +183,7 @@ public static void drawPsiBar(PoseStack poseStack, float partialTick, int screen
y = origY + v;

usePsiBarShader(a, d.shatter, data.overflowed);
GuiComponent.blit(poseStack, x, y, 32, v, width, height, 64, 256);
graphics.blit(psiBar, x, y, 32, v, width, height, 64, 256);
}

float textY = origY;
Expand All @@ -206,12 +205,12 @@ public static void drawPsiBar(PoseStack poseStack, float partialTick, int screen

RenderSystem.setShaderColor(r, g, b, 1F);
usePsiBarShader(1F, false, data.overflowed);
GuiComponent.blit(poseStack, x, y, 32, v, width, height, 64, 256);
graphics.blit(psiBar, x, y, 32, v, width, height, 64, 256);

RenderSystem.setShaderColor(1F, 1F, 1F, 1F);

poseStack.pushPose();
poseStack.translate(0F, textY, 0F);
graphics.pose().pushPose();
graphics.pose().translate(0F, textY, 0F);
width = 44;
height = 3;

Expand All @@ -235,22 +234,22 @@ public static void drawPsiBar(PoseStack poseStack, float partialTick, int screen
PsiRenderHelper.g(color) / 255F,
PsiRenderHelper.b(color) / 255F, 1F);

GuiComponent.blit(poseStack, x - offBar, -2, 0, 140, width, height, 64, 256);
mc.font.drawShadow(poseStack, s1, x - offStr1, -11, 0xFFFFFF);
poseStack.popPose();
graphics.blit(psiBar, x - offBar, -2, 0, 140, width, height, 64, 256);
graphics.drawString(mc.font, s1, x - offStr1, -11, 0xFFFFFF, true);
graphics.pose().popPose();

if(storedPsi != -1) {
poseStack.pushPose();
poseStack.translate(0F, Math.max(textY + 3, origY + 100), 0F);
mc.font.drawShadow(poseStack, s2, x - offStr2, 0, 0xFFFFFF);
poseStack.popPose();
graphics.pose().pushPose();
graphics.pose().translate(0F, Math.max(textY + 3, origY + 100), 0F);
graphics.drawString(mc.font, s2, x - offStr2, 0, 0xFFFFFF, true);
graphics.pose().popPose();
}
RenderSystem.disableBlend();
poseStack.popPose();
graphics.pose().popPose();
}

@OnlyIn(Dist.CLIENT)
private static void renderSocketableEquippedName(PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) {
private static void renderSocketableEquippedName(GuiGraphics graphics, float partialTick, int screenWidth, int screenHeight) {
Minecraft mc = Minecraft.getInstance();
ItemStack stack = mc.player.getItemInHand(InteractionHand.MAIN_HAND);
if(!ISocketable.isSocketable(stack)) {
Expand All @@ -277,19 +276,19 @@ private static void renderSocketableEquippedName(PoseStack poseStack, float part
y += 14;
}

mc.font.drawShadow(poseStack, name, x, y, color);
graphics.drawString(mc.font, name, x, y, color, true);

int w = mc.font.width(name);
poseStack.pushPose();
poseStack.translate(x + w, y - 6, 0);
poseStack.scale(alpha / 255F, 1F, 1);
PsiRenderHelper.transferMsToGl(poseStack, () -> mc.getItemRenderer().renderGuiItem(bullet, 0, 0));
poseStack.popPose();
graphics.pose().pushPose();
graphics.pose().translate(x + w, y - 6, 0);
graphics.pose().scale(alpha / 255F, 1F, 1);
graphics.renderFakeItem(bullet, 0, 0);
graphics.pose().popPose();
}
}

@OnlyIn(Dist.CLIENT)
private static void renderRemainingItems(PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) {
private static void renderRemainingItems(GuiGraphics graphics, float partialTick, int screenWidth, int screenHeight) {
if(remainingTime > 0 && !remainingDisplayStack.isEmpty()) {
int pos = maxRemainingTicks - remainingTime;
Minecraft mc = Minecraft.getInstance();
Expand All @@ -302,12 +301,12 @@ private static void renderRemainingItems(PoseStack poseStack, float partialTick,

RenderSystem.setShaderColor(1F, 1F, 1F, alpha);
int xp = x + (int) (16F * (1F - alpha));
poseStack.pushPose();
poseStack.translate(xp, y, 0F);
poseStack.scale(alpha, 1F, 1F);
PsiRenderHelper.transferMsToGl(poseStack, () -> mc.getItemRenderer().renderAndDecorateItem(remainingDisplayStack, 0, 0));
poseStack.scale(1F / alpha, 1F, 1F);
poseStack.translate(-xp, -y, 0F);
graphics.pose().pushPose();
graphics.pose().translate(xp, y, 0F);
graphics.pose().scale(alpha, 1F, 1F);
graphics.renderFakeItem(remainingDisplayStack, 0, 0);
graphics.pose().scale(1F / alpha, 1F, 1F);
graphics.pose().translate(-xp, -y, 0F);
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);

String text = remainingDisplayStack.getHoverName().plainCopy().withStyle(ChatFormatting.GREEN).getString();
Expand All @@ -328,23 +327,23 @@ private static void renderRemainingItems(PoseStack poseStack, float partialTick,
}

int color = 0x00FFFFFF | (int) (alpha * 0xFF) << 24;
mc.font.drawShadow(poseStack, text, x + 20, y + 6, color);
graphics.drawString(mc.font, text, x + 20, y + 6, color, true);

poseStack.popPose();
graphics.pose().popPose();
}
}

@OnlyIn(Dist.CLIENT)
private static void renderHUDItem(PoseStack poseStack, float partialTicks, int screenWidth, int screenHeight) {
private static void renderHUDItem(GuiGraphics graphics, float partialTicks, int screenWidth, int screenHeight) {
Minecraft mc = Minecraft.getInstance();
ItemStack stack = mc.player.getMainHandItem();
if(!stack.isEmpty() && stack.getItem() instanceof IHUDItem) {
((IHUDItem) stack.getItem()).drawHUD(poseStack, partialTicks, screenWidth, screenHeight, stack);
((IHUDItem) stack.getItem()).drawHUD(graphics, partialTicks, screenWidth, screenHeight, stack);
}

stack = mc.player.getOffhandItem();
if(!stack.isEmpty() && stack.getItem() instanceof IHUDItem) {
((IHUDItem) stack.getItem()).drawHUD(poseStack, partialTicks, screenWidth, screenHeight, stack);
((IHUDItem) stack.getItem()).drawHUD(graphics, partialTicks, screenWidth, screenHeight, stack);
}
}

Expand All @@ -358,7 +357,7 @@ public static void setRemaining(Player player, ItemStack displayStack, Pattern p
int count = 0;
for(int i = 0; i < player.getInventory().getContainerSize(); i++) {
ItemStack stack = player.getInventory().getItem(i);
if(!stack.isEmpty() && (pattern == null ? ItemStack.isSame(displayStack, stack) : pattern.matcher(stack.getDescriptionId()).find())) {
if(!stack.isEmpty() && (pattern == null ? ItemStack.isSameItem(displayStack, stack) : pattern.matcher(stack.getDescriptionId()).find())) {
count += stack.getCount();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class ShaderHandler {
@SubscribeEvent
static void registerShaders(RegisterShadersEvent event) throws IOException {
event.registerShader(
new ShaderInstance(event.getResourceManager(), new ResourceLocation(LibMisc.MOD_ID, LibResources.SHADER_PSI_BAR), DefaultVertexFormat.POSITION_TEX_COLOR),
new ShaderInstance(event.getResourceProvider(), new ResourceLocation(LibMisc.MOD_ID, LibResources.SHADER_PSI_BAR), DefaultVertexFormat.POSITION_TEX_COLOR),
shader -> psiBarShader = shader
);
}
Expand Down
Loading

0 comments on commit 85ef344

Please sign in to comment.