From 93ccc77ae64bf83fbdb2d69962621fb737650a21 Mon Sep 17 00:00:00 2001 From: Zepalesque <60141811+Zepalesque@users.noreply.github.com> Date: Wed, 1 Jan 2025 00:07:40 -0500 Subject: [PATCH] fix: fix shapes cache --- .../block/natural/DoubleDropsMossCarpet.java | 27 ++++++++++++++++++ .../common/accessor/MossyCarpetAccessor.java | 28 +++++++++++++++++++ src/main/resources/aether_redux.mixins.json | 1 + 3 files changed, 56 insertions(+) create mode 100644 src/main/java/net/zepalesque/redux/mixin/mixins/common/accessor/MossyCarpetAccessor.java diff --git a/src/main/java/net/zepalesque/redux/block/natural/DoubleDropsMossCarpet.java b/src/main/java/net/zepalesque/redux/block/natural/DoubleDropsMossCarpet.java index 8d38f9ce5..e520ecf9e 100644 --- a/src/main/java/net/zepalesque/redux/block/natural/DoubleDropsMossCarpet.java +++ b/src/main/java/net/zepalesque/redux/block/natural/DoubleDropsMossCarpet.java @@ -1,10 +1,16 @@ package net.zepalesque.redux.block.natural; import com.aetherteam.aether.block.AetherBlockStateProperties; +import com.google.common.collect.ImmutableMap; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.phys.shapes.VoxelShape; import net.zepalesque.redux.block.backport.MossyCarpetBlock; +import net.zepalesque.redux.mixin.mixins.common.accessor.MossyCarpetAccessor; +import net.zepalesque.redux.mixin.mixins.common.accessor.WallBlockAccessor; + +import java.util.Map; public class DoubleDropsMossCarpet extends MossyCarpetBlock { public DoubleDropsMossCarpet(Properties properties) { @@ -16,5 +22,26 @@ public DoubleDropsMossCarpet(Properties properties) { protected void createBlockStateDefinition(StateDefinition.Builder builder) { super.createBlockStateDefinition(builder); builder.add(AetherBlockStateProperties.DOUBLE_DROPS); + fixShapeMaps(); + } + + /** + * Based on the Framed Blocks mod's shape map fix for implementing a wall with additional block properties. + */ + protected void fixShapeMaps() { + MossyCarpetAccessor mossyCarpetAccessor = (MossyCarpetAccessor) this; + Map shapesCache = mossyCarpetAccessor.redux$getShapesCache(); + shapesCache = fixShapeMap(shapesCache); + mossyCarpetAccessor.redux$setShapesCache(shapesCache); + + } + + protected ImmutableMap fixShapeMap(Map map) { + ImmutableMap.Builder builder = ImmutableMap.builder(); + builder.putAll(map); + for (BlockState state : map.keySet()) { + builder.put(state.cycle(AetherBlockStateProperties.DOUBLE_DROPS), map.get(state)); + } + return builder.build(); } } diff --git a/src/main/java/net/zepalesque/redux/mixin/mixins/common/accessor/MossyCarpetAccessor.java b/src/main/java/net/zepalesque/redux/mixin/mixins/common/accessor/MossyCarpetAccessor.java new file mode 100644 index 000000000..29babe7bf --- /dev/null +++ b/src/main/java/net/zepalesque/redux/mixin/mixins/common/accessor/MossyCarpetAccessor.java @@ -0,0 +1,28 @@ +package net.zepalesque.redux.mixin.mixins.common.accessor; + +import net.minecraft.world.level.block.WallBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.VoxelShape; +import net.zepalesque.redux.block.backport.MossyCarpetBlock; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.Map; + +@Mixin(MossyCarpetBlock.class) +public interface MossyCarpetAccessor { + @Accessor("shapesCache") + Map redux$getShapesCache(); + + @Mutable + @Accessor("shapesCache") + void redux$setShapesCache(Map shapeByIndex); +/* + @Accessor("collisionShapeByIndex") + Map redux$getCollisionShapeByIndex(); + + @Mutable + @Accessor("collisionShapeByIndex") + void redux$setCollisionShapeByIndex(Map collisionShapeByIndex);*/ +} \ No newline at end of file diff --git a/src/main/resources/aether_redux.mixins.json b/src/main/resources/aether_redux.mixins.json index 5837948d7..c756933d6 100644 --- a/src/main/resources/aether_redux.mixins.json +++ b/src/main/resources/aether_redux.mixins.json @@ -9,6 +9,7 @@ "common.TabUtilMixin", "common.accessor.AetherNoiseBuildersMixin", "common.accessor.EntityAccessor", + "common.accessor.MossyCarpetAccessor", "common.accessor.WallBlockAccessor", "common.block.BlockBehaviorMixin", "common.block.QuicksoilMixin",