下面列出了怎么用net.minecraft.world.IBlockAccess的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world,
BlockPos pos) {
int offset = 0;
if(world.getBlockState(pos.add(1,0,0)).getBlock() == this)
offset |= 0x1;
if(world.getBlockState(pos.add(0,0,-1)).getBlock() == this)
offset |= 0x2;
if(world.getBlockState(pos.add(-1,0,0)).getBlock() == this)
offset |= 0x4;
if(world.getBlockState(pos.add(0,0,1)).getBlock() == this)
offset |= 0x8;
return state.withProperty(TYPE, IconNames.values()[offset]);
}
@Override
public void handleRenderBlockDamage(IBlockAccess world, BlockPos pos, IBlockState state, TextureAtlasSprite sprite, BufferBuilder buffer) {
MetaTileEntity metaTileEntity = BlockMachine.getMetaTileEntity(world, pos);
ArrayList<IndexedCuboid6> boundingBox = new ArrayList<>();
if (metaTileEntity != null) {
metaTileEntity.addCollisionBoundingBox(boundingBox);
metaTileEntity.addCoverCollisionBoundingBox(boundingBox);
}
CCRenderState renderState = CCRenderState.instance();
renderState.reset();
renderState.bind(buffer);
renderState.setPipeline(new Vector3(new Vec3d(pos)).translation(), new IconTransformation(sprite));
for (Cuboid6 cuboid : boundingBox) {
BlockRenderer.renderCuboid(renderState, cuboid, 0);
}
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
state = super.getActualState(state, world, pos);
TileEntityEnderFurnace te = getTileEntitySafely(world, pos, TileEntityEnderFurnace.class);
if (te != null)
{
EnumMachineMode mode = te.isCookingLast == false ? EnumMachineMode.OFF :
(te.isBurningLast == false ? EnumMachineMode.ON_NOFUEL :
te.fastMode ? EnumMachineMode.ON_FAST : EnumMachineMode.ON_NORMAL);
state = state.withProperty(MODE, mode);
}
return state;
}
private IIcon getAccessPortIcon(IBlockAccess blockAccess, int x, int y,
int z, int side) {
TileEntity te = blockAccess.getTileEntity(x, y, z);
if(te instanceof TileEntityReactorAccessPort) {
TileEntityReactorAccessPort port = (TileEntityReactorAccessPort)te;
if(!isReactorAssembled(port) || isOutwardsSide(port, side)) {
if(port.isInlet()) {
return _icons[METADATA_ACCESSPORT][PORT_INLET];
}
else {
return _icons[METADATA_ACCESSPORT][PORT_OUTLET];
}
}
}
return blockIcon;
}
@SuppressWarnings("deprecation")
@Override
public boolean shouldSideBeRendered(IBlockState state, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
{
IBlockState stateAdjacent = blockAccess.getBlockState(pos.offset(side));
if (state != stateAdjacent)
{
return true;
}
else if (stateAdjacent.getBlock() == this)
{
return false;
}
return super.shouldSideBeRendered(state, blockAccess, pos, side);
}
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
Random rand = world instanceof World ? ((World) world).rand : RANDOM;
int age = getAge(state);
int count = quantityDropped(state, fortune, rand);
for (int i = 0; i < count; i++) {
Item item = this.getItemDropped(state, rand, fortune);
if (item != Items.AIR) {
drops.add(new ItemStack(item, 1, this.damageDropped(state)));
}
}
if (age >= getMaxAge()) {
int k = 3 + fortune;
for (int i = 0; i < k; ++i) {
if (rand.nextInt(2 * getMaxAge()) <= age) {
drops.add(new ItemStack(this.getSeed(), 1, this.damageDropped(state)));
}
}
}
}
private int getBaseBlockYCoord (IBlockAccess world, int x, int y, int z) {
if (y == 0)
return 0;
Block underBlock = world.getBlock(x, --y, z);
while (y > 0 && underBlock instanceof IPlantProxy)
underBlock = world.getBlock(x, --y, z);
return y;
}
public void renderOuterBlock(Block block, int x, int y, int z, RenderBlocks renderer, IBlockAccess world)
{
Tessellator tessellator = Tessellator.instance;
boolean tankUp = world.getBlockTileEntity(x, y + 1, z) instanceof TileEntityCertusTank;
boolean tankDown = world.getBlockTileEntity(x, y - 1, z) instanceof TileEntityCertusTank;
int meta = 0;
if (tankUp && tankDown)
meta = 3;
else if (tankUp)
meta = 2;
else if (tankDown)
meta = 1;
if (!tankDown)
{
tessellator.setNormal(0.0F, -1F, 0.0F);
renderer.renderFaceYNeg(block, x, y, z, block.getIcon(0, 0));
}
if (!(tankUp))
{
tessellator.setNormal(0.0F, 1.0F, 0.0F);
renderer.renderFaceYPos(block, x, y, z, block.getIcon(1, 0));
}
Icon sideIcon = block.getIcon(3, meta);
tessellator.setNormal(0.0F, 0.0F, -1F);
renderer.renderFaceZNeg(block, x, y, z, sideIcon);
tessellator.setNormal(0.0F, 0.0F, 1.0F);
renderer.renderFaceZPos(block, x, y, z, sideIcon);
tessellator.setNormal(-1F, 0.0F, 0.0F);
renderer.renderFaceXNeg(block, x, y, z, sideIcon);
tessellator.setNormal(1.0F, 0.0F, 0.0F);
renderer.renderFaceXPos(block, x, y, z, sideIcon);
}
@SideOnly(Side.CLIENT)
@Override
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,
EnumFacing side) {
IBlockState iblockstate = blockAccess.getBlockState(pos.offset(side));
Block block = iblockstate.getBlock();
if (block == this || block == ModBlocks.clearplasticblock) {
return false;
}
return block == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side);
}
@Override
public int isProvidingStrongPower(IBlockAccess access, BlockPos pos, IBlockState state, EnumFacing side) {
Block blockInstance = getBlockInstance(access, VectorConverter.instance().toNova(pos));
WrapperEvent.StrongRedstone event = new WrapperEvent.StrongRedstone(blockInstance.world(), blockInstance.position(), Direction.fromOrdinal(side.ordinal()));
Game.events().publish(event);
return event.power;
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
boolean flag = canWallConnectTo(worldIn, pos, EnumFacing.NORTH);
boolean flag1 = canWallConnectTo(worldIn, pos, EnumFacing.EAST);
boolean flag2 = canWallConnectTo(worldIn, pos, EnumFacing.SOUTH);
boolean flag3 = canWallConnectTo(worldIn, pos, EnumFacing.WEST);
boolean flag4 = flag && !flag1 && flag2 && !flag3 || !flag && flag1 && !flag2 && flag3;
return state.withProperty(UP, !flag4 || !worldIn.isAirBlock(pos.up()))
.withProperty(NORTH, flag)
.withProperty(EAST, flag1)
.withProperty(SOUTH, flag2)
.withProperty(WEST, flag3);
}
public static boolean isHacked(IBlockAccess world, int x, int y, int z){
TileEntity te = world.getTileEntity(x, y, z);
if(te != null) {
NBTTagCompound tag = new NBTTagCompound();
te.writeToNBT(tag);
if(tag.hasKey("RequiredPlayerRange") && tag.getShort("RequiredPlayerRange") == 0) return true;
}
return false;
}
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
if (!Minecraft.getMinecraft().gameSettings.fancyGraphics) {
if (!(blockAccess.getBlockState(pos.offset(side)).getBlock() instanceof BlockLeaves)) {
return true;
}
return false;
}
return true;
}
public float getPlantOffsetY (IBlockAccess blockAccess, int x, int y, int z, int slot) {
BlockGarden gardenBlock = getGardenBlock(blockAccess, x, y, z);
if (gardenBlock == null)
return 0;
return gardenBlock.getSlotProfile().getPlantOffsetY(blockAccess, x, getBaseBlockYCoord(blockAccess, x, y, z), z, slot);
}
@Override
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face)
{
if (state.getValue(TYPE).isFullCube())
{
return BlockFaceShape.SOLID;
}
else
{
return BlockFaceShape.UNDEFINED;
}
}
/**
* Check for a world connection, if we're assembled.
* @param world
* @param x
* @param y
* @param z
*/
protected void checkForConnections(IBlockAccess world, int x, int y, int z) {
boolean wasConnected = (rfNetwork != null);
ForgeDirection out = getOutwardsDir();
if(out == ForgeDirection.UNKNOWN) {
wasConnected = false;
rfNetwork = null;
}
else {
// See if our adjacent non-reactor coordinate has a TE
rfNetwork = null;
TileEntity te = world.getTileEntity(x + out.offsetX, y + out.offsetY, z + out.offsetZ);
if(!(te instanceof TileEntityReactorPowerTap)) {
// Skip power taps, as they implement these APIs and we don't want to shit energy back and forth
if(te instanceof IEnergyReceiver) {
IEnergyReceiver handler = (IEnergyReceiver)te;
if(handler.canConnectEnergy(out.getOpposite())) {
rfNetwork = handler;
}
}
}
}
boolean isConnected = (rfNetwork != null);
if(wasConnected != isConnected && worldObj.isRemote) {
// Re-render on clients
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
/*******************************************************************************
* 2. Rendering
*******************************************************************************/
@Override
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos)
{
return false;
}
@Override
public void process(IBlockAccess iBlockAccess) {
if (SideReference.Side.Client) {
if (this.removal == 0)
GT_TileEntity_BioVat.staticColorMap.put(this.coords, this.integer);
else
GT_TileEntity_BioVat.staticColorMap.remove(this.coords);
}
}
@Override
public IBlockState getPlant(IBlockAccess world, BlockPos pos)
{
IBlockState state = world.getBlockState(pos);
if (state.getBlock() != this)
return getDefaultState();
return state;
}
public float getPlantOffsetX (IBlockAccess blockAccess, int x, int y, int z, int slot) {
BlockGarden gardenBlock = getGardenBlock(blockAccess, x, y, z);
if (gardenBlock == null)
return 0;
return gardenBlock.getSlotProfile().getPlantOffsetX(blockAccess, x, getBaseBlockYCoord(blockAccess, x, y, z), z, slot);
}
private TileMoving get(IBlockAccess w, int x, int y, int z) {
TileEntity te = w.getTileEntity(x, y, z);
if (te != null && te instanceof TileMoving)
return (TileMoving) te;
return null;
}
@Override
public boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
if (block instanceof BlockSmallFire)
return renderWorldBlock(world, x, y, z, (BlockSmallFire) block, modelId, renderer);
return false;
}
private static boolean isConnected(IBlockAccess world, int x, int y, int z, int side, Block block, int meta)
{
int x2 = x, y2 = y, z2 = z;
switch(side)
{
case 0:
y2--;
break;
case 1:
y2++;
break;
case 2:
z2--;
break;
case 3:
z2++;
break;
case 4:
x2--;
break;
case 5:
x2++;
break;
}
return getBlockOrFacade(world, x, y, z, side).equals(block) && getBlockOrFacadeMetadata(world, x, y, z, side) == meta && (!getBlockOrFacade(world, x2, y2, z2, side).equals(block) || getBlockOrFacadeMetadata(world, x2, y2, z2, side) != meta);
}
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
DesertCactusType veg = (DesertCactusType)state.getValue(META_PROPERTY);
if(plant.getBlock() == this)
{
}
return false;
}
public void setBlockAccess(IBlockAccess blockAccess) {
this.blockAccess = blockAccess;
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
return new AxisAlignedBB(0.3, 0, 0.3, 0.7, 0.9, 0.7);
}
@Override
public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
return false;
}
@Override
public int getFlammability(IBlockAccess world, BlockPos pos, EnumFacing face) {
return 5;
}
@Override
public ArrayList<ItemStack> onSheared (ItemStack item, IBlockAccess world, int x, int y, int z, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
ret.add(new ItemStack(this, 1));
return ret;
}
public void setupXPosAOPartial (IBlockAccess blockAccess, Block block, int x, int y, int z, float r, float g, float b) {
Tessellator tessellator = Tessellator.instance;
tessellator.setBrightness(983055);
int xGrass = (state.renderMaxX >= 1) ? x + 1 : x;
boolean blocksGrassXYNP = !blockAccess.getBlock(xGrass, y + 1, z).getCanBlockGrass();
boolean blocksGrassXYNN = !blockAccess.getBlock(xGrass, y - 1, z).getCanBlockGrass();
boolean blocksGrassXZNN = !blockAccess.getBlock(xGrass, y, z - 1).getCanBlockGrass();
boolean blocksGrassXZNP = !blockAccess.getBlock(xGrass, y, z + 1).getCanBlockGrass();
if (state.renderMaxX < 1)
setupAOBrightnessXPos(blockAccess, block, x, y, z, blocksGrassXYNP, blocksGrassXYNN, blocksGrassXZNN, blocksGrassXZNP);
setupAOBrightnessXNeg(blockAccess, block, x + 1, y, z, blocksGrassXYNP, blocksGrassXYNN, blocksGrassXZNN, blocksGrassXZNP);
float xClamp = MathHelper.clamp_float((float) state.renderMaxX, 0, 1);
mixAOBrightnessLightValueX(xClamp, 1 - xClamp);
int blockBrightness = block.getMixedBrightnessForBlock(blockAccess, x, y, z);
if (state.renderMaxX >= 1.0D || !blockAccess.getBlock(x + 1, y, z).isOpaqueCube())
blockBrightness = block.getMixedBrightnessForBlock(blockAccess, x + 1, y, z);
float aoOpposingBlock = blockAccess.getBlock(x + 1, y, z).getAmbientOcclusionLightValue();
float aoXYZPNP = (aoLightValueScratchXYIN + aoLightValueScratchXYZINP + aoOpposingBlock + aoLightValueScratchXZIP) / 4.0F;
float aoXYZPNN = (aoLightValueScratchXYZINN + aoLightValueScratchXYIN + aoLightValueScratchXZIN + aoOpposingBlock) / 4.0F;
float aoXYZPPN = (aoLightValueScratchXZIN + aoOpposingBlock + aoLightValueScratchXYZIPN + aoLightValueScratchXYIP) / 4.0F;
float aoXYZPPP = (aoOpposingBlock + aoLightValueScratchXZIP + aoLightValueScratchXYIP + aoLightValueScratchXYZIPP) / 4.0F;
float aoTL = (float)((double)aoXYZPNP * (1.0D - state.renderMinY) * state.renderMaxZ + (double)aoXYZPNN * (1.0D - state.renderMinY) * (1.0D - state.renderMaxZ) + (double)aoXYZPPN * state.renderMinY * (1.0D - state.renderMaxZ) + (double)aoXYZPPP * state.renderMinY * state.renderMaxZ);
float aoBL = (float)((double)aoXYZPNP * (1.0D - state.renderMinY) * state.renderMinZ + (double)aoXYZPNN * (1.0D - state.renderMinY) * (1.0D - state.renderMinZ) + (double)aoXYZPPN * state.renderMinY * (1.0D - state.renderMinZ) + (double)aoXYZPPP * state.renderMinY * state.renderMinZ);
float aoBR = (float)((double)aoXYZPNP * (1.0D - state.renderMaxY) * state.renderMinZ + (double)aoXYZPNN * (1.0D - state.renderMaxY) * (1.0D - state.renderMinZ) + (double)aoXYZPPN * state.renderMaxY * (1.0D - state.renderMinZ) + (double)aoXYZPPP * state.renderMaxY * state.renderMinZ);
float aoTR = (float)((double)aoXYZPNP * (1.0D - state.renderMaxY) * state.renderMaxZ + (double)aoXYZPNN * (1.0D - state.renderMaxY) * (1.0D - state.renderMaxZ) + (double)aoXYZPPN * state.renderMaxY * (1.0D - state.renderMaxZ) + (double)aoXYZPPP * state.renderMaxY * state.renderMaxZ);
int brXYZPNP = getAOBrightness(aoBrightnessXYIN, aoBrightnessXYZINP, aoBrightnessXZIP, blockBrightness);
int brXYZPNN = getAOBrightness(aoBrightnessXZIP, aoBrightnessXYIP, aoBrightnessXYZIPP, blockBrightness);
int brXYZPPN = getAOBrightness(aoBrightnessXZIN, aoBrightnessXYZIPN, aoBrightnessXYIP, blockBrightness);
int brXYZPPP = getAOBrightness(aoBrightnessXYZINN, aoBrightnessXYIN, aoBrightnessXZIN, blockBrightness);
state.brightnessTopLeft = mixAOBrightness(brXYZPNP, brXYZPPP, brXYZPPN, brXYZPNN, (1.0D - state.renderMinY) * state.renderMaxZ, (1.0D - state.renderMinY) * (1.0D - state.renderMaxZ), state.renderMinY * (1.0D - state.renderMaxZ), state.renderMinY * state.renderMaxZ);
state.brightnessBottomLeft = mixAOBrightness(brXYZPNP, brXYZPPP, brXYZPPN, brXYZPNN, (1.0D - state.renderMinY) * state.renderMinZ, (1.0D - state.renderMinY) * (1.0D - state.renderMinZ), state.renderMinY * (1.0D - state.renderMinZ), state.renderMinY * state.renderMinZ);
state.brightnessBottomRight = mixAOBrightness(brXYZPNP, brXYZPPP, brXYZPPN, brXYZPNN, (1.0D - state.renderMaxY) * state.renderMinZ, (1.0D - state.renderMaxY) * (1.0D - state.renderMinZ), state.renderMaxY * (1.0D - state.renderMinZ), state.renderMaxY * state.renderMinZ);
state.brightnessTopRight = mixAOBrightness(brXYZPNP, brXYZPPP, brXYZPPN, brXYZPNN, (1.0D - state.renderMaxY) * state.renderMaxZ, (1.0D - state.renderMaxY) * (1.0D - state.renderMaxZ), state.renderMaxY * (1.0D - state.renderMaxZ), state.renderMaxY * state.renderMaxZ);
state.setColor(r * state.colorMultXPos, g * state.colorMultXPos, b * state.colorMultXPos);
state.scaleColor(state.colorTopLeft, aoTL);
state.scaleColor(state.colorBottomLeft, aoBL);
state.scaleColor(state.colorBottomRight, aoBR);
state.scaleColor(state.colorTopRight, aoTR);
}