本文整理汇总了Java中net.minecraft.entity.player.EntityPlayer.getHeldItemMainhand方法的典型用法代码示例。如果您正苦于以下问题:Java EntityPlayer.getHeldItemMainhand方法的具体用法?Java EntityPlayer.getHeldItemMainhand怎么用?Java EntityPlayer.getHeldItemMainhand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.entity.player.EntityPlayer
的用法示例。
在下文中一共展示了EntityPlayer.getHeldItemMainhand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processInteract
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public boolean processInteract(EntityPlayer player, EnumHand hand) {
ItemStack equippedItem = player.getHeldItemMainhand();
if (!world.isRemote && !equippedItem.isEmpty()) {
if (equippedItem.getItem() == Itemss.GPS_TOOL) {
BlockPos gpsLoc = ItemGPSTool.getGPSLocation(equippedItem);
if (gpsLoc != null) {
getNavigator().tryMoveToXYZ(gpsLoc.getX(), gpsLoc.getY(), gpsLoc.getZ(), 0.1D);
}
} else {
int dyeIndex = TileEntityPlasticMixer.getDyeIndex(equippedItem);
if (dyeIndex >= 0) {
setDroneColor(ItemDye.DYE_COLORS[dyeIndex]);
equippedItem.shrink(1);
if (equippedItem.getCount() <= 0) {
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
}
}
}
}
return false;
}
示例2: onWitherBoneAttackEvent
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@SubscribeEvent
public void onWitherBoneAttackEvent(AttackEntityEvent event) {
EntityPlayer player = event.getEntityPlayer();
ItemStack stack = player.getHeldItemMainhand();
boolean flag = false;
if (stack.getItem() instanceof IHaftTool) {
if (IHaftTool.getHaftMat(stack) == ModMaterials.HAFT_WITHER_BONE) {
flag = true;
}
}
if (flag) {
if (player.dimension != DimensionType.NETHER.getId()) {
stack.damageItem(7, player);
}
}
}
示例3: onBlockActivated
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
ItemStack itm = playerIn.getHeldItemMainhand();
if (!itm.isEmpty() && itm.getItem() instanceof ItemBlock && Block.getBlockFromItem(itm.getItem()) == this && state.getValue(LAYERS) < 8)
{
if (!playerIn.capabilities.isCreativeMode)
{
itm.shrink(1);
}
worldIn.setBlockState(pos, state.cycleProperty(LAYERS));
return true;
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
示例4: onBlockActivated
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack stack, EnumFacing side, float hitX, float hitY, float hitZ) {
if (this.getAge(state) < getMaxAge()) return false;
if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
ItemStack stacky = player.getHeldItemMainhand();
if (stacky == null || (stacky != null && !stacky.isItemDamaged())) return false;
int repair = stacky.getMaxDamage() / 2;
stacky.setItemDamage(Math.max(stacky.getItemDamage() - repair, 0));
world.setBlockState(pos, this.withAge(0), 2);
return true;
}
return false;
}
示例5: onExecutionStart
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public void onExecutionStart(EntityPlayer player)
{
ItemStack is = player.getHeldItemMainhand().isEmpty() ? player.getHeldItemOffhand() : player.getHeldItemMainhand();
EnumWeaponWeight weight = EnumWeaponWeight.getWeaponWeight(is);
player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, SoundCategory.PLAYERS, 1, 1F);
Vec3d look = player.getLookVec().scale(5);
Vec3d pos = player.getPositionVector();
List<EntityLivingBase> targets = Helpers.rayTraceEntities(player.world, pos.addVector(0, player.getEyeHeight(), 0), look, Optional.of(e -> e != player), EntityLivingBase.class);
EntityLivingBase assumedToBeLookedAt = Helpers.getClosest(targets, player);
if (assumedToBeLookedAt != null)
{
if (!player.world.isRemote)
{
assumedToBeLookedAt.addPotionEffect(new PotionEffect(ExPPotions.stunned, weight == EnumWeaponWeight.NORMAL ? 20 : 30, 0, false, false));
}
player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, SoundCategory.PLAYERS, 1, 1F);
Vec3d targetPos = assumedToBeLookedAt.getPositionVector();
assumedToBeLookedAt.knockBack(player, 1, pos.x - targetPos.x, pos.z - targetPos.z);
for (int i = 0; i < 50; ++i)
{
player.world.spawnParticle(EnumParticleTypes.CRIT_MAGIC, targetPos.x + player.world.rand.nextDouble() - player.world.rand.nextDouble(), targetPos.z + assumedToBeLookedAt.getEyeHeight() + player.world.rand.nextDouble() - player.world.rand.nextDouble(), targetPos.z + player.world.rand.nextDouble() - player.world.rand.nextDouble(), 0, -0.1, 0);
}
}
}
示例6: getServerGuiElement
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Nullable
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
switch (id)
{
case BELT:
ItemStack heldItem = player.getHeldItem(EnumHand.values()[x]);
if (heldItem.getCount() > 0)
{
ToolBeltInventory inventory = ItemToolBelt.getItems(heldItem);
int blockedSlot = -1;
if (player.getHeldItemMainhand() == heldItem)
blockedSlot = player.inventory.currentItem;
return new ContainerBelt(player.inventory, inventory, blockedSlot);
}
break;
}
return null;
}
示例7: onPlayerAttackTarget
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
public static boolean onPlayerAttackTarget(EntityPlayer player, Entity target)
{
if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(player, target))) return false;
ItemStack stack = player.getHeldItemMainhand();
if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return false;
return true;
}
示例8: renderMinigunFirstPerson
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
private void renderMinigunFirstPerson() {
EntityPlayer player = Minecraft.getMinecraft().player;
ItemStack stack = player.getHeldItemMainhand();
if (stack.getItem() == Itemss.MINIGUN) {
Minigun minigun = ((ItemMinigun) Itemss.MINIGUN).getMinigun(stack, player);
if (minigun.isMinigunActivated() && minigun.getMinigunSpeed() == Minigun.MAX_GUN_SPEED) {
GlStateManager.disableTexture2D();
GlStateManager.disableLighting();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
RenderUtils.glColorHex(0x40000000 | minigun.getAmmoColor());
for (int i = 0; i < 5; i++) {
Vec3d directionVec = player.getLookVec().normalize();
Vec3d vec2 = new Vec3d(directionVec.x, directionVec.y, directionVec.z);
vec2 = vec2.rotateYaw(-(float)Math.PI / 2f);
minigunFire.startX = vec2.x ;
minigunFire.startY = 1.0;
minigunFire.startZ = vec2.z;
minigunFire.endX = directionVec.x * 20 + player.getRNG().nextDouble() - 0.5;
minigunFire.endY = directionVec.y * 20 + player.getEyeHeight() + player.getRNG().nextDouble() - 0.5;
minigunFire.endZ = directionVec.z * 20 + player.getRNG().nextDouble() - 0.5;
minigunFire.render();
}
GlStateManager.color(1, 1, 1, 1);
GlStateManager.enableLighting();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}
}
}
示例9: getServerGuiElement
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == 1) {
return new ContainerItem(player, player.inventory, new InventoryItem(player.getHeldItemMainhand()));
} else if (ID == 2) {
return new ContainerItem(player, player.inventory, new InventoryItem(player.getHeldItemOffhand()));
} else if (ID == 4) {
return new ContainerStockCrate(player.inventory, (TileEntityStockCrate) world.getTileEntity(new BlockPos(x, y, z)));
}
return null;
}
示例10: getPlayerRelativeBlockHardness
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public float getPlayerRelativeBlockHardness(IBlockState state, EntityPlayer player, World worldIn, BlockPos pos)
{
// Axes are hardcoded to break blocks with a material of PLANT at their efficiency speed, need to fix that.
ItemStack stack = player.getHeldItemMainhand();
return !stack.isEmpty() && stack.getItem() instanceof ItemAxe ? super.getPlayerRelativeBlockHardness(state, player, worldIn, pos) / stack.getItem().getStrVsBlock(stack, state) : super.getPlayerRelativeBlockHardness(state, player, worldIn, pos);
}
示例11: getClientGuiElement
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
switch (id) {
case TRANSPORTER_ID:
return new GuiTransporter(player, new ContainerTransporter(player.getHeldItemMainhand()));
default:
return null;
}
}
示例12: onItemRightClick
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
if (handIn != EnumHand.MAIN_HAND) return ActionResult.newResult(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
ItemStack stack = playerIn.getHeldItemMainhand();
if (worldIn.isRemote) {
BlockPos pos = getGPSLocation(stack);
FMLCommonHandler.instance().showGuiScreen(new GuiGPSTool(pos != null ? pos : new BlockPos(0, 0, 0), getVariable(stack)));
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
示例13: onExecutionStart
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
public void onExecutionStart(EntityPlayer player)
{
ItemStack is = player.getHeldItemMainhand().isEmpty() ? player.getHeldItemOffhand() : player.getHeldItemMainhand();
EntityThrownWeapon etw = new EntityThrownWeapon(player.getEntityWorld(), player, is.copy());
etw.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
if (!player.world.isRemote)
{
player.world.spawnEntity(etw);
is.setCount(0);
}
}
示例14: isStackInHand
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
private boolean isStackInHand(ItemStack itemStackIn) {
EntityPlayer player = EasyMappings.player();
if ((player.getHeldItemMainhand() == itemStackIn) || (player.getHeldItemOffhand() == itemStackIn)) {
return true;
}
return false;
}
示例15: getClientGuiElement
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@Override
@SideOnly(Side.CLIENT)
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
BlockPos pos = new BlockPos(x, y, z);
if (ID == RandoresGuiType.FORGE.ordinal()) {
TileEntity entity = world.getTileEntity(pos);
if (entity instanceof CraftiniumForgeTileEntity) {
return new CraftiniumForgeGui((CraftiniumForgeTileEntity) entity, player.inventory);
}
} else if (ID == RandoresGuiType.TABLE.ordinal()) {
return new CraftiniumTableGui(player.inventory, world, pos);
} else if (ID == RandoresGuiType.TOME.ordinal()) {
ItemStack[] stacks = new ItemStack[] {player.getHeldItemMainhand(), player.getHeldItemOffhand()};
for(ItemStack stack : stacks) {
if(stack.getItem() instanceof TomeItem && RandoresItemData.hasData(stack)) {
RandoresItemData data = new RandoresItemData(stack);
if(RandoresWorldData.contains(data)) {
return new TomeGui(RandoresWorldData.get(data).buildPages());
}
}
}
return new TomeGui(Arrays.asList(new TomeGui.StringElement("An example text page: \n" + TextFormatting.RED + "This tome has no data associated with it, so it instead displays examples of the different kinds of pages in a tome.", "Example"),
new TomeGui.CraftingElement("An example crafting recipe page: ", new ItemStack[][]{
{new ItemStack(Items.IRON_INGOT), new ItemStack(Items.IRON_INGOT), new ItemStack(Items.IRON_INGOT)},
{null, new ItemStack(Items.STICK), null},
{null, new ItemStack(Items.STICK), null}
}, new ItemStack(Items.IRON_PICKAXE), "Example"),
new TomeGui.FurnaceElement("An example furnace recipe page: ", new ItemStack(Items.STICK), new ItemStack(Blocks.IRON_ORE), new ItemStack(Items.IRON_INGOT), "Example")));
} else if (ID == RandoresGuiType.CONVERTER.ordinal()) {
return new CraftiniumConverterGui(player.inventory, world, pos);
}
return null;
}