本文整理汇总了Java中net.minecraft.world.World.getBlockState方法的典型用法代码示例。如果您正苦于以下问题:Java World.getBlockState方法的具体用法?Java World.getBlockState怎么用?Java World.getBlockState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.world.World
的用法示例。
在下文中一共展示了World.getBlockState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: safeImpact
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public void safeImpact(BlockPos pos, @Nullable EnumFacing side, World world, int amplifier) {
int box = 1 + (int) ((float) amplifier / 2F);
BlockPos posI = pos.add(box, 1, box);
BlockPos posF = pos.add(-box, -1, -box);
Iterable<BlockPos> spots = BlockPos.getAllInBox(posI, posF);
int chance = 10 + amplifier * 2;
int fortune = MathHelper.clamp(amplifier, 0, 5);
for (BlockPos spot : spots) {
IBlockState state = world.getBlockState(spot);
boolean place = amplifier > 1 || world.rand.nextBoolean();
if (place && state.getBlock() instanceof BlockCrops) {
BlockCrops crop = (BlockCrops) state.getBlock();
if (crop.isMaxAge(state)) {
crop.dropBlockAsItemWithChance(world, spot, state, chance, fortune);
world.setBlockToAir(spot);
}
}
}
}
示例2: tryPlace
import net.minecraft.world.World; //导入方法依赖的package包/类
private boolean tryPlace(ItemStack stack, World worldIn, BlockPos pos, Object variantInStack)
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == this.singleSlab)
{
Comparable comparable = iblockstate.getValue(this.singleSlab.getVariantProperty());
if (comparable == variantInStack)
{
IBlockState iblockstate1 = this.doubleSlab.getDefaultState().withProperty((IProperty)this.singleSlab.getVariantProperty(), comparable);
if (worldIn.checkNoEntityCollision(this.doubleSlab.getCollisionBoundingBox(worldIn, pos, iblockstate1)) && worldIn.setBlockState(pos, iblockstate1, 3))
{
worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.doubleSlab.stepSound.getPlaceSound(), (this.doubleSlab.stepSound.getVolume() + 1.0F) / 2.0F, this.doubleSlab.stepSound.getFrequency() * 0.8F);
--stack.stackSize;
}
return true;
}
}
return false;
}
示例3: shouldMoveTo
import net.minecraft.world.World; //导入方法依赖的package包/类
protected boolean shouldMoveTo(World worldIn, BlockPos pos)
{
Block block = worldIn.getBlockState(pos).getBlock();
if (block == Blocks.farmland)
{
pos = pos.up();
IBlockState iblockstate = worldIn.getBlockState(pos);
block = iblockstate.getBlock();
if (block instanceof BlockCarrot && ((Integer)iblockstate.getValue(BlockCarrot.AGE)).intValue() == 7 && this.field_179498_d && !this.field_179499_e)
{
this.field_179499_e = true;
return true;
}
}
return false;
}
示例4: placeBlockAt
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState)
{
if (!world.setBlockState(pos, newState, 11)) return false;
IBlockState state = world.getBlockState(pos);
if (state.getBlock() == this.block)
{
setTileEntityNBT(world, player, pos, stack);
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileOre)
{
int oreIndex = (stack.getMetadata() / EnumRockClass.values().length) % EnumOre.values().length;
int oreRichnessIndex = stack.getMetadata() / (EnumRockClass.values().length * EnumOre.values().length);
((TileOre)tile).type = EnumOre.values()[oreIndex];
((TileOre)tile).amount = (byte) (oreRichnessIndex == 0 ? 20 : oreRichnessIndex == 1 ? 30 : 50);
}
this.block.onBlockPlacedBy(world, pos, state, player, stack);
}
return true;
}
示例5: getPossibleFlowDirections
import net.minecraft.world.World; //导入方法依赖的package包/类
private Set<EnumFacing> getPossibleFlowDirections(World worldIn, BlockPos pos)
{
int i = 1000;
Set<EnumFacing> set = EnumSet.<EnumFacing>noneOf(EnumFacing.class);
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
BlockPos blockpos = pos.offset(enumfacing);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (!this.isBlocked(worldIn, blockpos, iblockstate) && (iblockstate.getBlock().getMaterial() != this.blockMaterial || ((Integer)iblockstate.getValue(LEVEL)).intValue() > 0))
{
int j;
if (this.isBlocked(worldIn, blockpos.down(), worldIn.getBlockState(blockpos.down())))
{
j = this.func_176374_a(worldIn, blockpos, 1, enumfacing.getOpposite());
}
else
{
j = 0;
}
if (j < i)
{
set.clear();
}
if (j <= i)
{
set.add(enumfacing);
i = j;
}
}
}
return set;
}
示例6: updateTick
import net.minecraft.world.World; //导入方法依赖的package包/类
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (!worldIn.isRemote)
{
if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getLightOpacity(worldIn, pos.up()) > 2)
{
worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
}
else
{
if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
{
for (int i = 0; i < 4; ++i)
{
BlockPos blockpos = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
if (blockpos.getY() >= 0 && blockpos.getY() < 256 && !worldIn.isBlockLoaded(blockpos))
{
return;
}
IBlockState iblockstate = worldIn.getBlockState(blockpos.up());
IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
if (iblockstate1.getBlock() == Blocks.DIRT && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos.up()) >= 4 && iblockstate.getLightOpacity(worldIn, pos.up()) <= 2)
{
worldIn.setBlockState(blockpos, UCBlocks.oldGrass.getDefaultState());
}
}
}
}
}
}
示例7: ignitesThings
import net.minecraft.world.World; //导入方法依赖的package包/类
public static boolean ignitesThings(World world, BlockPos pos) {
IBlockState state = world.getBlockState(pos);
if (state.getMaterial()==Material.FIRE) return true;
if (state.getBlock()==Blocks.FIRE) return true;
if (state.getBlock().isBurning(world, pos)) return true;
return false;
}
示例8: calculateInputStrength
import net.minecraft.world.World; //导入方法依赖的package包/类
protected int calculateInputStrength(World worldIn, BlockPos pos, IBlockState state)
{
int i = super.calculateInputStrength(worldIn, pos, state);
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
BlockPos blockpos = pos.offset(enumfacing);
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.hasComparatorInputOverride())
{
i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
}
else if (i < 15 && iblockstate.isNormalCube())
{
blockpos = blockpos.offset(enumfacing);
iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.hasComparatorInputOverride())
{
i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
}
else if (iblockstate.getMaterial() == Material.AIR)
{
EntityItemFrame entityitemframe = this.findItemFrame(worldIn, enumfacing, blockpos);
if (entityitemframe != null)
{
i = entityitemframe.getAnalogOutput();
}
}
}
return i;
}
示例9: canBlockStay
import net.minecraft.world.World; //导入方法依赖的package包/类
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
if (pos.getY() >= 0 && pos.getY() < 256)
{
IBlockState iblockstate = worldIn.getBlockState(pos.down());
return iblockstate.getBlock() == Blocks.mycelium ? true : (iblockstate.getBlock() == Blocks.dirt && iblockstate.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL ? true : worldIn.getLight(pos) < 13 && this.canPlaceBlockOn(iblockstate.getBlock()));
}
else
{
return false;
}
}
示例10: drop
import net.minecraft.world.World; //导入方法依赖的package包/类
private static void drop(World world, BlockPos pos, BlockPos newPos) {
EntityFallingBlock fallingBlock = new EntityFallingBlock(world, newPos.getX(), newPos.getY(), newPos.getZ(), world.getBlockState(pos));
fallingBlock.setEntityBoundingBox(new AxisAlignedBB(newPos.add(0, 0, 0), newPos.add(1, 1, 1)));
fallingBlock.fallTime = 1;
world.spawnEntityInWorld(fallingBlock);
world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
示例11: placeLeafAt
import net.minecraft.world.World; //导入方法依赖的package包/类
private void placeLeafAt(World worldIn, int x, int y, int z)
{
BlockPos blockpos = new BlockPos(x, y, z);
IBlockState state = worldIn.getBlockState(blockpos);
if (state.getBlock().isAir(state, worldIn, blockpos))
{
this.setBlockAndNotifyAdequately(worldIn, blockpos, DARK_OAK_LEAVES);
}
}
示例12: neighborChanged
import net.minecraft.world.World; //导入方法依赖的package包/类
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos p_189540_5_)
{
if (state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
{
BlockPos blockpos = pos.down();
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getBlock() != this)
{
worldIn.setBlockToAir(pos);
}
else if (blockIn != this)
{
iblockstate.neighborChanged(worldIn, blockpos, blockIn, p_189540_5_);
}
}
else
{
boolean flag1 = false;
BlockPos blockpos1 = pos.up();
IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
if (iblockstate1.getBlock() != this)
{
worldIn.setBlockToAir(pos);
flag1 = true;
}
if (!worldIn.getBlockState(pos.down()).isFullyOpaque())
{
worldIn.setBlockToAir(pos);
flag1 = true;
if (iblockstate1.getBlock() == this)
{
worldIn.setBlockToAir(blockpos1);
}
}
if (flag1)
{
if (!worldIn.isRemote)
{
this.dropBlockAsItem(worldIn, pos, state, 0);
}
}
else
{
boolean flag = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos1);
if (blockIn != this && (flag || blockIn.getDefaultState().canProvidePower()) && flag != ((Boolean)iblockstate1.getValue(POWERED)).booleanValue())
{
worldIn.setBlockState(blockpos1, iblockstate1.withProperty(POWERED, Boolean.valueOf(flag)), 2);
if (flag != ((Boolean)state.getValue(OPEN)).booleanValue())
{
worldIn.setBlockState(pos, state.withProperty(OPEN, Boolean.valueOf(flag)), 2);
worldIn.markBlockRangeForRenderUpdate(pos, pos);
worldIn.playEvent((EntityPlayer)null, flag ? this.getOpenSound() : this.getCloseSound(), pos, 0);
}
}
}
}
}
示例13: getGrowthChance
import net.minecraft.world.World; //导入方法依赖的package包/类
protected static float getGrowthChance(Block blockIn, World worldIn, BlockPos pos)
{
float f = 1.0F;
BlockPos blockpos = pos.down();
for (int i = -1; i <= 1; ++i)
{
for (int j = -1; j <= 1; ++j)
{
float f1 = 0.0F;
IBlockState iblockstate = worldIn.getBlockState(blockpos.add(i, 0, j));
if (iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, blockpos.add(i, 0, j), net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable)blockIn))
{
f1 = 1.0F;
if (iblockstate.getBlock().isFertile(worldIn, blockpos.add(i, 0, j)))
{
f1 = 3.0F;
}
}
if (i != 0 || j != 0)
{
f1 /= 4.0F;
}
f += f1;
}
}
BlockPos blockpos1 = pos.north();
BlockPos blockpos2 = pos.south();
BlockPos blockpos3 = pos.west();
BlockPos blockpos4 = pos.east();
boolean flag = blockIn == worldIn.getBlockState(blockpos3).getBlock() || blockIn == worldIn.getBlockState(blockpos4).getBlock();
boolean flag1 = blockIn == worldIn.getBlockState(blockpos1).getBlock() || blockIn == worldIn.getBlockState(blockpos2).getBlock();
if (flag && flag1)
{
f /= 2.0F;
}
else
{
boolean flag2 = blockIn == worldIn.getBlockState(blockpos3.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos3.south()).getBlock();
if (flag2)
{
f /= 2.0F;
}
}
return f;
}
示例14: execute
import net.minecraft.world.World; //导入方法依赖的package包/类
/**
* Callback for when the command is executed
*/
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if (args.length < 4)
{
throw new WrongUsageException("commands.blockdata.usage", new Object[0]);
}
else
{
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 0);
BlockPos blockpos = parseBlockPos(sender, args, 0, false);
World world = sender.getEntityWorld();
if (!world.isBlockLoaded(blockpos))
{
throw new CommandException("commands.blockdata.outOfWorld", new Object[0]);
}
else
{
IBlockState iblockstate = world.getBlockState(blockpos);
TileEntity tileentity = world.getTileEntity(blockpos);
if (tileentity == null)
{
throw new CommandException("commands.blockdata.notValid", new Object[0]);
}
else
{
NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
NBTTagCompound nbttagcompound1 = nbttagcompound.copy();
NBTTagCompound nbttagcompound2;
try
{
nbttagcompound2 = JsonToNBT.getTagFromJson(getChatComponentFromNthArg(sender, args, 3).getUnformattedText());
}
catch (NBTException nbtexception)
{
throw new CommandException("commands.blockdata.tagError", new Object[] {nbtexception.getMessage()});
}
nbttagcompound.merge(nbttagcompound2);
nbttagcompound.setInteger("x", blockpos.getX());
nbttagcompound.setInteger("y", blockpos.getY());
nbttagcompound.setInteger("z", blockpos.getZ());
if (nbttagcompound.equals(nbttagcompound1))
{
throw new CommandException("commands.blockdata.failed", new Object[] {nbttagcompound.toString()});
}
else
{
tileentity.readFromNBT(nbttagcompound);
tileentity.markDirty();
world.notifyBlockUpdate(blockpos, iblockstate, iblockstate, 3);
sender.setCommandStat(CommandResultStats.Type.AFFECTED_BLOCKS, 1);
notifyCommandListener(sender, this, "commands.blockdata.success", new Object[] {nbttagcompound.toString()});
}
}
}
}
}
示例15: getGrowthChance
import net.minecraft.world.World; //导入方法依赖的package包/类
protected static float getGrowthChance(Block blockIn, World worldIn, BlockPos pos)
{
float f = 1.0F;
BlockPos blockpos1 = pos.down();
for (int i = -1; i <= 1; ++i)
{
for (int j = -1; j <= 1; ++j)
{
float f1 = 0.0F;
IBlockState iblockstate = worldIn.getBlockState(blockpos1.add(i, 0, j));
if (iblockstate.getBlock().canSustainPlant(worldIn.getBlockState(blockpos1.add(i, 0, j)),
worldIn, blockpos1.add(i, 0, j), EnumFacing.UP, (IPlantable)blockIn))
{
f1 = 1.0F;
if (iblockstate.getBlock().isFertile(worldIn, blockpos1.add(i, 0, j)))
{
f1 = 3.0F;
}
}
if (i != 0 || j != 0)
{
f1 /= 4.0F;
}
f += f1;
}
}
BlockPos blockpos2 = pos.north();
BlockPos blockpos3 = pos.south();
BlockPos blockpos4 = pos.west();
BlockPos blockpos5 = pos.east();
boolean flag = blockIn == worldIn.getBlockState(blockpos4).getBlock() || blockIn == worldIn.getBlockState(blockpos5).getBlock();
boolean flag1 = blockIn == worldIn.getBlockState(blockpos2).getBlock() || blockIn == worldIn.getBlockState(blockpos3).getBlock();
if (flag && flag1)
{
f /= 2.0F;
}
else
{
boolean flag2 = blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos5.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos5.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock();
if (flag2)
{
f /= 2.0F;
}
}
return f;
}