下面列出了怎么用net.minecraft.util.shape.VoxelShape的API类实例代码及写法,或者点击链接到github查看源代码。
public boolean isOverLiquid()
{
boolean foundLiquid = false;
boolean foundSolid = false;
// check collision boxes below player
ArrayList<Box> blockCollisions = MC.world
.getBlockCollisions(MC.player,
MC.player.getBoundingBox().offset(0, -0.5, 0))
.map(VoxelShape::getBoundingBox)
.collect(Collectors.toCollection(() -> new ArrayList<>()));
for(Box bb : blockCollisions)
{
BlockPos pos = new BlockPos(bb.getCenter());
Material material = BlockUtils.getState(pos).getMaterial();
if(material == Material.WATER || material == Material.LAVA)
foundLiquid = true;
else if(material != Material.AIR)
foundSolid = true;
}
return foundLiquid && !foundSolid;
}
@Override
public void onUpdate()
{
if(!MC.player.isOnGround() || MC.options.keyJump.isPressed())
return;
if(MC.player.isSneaking() || MC.options.keySneak.isPressed())
return;
Box box = MC.player.getBoundingBox();
Box adjustedBox = box.offset(0, -0.5, 0).expand(-0.001, 0, -0.001);
Stream<VoxelShape> blockCollisions =
MC.world.getBlockCollisions(MC.player, adjustedBox);
if(blockCollisions.findAny().isPresent())
return;
MC.player.jump();
}
@Inject(at = {@At("HEAD")},
method = {
"getOutlineShape(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/ShapeContext;)Lnet/minecraft/util/shape/VoxelShape;"},
cancellable = true)
private void onGetOutlineShape(BlockView view, BlockPos pos,
ShapeContext context, CallbackInfoReturnable<VoxelShape> cir)
{
if(context == ShapeContext.absent())
return;
HackList hax = WurstClient.INSTANCE.getHax();
if(hax == null)
return;
HandNoClipHack handNoClipHack = hax.handNoClipHack;
if(!handNoClipHack.isEnabled() || handNoClipHack.isBlockInList(pos))
return;
cir.setReturnValue(VoxelShapes.empty());
}
@Inject(at = {@At("HEAD")},
method = {
"getOutlineShape(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/ShapeContext;)Lnet/minecraft/util/shape/VoxelShape;"},
cancellable = true)
private void onGetCollisionShape(BlockState blockState_1,
BlockView blockView_1, BlockPos blockPos_1,
ShapeContext entityContext_1, CallbackInfoReturnable<VoxelShape> cir)
{
EventManager events = WurstClient.INSTANCE.getEventManager();
if(events == null)
return;
CactusCollisionShapeEvent event = new CactusCollisionShapeEvent();
events.fire(event);
VoxelShape collisionShape = event.getCollisionShape();
if(collisionShape != null)
cir.setReturnValue(collisionShape);
}
@Redirect(method = "canPlace", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/World;canPlace(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/EntityContext;)Z"
))
private boolean canSpectatingPlace(World world, BlockState state, BlockPos pos, EntityContext context,
ItemPlacementContext contextOuter, BlockState stateOuter)
{
PlayerEntity player = contextOuter.getPlayer();
if (CarpetSettings.creativeNoClip && player != null && player.isCreative() && player.abilities.flying)
{
// copy from canPlace
VoxelShape voxelShape = state.getCollisionShape(world, pos, context);
return voxelShape.isEmpty() || world.intersectsEntities(player, voxelShape.offset(pos.getX(), pos.getY(), pos.getZ()));
}
return world.canPlace(state, pos, context);
}
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext context) {
if (blockState.get(AGE) == 0) {
return SMALL_SHAPE;
} else {
return blockState.get(AGE) < 3 ? LARGE_SHAPE : super.getOutlineShape(blockState, blockView, blockPos, context);
}
}
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext context) {
ArrayList<VoxelShape> shapes = new ArrayList<>();
if (blockState.get(ATTACHED_NORTH)) {
shapes.add(NORTH);
}
if (blockState.get(ATTACHED_SOUTH)) {
shapes.add(SOUTH);
}
if (blockState.get(ATTACHED_EAST)) {
shapes.add(EAST);
}
if (blockState.get(ATTACHED_WEST)) {
shapes.add(WEST);
}
if (blockState.get(ATTACHED_UP)) {
shapes.add(UP);
}
if (blockState.get(ATTACHED_DOWN)) {
shapes.add(DOWN);
}
if (shapes.isEmpty()) {
return NONE;
} else {
return VoxelShapes.union(NONE, shapes.toArray(new VoxelShape[0]));
}
}
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext context) {
ArrayList<VoxelShape> shapes = new ArrayList<>();
if (blockState.get(ATTACHED_NORTH)) {
shapes.add(NORTH);
}
if (blockState.get(ATTACHED_SOUTH)) {
shapes.add(SOUTH);
}
if (blockState.get(ATTACHED_EAST)) {
shapes.add(EAST);
}
if (blockState.get(ATTACHED_WEST)) {
shapes.add(WEST);
}
if (blockState.get(ATTACHED_UP)) {
shapes.add(UP);
}
if (blockState.get(ATTACHED_DOWN)) {
shapes.add(DOWN);
}
if (shapes.isEmpty()) {
return NONE;
} else {
return VoxelShapes.union(NONE, shapes.toArray(new VoxelShape[0]));
}
}
private static VoxelShape createShape(boolean north, boolean south, boolean east, boolean west) {
VoxelShape top1 = Block.createCuboidShape(0.0D, 13.0D, 0.0D, 2.0D, 16.0D, 16.0D);
VoxelShape top2 = Block.createCuboidShape(0.0D, 13.0D, 16.0D, 16.0D, 16.0D, 14.0D);
VoxelShape top3 = Block.createCuboidShape(16.0D, 13.0D, 16.0D, 14.0D, 16.0D, 0.0D);
VoxelShape top4 = Block.createCuboidShape(16.0D, 13.0D, 0.0D, 0.0D, 16.0D, 2.0D);
VoxelShape mTop1 = Block.createCuboidShape(6.0D, 15.0D, 2.0D, 16.0D - 6.0D, 14.0D, 16.0D - 2.0D);
VoxelShape mTop2 = Block.createCuboidShape(2.0D, 15.0D, 6.0D, 16.0D - 2.0D, 14.0D, 16.0D - 6.0D);
VoxelShape center = Block.createCuboidShape(6.0D, 15.0D, 6.0D, 10.0D, 6.0D, 10.0);
VoxelShape base = VoxelShapes.union(top1, top2, top3, top4, mTop1, mTop2, center);
if (north) {
base = VoxelShapes.union(base, Block.createCuboidShape(7.0D, 9.0D, 7.0D, 9.0D, 7.0D, 0.0D));
}
if (south) {
base = VoxelShapes.union(base, Block.createCuboidShape(7.0D, 9.0D, 9.0D, 9.0D, 7.0D, 16.0D));
}
if (east) {
base = VoxelShapes.union(base, Block.createCuboidShape(9.0D, 9.0D, 7.0D, 16.0D, 7.0D, 9.0D));
}
if (west) {
base = VoxelShapes.union(base, Block.createCuboidShape(7.0D, 9.0D, 7.0D, 0.0D, 7.0D, 9.0D));
}
return VoxelShapes.union(base);
}
private VoxelShape getShape(BlockState state) {
int index = getShapeIndex(state);
if (shape[index] != null) {
return shape[index];
}
return shape[index] = createShape(state.get(NORTH), state.get(SOUTH), state.get(EAST), state.get(WEST));
}
@Override
public VoxelShape getOutlineShape(BlockState blockState_1, BlockView blockView_1, BlockPos pos, ShapeContext context) {
Block down = blockView_1.getBlockState(pos.down()).getBlock();
if (down == GalacticraftBlocks.BASIC_SOLAR_PANEL) {
return POLE_SHAPE;
} else if (blockView_1.getBlockState(pos.down().down()).getBlock() == GalacticraftBlocks.BASIC_SOLAR_PANEL) {
return TOP_MID_SHAPE;
}
return TOP_SHAPE;
}
@Override
public VoxelShape getCollisionShape(BlockState blockState_1,
BlockView blockView_1, BlockPos blockPos_1,
ShapeContext entityContext_1)
{
HackList hax = WurstClient.INSTANCE.getHax();
if(hax != null && hax.jesusHack.shouldBeSolid())
return VoxelShapes.fullCube();
return super.getCollisionShape(blockState_1, blockView_1, blockPos_1,
entityContext_1);
}
@Inject(method = "isShapeFullCube", at = @At("HEAD"), cancellable = true)
private static void isShapeFullCube(VoxelShape voxelShape_1, CallbackInfoReturnable<Boolean> callback) {
if (ModuleManager.getModule(Xray.class).isToggled()) {
callback.setReturnValue(false);
callback.cancel();
}
}
@Inject(method = "isShapeFullCube", at = @At("HEAD"), cancellable = true)
private static void isShapeFullCube(VoxelShape voxelShape_1, CallbackInfoReturnable<Boolean> callback) {
if (ModuleManager.getModule(Xray.class).isToggled()) {
callback.setReturnValue(false);
callback.cancel();
}
}
@Inject(method = "isShapeFullCube", at = @At("HEAD"), cancellable = true)
private static void isShapeFullCube(VoxelShape voxelShape_1, CallbackInfoReturnable<Boolean> callback) {
if (ModuleManager.getModule(Xray.class).isToggled()) {
callback.setReturnValue(false);
callback.cancel();
}
}
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, ShapeContext context) {
return blockState.get(GRATING_STATE) == GratingState.UPPER ?
Block.createCuboidShape(0.0D, 14.0D, 0.0D, 16.0D, 16.0D, 16.0D) :
Block.createCuboidShape(0.0D, 6.0D, 0.0D, 16.0D, 8.0D, 16.0D);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return getShape(state);
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return getShape(state);
}
@Inject(at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;)V"), method = "generatePiece", remap = false)
private void extraDebugInfoGC(PoolStructurePiece piece, MutableObject<VoxelShape> mutableObject, int minY, int currentSize, boolean bl, CallbackInfo ci) {
if (Galacticraft.configManager.get().isDebugLogEnabled()) {
Galacticraft.logger.warn("Pool referencer: {}", piece.toString());
}
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPosition, EntityContext entityContext) {
return Y_SHAPE;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) {
return COLLISION_SHAPE;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) {
return OUTLINE_SHAPE;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView blockView, BlockPos pos, EntityContext entityContext) {
return SHAPE[state.get(BITES) - 1];
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPosition, EntityContext entityContext) {
return SHAPE;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, EntityContext entityContext) {
return SHAPE;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getCollisionShape(BlockState blockState, BlockView blockView, BlockPos blockPos, EntityContext entityContext) {
return SHAPE;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, EntityContext context) {
return VoxelShapes.empty();
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView blockView, BlockPos pos, EntityContext context) {
return SHAPE;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPosition, EntityContext entityContext) {
return SHAPE;
}
@SuppressWarnings("deprecation")
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView blockView, BlockPos pos, EntityContext context) {
return SHAPES.get(state.get(FACING));
}