83 lines
2.3 KiB
Java
83 lines
2.3 KiB
Java
package net.Chipperfluff.chipi.block;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.ShapeContext;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.registry.RegistryKey;
|
|
import net.minecraft.registry.RegistryKeys;
|
|
import net.minecraft.server.world.ServerWorld;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.Vec3d;
|
|
import net.minecraft.util.shape.VoxelShape;
|
|
import net.minecraft.util.shape.VoxelShapes;
|
|
import net.minecraft.world.BlockView;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.TeleportTarget;
|
|
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
|
import java.util.EnumSet;
|
|
|
|
public class ChipperPortalBlock extends Block {
|
|
|
|
public ChipperPortalBlock(Settings settings) {
|
|
super(settings);
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getCollisionShape(
|
|
BlockState state,
|
|
BlockView world,
|
|
BlockPos pos,
|
|
ShapeContext context
|
|
) {
|
|
return VoxelShapes.empty();
|
|
}
|
|
|
|
@Override
|
|
public void onEntityCollision(
|
|
BlockState state,
|
|
World world,
|
|
BlockPos pos,
|
|
Entity entity
|
|
) {
|
|
if (world.isClient) return;
|
|
if (!(entity instanceof PlayerEntity player)) return;
|
|
|
|
ServerWorld targetWorld = world.getServer().getWorld(
|
|
RegistryKey.of(
|
|
RegistryKeys.WORLD,
|
|
new Identifier("chipi", "chipi_dimension")
|
|
)
|
|
);
|
|
|
|
if (targetWorld == null) return;
|
|
|
|
TeleportTarget target = new TeleportTarget(
|
|
new Vec3d(5.5, 90, 5.5),
|
|
Vec3d.ZERO,
|
|
player.getYaw(),
|
|
player.getPitch()
|
|
);
|
|
|
|
player.teleport(
|
|
targetWorld,
|
|
5.5,
|
|
88.0,
|
|
6.5,
|
|
EnumSet.noneOf(PositionFlag.class),
|
|
player.getYaw(),
|
|
player.getPitch()
|
|
);
|
|
}
|
|
|
|
@Override
|
|
public float calcBlockBreakingDelta(BlockState state, PlayerEntity player, BlockView world, BlockPos pos) {
|
|
if (!player.isCreative()) {
|
|
return 0.0F;
|
|
}
|
|
return super.calcBlockBreakingDelta(state, player, world, pos);
|
|
}
|
|
}
|