下面列出了net.minecraft.util.math.AxisAlignedBB#offset ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Nullable
@Override
public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
{
AxisAlignedBB bounds = getContent().selectionBounds.get(getSubtype(state)).orElse(null);
if (bounds == DEFAULT_AABB_MARKER)
return super.getSelectedBoundingBox(state, worldIn, pos);
else
return bounds != null ? bounds.offset(pos) : null;
}
@Override
public AxisAlignedBB makeVoxelFieldAABB() {
if (voxelCount == 0) {
return null;
}
AxisAlignedBB inLocal = new AxisAlignedBB(minCoords, maxCoords);
return inLocal.offset(centerPos);
}
@Override
public boolean intersects(AxisAlignedBB aabb) {
//if(chunk == null || true)
// return super.intersectsWith(aabb);
boolean collides = false;
double diffX = 0;//((this.maxX - this.minX) - chunk.sizeX)/2f;
double diffZ = 0;//((this.maxX - this.minX) - chunk.sizeX)/2f;
out:
for(int x = 0; x < chunk.blocks.length; x++) {
for(int y = 0; y < chunk.blocks[0].length; y++) {
for(int z = 0; z < chunk.blocks[0][0].length; z++) {
Block block = chunk.blocks[x][y][z];
if(!block.getDefaultState().getMaterial().isSolid())
continue;
AxisAlignedBB bb = block.getDefaultState().getCollisionBoundingBox(chunk.world, new BlockPos(x,y,z));
if(bb == null)
continue;
bb = bb.offset(this.minX + x + diffX, this.minY + y, this.minZ + z + diffZ);
if(bb.intersects(aabb)) {
collides = true;
break out;
}
}
}
}
return collides;
}
@SubscribeEvent
public void drawBlockHighlightEvent(DrawBlockHighlightEvent evt)
{
RayTraceResult target = evt.getTarget();
if(target.typeOfHit != RayTraceResult.Type.BLOCK)
return;
World world = evt.getPlayer().world;
EntityPlayer player = evt.getPlayer();
IBlockState state = world.getBlockState(target.getBlockPos());
double posX = player.lastTickPosX + (player.posX - player.lastTickPosX) * evt.getPartialTicks();
double posY = player.lastTickPosY + (player.posY - player.lastTickPosY) * evt.getPartialTicks();
double posZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * evt.getPartialTicks();
double hitX = Math.round((target.hitVec.xCoord - target.getBlockPos().getX())*100)/100.0d;
double hitY = Math.round((target.hitVec.yCoord - target.getBlockPos().getY())*100)/100.0d;
double hitZ = Math.round((target.hitVec.zCoord - target.getBlockPos().getZ())*100)/100.0d;
AxisAlignedBB box = null;
int index = getIndex(hitX, hitZ);
if((state.getBlock() == TFCBlocks.SmallVessel) || (target.sideHit == EnumFacing.UP && player.getHeldItemMainhand().getItem() == TFCItems.PotteryVessel &&
state.getBlock().isSideSolid(state, world, target.getBlockPos(), EnumFacing.UP) && player.isSneaking() && player.getHeldItemMainhand().getItemDamage() == 1))
{
GlStateManager.enableBlend();
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
GlStateManager.disableCull();
if(index == 0)
box = aabb0.offset(target.getBlockPos());
else if(index == 1)
box = aabb1.offset(target.getBlockPos());
else if(index == 2)
box = aabb2.offset(target.getBlockPos());
else
box = aabb3.offset(target.getBlockPos());
if(state.getBlock() != TFCBlocks.SmallVessel)
box = box.offset(0, 1, 0);
GlStateManager.enableTexture2D();
Core.bindTexture(selectTex);
drawFace(box.expand(0.002F, 0.002F, 0.002F).offset(-posX, -posY, -posZ), new float[]{1f,1f,1f, 1f}, EnumFacing.UP);
GlStateManager.disableTexture2D();
GlStateManager.enableCull();
GlStateManager.disableBlend();
}
}
private void renderStackedArea(Area3D area, EntityPlayer player, BlockPosEU posStart, BlockPosEU posEnd, float partialTicks)
{
if (posStart == null || posEnd == null)
{
return;
}
int xp = area.getXPos();
int yp = area.getYPos();
int zp = area.getZPos();
int xn = area.getXNeg();
int yn = area.getYNeg();
int zn = area.getZNeg();
int sx = Math.abs(posEnd.getX() - posStart.getX()) + 1;
int sy = Math.abs(posEnd.getY() - posStart.getY()) + 1;
int sz = Math.abs(posEnd.getZ() - posStart.getZ()) + 1;
AxisAlignedBB originalBox = createEnclosingAABB(posStart, posEnd, player, partialTicks);
GlStateManager.glLineWidth(2.0f);
// Non-empty area on at least one axis
if ((xp + xn + yp + yn + zp + zn) != 0)
{
for (int y = -yn; y <= yp; y++)
{
for (int x = -xn; x <= xp; x++)
{
for (int z = -zn; z <= zp; z++)
{
AxisAlignedBB aabb = originalBox.offset(x * sx, y * sy, z * sz);
if (x != 0 || y != 0 || z != 0)
{
RenderGlobal.drawSelectionBoundingBox(aabb, 1f, 1f, 1f, 0xCC / 255f);
}
else
{
RenderGlobal.drawSelectionBoundingBox(aabb, 0.5f, 1f, 0.5f, 0xCC / 255f);
}
}
}
}
}
}
public static AxisAlignedBB aabbOffset(BlockPos pos, AxisAlignedBB aabb) {
return aabb.offset(pos.getX(), pos.getY(), pos.getZ());
}