本文整理汇总了Java中net.minecraftforge.event.entity.player.PlayerInteractEvent.getPos方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerInteractEvent.getPos方法的具体用法?Java PlayerInteractEvent.getPos怎么用?Java PlayerInteractEvent.getPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.event.entity.player.PlayerInteractEvent
的用法示例。
在下文中一共展示了PlayerInteractEvent.getPos方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onBlockInteract(PlayerInteractEvent event) {
cachedItem = event.getItemStack();
cachedBlockPos = event.getPos();
IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(event.getPos());
Material mat = state.getMaterial();
cachedVariant = state.getBlock().getMetaFromState(state);
// we use this to detect the material of a broken block, so we want to ignore air, because otherwise this would
// always be set to air at the point we handle a block break
if (mat != Material.AIR) {
cachedMaterial = mat;
}
}
示例2: onBlockInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onBlockInteract(PlayerInteractEvent event) {
World world = event.getWorld();
BlockPos pos = event.getPos();
IBlockState blockstate = world.getBlockState(pos);
EntityPlayer player = event.getEntityPlayer();
if (blockstate.getBlock() instanceof BlockBanner) {
EnumHand hand = EnumHand.MAIN_HAND;
ItemStack stack = player.getHeldItemMainhand();
BlockBanner bannerblock = (BlockBanner) blockstate.getBlock();
if (stack.isEmpty() && player.isSneaking() && player.getItemStackFromSlot(EntityEquipmentSlot.HEAD).isEmpty()) {
ItemStack bannerstack = bannerblock.getItem(world, pos, blockstate);
player.swingArm(hand);
world.removeTileEntity(pos);
world.setBlockToAir(pos);
player.setItemStackToSlot(EntityEquipmentSlot.HEAD, bannerstack);
if (!event.getWorld().isRemote) {
event.setCanceled(true);
}
}
}
}
示例3: onPlayerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event)
{
// Disallow creating or destroying events in the player structure:
if (event instanceof PlayerInteractEvent.LeftClickBlock)
{
// Destroy block
if (blockInBounds(event.getPos(), this.sourceBounds))
event.setCanceled(true);
}
else if (event instanceof PlayerInteractEvent.RightClickBlock)
{
// Place block - need to work out *where* the block would be placed.
// This code was cribbed from ItemBlock.onItemUse()
IBlockState iblockstate = event.getWorld().getBlockState(event.getPos());
Block block = iblockstate.getBlock();
EnumFacing side = event.getFace();
BlockPos pos = event.getPos();
if (block == Blocks.SNOW_LAYER && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
{
side = EnumFacing.UP;
}
else if (!block.isReplaceable(event.getWorld(), pos))
{
pos = pos.offset(side);
}
if (blockInBounds(pos, this.sourceBounds))
event.setCanceled(true);
}
}
示例4: stopBedUse
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void stopBedUse(PlayerInteractEvent e){
if(!e.getWorld().isRemote) {
if (e.getWorld().getBlockState(e.getPos()).getBlock() == Blocks.BED && ConfigurationFile.clickingBedSetsSpawnPoint) {
e.getEntityPlayer().setSpawnPoint(e.getPos(), true);
e.getEntityPlayer().bedLocation = e.getPos();
e.getEntityPlayer().addChatComponentMessage(new TextComponentTranslation("Spawn point set!"));
if (ConfigurationFile.stopBedUse && !e.getEntity().getEntityWorld().isDaytime()) {
e.getEntityPlayer().addChatComponentMessage(new TextComponentTranslation("You don't feel tired enough to sleep.."));
e.setCanceled(true);
}
}
}
}
示例5: onPlayerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent event) {
if (signSkullName) {
EntityPlayer entityPlayer = event.getEntityPlayer();
BlockPos pos = event.getPos();
World worldObj = event.getWorld();
if (pos == null) {
return;
}
// event has no hand??
// and no item stack. and right click rarely works. known bug
// http://www.minecraftforge.net/forum/index.php?topic=37416.0
ItemStack held = entityPlayer.getHeldItemMainhand();
if (held == null) {
held = entityPlayer.getHeldItemOffhand();
}
TileEntity container = worldObj.getTileEntity(pos);
if (held != null && held.getItem() == Items.SKULL && held.getItemDamage() == Const.skull_player && container != null && container instanceof TileEntitySign) {
TileEntitySign sign = (TileEntitySign) container;
String firstLine = sign.signText[0].getUnformattedText();
if (firstLine == null) {
firstLine = "";
}
if (firstLine.isEmpty() || firstLine.split(" ").length == 0) {
held.setTagCompound(null);
}
else {
firstLine = firstLine.split(" ")[0];
NBTTagCompound nbt = UtilNBT.getItemStackNBT(held);
nbt.setString(Const.SkullOwner, firstLine);
}
}
}
}
示例6: onEvent
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onEvent(PlayerInteractEvent event) {
if (event.getPos() != null) {
IBlockState state = event.getWorld().getBlockState(event.getPos());
Block block = state.getBlock();
int meta = block.getMetaFromState(state);
if (ProgressionAPI.registry.fireTrigger(event.getEntityPlayer(), getProvider().getUnlocalisedName(), block, meta) == Result.DENY) {
event.setCanceled(true);
}
}
}
示例7: onPlayerInteract
import net.minecraftforge.event.entity.player.PlayerInteractEvent; //导入方法依赖的package包/类
@SubscribeEvent
public void onPlayerInteract(PlayerInteractEvent evt) {
// only handle right clicks on blocks
// TODO: port for 1.9
// if (evt.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
// return;
// }
BlockPos pos = evt.getPos();
World world = evt.getWorld();
IBlockState state = world.getBlockState(pos);
Block block = world.getBlockState(pos).getBlock();
// don't interact with vanilla egg blocks if configured
if (DragonMounts.instance.getConfig().isDisableBlockOverride() &&
block == Blocks.DRAGON_EGG) {
return;
}
// ignore non-egg blocks
if (block != Blocks.DRAGON_EGG && block != BlockDragonBreedEgg.INSTANCE) {
return;
}
// deny action
evt.setResult(Event.Result.DENY);
// clear dragon egg block
world.setBlockToAir(pos);
// create dragon egg entity on server
if (!world.isRemote) { // this was inverted, i.e. evt.world.isRemote, but it should surely be this way
EntityTameableDragon dragon = new EntityTameableDragon(world);
dragon.setPosition(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
dragon.getReproductionHelper().setBreeder(evt.getEntityPlayer());
dragon.getLifeStageHelper().setLifeStage(EnumDragonLifeStage.EGG);
// set breed type (custom dragon egg only, otherwise use default breed)
if (block == BlockDragonBreedEgg.INSTANCE) {
EnumDragonBreed breed = state.getValue(BlockDragonBreedEgg.BREED);
dragon.getBreedHelper().setBreedType(breed);
}
world.spawnEntityInWorld(dragon);
}
}