Skip to content

Commit

Permalink
ported to 24w14potato
Browse files Browse the repository at this point in the history
Quilt Mappings for 24w12a are used as it is closest to 24w14potato
  • Loading branch information
UnlikePaladin committed Apr 3, 2024
1 parent 631e415 commit 104221c
Show file tree
Hide file tree
Showing 39 changed files with 264 additions and 169 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
}

architectury {
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {

dependencies {
mappings loom.layered {
mappings("org.quiltmc:quilt-mappings:$minecraft_version+build.$mappings:intermediary-v2")
mappings("org.quiltmc:quilt-mappings:24w12a+build.$mappings:intermediary-v2")
officialMojangMappings()
}

Expand Down
13 changes: 13 additions & 0 deletions common/src/main/java/org/figuramc/figura/ducks/GameEffects.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.figuramc.figura.ducks;

import net.minecraft.resources.ResourceLocation;

// Mojang no longer ships the effects field in GameRenderer, instead statically calling the shaders themselves
public interface GameEffects {

static ResourceLocation[] getEffects() {
return EFFECTS;
}

ResourceLocation[] EFFECTS = new ResourceLocation[]{new ResourceLocation("shaders/post/notch.json"), new ResourceLocation("shaders/post/fxaa.json"), new ResourceLocation("shaders/post/art.json"), new ResourceLocation("shaders/post/bumpy.json"), new ResourceLocation("shaders/post/blobs2.json"), new ResourceLocation("shaders/post/pencil.json"), new ResourceLocation("shaders/post/color_convolve.json"), new ResourceLocation("shaders/post/deconverge.json"), new ResourceLocation("shaders/post/flip.json"), new ResourceLocation("shaders/post/invert.json"), new ResourceLocation("shaders/post/ntsc.json"), new ResourceLocation("shaders/post/outline.json"), new ResourceLocation("shaders/post/phosphor.json"), new ResourceLocation("shaders/post/scan_pincushion.json"), new ResourceLocation("shaders/post/sobel.json"), new ResourceLocation("shaders/post/bits.json"), new ResourceLocation("shaders/post/desaturate.json"), new ResourceLocation("shaders/post/green.json"), new ResourceLocation("shaders/post/blur.json"), new ResourceLocation("shaders/post/wobble.json"), new ResourceLocation("shaders/post/blobs.json"), new ResourceLocation("shaders/post/antialias.json"), new ResourceLocation("shaders/post/creeper.json"), new ResourceLocation("shaders/post/spider.json")};
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,9 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {

return super.keyPressed(keyCode, scanCode, modifiers);
}

// No blur in our screens!
@Override
protected void renderBlurredBackground(float tickDelta) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public void removed() {
}

@Override
public void renderBackground(GuiGraphics gui, float delta) {
super.renderBackground(gui, delta);
public void renderOverlays(GuiGraphics gui, int mouseX, int mouseY, float delta) {
super.renderOverlays(gui, mouseX, mouseY, delta);
if (renderPaperdoll)
UIHelper.renderWithoutScissors(gui, g -> PaperDoll.render(g, true));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.figuramc.figura.lua;

import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component;
import org.figuramc.figura.lua.docs.FiguraDocsManager;
import org.figuramc.figura.lua.docs.LuaTypeDoc;
Expand Down Expand Up @@ -331,7 +332,7 @@ else if (val instanceof Collection<?> collection)
else if (val.getClass().isArray())
return wrapArray(val);
else if (val instanceof Component c)
return LuaValue.valueOf(Component.Serializer.toJson(c));
return LuaValue.valueOf(Component.Serializer.toJson(c, RegistryAccess.EMPTY));
else
return wrap(val);
}
Expand Down
29 changes: 29 additions & 0 deletions common/src/main/java/org/figuramc/figura/lua/NbtToLua.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package org.figuramc.figura.lua;

import com.mojang.serialization.DynamicOps;
import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.*;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import org.figuramc.figura.lua.api.world.WorldAPI;
import org.luaj.vm2.LuaTable;
import org.luaj.vm2.LuaValue;

import java.util.HashMap;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;

public class NbtToLua {

Expand Down Expand Up @@ -59,4 +71,21 @@ public static LuaValue convert(Tag tag) {

return builder.apply(tag);
}

public static CompoundTag convertToNbt(DataComponentMap components) {
if (components == null)
return null;

CompoundTag tag = new CompoundTag();
DynamicOps<Tag> dynamicOps = WorldAPI.getCurrentWorld().registryAccess().createSerializationContext(NbtOps.INSTANCE);
components.forEach(typedDataComponent -> {
Optional<Tag> optional = typedDataComponent.encodeValue(dynamicOps).result();
ResourceLocation resourceLocation = BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(typedDataComponent.type());
if (optional.isPresent() && resourceLocation != null){
tag.put(resourceLocation.toString(), optional.get());
}
});

return tag;
}
}
4 changes: 2 additions & 2 deletions common/src/main/java/org/figuramc/figura/lua/api/HostAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public List<Map<String, Object>> getStatusEffects() {

for (MobEffectInstance effect : player.getActiveEffects()) {
Map<String, Object> map = new HashMap<>();
map.put("name", effect.getEffect().getDescriptionId());
map.put("name", effect.getEffect().getRegisteredName());
map.put("amplifier", effect.getAmplifier());
map.put("duration", effect.getDuration());
map.put("visible", effect.isVisible());
Expand Down Expand Up @@ -587,7 +587,7 @@ public boolean isFlying() {
@LuaWhitelist
@LuaMethodDoc("host.get_reach_distance")
public double getReachDistance() {
return this.minecraft.gameMode == null ? 0 : this.minecraft.gameMode.getPickRange();
return this.minecraft.gameMode == null ? 0 : this.minecraft.player.blockInteractionRange();
}

@LuaWhitelist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public float getEyeHeight() {
public FiguraVec3 getBoundingBox() {
checkEntity();
EntityDimensions dim = entity.getDimensions(entity.getPose());
return FiguraVec3.of(dim.width, dim.height, dim.width);
return FiguraVec3.of(dim.width(), dim.height(), dim.width());
}

@LuaWhitelist
Expand Down Expand Up @@ -328,10 +328,12 @@ public ItemStackAPI getItem(int index) {
return null;

int i = 0;
for (ItemStack item : entity.getAllSlots()) {
if (i == index)
return ItemStackAPI.verify(item);
i++;
if (entity instanceof LivingEntity) {
for (ItemStack item : ((LivingEntity) entity).getAllSlots()) {
if (i == index)
return ItemStackAPI.verify(item);
i++;
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.figuramc.figura.lua.api.entity;

import net.minecraft.tags.EntityTypeTags;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MobType;
import org.figuramc.figura.lua.LuaWhitelist;
import org.figuramc.figura.lua.api.world.ItemStackAPI;
import org.figuramc.figura.lua.docs.LuaMethodDoc;
Expand Down Expand Up @@ -186,14 +187,14 @@ public boolean isSensitiveToWater() {
public String getEntityCategory() {
checkEntity();

MobType mobType = entity.getMobType(); // why it is not an enum
if (mobType == MobType.ARTHROPOD)
EntityType<?> mobType = entity.getType(); // why it is not an enum
if (mobType.is(EntityTypeTags.ARTHROPOD))
return "ARTHROPOD";
if (mobType == MobType.UNDEAD)
if (mobType.is(EntityTypeTags.UNDEAD))
return "UNDEAD";
if (mobType == MobType.WATER)
if (mobType.is(EntityTypeTags.AQUATIC))
return "WATER";
if (mobType == MobType.ILLAGER)
if (mobType.is(EntityTypeTags.ILLAGER))
return "ILLAGER";

return "UNDEFINED";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.Particle;
import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.registries.BuiltInRegistries;
import org.figuramc.figura.avatar.Avatar;
Expand Down Expand Up @@ -37,7 +38,7 @@ public static ParticleEngineAccessor getParticleEngine() {

private LuaParticle generate(String id, double x, double y, double z, double w, double t, double h) {
try {
ParticleOptions options = ParticleArgument.readParticle(new StringReader(id), BuiltInRegistries.PARTICLE_TYPE.asLookup());
ParticleOptions options = ParticleArgument.readParticle(new StringReader(id), (HolderLookup.Provider) BuiltInRegistries.PARTICLE_TYPE.asLookup());
Particle p = getParticleEngine().figura$makeParticle(options, x, y, z, w, t, h);
if (p == null) throw new LuaError("Could not parse particle \"" + id + "\"");
return new LuaParticle(id, p, owner);
Expand Down Expand Up @@ -106,7 +107,7 @@ public ParticleAPI removeParticles() {
)
public boolean isPresent(String id) {
try {
ParticleOptions options = ParticleArgument.readParticle(new StringReader(id), BuiltInRegistries.PARTICLE_TYPE.asLookup());
ParticleOptions options = ParticleArgument.readParticle(new StringReader(id), (HolderLookup.Provider) BuiltInRegistries.PARTICLE_TYPE.asLookup());
return getParticleEngine().figura$makeParticle(options, 0, 0, 0, 0, 0, 0) != null;
} catch (Exception ignored) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ public List<String> getFluidTags() {
@LuaMethodDoc("blockstate.get_entity_data")
public LuaTable getEntityData() {
BlockEntity entity = WorldAPI.getCurrentWorld().getBlockEntity(getBlockPos());
return (LuaTable) NbtToLua.convert(entity != null ? entity.saveWithoutMetadata() : null);
return (LuaTable) NbtToLua.convert(entity != null ? entity.saveWithoutMetadata(WorldAPI.getCurrentWorld().registryAccess()) : null);
}

@LuaWhitelist
@LuaMethodDoc("blockstate.to_state_string")
public String toStateString() {
BlockEntity entity = WorldAPI.getCurrentWorld().getBlockEntity(getBlockPos());
CompoundTag tag = entity != null ? entity.saveWithoutMetadata() : new CompoundTag();
CompoundTag tag = entity != null ? entity.saveWithoutMetadata(WorldAPI.getCurrentWorld().registryAccess()) : new CompoundTag();

return BlockStateParser.serialize(blockState) + tag;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.figuramc.figura.lua.api.world;

import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -51,7 +53,7 @@ public static ItemStackAPI verify(ItemStack itemStack) {
public ItemStackAPI(ItemStack itemStack) {
this.itemStack = itemStack;
this.id = BuiltInRegistries.ITEM.getKey(itemStack.getItem()).toString();
this.tag = new ReadOnlyLuaTable(itemStack.getTag() != null ? NbtToLua.convert(itemStack.getTag()) : new LuaTable());
this.tag = new ReadOnlyLuaTable(itemStack.getComponents() != null ? NbtToLua.convert(NbtToLua.convertToNbt(itemStack.getComponents())) : new LuaTable());
}

@LuaWhitelist
Expand Down Expand Up @@ -116,7 +118,7 @@ public boolean isBlockItem() {
@LuaWhitelist
@LuaMethodDoc("itemstack.is_food")
public boolean isFood() {
return itemStack.isEdible();
return itemStack.getComponents().has(DataComponents.FOOD);
}

@LuaWhitelist
Expand Down Expand Up @@ -170,7 +172,7 @@ public boolean isStackable() {
@LuaWhitelist
@LuaMethodDoc("itemstack.get_repair_cost")
public int getRepairCost() {
return itemStack.getBaseRepairCost();
return itemStack.get(DataComponents.REPAIR_COST);
}

@LuaWhitelist
Expand All @@ -185,7 +187,7 @@ public String toStackString() {
ItemStack stack = itemStack;
String ret = BuiltInRegistries.ITEM.getKey(stack.getItem()).toString();

CompoundTag nbt = stack.getTag();
CompoundTag nbt = NbtToLua.convertToNbt(stack.getComponents());
if (nbt != null)
ret += nbt.toString();

Expand Down Expand Up @@ -234,8 +236,8 @@ public boolean __eq(ItemStackAPI other) {
if (!t.is(o.getItem()))
return false;

CompoundTag tag1 = t.getTag();
CompoundTag tag2 = o.getTag();
DataComponentMap tag1 = t.getComponents();
DataComponentMap tag2 = o.getComponents();
if (tag1 == null && tag2 != null)
return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.figuramc.figura.FiguraMod;
import org.figuramc.figura.animation.Animation;
import org.figuramc.figura.mixin.input.KeyMappingAccessor;
import org.figuramc.figura.mixin.render.GameRendererAccessor;
import org.figuramc.figura.ducks.GameEffects;
import org.figuramc.figura.model.ParentType;
import org.figuramc.figura.model.rendering.EntityRenderMode;
import org.figuramc.figura.model.rendering.texture.FiguraTextureSet;
Expand All @@ -29,7 +29,6 @@
import org.figuramc.figura.utils.FiguraClientCommandSource;
import org.figuramc.figura.utils.FiguraText;

import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Supplier;

Expand Down Expand Up @@ -70,7 +69,7 @@ public class FiguraListDocs {
add(value.name());
}};
private static final LinkedHashSet<String> POST_EFFECTS = new LinkedHashSet<>() {{
for (ResourceLocation effect : GameRendererAccessor.getEffects()) {
for (ResourceLocation effect : GameEffects.getEffects()) {
String[] split = effect.getPath().split("/");
String name = split[split.length - 1];
add(name.split("\\.")[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public abstract class FontSetMixin {
@Unique
int figura$codePoint = -1;

//method_27545 for fabric intermediary, m_232558_ for SRG, lambda$setGlyphProviders$5 unmapped for OF, i had dig at the bytecode for this one
@Inject(method = {"method_27545", "m_232558_", "lambda$setGlyphProviders$5"}, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/font/GlyphInfo;getAdvance(Z)F", shift = At.Shift.BEFORE, remap = true), locals = LocalCapture.CAPTURE_FAILEXCEPTION, remap = false)
//method_57035 for fabric intermediary
@Inject(method = {"method_57035"}, at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/font/GlyphInfo;getAdvance(Z)F", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
public void thing(List<?> list, Set<?> set, int i, CallbackInfo ci, Iterator<?> var4, GlyphProvider glyphProvider, GlyphInfo glyphInfo) {
if (figura$isEmojiFont() && glyphInfo instanceof BitmapProvider.Glyph) {
((BitmapProviderGlyphAccessor) glyphInfo).figura$setAdvance(8);
Expand All @@ -59,8 +59,8 @@ public BakedGlyph insertDataIntoBakedGlyph(FontTexture instance, SheetGlyphInfo
return glyph;
}

@Inject(method = "reload", at = @At("HEAD"))
public void reload(List<GlyphProvider> fonts, CallbackInfo ci) {
@Inject(method = "reload(Ljava/util/Set;)V", at = @At("HEAD"))
public void reload(CallbackInfo ci) {
figura$codePoint = -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.GuiMessage;
import net.minecraft.client.GuiMessageTag;
import net.minecraft.client.gui.components.ChatComponent;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MessageSignature;
import org.figuramc.figura.FiguraMod;
Expand Down Expand Up @@ -48,7 +49,7 @@ private Component addMessage(Component message, Component msg, MessageSignature
// receive event
Avatar localPlayer = AvatarManager.getAvatarForPlayer(FiguraMod.getLocalPlayerUUID());
if (localPlayer != null) {
String json = Component.Serializer.toJson(message);
String json = Component.Serializer.toJson(message, RegistryAccess.EMPTY);

Pair<String, Integer> event = localPlayer.chatReceivedMessageEvent(message.getString(), json);
if (event != null) {
Expand Down
10 changes: 5 additions & 5 deletions common/src/main/java/org/figuramc/figura/mixin/gui/GuiMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private void afterRender(GuiGraphics guiGraphics, float tickDelta, CallbackInfo
}

@Inject(at = @At("HEAD"), method = "renderCrosshair", cancellable = true)
private void renderCrosshair(GuiGraphics guiGraphics, CallbackInfo ci) {
private void renderCrosshair(GuiGraphics guiGraphics, float delta, CallbackInfo ci) {
crosshairOffset = null;

if (ActionWheel.isEnabled()) {
Expand All @@ -59,29 +59,29 @@ private void renderCrosshair(GuiGraphics guiGraphics, CallbackInfo ci) {
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V"), method = "renderCrosshair")
private void blitRenderCrosshair(GuiGraphics guiGraphics, CallbackInfo ci) {
private void blitRenderCrosshair(GuiGraphics guiGraphics, float delta, CallbackInfo ci) {
if (crosshairOffset != null) {
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(crosshairOffset.x, crosshairOffset.y, 0d);
}
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", shift = At.Shift.AFTER), method = "renderCrosshair")
private void afterBlitRenderCrosshair(GuiGraphics guiGraphics, CallbackInfo ci) {
private void afterBlitRenderCrosshair(GuiGraphics guiGraphics, float delta, CallbackInfo ci) {
if (crosshairOffset != null)
guiGraphics.pose().popPose();
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIIIIIII)V"), method = "renderCrosshair")
private void blitRenderCrosshairSliced(GuiGraphics guiGraphics, CallbackInfo ci) {
private void blitRenderCrosshairSliced(GuiGraphics guiGraphics, float delta, CallbackInfo ci) {
if (crosshairOffset != null) {
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(crosshairOffset.x, crosshairOffset.y, 0d);
}
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIIIIIII)V", shift = At.Shift.AFTER), method = "renderCrosshair")
private void afterBlitRenderCrosshairSliced(GuiGraphics guiGraphics, CallbackInfo ci) {
private void afterBlitRenderCrosshairSliced(GuiGraphics guiGraphics, float delta, CallbackInfo ci) {
if (crosshairOffset != null)
guiGraphics.pose().popPose();
}
Expand Down
Loading

0 comments on commit 104221c

Please sign in to comment.