Skip to content

Commit

Permalink
fix: fix shapes cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Zepalesque committed Jan 1, 2025
1 parent f1092a2 commit 93ccc77
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -16,5 +22,26 @@ public DoubleDropsMossCarpet(Properties properties) {
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> 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<BlockState, VoxelShape> shapesCache = mossyCarpetAccessor.redux$getShapesCache();
shapesCache = fixShapeMap(shapesCache);
mossyCarpetAccessor.redux$setShapesCache(shapesCache);

}

protected ImmutableMap<BlockState, VoxelShape> fixShapeMap(Map<BlockState, VoxelShape> map) {
ImmutableMap.Builder<BlockState, VoxelShape> builder = ImmutableMap.builder();
builder.putAll(map);
for (BlockState state : map.keySet()) {
builder.put(state.cycle(AetherBlockStateProperties.DOUBLE_DROPS), map.get(state));
}
return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -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<BlockState, VoxelShape> redux$getShapesCache();

@Mutable
@Accessor("shapesCache")
void redux$setShapesCache(Map<BlockState, VoxelShape> shapeByIndex);
/*
@Accessor("collisionShapeByIndex")
Map<BlockState, VoxelShape> redux$getCollisionShapeByIndex();
@Mutable
@Accessor("collisionShapeByIndex")
void redux$setCollisionShapeByIndex(Map<BlockState, VoxelShape> collisionShapeByIndex);*/
}
1 change: 1 addition & 0 deletions src/main/resources/aether_redux.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"common.TabUtilMixin",
"common.accessor.AetherNoiseBuildersMixin",
"common.accessor.EntityAccessor",
"common.accessor.MossyCarpetAccessor",
"common.accessor.WallBlockAccessor",
"common.block.BlockBehaviorMixin",
"common.block.QuicksoilMixin",
Expand Down

0 comments on commit 93ccc77

Please sign in to comment.