Refactor Carpet's sticky blocks code (#1505)

refactor sticky blocks code
This commit is contained in:
Space Walker authored and GitHub committed 2022-09-03 22:49:01 +02:00
1 parent fce4918c87
commit c528695d1a
9 files changed
+290 -315

No files matched your search

@@ -0,0 +1,45 @@
package carpet.mixins;
import org.spongepowered.asm.mixin.Mixin;
import carpet.CarpetSettings;
import carpet.fakes.BlockBehaviourInterface;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.ChestType;
@Mixin(ChestBlock.class)
public class ChestBlock_customStickyMixin implements BlockBehaviourInterface {
@Override
public boolean isSticky(BlockState state) {
return CarpetSettings.movableBlockEntities;
}
@Override
public boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir) {
if (!neighborState.is((Block)(Object)this)) {
return false;
}
ChestType type = state.getValue(ChestBlock.TYPE);
ChestType neighborType = neighborState.getValue(ChestBlock.TYPE);
if (type == ChestType.SINGLE || neighborType == ChestType.SINGLE) {
return false;
}
if (type != neighborType.getOpposite()) {
return false;
}
Direction facing = state.getValue(ChestBlock.FACING);
Direction neighborFacing = state.getValue(ChestBlock.FACING);
return facing == neighborFacing;
}
}