Waterpicker 2021-06-05 07:03:56 -05:00
parent 63f75c0012
commit e3a5a93c6f

View file

@ -1,5 +1,6 @@
package org.dimdev.dimdoors.block.door;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import org.dimdev.dimdoors.DimensionalDoorsInitializer;
import org.dimdev.dimdoors.api.util.math.MathUtil;
import org.dimdev.dimdoors.api.util.math.TransformationMatrix3d;
@ -93,17 +94,6 @@ public class DimensionalDoorBlock extends WaterLoggableDoorBlock implements Rift
return new EntranceRiftBlockEntity(pos, state);
}
@Override
public void afterBreak(World world, PlayerEntity player, BlockPos pos, BlockState blockState, BlockEntity entity, ItemStack stack) {
if (player.isCreative() && !DimensionalDoorsInitializer.getConfig().getDoorsConfig().placeRiftsInCreativeMode) {
return;
}
if (entity instanceof EntranceRiftBlockEntity && blockState.get(HALF) == DoubleBlockHalf.LOWER) {
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
((DetachedRiftBlockEntity) world.getBlockEntity(pos)).setData(((EntranceRiftBlockEntity) entity).getData());
}
}
@Override
public EntranceRiftBlockEntity getRift(World world, BlockPos pos, BlockState state) {
BlockEntity bottomEntity;
@ -158,4 +148,16 @@ public class DimensionalDoorBlock extends WaterLoggableDoorBlock implements Rift
public boolean isTall(BlockState cachedState) {
return true;
}
static {
PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, blockEntity) -> {
if (player.isCreative() && !DimensionalDoorsInitializer.getConfig().getDoorsConfig().placeRiftsInCreativeMode) {
return;
}
if (blockEntity instanceof EntranceRiftBlockEntity && state.get(HALF) == DoubleBlockHalf.LOWER) {
world.setBlockState(pos, ModBlocks.DETACHED_RIFT.getDefaultState());
((DetachedRiftBlockEntity) world.getBlockEntity(pos)).setData(((EntranceRiftBlockEntity) blockEntity).getData());
}
});
}
}