下面列出了net.minecraft.util.BlockPos#getZ ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
@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));
}
private static void fill(World world, BlockPos start, BlockPos end,
Block material) {
int startX = start.getX();
int endX = end.getX();
int startY = start.getY();
int endY = end.getY();
int startZ = start.getZ();
int endZ = end.getZ();
int[] intSwitchArray = new int[2];
if (endX < startX) {
intSwitchArray = switchNumbers(startX, endX);
startX = intSwitchArray[0];
endX = intSwitchArray[1];
}
if (endY < startY) {
intSwitchArray = switchNumbers(startY, endY);
startY = intSwitchArray[0];
endY = intSwitchArray[1];
}
if (endZ < startZ) {
intSwitchArray = switchNumbers(startZ, endZ);
startZ = intSwitchArray[0];
endZ = intSwitchArray[1];
}
for (int x = startX; x < endX + 1; x++) {
for (int y = startY; y < endY + 1; y++) {
for (int z = startZ; z < endZ + 1; z++) {
world.setBlockState(new BlockPos(x, y, z),
material.getDefaultState());
}
}
}
}
public void refreshMinMaxPositions() {
BlockPos startPos = configurationCommands.getStartPos();
int minX = startPos.getX() - 2;
int minY = startPos.getY();
int minZ = startPos.getZ() - 10;
int maxX;
int maxY;
int maxZ = startPos.getZ() + 10;
int containerHeight = 0;
int size = boxContainers.size();
if (size < 10) {
containerHeight = size;
} else {
containerHeight = 10;
}
maxY = startPos.getY() - 1 + (6 * containerHeight);
int containerLength = ((size - (size % 10)) / 10) + 1;
maxX = (minX - 1) + (containerLength * 6);
minPos = new BlockPos(minX, minY, minZ);
maxPos = new BlockPos(maxX, maxY, maxZ);
}
public static void chunkSetBlockEvent(Chunk chunk, BlockPos pos, IBlockState oldBlockState, IBlockState newBlockState) {
nova.core.world.World world = WorldConverter.instance().toNova(chunk.getWorld());
Vector3D position = new Vector3D((chunk.xPosition << 4) + pos.getX(), pos.getY(), (chunk.zPosition << 4) + pos.getZ());
Block oldBlockInstance;
Block newBlockInstance;
if (oldBlockState.getBlock() instanceof FWBlock) {
oldBlockInstance = ((FWBlock) oldBlockState.getBlock()).getFactory().build();
oldBlockInstance.components.add(new MCBlockTransform(oldBlockInstance, world, position));
} else {
oldBlockInstance = new BWBlock(oldBlockState.getBlock(), world, position);
Game.blocks().get(Objects.toString(net.minecraft.block.Block.blockRegistry.getNameForObject(oldBlockState.getBlock())))
.ifPresent(blockFactory -> oldBlockInstance.components.getOrAdd(new FactoryProvider(blockFactory)));
}
if (newBlockState.getBlock() instanceof FWBlock) {
newBlockInstance = ((FWBlock) newBlockState.getBlock()).getFactory().build();
oldBlockInstance.components.add(new MCBlockTransform(oldBlockInstance, world, position));
} else {
newBlockInstance = new BWBlock(newBlockState.getBlock());
Game.blocks().get(Objects.toString(net.minecraft.block.Block.blockRegistry.getNameForObject(newBlockState.getBlock())))
.ifPresent(blockFactory -> newBlockInstance.components.getOrAdd(new FactoryProvider(blockFactory)));
}
// Publish the event
Game.events().publish(new BlockEvent.Change(world, position, oldBlockInstance, newBlockInstance));
}
public static void drawBlockBox(final BlockPos blockPos, final Color color, final boolean outline) {
final RenderManager renderManager = mc.getRenderManager();
final Timer timer = mc.timer;
final double x = blockPos.getX() - renderManager.renderPosX;
final double y = blockPos.getY() - renderManager.renderPosY;
final double z = blockPos.getZ() - renderManager.renderPosZ;
AxisAlignedBB axisAlignedBB = new AxisAlignedBB(x, y, z, x + 1.0, y + 1.0, z + 1.0);
final Block block = BlockUtils.getBlock(blockPos);
if (block != null) {
final EntityPlayer player = mc.thePlayer;
final double posX = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double) timer.renderPartialTicks;
final double posY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double) timer.renderPartialTicks;
final double posZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double) timer.renderPartialTicks;
axisAlignedBB = block.getSelectedBoundingBox(mc.theWorld, blockPos)
.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D)
.offset(-posX, -posY, -posZ);
}
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
enableGlCap(GL_BLEND);
disableGlCap(GL_TEXTURE_2D, GL_DEPTH_TEST);
glDepthMask(false);
glColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() != 255 ? color.getAlpha() : outline ? 26 : 35);
drawFilledBox(axisAlignedBB);
if (outline) {
glLineWidth(1F);
enableGlCap(GL_LINE_SMOOTH);
glColor(color);
drawSelectionBoundingBox(axisAlignedBB);
}
GlStateManager.resetColor();
glDepthMask(true);
resetCaps();
}
public static void replace(World world, BlockPos start, BlockPos end,
Block blockToReplace, Block blockToReplaceWith) {
int startX = start.getX();
int endX = end.getX();
int startY = start.getY();
int endY = end.getY();
int startZ = start.getZ();
int endZ = end.getZ();
int[] intSwitchArray = new int[2];
if (endX < startX) {
intSwitchArray = switchNumbers(startX, endX);
startX = intSwitchArray[0];
endX = intSwitchArray[1];
}
if (endY < startY) {
intSwitchArray = switchNumbers(startY, endY);
startY = intSwitchArray[0];
endY = intSwitchArray[1];
}
if (endZ < startZ) {
intSwitchArray = switchNumbers(startZ, endZ);
startZ = intSwitchArray[0];
endZ = intSwitchArray[1];
}
for (int x = startX; x < endX + 1; x++) {
for (int y = startY; y < endY + 1; y++) {
for (int z = startZ; z < endZ + 1; z++) {
if (world.getBlockState(new BlockPos(x, y, z)) == blockToReplace
.getDefaultState()) {
world.setBlockState(new BlockPos(x, y, z),
blockToReplaceWith.getDefaultState());
}
}
}
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate() {
super.onUpdate();
this.motionY *= 0.6000000238418579D;
if (chaosCountdown > 0) {
chaosCountdown--;
return;
}
BlockPos pos = this.getPosition();
BlockPos minPos = buildCommands.getMinPos();
BlockPos maxPos = buildCommands.getMaxPos();
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
int minX = minPos.getX();
int minY = minPos.getY();
int minZ = minPos.getZ();
int maxX = maxPos.getX();
int maxY = maxPos.getY();
int maxZ = maxPos.getZ();
if (x < minX || y < minY || z < minZ || x > maxX || y > maxY
|| z > maxZ) {
this.setLocationAndAngles(Utils.negativeNextInt(minX, maxX),
Utils.negativeNextInt(minY, maxY), minZ + 8, 0, 0);
}
World world = this.worldObj;
if (world.getTileEntity(this.getPosition()) == null) {
return;
}
TileEntity entity = world.getTileEntity(this.getPosition());
if (!(entity instanceof TileEntitySign)) {
return;
}
TileEntitySign sign = (TileEntitySign) entity;
if (!sign.signText[0].getUnformattedText().contains("Name:")) {
return;
}
String name = sign.signText[1].getUnformattedText().concat(
sign.signText[2].getUnformattedText().concat(
sign.signText[3].getUnformattedText()));
if (listCommands.getWithName(name) == null) {
return;
}
Container container = listCommands.getWithName(name);
lifecycleCommands.removeContainer(container.getId());
if (!world.isRemote) {
sendErrorMessage("Oh no! The Chaos Monkey has destroyed the container \""
+ name + "\"!");
}
if (sender instanceof EntityPlayer) {
((EntityPlayer) sender).inventory
.addItemStackToInventory(new ItemStack(
Mobycraft.container_essence, new Random().nextInt(3)));
}
chaosCountdown = maxChaosCountdown;
buildCommands.updateContainers(false);
}
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
return ItemWrapperMethods.super.onItemUse(itemStack, player, world, pos.getX(), pos.getY(), pos.getZ(), side.ordinal(), hitX, hitY, hitZ);
}
@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
return ItemWrapperMethods.super.onItemUse(itemStack, player, world, pos.getX(), pos.getY(), pos.getZ(), side.ordinal(), hitX, hitY, hitZ);
}
@Override
public FaweLocation getLocation() {
World world = parent.worldObj;
BlockPos pos = parent.getPosition();
return new FaweLocation(Fawe.<FaweForge>imp().getWorldName(world), pos.getX(), pos.getY(), pos.getZ());
}
public BlockCoord(BlockPos pos) {
this(pos.getX(), pos.getY(), pos.getZ());
}
public Vector3(BlockPos pos) {
x = pos.getX();
y = pos.getY();
z = pos.getZ();
}
public static void draw2D(final BlockPos blockPos, final int color, final int backgroundColor) {
final RenderManager renderManager = mc.getRenderManager();
final double posX = (blockPos.getX() + 0.5) - renderManager.renderPosX;
final double posY = blockPos.getY() - renderManager.renderPosY;
final double posZ = (blockPos.getZ() + 0.5) - renderManager.renderPosZ;
GlStateManager.pushMatrix();
GlStateManager.translate(posX, posY, posZ);
GlStateManager.rotate(-mc.getRenderManager().playerViewY, 0F, 1F, 0F);
GlStateManager.scale(-0.1D, -0.1D, 0.1D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.depthMask(true);
glColor(color);
glCallList(DISPLAY_LISTS_2D[0]);
glColor(backgroundColor);
glCallList(DISPLAY_LISTS_2D[1]);
GlStateManager.translate(0, 9, 0);
glColor(color);
glCallList(DISPLAY_LISTS_2D[2]);
glColor(backgroundColor);
glCallList(DISPLAY_LISTS_2D[3]);
// Stop render
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
GlStateManager.popMatrix();
}