本文整理了Java中net.minecraft.world.World.isBlockModifiable()
方法的一些代码示例,展示了World.isBlockModifiable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。World.isBlockModifiable()
方法的具体详情如下:
包路径:net.minecraft.world.World
类名称:World
方法名:isBlockModifiable
暂无
代码示例来源:origin: Vazkii/Botania
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float par8, float par9, float par10) {
ItemStack stack = player.getHeldItem(hand);
if(ManaItemHandler.requestManaExactForTool(stack, player, COST, false) && !world.provider.doesWaterVaporize()) {
// Adapted from bucket code
RayTraceResult mop = rayTrace(world, player, false);
if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos hitPos = mop.getBlockPos();
if(!world.isBlockModifiable(player, hitPos))
return EnumActionResult.FAIL;
BlockPos placePos = hitPos.offset(mop.sideHit);
if(player.canPlayerEdit(placePos, mop.sideHit, stack)) {
if (ManaItemHandler.requestManaExactForTool(stack, player, COST, true)
&& ((ItemBucket) Items.WATER_BUCKET).tryPlaceContainedLiquid(player, world, placePos)) {
for(int i = 0; i < 6; i++)
Botania.proxy.sparkleFX(pos.getX() + side.getXOffset() + Math.random(), pos.getY() + side.getYOffset() + Math.random(), pos.getZ() + side.getZOffset() + Math.random(), 0.2F, 0.2F, 1F, 1F, 5);
return EnumActionResult.SUCCESS;
}
}
}
return EnumActionResult.FAIL;
}
return EnumActionResult.PASS;
}
代码示例来源:origin: Vazkii/Botania
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) {
RayTraceResult rtr = rayTrace(world, player, true);
ItemStack stack = player.getHeldItem(hand);
if(rtr == null)
return ActionResult.newResult(EnumActionResult.PASS, stack);
else {
if(rtr.typeOfHit == net.minecraft.util.math.RayTraceResult.Type.BLOCK) {
BlockPos pos = rtr.getBlockPos();
if(!world.isBlockModifiable(player, pos))
return ActionResult.newResult(EnumActionResult.PASS, stack);
if(!player.canPlayerEdit(pos, rtr.sideHit, stack))
return ActionResult.newResult(EnumActionResult.PASS, stack);
IBlockState state = world.getBlockState(pos);
Fluid fluid = FluidRegistry.lookupFluidForBlock(state.getBlock());
boolean isFull = state.getBlock() instanceof BlockLiquid && state.getValue(BlockLiquid.LEVEL) == 0
|| state.getBlock() instanceof IFluidBlock && Math.abs(((IFluidBlock) state.getBlock()).getFilledPercentage(world, pos)) >= 1;
if(fluid != null && isFull) {
player.playSound(fluid.getFillSound(world, pos), 1.0f, 1.0f);
world.setBlockToAir(pos);
for(int x = 0; x < 5; x++)
world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), 0, 0, 0);
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
}
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
}
代码示例来源:origin: SleepyTrousers/EnderIO
@Override
public boolean isBlockModifiable(@Nonnull EntityPlayer player1, @Nonnull BlockPos pos) {
return wrapped.isBlockModifiable(player1, pos);
}
代码示例来源:origin: amadornes/MCMultiPart
@Override
public boolean isBlockModifiable(EntityPlayer player, BlockPos pos) {
return getActualWorld().isBlockModifiable(player, pos);
}
代码示例来源:origin: AlgorithmX2/Chisels-and-Bits
public boolean canPlayerManipulate(
final @Nonnull BlockPos pos,
final @Nonnull EnumFacing side,
final @Nonnull ItemStack is,
final boolean placement )
{
// only re-test if something changes.
if ( permissionResult == null || lastPermissionBit != is || lastPos != pos || placement != lastPlacement )
{
lastPos = pos;
lastPlacement = placement;
lastPermissionBit = is;
if ( innerPlayer.canPlayerEdit( pos, side, is ) && innerPlayer.worldObj.isBlockModifiable( innerPlayer, pos ) )
{
final EventBlockBitModification event = new EventBlockBitModification( innerPlayer.worldObj, pos, innerPlayer, hand, is, placement );
MinecraftForge.EVENT_BUS.post( event );
permissionResult = !event.isCanceled();
}
else
{
permissionResult = false;
}
}
return permissionResult;
}
代码示例来源:origin: Vazkii/Psi
public static void conjure(World world, BlockPos pos, EntityPlayer player, IBlockState state) {
if(world.isRemote || !world.isBlockLoaded(pos) || !world.isBlockModifiable(player, pos))
return;
IBlockState inWorld = world.getBlockState(pos);
Block block = inWorld.getBlock();
if(block.isAir(inWorld, world, pos) || block.isReplaceable(world, pos))
world.setBlockState(pos, state);
}
代码示例来源:origin: OpenMods/OpenModsLib
public boolean place(IBlockState state, EnumFacing direction, EnumHand hand) {
if (!world.isBlockLoaded(blockPos)) return false;
if (spawnProtection) {
if (!world.isBlockModifiable(player, blockPos)) return false;
}
final BlockSnapshot snapshot = BlockSnapshot.getBlockSnapshot(world, blockPos);
if (!world.setBlockState(blockPos, state, blockPlaceFlags)) return false;
if (ForgeEventFactory.onPlayerBlockPlace(player, snapshot, direction, hand).isCanceled()) {
world.restoringBlockSnapshots = true;
snapshot.restore(true, false);
world.restoringBlockSnapshots = false;
return false;
}
return true;
}
}
代码示例来源:origin: GregTechCE/GregTech
public static int applyTimberAxe(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer harvester, List<ItemStack> drops) {
if(harvester.isSneaking() ||
!GTUtility.isBlockOrePrefixed(world, blockPos, blockState, OrePrefix.log, drops))
return 0; //do not try to convert while shift-clicking or non-log blocks
MutableBlockPos mutableBlockPos = new MutableBlockPos(blockPos);
int destroyedAmount = 0;
while(true) {
mutableBlockPos.move(EnumFacing.UP);
IBlockState targetState = world.getBlockState(mutableBlockPos);
if(targetState != blockState ||
!world.isBlockModifiable(harvester, mutableBlockPos) ||
!((EntityPlayerMP) harvester).interactionManager.tryHarvestBlock(mutableBlockPos))
return destroyedAmount;
destroyedAmount++;
}
}
代码示例来源:origin: CoFH/ThermalExpansion
ActionResult<ItemStack> doBucketFill(ItemStack stack, @Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
if (getSpace(stack) < Fluid.BUCKET_VOLUME) {
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
RayTraceResult traceResult = RayTracer.retrace(player, true);
if (traceResult == null || traceResult.sideHit == null || traceResult.typeOfHit != RayTraceResult.Type.BLOCK) {
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
BlockPos pos = traceResult.getBlockPos();
if (world.isBlockModifiable(player, pos)) {
if (player.canPlayerEdit(pos, traceResult.sideHit, stack)) {
FluidActionResult result = FluidUtil.tryPickUpFluid(stack, player, world, pos, traceResult.sideHit);
if (result.isSuccess() && !player.capabilities.isCreativeMode) {
player.addStat(StatList.getObjectUseStats(this));
return ActionResult.newResult(EnumActionResult.SUCCESS, result.getResult());
}
}
}
return ActionResult.newResult(EnumActionResult.FAIL, stack);
}
代码示例来源:origin: OpenMods/OpenModsLib
public boolean remove() {
if (!world.isBlockLoaded(blockPos)) return false;
if (spawnProtection) {
if (!world.isBlockModifiable(player, blockPos)) return false;
}
if (eventCheck) {
final IBlockState blockState = world.getBlockState(blockPos);
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockState, player);
event.setExpToDrop(0);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled()) return false;
}
if (silentTeRemove) world.removeTileEntity(blockPos);
return world.setBlockToAir(blockPos);
}
代码示例来源:origin: CoFH/ThermalExpansion
ActionResult<ItemStack> doBucketEmpty(ItemStack stack, @Nonnull World world, @Nonnull EntityPlayer player, @Nonnull EnumHand hand) {
if (getFluidAmount(stack) < Fluid.BUCKET_VOLUME) {
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
RayTraceResult traceResult = this.rayTrace(world, player, false);
if (traceResult == null || traceResult.typeOfHit != RayTraceResult.Type.BLOCK) {
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
BlockPos pos = traceResult.getBlockPos();
if (world.isBlockModifiable(player, pos)) {
BlockPos targetPos = pos.offset(traceResult.sideHit);
if (player.canPlayerEdit(targetPos, traceResult.sideHit.getOpposite(), stack)) {
FluidActionResult result = FluidUtil.tryPlaceFluid(player, world, targetPos, stack, new FluidStack(getFluid(stack), Fluid.BUCKET_VOLUME));
if (result.isSuccess() && !player.capabilities.isCreativeMode) {
player.addStat(StatList.getObjectUseStats(this));
return ActionResult.newResult(EnumActionResult.SUCCESS, result.getResult());
}
}
}
return ActionResult.newResult(EnumActionResult.FAIL, stack);
}
代码示例来源:origin: OpenMods/OpenModsLib
@Override
public List<EntityItem> usePlayer(OpenModsFakePlayer fakePlayer) {
if (!worldObj.isBlockModifiable(fakePlayer, blockPos)) return Lists.newArrayList();
代码示例来源:origin: Vazkii/Psi
@Override
public Object execute(SpellContext context) throws SpellRuntimeException {
Vector3 positionVal = this.getParamValue(context, position);
Double timeVal = this.<Double>getParamValue(context, time);
if(positionVal == null)
throw new SpellRuntimeException(SpellRuntimeException.NULL_VECTOR);
if(!context.isInRadius(positionVal))
throw new SpellRuntimeException(SpellRuntimeException.OUTSIDE_RADIUS);
BlockPos pos = positionVal.toBlockPos();
World world = context.caster.getEntityWorld();
if(!world.isBlockModifiable(context.caster, pos))
return null;
conjure(context, timeVal, pos, world, messWithState(ModBlocks.conjured.getDefaultState()));
return null;
}
代码示例来源:origin: Vazkii/Psi
@Override
public Object execute(SpellContext context) throws SpellRuntimeException {
Vector3 positionVal = this.getParamValue(context, position);
Vector3 targetVal = this.getParamValue(context, target);
Double maxBlocksVal = this.<Double>getParamValue(context, maxBlocks);
Double timeVal = this.<Double>getParamValue(context, time);
int maxBlocksInt = maxBlocksVal.intValue();
if(positionVal == null)
throw new SpellRuntimeException(SpellRuntimeException.NULL_VECTOR);
int len = (int) targetVal.mag();
Vector3 targetNorm = targetVal.copy().normalize();
World world = context.caster.getEntityWorld();
for(int i = 0; i < Math.min(len, maxBlocksInt); i++) {
Vector3 blockVec = positionVal.copy().add(targetNorm.copy().multiply(i));
if(!context.isInRadius(blockVec))
throw new SpellRuntimeException(SpellRuntimeException.OUTSIDE_RADIUS);
BlockPos pos = blockVec.toBlockPos();
if(!world.isBlockModifiable(context.caster, pos))
continue;
PieceTrickConjureBlock.conjure(context, timeVal, pos, world, messWithState(ModBlocks.conjured.getDefaultState()));
}
return null;
}
代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
if (!(entityLiving instanceof EntityPlayer)) {
return stack;
}
if (worldIn.isRemote) {
if (!MinecraftForge.EVENT_BUS.post(new MOEventScan((EntityPlayer) entityLiving, stack, getScanningPos(stack, entityLiving)))) {
stopScanSounds();
}
} else {
MOEventScan event = new MOEventScan((EntityPlayer) entityLiving, stack, getScanningPos(stack, entityLiving));
if (!MinecraftForge.EVENT_BUS.post(event)) {
if (destroysBlocks(stack) && worldIn.isBlockModifiable((EntityPlayer) entityLiving, event.position.getBlockPos())) {
worldIn.setBlockToAir(event.position.getBlockPos());
}
SoundHandler.PlaySoundAt(worldIn, MatterOverdriveSounds.scannerSuccess, SoundCategory.PLAYERS, entityLiving);
}
}
return stack;
}
代码示例来源:origin: Glitchfiend/ToughAsNails
@SubscribeEvent
public void onRightClickHoldingBucket(FillBucketEvent event)
{
// check we're using a bucket, on a block we can modify
if (event.getEmptyBucket().getItem() != Items.BUCKET) {return;}
if (event.getTarget() == null || event.getTarget().typeOfHit != RayTraceResult.Type.BLOCK) {return;}
BlockPos blockpos = event.getTarget().getBlockPos();
if (!event.getWorld().isBlockModifiable(event.getEntityPlayer(), blockpos)) {return;}
if (!event.getEntityPlayer().canPlayerEdit(blockpos.offset(event.getTarget().sideHit), event.getTarget().sideHit, event.getEmptyBucket())) {return;}
// determine if the block is one of our TAN fluids
IBlockState iblockstate = event.getWorld().getBlockState(blockpos);
Fluid filled_fluid = null;
if (iblockstate.getBlock() == TANBlocks.purified_water && iblockstate.getValue(BlockPurifiedWaterFluid.LEVEL).intValue() == 0)
{
filled_fluid = PurifiedWaterFluid.instance;
}
else
{
return;
}
// remove the fluid and return the appropriate filled bucket
event.setResult(Result.ALLOW);
event.setFilledBucket(UniversalBucket.getFilledBucket(ForgeModContainer.getInstance().universalBucket, filled_fluid));
event.getWorld().setBlockToAir(blockpos);
//TODO: event.entityPlayer.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(event.getEmptyBucket().getItem())]);
}
}
代码示例来源:origin: Vazkii/Psi
public static void removeBlockWithDrops(SpellContext context, EntityPlayer player, World world, ItemStack tool, BlockPos pos, boolean particles) {
if(!world.isBlockLoaded(pos) || (context.positionBroken != null && pos.equals(context.positionBroken.getBlockPos())) || !world.isBlockModifiable(player, pos))
return;
if (tool.isEmpty())
tool = PsiAPI.getPlayerCAD(player);
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if(!world.isRemote && !block.isAir(state, world, pos) && !(block instanceof BlockLiquid) && !(block instanceof IFluidBlock) && state.getPlayerRelativeBlockHardness(player, world, pos) > 0) {
if(!canHarvestBlock(block, player, world, pos, tool))
return;
BreakEvent event = createBreakEvent(state, player, world, pos, tool);
MinecraftForge.EVENT_BUS.post(event);
if(!event.isCanceled()) {
if(!player.capabilities.isCreativeMode) {
TileEntity tile = world.getTileEntity(pos);
if(block.removedByPlayer(state, world, pos, player, true)) {
block.onBlockDestroyedByPlayer(world, pos, state);
block.harvestBlock(world, player, pos, state, tile, tool);
}
} else world.setBlockToAir(pos);
}
if(particles)
world.playEvent(2001, pos, Block.getStateId(state));
}
}
代码示例来源:origin: Vazkii/Psi
public static void placeBlock(EntityPlayer player, World world, BlockPos pos, int slot, boolean particles, boolean conjure) {
if(!world.isBlockLoaded(pos) || !world.isBlockModifiable(player, pos))
return;
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if(block.isAir(state, world, pos) || block.isReplaceable(world, pos)) {
if(conjure) {
if(!world.isRemote)
world.setBlockState(pos, ModBlocks.conjured.getDefaultState());
} else {
ItemStack stack = player.inventory.getStackInSlot(slot);
if(!stack.isEmpty() && stack.getItem() instanceof ItemBlock) {
ItemStack rem = removeFromInventory(player, stack);
ItemBlock iblock = (ItemBlock) rem.getItem();
Block blockToPlace = Block.getBlockFromItem(rem.getItem());
if(!world.isRemote) {
IBlockState newState = blockToPlace.getStateForPlacement(world, pos, EnumFacing.UP, 0, 0, 0, rem.getItemDamage(), player, EnumHand.MAIN_HAND);
iblock.placeBlockAt(stack, player, world, pos, EnumFacing.UP, 0, 0, 0, newState);
}
if(player.capabilities.isCreativeMode)
HUDHandler.setRemaining(rem, -1);
else HUDHandler.setRemaining(player, rem, null);
}
}
if(particles && !world.isRemote)
world.playEvent(2001, pos, Block.getStateId(world.getBlockState(pos)));
}
}
代码示例来源:origin: Vazkii/Psi
@Override
public Object execute(SpellContext context) throws SpellRuntimeException {
if(context.caster.getEntityWorld().isRemote)
return null;
Vector3 positionVal = this.getParamValue(context, position);
if(positionVal == null)
throw new SpellRuntimeException(SpellRuntimeException.NULL_VECTOR);
if(!context.isInRadius(positionVal))
throw new SpellRuntimeException(SpellRuntimeException.OUTSIDE_RADIUS);
BlockPos pos = positionVal.toBlockPos();
if(!context.caster.getEntityWorld().isBlockModifiable(context.caster, pos))
return null;
IBlockState state = context.caster.getEntityWorld().getBlockState(pos);
Block block = state.getBlock();
int meta = block.getMetaFromState(state);
ItemStack stack = new ItemStack(block, 1, meta);
ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
if(!result.isEmpty()) {
Item item = result.getItem();
Block block1 = Block.getBlockFromItem(item);
if(block1 != Blocks.AIR) {
context.caster.getEntityWorld().setBlockState(pos, block1.getStateFromMeta(result.getMetadata()));
state = context.caster.getEntityWorld().getBlockState(pos);
context.caster.getEntityWorld().playEvent(2001, pos, Block.getStateId(state));
}
}
return null;
}
代码示例来源:origin: CyclopsMC/EvilCraft
@SubscribeEvent
public void onPoisonRightClick(PlayerInteractEvent.RightClickBlock event) {
EnumHand hand = event.getEntityPlayer().getActiveHand();
// Return poison bottle instead of water bottle when right clicking poison fluid source with empty bottle.
if(hand != null && !event.getEntityPlayer().getHeldItem(hand).isEmpty() &&
event.getEntityPlayer().getHeldItem(hand).getItem() == Items.GLASS_BOTTLE && Configs.isEnabled(PoisonConfig.class)) {
RayTraceResult pos = this.rayTrace(event.getWorld(), event.getEntityPlayer(), true);
if(pos != null && pos.typeOfHit == RayTraceResult.Type.BLOCK) {
if(event.getWorld().isBlockModifiable(event.getEntityPlayer(), pos.getBlockPos()) &&
event.getEntityPlayer().canPlayerEdit(pos.getBlockPos(), pos.sideHit, event.getEntityPlayer().getHeldItem(hand)) &&
event.getWorld().getBlockState(pos.getBlockPos()).getMaterial() == Material.WATER) {
if(event.getWorld().getBlockState(pos.getBlockPos()).getBlock() == FluidBlockPoison.getInstance()) {
InventoryHelpers.tryReAddToStack(event.getEntityPlayer(), event.getEntityPlayer().getHeldItem(hand), new ItemStack(this), hand);
event.getWorld().setBlockToAir(pos.getBlockPos());
event.setCanceled(true);
}
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!