本文整理汇总了Java中net.minecraft.block.BlockCommandBlock类的典型用法代码示例。如果您正苦于以下问题:Java BlockCommandBlock类的具体用法?Java BlockCommandBlock怎么用?Java BlockCommandBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlockCommandBlock类属于net.minecraft.block包,在下文中一共展示了BlockCommandBlock类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAuto
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
public void setAuto(boolean autoIn)
{
boolean flag = this.auto;
this.auto = autoIn;
if (!flag && autoIn && !this.powered && this.world != null && this.getMode() != TileEntityCommandBlock.Mode.SEQUENCE)
{
Block block = this.getBlockType();
if (block instanceof BlockCommandBlock)
{
BlockPos blockpos = this.getPos();
BlockCommandBlock blockcommandblock = (BlockCommandBlock)block;
this.conditionMet = !this.isConditional() || blockcommandblock.isNextToSuccessfulCommandBlock(this.world, blockpos, this.world.getBlockState(blockpos));
this.world.scheduleUpdate(blockpos, block, block.tickRate(this.world));
if (this.conditionMet)
{
blockcommandblock.propagateUpdate(this.world, blockpos);
}
}
}
}
示例2: setAuto
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
public void setAuto(boolean autoIn)
{
boolean flag = this.auto;
this.auto = autoIn;
if (!flag && autoIn && !this.powered && this.worldObj != null && this.getMode() != TileEntityCommandBlock.Mode.SEQUENCE)
{
Block block = this.getBlockType();
if (block instanceof BlockCommandBlock)
{
BlockPos blockpos = this.getPos();
BlockCommandBlock blockcommandblock = (BlockCommandBlock)block;
this.conditionMet = !this.isConditional() || blockcommandblock.isNextToSuccessfulCommandBlock(this.worldObj, blockpos, this.worldObj.getBlockState(blockpos));
this.worldObj.scheduleUpdate(blockpos, block, block.tickRate(this.worldObj));
if (this.conditionMet)
{
blockcommandblock.propagateUpdate(this.worldObj, blockpos);
}
}
}
}
示例3: rightClick
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
private boolean rightClick(BlockPos pos) {
EnumFacing faceDir = ProgWidgetPlace.getDirForSides(((ISidedWidget) widget).getSides());
EntityPlayer player = drone.getFakePlayer();
World world = drone.world();
ItemStack stack = player.getHeldItemMainhand();
player.setPosition(pos.getX() + 0.5, pos.getY() + 0.5 - player.eyeHeight, pos.getZ() + 0.5);
player.rotationPitch = faceDir.getFrontOffsetY() * -90;
player.rotationYaw = PneumaticCraftUtils.getYawFromFacing(faceDir);
float hitX = (float)(player.posX - pos.getX());
float hitY = (float)(player.posY - pos.getY());
float hitZ = (float)(player.posZ - pos.getZ());
// this is adapted from PlayerInteractionManager#processRightClickBlock()
try {
PlayerInteractEvent.RightClickBlock event = ForgeHooks.onRightClickBlock(player, EnumHand.MAIN_HAND, pos, faceDir.getOpposite(), ForgeHooks.rayTraceEyeHitVec(player, 2.0D));
if (event.isCanceled() || event.getUseItem() == Event.Result.DENY) {
return false;
}
EnumActionResult ret = stack.onItemUseFirst(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
if (ret != EnumActionResult.PASS) return false;
boolean bypass = player.getHeldItemMainhand().doesSneakBypassUse(world, pos, player);
EnumActionResult result = EnumActionResult.PASS;
if (!player.isSneaking() || bypass || event.getUseBlock() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
IBlockState iblockstate = world.getBlockState(pos);
if(event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
if (iblockstate.getBlock().onBlockActivated(world, pos, iblockstate, player, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ)) {
result = EnumActionResult.SUCCESS;
}
}
if (stack.isEmpty() || player.getCooldownTracker().hasCooldown(stack.getItem())) {
return false;
}
if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock()) {
Block block = ((ItemBlock)stack.getItem()).getBlock();
if (block instanceof BlockCommandBlock || block instanceof BlockStructure) {
return false;
}
}
if (result != EnumActionResult.SUCCESS && event.getUseItem() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY
|| result == EnumActionResult.SUCCESS && event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.ALLOW) {
ItemStack copyBeforeUse = stack.copy();
result = stack.onItemUse(player, world, pos, EnumHand.MAIN_HAND, faceDir, hitX, hitY, hitZ);
if (result == EnumActionResult.PASS) {
ActionResult<ItemStack> rightClickResult = stack.getItem().onItemRightClick(world, player, EnumHand.MAIN_HAND);
player.setHeldItem(EnumHand.MAIN_HAND, rightClickResult.getResult());
}
if (player.getHeldItem(EnumHand.MAIN_HAND).isEmpty()) {
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, copyBeforeUse, EnumHand.MAIN_HAND);
}
}
return false;
} catch (Throwable e) {
Log.error("DroneAIBlockInteract crashed! Stacktrace: ");
e.printStackTrace();
return false;
}
}
示例4: auxHarvestBlock
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
/**
* Destroys and tries to harvest a block with the currently active tool, except that instead of calling
* onBlockDestroyed, it calls onBlockAuxDestroyed on the tool, preventing infinite loops.
*/
public static boolean auxHarvestBlock(World world, BlockPos pos, EntityPlayerMP player) {
if (world.isRemote) return false; //Shouldn't even be possible if we have an EntityPlayerMP!
GameType gameType = player.interactionManager.getGameType();
int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos);
if (exp == -1) {
return false;
} else {
IBlockState iblockstate = world.getBlockState(pos);
if (iblockstate.getBlockHardness(world, pos)<0) return false;
TileEntity tileentity = world.getTileEntity(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
return false;
} else {
ItemStack stack = player.getHeldItemMainhand();
if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false;
world.playEvent(player, 2001, pos, Block.getStateId(iblockstate));
boolean removed = false;
if (gameType==GameType.CREATIVE) {
removed = removeBlock(world, pos, player, false);
player.connection.sendPacket(new SPacketBlockChange(world, pos));
} else {
ItemStack itemstack1 = player.getHeldItemMainhand();
ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
boolean canHarvest = iblockstate.getBlock().canHarvestBlock(world, pos, player);
if (!itemstack1.isEmpty()) {
// itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
if (itemstack1.getItem() instanceof IAuxDestroyBlock) {
((IAuxDestroyBlock)itemstack1.getItem()).onBlockAuxDestroyed(world, iblockstate, pos, player);
}
}
removed = removeBlock(world, pos, player, canHarvest);
if (removed && canHarvest) {
iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
}
}
// Drop experience
if (gameType!=GameType.CREATIVE && removed && exp > 0) {
iblockstate.getBlock().dropXpOnBlockBreak(world, pos, exp);
}
return removed;
}
}
}
示例5: processRightClickBlock
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
public EnumActionResult processRightClickBlock(EntityPlayerSP player, WorldClient worldIn, BlockPos stack, EnumFacing pos, Vec3d facing, EnumHand vec)
{
this.syncCurrentPlayItem();
ItemStack itemstack = player.getHeldItem(vec);
float f = (float)(facing.xCoord - (double)stack.getX());
float f1 = (float)(facing.yCoord - (double)stack.getY());
float f2 = (float)(facing.zCoord - (double)stack.getZ());
boolean flag = false;
if (!this.mc.world.getWorldBorder().contains(stack))
{
return EnumActionResult.FAIL;
}
else
{
if (this.currentGameType != GameType.SPECTATOR)
{
IBlockState iblockstate = worldIn.getBlockState(stack);
if ((!player.isSneaking() || player.getHeldItemMainhand().func_190926_b() && player.getHeldItemOffhand().func_190926_b()) && iblockstate.getBlock().onBlockActivated(worldIn, stack, iblockstate, player, vec, pos, f, f1, f2))
{
flag = true;
}
if (!flag && itemstack.getItem() instanceof ItemBlock)
{
ItemBlock itemblock = (ItemBlock)itemstack.getItem();
if (!itemblock.canPlaceBlockOnSide(worldIn, stack, pos, player, itemstack))
{
return EnumActionResult.FAIL;
}
}
}
this.connection.sendPacket(new CPacketPlayerTryUseItemOnBlock(stack, pos, vec, f, f1, f2));
if (!flag && this.currentGameType != GameType.SPECTATOR)
{
if (itemstack.func_190926_b())
{
return EnumActionResult.PASS;
}
else if (player.getCooldownTracker().hasCooldown(itemstack.getItem()))
{
return EnumActionResult.PASS;
}
else
{
if (itemstack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
{
Block block = ((ItemBlock)itemstack.getItem()).getBlock();
if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
{
return EnumActionResult.FAIL;
}
}
if (this.currentGameType.isCreative())
{
int i = itemstack.getMetadata();
int j = itemstack.func_190916_E();
EnumActionResult enumactionresult = itemstack.onItemUse(player, worldIn, stack, vec, pos, f, f1, f2);
itemstack.setItemDamage(i);
itemstack.func_190920_e(j);
return enumactionresult;
}
else
{
return itemstack.onItemUse(player, worldIn, stack, vec, pos, f, f1, f2);
}
}
}
else
{
return EnumActionResult.SUCCESS;
}
}
}
示例6: tryHarvestBlock
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
/**
* Attempts to harvest a block
*/
public boolean tryHarvestBlock(BlockPos pos)
{
if (this.gameType.isCreative() && !this.thisPlayerMP.getHeldItemMainhand().func_190926_b() && this.thisPlayerMP.getHeldItemMainhand().getItem() instanceof ItemSword)
{
return false;
}
else
{
IBlockState iblockstate = this.theWorld.getBlockState(pos);
TileEntity tileentity = this.theWorld.getTileEntity(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.thisPlayerMP.canUseCommandBlock())
{
this.theWorld.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
return false;
}
else
{
if (this.gameType.isAdventure())
{
if (this.gameType == GameType.SPECTATOR)
{
return false;
}
if (!this.thisPlayerMP.isAllowEdit())
{
ItemStack itemstack = this.thisPlayerMP.getHeldItemMainhand();
if (itemstack.func_190926_b())
{
return false;
}
if (!itemstack.canDestroy(block))
{
return false;
}
}
}
this.theWorld.playEvent(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
boolean flag1 = this.removeBlock(pos);
if (this.isCreative())
{
this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
}
else
{
ItemStack itemstack1 = this.thisPlayerMP.getHeldItemMainhand();
ItemStack itemstack2 = itemstack1.func_190926_b() ? ItemStack.field_190927_a : itemstack1.copy();
boolean flag = this.thisPlayerMP.canHarvestBlock(iblockstate);
if (!itemstack1.func_190926_b())
{
itemstack1.onBlockDestroyed(this.theWorld, iblockstate, pos, this.thisPlayerMP);
}
if (flag1 && flag)
{
iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity, itemstack2);
}
}
return flag1;
}
}
}
示例7: processRightClickBlock
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
public EnumActionResult processRightClickBlock(EntityPlayer player, World worldIn, ItemStack stack, EnumHand hand, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (this.gameType == GameType.SPECTATOR)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof ILockableContainer)
{
Block block1 = worldIn.getBlockState(pos).getBlock();
ILockableContainer ilockablecontainer = (ILockableContainer)tileentity;
if (ilockablecontainer instanceof TileEntityChest && block1 instanceof BlockChest)
{
ilockablecontainer = ((BlockChest)block1).getLockableContainer(worldIn, pos);
}
if (ilockablecontainer != null)
{
player.displayGUIChest(ilockablecontainer);
return EnumActionResult.SUCCESS;
}
}
else if (tileentity instanceof IInventory)
{
player.displayGUIChest((IInventory)tileentity);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
else
{
if (!player.isSneaking() || player.getHeldItemMainhand().func_190926_b() && player.getHeldItemOffhand().func_190926_b())
{
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock().onBlockActivated(worldIn, pos, iblockstate, player, hand, facing, hitX, hitY, hitZ))
{
return EnumActionResult.SUCCESS;
}
}
if (stack.func_190926_b())
{
return EnumActionResult.PASS;
}
else if (player.getCooldownTracker().hasCooldown(stack.getItem()))
{
return EnumActionResult.PASS;
}
else
{
if (stack.getItem() instanceof ItemBlock && !player.canUseCommandBlock())
{
Block block = ((ItemBlock)stack.getItem()).getBlock();
if (block instanceof BlockCommandBlock || block instanceof BlockStructure)
{
return EnumActionResult.FAIL;
}
}
if (this.isCreative())
{
int j = stack.getMetadata();
int i = stack.func_190916_E();
EnumActionResult enumactionresult = stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
stack.setItemDamage(j);
stack.func_190920_e(i);
return enumactionresult;
}
else
{
return stack.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
}
}
}
示例8: isConditional
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
public boolean isConditional()
{
IBlockState iblockstate = this.world.getBlockState(this.getPos());
return iblockstate.getBlock() instanceof BlockCommandBlock ? ((Boolean)iblockstate.getValue(BlockCommandBlock.CONDITIONAL)).booleanValue() : false;
}
示例9: onPlayerDestroyBlock
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
public boolean onPlayerDestroyBlock(BlockPos pos)
{
if (this.currentGameType.isAdventure())
{
if (this.currentGameType == GameType.SPECTATOR)
{
return false;
}
if (!this.mc.thePlayer.isAllowEdit())
{
ItemStack itemstack = this.mc.thePlayer.getHeldItemMainhand();
if (itemstack == null)
{
return false;
}
if (!itemstack.canDestroy(this.mc.theWorld.getBlockState(pos).getBlock()))
{
return false;
}
}
}
ItemStack stack = mc.thePlayer.getHeldItemMainhand();
if (stack != null && stack.getItem() != null && stack.getItem().onBlockStartBreak(stack, pos, mc.thePlayer))
{
return false;
}
if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItemMainhand() != null && this.mc.thePlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
{
return false;
}
else
{
World world = this.mc.theWorld;
IBlockState iblockstate = world.getBlockState(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.mc.thePlayer.canUseCommandBlock())
{
return false;
}
else if (iblockstate.getMaterial() == Material.AIR)
{
return false;
}
else
{
world.playEvent(2001, pos, Block.getStateId(iblockstate));
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
if (!this.currentGameType.isCreative())
{
ItemStack itemstack1 = this.mc.thePlayer.getHeldItemMainhand();
if (itemstack1 != null)
{
itemstack1.onBlockDestroyed(world, iblockstate, pos, this.mc.thePlayer);
if (itemstack1.stackSize <= 0)
{
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.mc.thePlayer, itemstack1, EnumHand.MAIN_HAND);
this.mc.thePlayer.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
}
}
}
boolean flag = block.removedByPlayer(iblockstate, world, pos, mc.thePlayer, false);
if (flag)
{
block.onBlockDestroyedByPlayer(world, pos, iblockstate);
}
return flag;
}
}
}
示例10: tryHarvestBlock
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
/**
* Attempts to harvest a block
*/
public boolean tryHarvestBlock(BlockPos pos)
{
int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(theWorld, gameType, thisPlayerMP, pos);
if (exp == -1)
{
return false;
}
else
{
IBlockState iblockstate = this.theWorld.getBlockState(pos);
TileEntity tileentity = this.theWorld.getTileEntity(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.thisPlayerMP.canUseCommandBlock())
{
this.theWorld.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
return false;
}
else
{
ItemStack stack = thisPlayerMP.getHeldItemMainhand();
if (stack != null && stack.getItem().onBlockStartBreak(stack, pos, thisPlayerMP)) return false;
this.theWorld.playEvent(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
boolean flag1 = false;
if (this.isCreative())
{
flag1 = this.removeBlock(pos);
this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
}
else
{
ItemStack itemstack1 = this.thisPlayerMP.getHeldItemMainhand();
ItemStack itemstack2 = itemstack1 == null ? null : itemstack1.copy();
boolean flag = iblockstate.getBlock().canHarvestBlock(theWorld, pos, thisPlayerMP);
if (itemstack1 != null)
{
itemstack1.onBlockDestroyed(this.theWorld, iblockstate, pos, this.thisPlayerMP);
if (itemstack1.stackSize <= 0)
{
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.thisPlayerMP, itemstack1, EnumHand.MAIN_HAND);
this.thisPlayerMP.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
}
}
flag1 = this.removeBlock(pos, flag);
if (flag1 && flag)
{
iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity, itemstack2);
}
}
// Drop experience
if (!this.isCreative() && flag1 && exp > 0)
{
iblockstate.getBlock().dropXpOnBlockBreak(theWorld, pos, exp);
}
return flag1;
}
}
}
示例11: isConditional
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
public boolean isConditional()
{
IBlockState iblockstate = this.worldObj.getBlockState(this.getPos());
return iblockstate.getBlock() instanceof BlockCommandBlock ? ((Boolean)iblockstate.getValue(BlockCommandBlock.CONDITIONAL)).booleanValue() : false;
}
示例12: execute
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if(args.length == 0) {
throw new WrongUsageException("Not enough parameters for meaningful action. ("+args.length+")");
}
if(sender.getCommandSenderEntity() == null) {
throw new WrongUsageException("ICommandSender does not have a entity assigned! Bug?");
}
boolean cmd = sender instanceof BlockCommandBlock;
if(!(sender.getCommandSenderEntity() instanceof EntityPlayerMP || cmd)) {
throw new WrongUsageException("This command can only be executed by a opped player or command block.");
}
EntityPlayerMP player = null;
if(!cmd){
player = (EntityPlayerMP) sender.getCommandSenderEntity();
if(!PlayerHelper.isOp(player)) {
throw new WrongUsageException("This command can only be executed by a opped player.");
}
}
if(args[0].equals("run")) {
if(args.length == 2) {
// Runs a script
String script = args[1];
if(script != null && !script.isEmpty()) {
Invoke.invoke(new FileScriptInvoke(script), new CommandSenderInvokeSource(sender), null, EnumTriggerState.ON);
}
} else {
throw new WrongUsageException("Wrong parameter count: /tc_script run <scriptname>");
}
}
if(args[0].equals("edit")) {
if(cmd) throw new WrongUsageException("Edit can only be run by a player.");
if(args.length == 2) {
// Get Script name
String fileName = args[1];
// Load Script
String fileContent = TaleCraft.globalScriptManager.loadScript(sender.getEntityWorld(), fileName);
// Send Command-Packet with script to sender!
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("scriptname", fileName);
nbt.setString("script", fileContent);
TaleCraft.network.sendTo(new StringNBTCommandPacket("script_edit", nbt), player);
} else {
throw new WrongUsageException("Wrong parameter count: /tc_script edit <scriptname>");
}
}
}
示例13: trigger
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
public static final void trigger(World world, BlockPos position, IBlockState state, EnumTriggerState state2) {
Block block = state.getBlock();
if(block instanceof TCITriggerableBlock){
((TCITriggerableBlock) state.getBlock()).trigger(world, position, state2);
return;
}
if(block instanceof BlockCommandBlock) {
((TileEntityCommandBlock)world.getTileEntity(position)).getCommandBlockLogic().trigger(world);
return;
}
// Just for the heck of it!
if(block instanceof BlockTNT) {
((BlockTNT) block).explode(world, position, state.withProperty(BlockTNT.EXPLODE, Boolean.TRUE), null);
world.setBlockToAir(position);
return;
}
if(block instanceof BlockDispenser) {
block.updateTick(world, position, state, TaleCraft.random);
return;
}
if(block instanceof BlockDropper) {
block.updateTick(world, position, state, TaleCraft.random);
return;
}
// XXX: Experimental: This could break with any update.
if(block instanceof BlockLever) {
state = state.cycleProperty(BlockLever.POWERED);
world.setBlockState(position, state, 3);
world.playSound(position.getX() + 0.5D, position.getY() + 0.5D, position.getZ() + 0.5D, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3F, state.getValue(BlockLever.POWERED).booleanValue() ? 0.6F : 0.5F, false);
world.notifyNeighborsOfStateChange(position, block, true);
EnumFacing enumfacing1 = state.getValue(BlockLever.FACING).getFacing();
world.notifyNeighborsOfStateChange(position.offset(enumfacing1.getOpposite()), block, true);
return;
}
// XXX: Experimental: This could break with any update.
if(block instanceof BlockButton) {
world.setBlockState(position, state.withProperty(BlockButton.POWERED, Boolean.valueOf(true)), 3);
world.markBlockRangeForRenderUpdate(position, position);
world.playSound(position.getX() + 0.5D, position.getY() + 0.5D, position.getZ() + 0.5D, SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, SoundCategory.BLOCKS, 0.3F, 0.6F, false); //TODO There are multiple button click sounds
world.notifyNeighborsOfStateChange(position, block, true);
world.notifyNeighborsOfStateChange(position.offset(state.getValue(BlockDirectional.FACING).getOpposite()), block, true);
world.scheduleUpdate(position, block, block.tickRate(world));
}
// XXX: Implement more vanilla triggers?
}
示例14: onPlayerDestroyBlock
import net.minecraft.block.BlockCommandBlock; //导入依赖的package包/类
public boolean onPlayerDestroyBlock(BlockPos pos)
{
if (this.currentGameType.isAdventure())
{
if (this.currentGameType == GameType.SPECTATOR)
{
return false;
}
if (!this.mc.thePlayer.isAllowEdit())
{
ItemStack itemstack = this.mc.thePlayer.getHeldItemMainhand();
if (itemstack == null)
{
return false;
}
if (!itemstack.canDestroy(this.mc.theWorld.getBlockState(pos).getBlock()))
{
return false;
}
}
}
ItemStack stack = mc.thePlayer.getHeldItemMainhand();
if (stack != null && stack.getItem() != null && stack.getItem().onBlockStartBreak(stack, pos, mc.thePlayer))
{
return false;
}
if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItemMainhand() != null && this.mc.thePlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
{
return false;
}
else
{
World world = this.mc.theWorld;
IBlockState iblockstate = world.getBlockState(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.mc.thePlayer.func_189808_dh())
{
return false;
}
else if (iblockstate.getMaterial() == Material.AIR)
{
return false;
}
else
{
world.playEvent(2001, pos, Block.getStateId(iblockstate));
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
if (!this.currentGameType.isCreative())
{
ItemStack itemstack1 = this.mc.thePlayer.getHeldItemMainhand();
if (itemstack1 != null)
{
itemstack1.onBlockDestroyed(world, iblockstate, pos, this.mc.thePlayer);
if (itemstack1.stackSize <= 0)
{
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.mc.thePlayer, itemstack1, EnumHand.MAIN_HAND);
this.mc.thePlayer.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
}
}
}
boolean flag = block.removedByPlayer(iblockstate, world, pos, mc.thePlayer, false);
if (flag)
{
block.onBlockDestroyedByPlayer(world, pos, iblockstate);
}
return flag;
}
}
}