下面列出了怎么用net.minecraft.util.BlockPos的API类实例代码及写法,或者点击链接到github查看源代码。
public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
if (args.length == 1) {
if (main.isDevMode()) {
return getListOfStringsMatchingLastWord(args, "set", "edit", "folder", "dev", "sidebar", "brand");
} else {
return getListOfStringsMatchingLastWord(args, "set", "edit", "folder", "dev");
}
} else if (args.length == 2) {
if (main.isDevMode() && args[1].equalsIgnoreCase("sidebar")) {
return getListOfStringsMatchingLastWord(args, "formatted");
} else if (args[1].equalsIgnoreCase("set")) {
return getListOfStringsMatchingLastWord(args, "total", "zealots", "eyes");
}
}
return null;
}
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public void addCollisionBoxesToList(World world, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity entity) {
Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos));
blockInstance.components.getOp(Collider.class).ifPresent(
collider -> {
Set<Cuboid> boxes = collider.occlusionBoxes.apply(Optional.ofNullable(entity != null ? EntityConverter.instance().toNova(entity) : null));
list.addAll(
boxes
.stream()
.map(c -> c.add(VectorConverter.instance().toNova(pos)))
.filter(c -> c.intersects(CuboidConverter.instance().toNova(mask)))
.map(CuboidConverter.instance()::toNative)
.collect(Collectors.toList())
);
}
);
}
/**
* @author CCBlueX
*/
@Overwrite
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
final IBlockState iblockstate = worldIn.getBlockState(pos);
if(iblockstate.getBlock() instanceof BlockLadder) {
final FastClimb fastClimb = (FastClimb) LiquidBounce.moduleManager.getModule(FastClimb.class);
final float f = fastClimb.getState() && fastClimb.getModeValue().get().equalsIgnoreCase("AAC3.0.0") ? 0.99f : 0.125f;
switch(iblockstate.getValue(FACING)) {
case NORTH:
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
break;
case SOUTH:
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
break;
case WEST:
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case EAST:
default:
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}
}
}
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
if(!playerIn.isSneaking())
{
if(stack.getTagCompound() == null)
{
stack.setTagCompound(new NBTTagCompound());
}
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("dim", playerIn.dimension);
nbt.setInteger("posX", pos.getX());
nbt.setInteger("posY", pos.getY());
nbt.setInteger("posZ", pos.getZ());
stack.getTagCompound().setTag("coords", nbt);
stack.setStackDisplayName(EnumChatFormatting.DARK_PURPLE + "Coordinate Cache");
}
return false;
}
@EventTarget
public void onRender3D(final Render3DEvent event) {
final Color color = colorRainbow.get() ? ColorUtils.rainbow() : new Color(colorRedValue.get(), colorGreenValue.get(), colorBlueValue.get());
for(final Entity entity : mc.theWorld.loadedEntityList) {
if(!(entity instanceof EntityFallingBlock))
continue;
RenderUtils.drawEntityBox(entity, color, true);
}
synchronized(blocks) {
final Iterator<Map.Entry<BlockPos, Long>> iterator = blocks.entrySet().iterator();
while(iterator.hasNext()) {
final Map.Entry<BlockPos, Long> entry = iterator.next();
if(System.currentTimeMillis() - entry.getValue() > 2000L) {
iterator.remove();
continue;
}
RenderUtils.drawBlockBox(entry.getKey(), color, true);
}
}
}
public BlockPos getAverageContainerPosition() {
double x = 0;
double y = 0;
int z = configurationCommands.getStartPos().getZ();
for (BoxContainer container : boxContainers) {
BlockPos containerPos = container.getPosition();
x += containerPos.getX();
y += containerPos.getY();
}
x /= boxContainers.size();
y /= boxContainers.size();
return new BlockPos(Math.floor(x), Math.floor(y), z);
}
@EventTarget
public void onRender3D(Render3DEvent event) {
synchronized(posList) {
final Color color = colorRainbow.get() ? ColorUtils.rainbow() : new Color(colorRedValue.get(), colorGreenValue.get(), colorBlueValue.get());
for(final BlockPos blockPos : posList) {
switch(modeValue.get().toLowerCase()) {
case "box":
RenderUtils.drawBlockBox(blockPos, color, true);
break;
case "2d":
RenderUtils.draw2D(blockPos, color.getRGB(), Color.BLACK.getRGB());
break;
}
}
}
}
@Override
public void onUpdate() {
if(!MovementUtils.isMoving())
return;
final float f = mc.thePlayer.rotationYaw * 0.017453292F;
for (double d = 0.2; d <= ((Speed) LiquidBounce.moduleManager.getModule(Speed.class)).portMax.get(); d += 0.2) {
final double x = mc.thePlayer.posX - MathHelper.sin(f) * d;
final double z = mc.thePlayer.posZ + MathHelper.cos(f) * d;
if(mc.thePlayer.posY < (int) mc.thePlayer.posY + 0.5 && !(BlockUtils.getBlock(new BlockPos(x, mc.thePlayer.posY, z)) instanceof BlockAir))
break;
mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(x, mc.thePlayer.posY, z, true));
}
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
ItemStack stack = playerIn.getCurrentEquippedItem();
if(stack != null)
{
if(stack.getItem() instanceof ItemCoordinateCache)
{
if(stack.getItem().hasEffect(stack))
{
TileEntityCoordTransporter tect = (TileEntityCoordTransporter) worldIn.getTileEntity(pos);
stack.stackSize--;
playerIn.addChatMessage(new ChatComponentText("Added cordinate cache to tile entity"));
}
}
}
return true;
}
@EventTarget
public void onUpdate(final UpdateEvent event) {
if(glassValue.get() && !(BlockUtils.getBlock(new BlockPos(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)) instanceof BlockPane))
return;
switch(modeValue.get().toLowerCase()) {
case "damage":
if(mc.thePlayer.hurtTime > 0 && mc.thePlayer.onGround)
mc.thePlayer.motionY += 0.42F * heightValue.get();
break;
case "aacv3":
if(!mc.thePlayer.onGround) mc.thePlayer.motionY += 0.059D;
break;
case "dac":
if(!mc.thePlayer.onGround) mc.thePlayer.motionY += 0.049999;
break;
case "mineplex":
if(!mc.thePlayer.onGround) MovementUtils.strafe(0.35F);
break;
}
}
/**
* @author CCBlueX
*/
@Overwrite
public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
final IBlockState iblockstate = worldIn.getBlockState(pos);
if(iblockstate.getBlock() instanceof BlockLadder) {
final FastClimb fastClimb = (FastClimb) LiquidBounce.moduleManager.getModule(FastClimb.class);
final float f = fastClimb.getState() && fastClimb.getModeValue().get().equalsIgnoreCase("AAC3.0.0") ? 0.99f : 0.125f;
switch(iblockstate.getValue(FACING)) {
case NORTH:
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
break;
case SOUTH:
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
break;
case WEST:
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case EAST:
default:
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
}
}
}
@Override
public void setWorld(World world) {
BlockPos pos = blockPos();
net.minecraft.world.World oldWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world);
net.minecraft.world.World newWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(world);
Optional<TileEntity> tileEntity = Optional.ofNullable(oldWorld.getTileEntity(pos));
Optional<NBTTagCompound> nbt = Optional.empty();
if (tileEntity.isPresent()) {
NBTTagCompound compound = new NBTTagCompound();
tileEntity.get().writeToNBT(compound);
nbt = Optional.of(compound);
}
newWorld.setBlockState(pos, block.blockState());
oldWorld.removeTileEntity(pos);
oldWorld.setBlockToAir(pos);
Optional<TileEntity> newTileEntity = Optional.ofNullable(newWorld.getTileEntity(pos));
if (newTileEntity.isPresent() && nbt.isPresent()) {
newTileEntity.get().readFromNBT(nbt.get());
}
this.world = world;
}
@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
Block blockInstance;
// see onBlockHarvested for why the harvestedBlocks hack exists
// this method will be called exactly once after destroying the block
BlockPosition position = new BlockPosition((World) world, pos.getX(), pos.getY(), pos.getZ());
if (harvestedBlocks.containsKey(position)) {
blockInstance = harvestedBlocks.remove(position);
} else {
blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos));
}
Block.DropEvent event = new Block.DropEvent(blockInstance);
blockInstance.events.publish(event);
return event.drops
.stream()
.map(ItemConverter.instance()::toNative)
.collect(Collectors.toCollection(ArrayList::new));
}
public void showDetailedInfo() throws InterruptedException {
listCommands.refreshContainerIDMap();
if (listCommands.getBoxContainerWithID(arg1).equals(null)) {
return;
}
BlockPos senderPos = sender.getPosition();
sender = sender.getEntityWorld().getClosestPlayer(senderPos.getX(),
senderPos.getY(), senderPos.getZ(), -1);
if (listCommands.isStopped(listCommands.getBoxContainerWithID(arg1).getName())) {
BoxContainer boxContainer = listCommands.getBoxContainerWithID(arg1);
Container container = listCommands.getFromAllWithName(boxContainer.getName());
printContainerInfo(boxContainer, container);
return;
}
listCommands.execStatsCommand(arg1, true);
}
public static void room(World world, BlockPos start, BlockPos end,
Block material) {
fill(world, start, end, material);
int airStartX = -(start.getX() - end.getX())
/ Math.abs(start.getX() - end.getX());
int airEndX = -(end.getX() - start.getX())
/ Math.abs(end.getX() - start.getX());
int airStartY = -(start.getY() - end.getY())
/ Math.abs(start.getY() - end.getY());
int airEndY = -(end.getY() - start.getY())
/ Math.abs(end.getY() - start.getY());
int airStartZ = -(start.getZ() - end.getZ())
/ Math.abs(start.getZ() - end.getZ());
int airEndZ = -(end.getZ() - start.getZ())
/ Math.abs(end.getZ() - start.getZ());
fill(world, start.add(airStartX, airStartY, airStartZ),
end.add(airEndX, airEndY, airEndZ), Blocks.air);
}
/**
* Checks if the entity's current position is a valid location to spawn this
* entity.
*/
public boolean getCanSpawnHere() {
BlockPos blockpos = new BlockPos(this.posX,
this.getEntityBoundingBox().minY, this.posZ);
if (blockpos.getY() >= this.worldObj.getSeaLevel()) {
return false;
} else {
int i = this.worldObj.getLightFromNeighbors(blockpos);
int j = 4;
if (this.isDateAroundHalloween(this.worldObj.getCurrentDate())) {
j = 7;
} else if (this.rand.nextBoolean()) {
return false;
}
return i <= this.rand.nextInt(j) && super.getCanSpawnHere();
}
}
public static Stage detectStage() {
EXECUTOR.submit(() -> {
try {
World world = Minecraft.getMinecraft().theWorld;
if (lastStage != null && lastPos != null) {
if (Blocks.skull == world.getBlockState(lastPos).getBlock()) {
return;
}
}
for (Stage stage : values()) {
if (stage.blocksUp != -1) {
// These 4 coordinates are the bounds of the dragon's nest.
for (int x = -749; x < -602; x++) {
for (int z = -353; z < -202; z++) {
BlockPos blockPos = new BlockPos(x, 5 + stage.blocksUp, z);
if (Blocks.skull.equals(world.getBlockState(blockPos).getBlock())) {
lastStage = stage;
lastPos = blockPos;
return;
}
}
}
}
}
lastStage = Stage.NO_HEAD;
lastPos = null;
} catch (Throwable ex) {
ex.printStackTrace();
// It's fine I guess, just try checking next tick...
}
});
return lastStage;
}
public int sample(int side) {
if ((sampled & 1 << side) == 0) {
BlockPos bp = c.set(pos).offset(side).pos();
IBlockState b = access.getBlockState(bp);
samples[side] = access.getCombinedLight(bp, b.getBlock().getLightValue(access, bp));
sampled |= 1 << side;
}
return samples[side];
}
@Inject(method = "onBlockPlaced", cancellable = true, at = @At("HEAD"))
private void injectAnvilCrashFix(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, CallbackInfoReturnable<IBlockState> cir) {
if (((meta >> 2) & ~0x3) != 0) {
cir.setReturnValue(super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(BlockAnvil.FACING, placer.getHorizontalFacing().rotateY()).withProperty(BlockAnvil.DAMAGE, 2));
cir.cancel();
}
}
/**
* @author CCBlueX
*/
@Overwrite
public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) {
AxisAlignedBB axisalignedbb = this.getCollisionBoundingBox(worldIn, pos, state);
BlockBBEvent blockBBEvent = new BlockBBEvent(pos, blockState.getBlock(), axisalignedbb);
LiquidBounce.eventManager.callEvent(blockBBEvent);
axisalignedbb = blockBBEvent.getBoundingBox();
if(axisalignedbb != null && mask.intersectsWith(axisalignedbb))
list.add(axisalignedbb);
}
@Inject(method = "renderModelAmbientOcclusion", at = @At("HEAD"), cancellable = true)
private void renderModelAmbientOcclusion(IBlockAccess blockAccessIn, IBakedModel modelIn, Block blockIn, BlockPos blockPosIn, WorldRenderer worldRendererIn, boolean checkSide, final CallbackInfoReturnable<Boolean> booleanCallbackInfoReturnable) {
final XRay xray = (XRay) LiquidBounce.moduleManager.getModule(XRay.class);
if (xray.getState() && !xray.getXrayBlocks().contains(blockIn))
booleanCallbackInfoReturnable.setReturnValue(false);
}
@Inject(method = "renderModelStandard", at = @At("HEAD"), cancellable = true)
private void renderModelStandard(IBlockAccess blockAccessIn, IBakedModel modelIn, Block blockIn, BlockPos blockPosIn, WorldRenderer worldRendererIn, boolean checkSides, final CallbackInfoReturnable<Boolean> booleanCallbackInfoReturnable) {
final XRay xray = (XRay) LiquidBounce.moduleManager.getModule(XRay.class);
if (xray.getState() && !xray.getXrayBlocks().contains(blockIn))
booleanCallbackInfoReturnable.setReturnValue(false);
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) {
Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos));
Block.RightClickEvent evt = new Block.RightClickEvent(EntityConverter.instance().toNova(player), DirectionConverter.instance().toNova(side), new Vector3D(hitX, hitY, hitZ));
blockInstance.events.publish(evt);
return evt.result;
}
@Override
public boolean setBlock(Vector3D position, BlockFactory blockFactory) {
net.minecraft.block.Block mcBlock = BlockConverter.instance().toNative(blockFactory);
BlockPos pos = VectorConverter.instance().toNative(position);
net.minecraft.block.Block actualBlock = mcBlock != null ? mcBlock : Blocks.air;
IBlockState defaultState = actualBlock.getDefaultState();
IBlockState extendedState = actualBlock.getExtendedState(defaultState, world(), pos);
return world().setBlockState(pos, extendedState);
}
@EventTarget
public void onJump(final JumpEvent event) {
if (mc.thePlayer == null)
return;
final Block block = BlockUtils.getBlock(new BlockPos(mc.thePlayer.posX, mc.thePlayer.posY - 0.01, mc.thePlayer.posZ));
if (noJumpValue.get() && block instanceof BlockLiquid)
event.cancelEvent();
}
@EventTarget
public void onMove(final MoveEvent event) {
if(glassValue.get() && !(BlockUtils.getBlock(new BlockPos(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ)) instanceof BlockPane))
return;
if(!mc.thePlayer.onGround) {
if ("mineplex".equals(modeValue.get().toLowerCase())) {
mc.thePlayer.motionY += mc.thePlayer.fallDistance == 0 ? 0.0499D : 0.05D;
}
}
}
@Override
public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest) {
Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos));
Block.RemoveEvent evt = new Block.RemoveEvent(Optional.of(EntityConverter.instance().toNova(player)));
blockInstance.events.publish(evt);
if (evt.result) {
return super.removedByPlayer(world, pos, player, willHarvest);
}
return false;
}
@Override
public CompoundTag getTileEntity(Chunk chunk, int x, int y, int z) {
Map<BlockPos, TileEntity> tiles = chunk.getTileEntityMap();
pos.set(x, y, z);
TileEntity tile = tiles.get(pos);
return tile != null ? getTag(tile) : null;
}
@Inject(method = "setBlockState", at = @At("HEAD"))
private void setProphuntBlock(BlockPos pos, IBlockState state, final CallbackInfoReturnable callbackInfo) {
final ProphuntESP prophuntESP = (ProphuntESP) LiquidBounce.moduleManager.getModule(ProphuntESP.class);
if(prophuntESP.getState()) {
synchronized(prophuntESP.blocks) {
prophuntESP.blocks.put(pos, System.currentTimeMillis());
}
}
}
@Override
public void setBlockBoundsBasedOnState(IBlockAccess access, BlockPos pos) {
Block blockInstance = getBlockInstance(access, VectorConverter.instance().toNova(pos));
if (blockInstance.components.has(Collider.class)) {
Cuboid cuboid = blockInstance.components.get(Collider.class).boundingBox.get();
setBlockBounds((float) cuboid.min.getX(), (float) cuboid.min.getY(), (float) cuboid.min.getZ(), (float) cuboid.max.getX(), (float) cuboid.max.getY(), (float) cuboid.max.getZ());
}
}