Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -32,6 +32,7 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -55,7 +56,8 @@ protected MixinBedBlock(Settings settings) {
private void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ViaFabricPlusMixinPlugin.MORE_CULLING_PRESENT && viaFabricPlus$requireOriginalShape) {
viaFabricPlus$requireOriginalShape = false;
} else if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) {
} else if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)
|| ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
cir.setReturnValue(viaFabricPlus$shape_r1_13_2);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2025 the original authors
* - FlorianMichael/EnZaXD <[email protected]>
* - RK_01/RaphiMC
* Copyright (C) 2023-2025 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.injection.mixin.features.block.shape;

import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.block.BlockState;
import net.minecraft.block.CactusBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(CactusBlock.class)
public abstract class MixinCactusBlock {

@Unique
private static final VoxelShape viaFabricPlus$shape_bedrock = VoxelShapes.cuboid(0.025, 0, 0.025, 0.975, 1, 0.975);

@Inject(method = "getCollisionShape", at = @At(value = "RETURN"), cancellable = true)
private void modifyCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
cir.setReturnValue(viaFabricPlus$shape_bedrock);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,43 @@
import java.util.Map;
import java.util.function.Supplier;
import net.minecraft.block.AbstractChestBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.enums.ChestType;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ChestBlock.class)
public abstract class MixinChestBlock extends AbstractChestBlock<ChestBlockEntity> {

@Unique
private static final VoxelShape viaFabricPlus$single_chest_shape_bedrock = VoxelShapes.cuboid(0.025F, 0, 0.025F, 0.975F, 0.95F, 0.975F);

@Unique
private static final Map<Direction, VoxelShape> viaFabricPlus$double_chest_shapes_bedrock = Map.of(
Direction.NORTH, VoxelShapes.cuboid(0.025F, 0, 0, 0.975F, 0.95F, 0.975F),
Direction.SOUTH, VoxelShapes.cuboid(0.025F, 0, 0.025F, 0.975F, 0.95F, 1),
Direction.WEST, VoxelShapes.cuboid(0, 0, 0.025F, 0.975F, 0.95F, 0.975F),
Direction.EAST, VoxelShapes.cuboid(0.025F, 0, 0.025F, 1, 0.95F, 0.975F)
);

@Shadow
@Final
private static Map<Direction, VoxelShape> DOUBLE_SHAPES_BY_DIRECTION;
Expand All @@ -55,6 +70,15 @@ public abstract class MixinChestBlock extends AbstractChestBlock<ChestBlockEntit
@Final
private static VoxelShape SINGLE_SHAPE;

@Shadow
@Final
public static EnumProperty<ChestType> CHEST_TYPE;

@Shadow
public static Direction getFacing(final BlockState state) {
return null;
}

protected MixinChestBlock(Settings settings, Supplier<BlockEntityType<? extends ChestBlockEntity>> blockEntityTypeSupplier) {
super(settings, blockEntityTypeSupplier);
}
Expand All @@ -63,12 +87,18 @@ protected MixinChestBlock(Settings settings, Supplier<BlockEntityType<? extends
private void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)) {
cir.setReturnValue(VoxelShapes.fullCube());
} else if (ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
cir.setReturnValue(switch (state.get(CHEST_TYPE)) {
case SINGLE -> viaFabricPlus$single_chest_shape_bedrock;
case LEFT, RIGHT -> viaFabricPlus$double_chest_shapes_bedrock.get(getFacing(state));
});
}
}

@Override
public VoxelShape getCullingShape(BlockState state) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)
|| ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
if (state.get(ChestBlock.CHEST_TYPE) == ChestType.SINGLE) {
return SINGLE_SHAPE;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2025 the original authors
* - FlorianMichael/EnZaXD <[email protected]>
* - RK_01/RaphiMC
* Copyright (C) 2023-2025 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.injection.mixin.features.block.shape;

import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.block.BlockState;
import net.minecraft.block.ConduitBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ConduitBlock.class)
public abstract class MixinConduitBlock {

@Unique
private static final VoxelShape viaFabricPlus$shape_bedrock = VoxelShapes.cuboid(0.25F, 0, 0.25F, 0.75f, 0.5F, 0.75f);

@Inject(method = "getOutlineShape", at = @At(value = "RETURN"), cancellable = true)
private void modifyCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
cir.setReturnValue(viaFabricPlus$shape_bedrock);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2025 the original authors
* - FlorianMichael/EnZaXD <[email protected]>
* - RK_01/RaphiMC
* Copyright (C) 2023-2025 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.injection.mixin.features.block.shape;

import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.enums.DoorHinge;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Map;

@Mixin(DoorBlock.class)
public abstract class MixinDoorBlock {

@Unique
private static final Map<Direction, VoxelShape> viaFabricPlus$shape_bedrock = Map.of(
Direction.NORTH, VoxelShapes.cuboid(0, 0, 0, 1, 1, 0.1825F),
Direction.SOUTH, VoxelShapes.cuboid(0, 0, 0.8175F, 1, 1, 1),
Direction.WEST, VoxelShapes.cuboid(0.8175F, 0, 0, 1, 1, 1),
Direction.EAST, VoxelShapes.cuboid(0, 0, 0, 0.1825F, 1, 1)
);

@Shadow
@Final
public static EnumProperty<Direction> FACING;

@Shadow
@Final
public static BooleanProperty OPEN;

@Shadow
@Final
public static EnumProperty<DoorHinge> HINGE;

@Inject(method = "getOutlineShape", at = @At(value = "RETURN"), cancellable = true)
private void modifyCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
Direction direction = state.get(FACING);
Direction direction2 = (Boolean)state.get(OPEN) ? (state.get(HINGE) == DoorHinge.RIGHT ? direction.rotateYCounterclockwise() : direction.rotateYClockwise()) : direction;
cir.setReturnValue(viaFabricPlus$shape_bedrock.get(direction2));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -57,6 +58,9 @@ public abstract class MixinEndPortalFrameBlock extends Block {
@Unique
private static final VoxelShape viaFabricPlus$frame_with_eye_shape_r1_12_2 = VoxelShapes.union(FRAME_SHAPE, viaFabricPlus$eye_shape_r1_12_2);

@Unique
private static final VoxelShape viaFabricPlus$shape_frame_bedrock = VoxelShapes.cuboid(0, 0, 0, 1, 0.8125F, 1);

public MixinEndPortalFrameBlock(Settings settings) {
super(settings);
}
Expand All @@ -65,6 +69,9 @@ public MixinEndPortalFrameBlock(Settings settings) {
private void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
cir.setReturnValue(FRAME_SHAPE);
} else if (ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
//The eye doesn't have a different shape on bedrock
cir.setReturnValue(viaFabricPlus$shape_frame_bedrock);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package com.viaversion.viafabricplus.injection.mixin.features.block.shape;

import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.EnderChestBlock;
Expand All @@ -30,17 +31,22 @@
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(EnderChestBlock.class)
public abstract class MixinEnderChestBlock extends BlockWithEntity {

@Unique
private static final VoxelShape viaFabricPlus$shape_bedrock = VoxelShapes.cuboid(0.025F, 0, 0.025F, 0.975F, 0.95F, 0.975F);

@Shadow
@Final
private static VoxelShape SHAPE;
Expand All @@ -53,12 +59,15 @@ protected MixinEnderChestBlock(Settings settings) {
private void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable<VoxelShape> cir) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)) {
cir.setReturnValue(VoxelShapes.fullCube());
} else if (ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
cir.setReturnValue(viaFabricPlus$shape_bedrock);
}
}

@Override
public VoxelShape getCullingShape(BlockState state) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_2)
|| ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
return SHAPE;
} else {
return super.getCullingShape(state);
Expand Down
Loading