Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc bugfixes #761

Merged
merged 6 commits into from
Aug 24, 2024
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 @@ -62,9 +62,7 @@ public void onInitializeClient() {
PatchouliItems.BOOK_ID.equals(ctx.topLevelId().id()) // checks namespace and path
&& ctx.topLevelId().getVariant().equals("inventory")
&& oldModel != null) {
return new BookModel(oldModel, ctx.loader(), (model) -> {
return Minecraft.getInstance().getModelManager().getModel(model);
});
return new BookModel(oldModel, (model) -> Minecraft.getInstance().getModelManager().getModel(model));
}
return oldModel;
}
Expand Down
2 changes: 1 addition & 1 deletion NeoForge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ runs {
}

dependencies {
implementation "net.neoforged:neoforge:21.0.106-beta"
implementation "net.neoforged:neoforge:21.0.143"
implementation project(":Xplat")

compileOnly "mezz.jei:jei-1.21-common-api:19.5.0.33"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ public static void onInitializeClient(FMLClientSetupEvent evt) {
@SubscribeEvent
public static void replaceBookModel(ModelEvent.ModifyBakingResult evt) {
ModelResourceLocation key = ModelResourceLocation.inventory(PatchouliItems.BOOK_ID);
evt.getModels().computeIfPresent(key, (k, oldModel) -> new BookModel(oldModel, evt.getModelBakery(), (model) -> {
ModelResourceLocation modelPath = ModelResourceLocation.standalone(model);
return Minecraft.getInstance().getModelManager().getModel(modelPath);
}));
evt.getModels().computeIfPresent(key, (k, oldModel) -> new BookModel(oldModel, (model) -> Minecraft.getInstance().getModelManager().getModel(ModelResourceLocation.standalone(model))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@ public static NeoForgeClientPayloadHandler getInstance() {
}

public void handleData(final MessageOpenBookGui data, final IPayloadContext context) {
context.enqueueWork(() -> {
try {
ClientBookRegistry.INSTANCE.displayBookGui(data.book(), data.entry(), data.page());
})
.exceptionally(e -> {
// Handle exception
context.disconnect(Component.translatable("patchouli.networking.open_book.failed", e.getMessage()));
return null;
});
} catch (Exception e) {
context.disconnect(Component.translatable("patchouli.networking.open_book.failed", e.getMessage()));
}
}

public void handleData(final MessageReloadBookContents data, final IPayloadContext context) {
context.enqueueWork(() -> {
try {
ClientBookRegistry.INSTANCE.reload();
})
.exceptionally(e -> {
// Handle exception
context.disconnect(Component.translatable("patchouli.networking.reload_contents.failed", e.getMessage()));
return null;
});
} catch (Exception e) {
context.disconnect(Component.translatable("patchouli.networking.reload_contents.failed", e.getMessage()));
}
}
}
73 changes: 37 additions & 36 deletions Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
Expand All @@ -16,7 +15,6 @@

import vazkii.patchouli.common.book.Book;
import vazkii.patchouli.common.item.ItemModBook;
import vazkii.patchouli.mixin.client.AccessorModelBakery;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -29,42 +27,10 @@ public class BookModel implements BakedModel {
private final BakedModel original;
private final ItemOverrides itemHandler;

public BookModel(BakedModel original, ModelBakery loader, Function<ResourceLocation, BakedModel> modelGetter) {
public BookModel(BakedModel original, Function<ResourceLocation, BakedModel> modelGetter) {
this.original = original;
BlockModel missing = (BlockModel) ((AccessorModelBakery) loader).invokeGetModel(ModelBakery.MISSING_MODEL_LOCATION);

this.itemHandler = new ItemOverrides(new ModelBaker() {
// soft implement IModelBakerExtension
public Function<Material, TextureAtlasSprite> getModelTextureGetter() {
return null;
}

// soft implement IModelBakerExtension
public BakedModel bake(ResourceLocation location, ModelState state, Function<Material, TextureAtlasSprite> sprites) {
return null;
}

// soft implement IModelBakerExtension
public BakedModel bakeUncached(UnbakedModel model, ModelState state, Function<Material, TextureAtlasSprite> sprites) {
return null;
}

// soft implement IModelBakerExtension
public UnbakedModel getTopLevelModel(ModelResourceLocation location) {
return null;
}

@Override
public UnbakedModel getModel(ResourceLocation resourceLocation) {
return null;
}

@Nullable
@Override
public BakedModel bake(ResourceLocation resourceLocation, ModelState modelState) {
return null;
}
}, missing, Collections.emptyList()) {
this.itemHandler = new ItemOverrides(DummyModelBaker.INSTANCE, null, Collections.emptyList()) {
@Override
public BakedModel resolve(@NotNull BakedModel original, @NotNull ItemStack stack,
@Nullable ClientLevel world, @Nullable LivingEntity entity, int seed) {
Expand Down Expand Up @@ -119,4 +85,39 @@ public TextureAtlasSprite getParticleIcon() {
public ItemTransforms getTransforms() {
return original.getTransforms();
}

private static class DummyModelBaker implements ModelBaker {
static ModelBaker INSTANCE = new DummyModelBaker();

// soft implement IModelBakerExtension
public Function<Material, TextureAtlasSprite> getModelTextureGetter() {
return null;
}

// soft implement IModelBakerExtension
public BakedModel bake(ResourceLocation location, ModelState state, Function<Material, TextureAtlasSprite> sprites) {
return null;
}

// soft implement IModelBakerExtension
public BakedModel bakeUncached(UnbakedModel model, ModelState state, Function<Material, TextureAtlasSprite> sprites) {
return null;
}

// soft implement IModelBakerExtension
public UnbakedModel getTopLevelModel(ModelResourceLocation location) {
return null;
}

@Override
public UnbakedModel getModel(ResourceLocation resourceLocation) {
return null;
}

@Nullable
@Override
public BakedModel bake(ResourceLocation resourceLocation, ModelState modelState) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private static String[] splitStacksFromSerializedIngredient(String ingredientSer

int lastIndex = 0;
int braces = 0;
int brackets = 0;
Character insideString = null;
for (int i = 0; i < ingredientSerialized.length(); i++) {
switch (ingredientSerialized.charAt(i)) {
Expand All @@ -156,14 +157,24 @@ private static String[] splitStacksFromSerializedIngredient(String ingredientSer
braces--;
}
break;
case '[':
if (insideString == null) {
brackets++;
}
break;
case ']':
if (insideString == null) {
brackets--;
}
break;
case '\'':
insideString = insideString == null ? '\'' : null;
break;
case '"':
insideString = insideString == null ? '"' : null;
break;
case ',':
if (braces <= 0) {
if (braces <= 0 && brackets <= 0) {
result.add(ingredientSerialized.substring(lastIndex, i));
lastIndex = i + 1;
break;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vazkii.patchouli.network;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -12,26 +13,17 @@
public record MessageOpenBookGui(ResourceLocation book, @Nullable ResourceLocation entry, int page) implements CustomPacketPayload {

public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "open_book");
public static final StreamCodec<FriendlyByteBuf, MessageOpenBookGui> CODEC = CustomPacketPayload.codec(
MessageOpenBookGui::write,
MessageOpenBookGui::new);
public static final StreamCodec<FriendlyByteBuf, MessageOpenBookGui> CODEC = StreamCodec.composite(
ResourceLocation.STREAM_CODEC,
MessageOpenBookGui::book,
ByteBufCodecs.STRING_UTF8.map(entry -> entry.isEmpty() ? null : ResourceLocation.tryParse(entry), entry -> entry == null ? "" : entry.toString()),
MessageOpenBookGui::entry,
ByteBufCodecs.VAR_INT,
MessageOpenBookGui::page,
MessageOpenBookGui::new
);
public static final Type<MessageOpenBookGui> TYPE = new Type<>(ID);

public MessageOpenBookGui(FriendlyByteBuf buf) {
this(buf.readResourceLocation(), getEntry(buf), buf.readVarInt());
}

private static ResourceLocation getEntry(FriendlyByteBuf buf) {
String entry = buf.readUtf();
return entry.isEmpty() ? null : ResourceLocation.tryParse(entry);
}

public void write(FriendlyByteBuf buf) {
buf.writeResourceLocation(book);
buf.writeUtf(entry == null ? "" : entry.toString());
buf.writeVarInt(page);
}

@Override
public Type<? extends CustomPacketPayload> type() {
return TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@

public record MessageReloadBookContents() implements CustomPacketPayload {
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "reload_books");
public static final StreamCodec<FriendlyByteBuf, MessageReloadBookContents> CODEC = CustomPacketPayload.codec(
MessageReloadBookContents::write,
MessageReloadBookContents::new);
public static final StreamCodec<FriendlyByteBuf, MessageReloadBookContents> CODEC = StreamCodec.unit(new MessageReloadBookContents());
public static final Type<MessageReloadBookContents> TYPE = new Type<>(ID);

public MessageReloadBookContents(final FriendlyByteBuf packetBuffer) {
this();
}

public void write(FriendlyByteBuf buf) {}

@Override
public Type<? extends CustomPacketPayload> type() {
return TYPE;
Expand Down
1 change: 0 additions & 1 deletion Xplat/src/main/resources/patchouli_xplat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"client": [
"client.AccessorClientAdvancements",
"client.AccessorKeyMapping",
"client.AccessorModelBakery",
"client.AccessorMultiBufferSource",
"client.AccessorScreen",
"client.MixinClientAdvancements",
Expand Down
9 changes: 6 additions & 3 deletions scripts/upload_releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ function release_curseforge() {

# Hardcoded from https://minecraft.curseforge.com/api/game/versions
# I'm not betting on these changing any time soon, so hardcoding is ok
local CURSEFORGE_JAVA_VERSION=8326 # Java 17
local CURSEFORGE_JAVA_17_VERSION=8326 # Java 17
local CURSEFORGE_JAVA_21_VERSION=11135 # Java 21
local CURSEFORGE_FABRIC_VERSION=7499
local CURSEFORGE_QUILT_VERSION=9153
local CURSEFORGE_FORGE_VERSION=7498
local CURSEFORGE_NEOFORGE_VERSION=10150
local CURSEFORGE_CLIENT_VERSION=9638
Expand Down Expand Up @@ -129,10 +131,11 @@ EOF
)

local CURSEFORGE_FABRIC_GAMEVERS="[\
$CURSEFORGE_JAVA_VERSION,\
$CURSEFORGE_JAVA_21_VERSION,\
$CURSEFORGE_CLIENT_VERSION,\
$CURSEFORGE_SERVER_VERSION,\
$CURSEFORGE_FABRIC_VERSION,\
$CURSEFORGE_QUILT_VERSION,\
$CURSEFORGE_GAME_VERSION]"

CURSEFORGE_FABRIC_SPEC=$(echo "$CURSEFORGE_FABRIC_SPEC" | \
Expand All @@ -156,7 +159,7 @@ EOF
)

local CURSEFORGE_NEOFORGE_GAMEVERS="[\
$CURSEFORGE_JAVA_VERSION,\
$CURSEFORGE_JAVA_21_VERSION,\
$CURSEFORGE_CLIENT_VERSION,\
$CURSEFORGE_SERVER_VERSION,\
$CURSEFORGE_NEOFORGE_VERSION,\
Expand Down
Loading