Skip to content

Commit

Permalink
fix menuworlds with FerriteCore
Browse files Browse the repository at this point in the history
  • Loading branch information
fayer3 committed Aug 21, 2024
1 parent 3450698 commit ab0eed7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.vivecraft.client_vr.extensions;

import net.minecraft.world.level.block.state.properties.Property;

import java.util.Map;

public interface StateHolderExtension {
void vivecraft$setValues(Map<Property<?>, Comparable<?>> values);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.vivecraft.client.extensions.BufferBuilderExtension;
import org.vivecraft.client.utils.Utils;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.extensions.StateHolderExtension;
import org.vivecraft.client_vr.render.helpers.RenderHelper;
import org.vivecraft.client_vr.settings.VRSettings;
import org.vivecraft.mixin.client.renderer.RenderStateShardAccessor;
Expand Down Expand Up @@ -1776,9 +1777,10 @@ public void levelFogColor() {
private static class FluidStateWrapper extends FluidState {
private final FluidState fluidState;

@SuppressWarnings("unchecked")
public FluidStateWrapper(FluidState fluidState) {
super(fluidState.getType(), (Reference2ObjectArrayMap<Property<?>, Comparable<?>>) fluidState.getValues(), fluidState.propertiesCodec);
// need to do it this way, because FerriteCore changes the field type, which would error on a cast
super(fluidState.getType(), null, fluidState.propertiesCodec);
((StateHolderExtension) (this)).vivecraft$setValues(fluidState.getValues());

this.fluidState = fluidState;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.vivecraft.mixin.client_vr.world.level.block.state;

import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap;
import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.properties.Property;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.vivecraft.client_vr.extensions.StateHolderExtension;

import java.util.Map;

// low priority, because we want to apply before FerriteCore
@Mixin(value = StateHolder.class, priority = 500)
public class StateHolderVRMixin implements StateHolderExtension {

@Shadow
private Reference2ObjectArrayMap<Property<?>, Comparable<?>> values;

@Override
public void vivecraft$setValues(Map<Property<?>, Comparable<?>> values) {
// this cast is fine, because the supplied map always comes from a StateHolder

This comment has been minimized.

Copy link
@Techjar

Techjar Aug 21, 2024

Collaborator

This comment should more specifically state that FerriteCore modifies the type of the resulting CHECKCAST instruction.

this.values = (Reference2ObjectArrayMap<Property<?>, Comparable<?>>) values;
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/vivecraft.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ accessible class net/minecraft/world/level/biome/Biome$ClimateSettings
accessible field net/minecraft/world/level/biome/AmbientParticleSettings probability F
extendable class net/minecraft/world/level/material/FluidState
accessible field net/minecraft/world/level/block/state/StateHolder propertiesCodec Lcom/mojang/serialization/MapCodec;
# to fix an issue with FerriteCore
mutable field net/minecraft/world/level/block/state/StateHolder values Lit/unimi/dsi/fastutil/objects/Reference2ObjectArrayMap;

This comment has been minimized.

Copy link
@Techjar

Techjar Aug 21, 2024

Collaborator

You can use @Final and @Mutable on the shadowed field in the mixin instead of using the access widener.


# to init VR
accessible class net/minecraft/client/ResourceLoadStateTracker$ReloadState
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/resources/vivecraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
"client_vr.world.entity.projectile.FireworkRocketEntityVRMixin",
"client_vr.world.level.block.DoorBlockVRMixin",
"client_vr.world.level.block.FenceGateBlockVRMixin",
"client_vr.world.level.block.TrapDoorBlockVRMixin"
"client_vr.world.level.block.TrapDoorBlockVRMixin",
"client_vr.world.level.block.state.StateHolderVRMixin"
],
"minVersion": "0.8.4",
"mixins": [
Expand Down

0 comments on commit ab0eed7

Please sign in to comment.