Java Code Examples for net.minecraft.entity.player.EntityPlayer.getEntityWorld()

The following are Jave code examples for showing how to use getEntityWorld() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Loot-Slash-Conquer   File: EventLivingDeath.java   View Source Code Vote up 6 votes
@SubscribeEvent
public void onLivingDeath(LivingDeathEvent event)
{
	/*
	 * Update player experience when they kill a monster. Experience gained is determined from how much health/damage the monsters has.
	 */

	if (event.getSource().getTrueSource() instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource();
		EntityLivingBase enemy = event.getEntityLiving();
		PlayerInformation playerInfo = (PlayerInformation) player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null);
		
		if (!player.getEntityWorld().isRemote && playerInfo != null)
		{
			addExperience(player, playerInfo, enemy);
		}
	}
}
 
Example 2
Project: Backmemed   File: TileEntityStructure.java   View Source Code Vote up 6 votes
public boolean usedBy(EntityPlayer player)
{
    if (!player.canUseCommandBlock())
    {
        return false;
    }
    else
    {
        if (player.getEntityWorld().isRemote)
        {
            player.openEditStructure(this);
        }

        return true;
    }
}
 
Example 3
Project: MineCamera   File: ContainerPictureBook.java   View Source Code Vote up 6 votes
@Nullable
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
	if (!player.getEntityWorld().isRemote) {
		if (slotId == 1 && getSlot(1) != null && getSlot(1).getHasStack()) {
			listPid.remove(index);
			if (index +1>=totalPictureNum) {
				index--;
			}
			totalPictureNum--;
			if(totalPictureNum==0){
				index=-1;
			}
		}
	}
	ItemStack i = super.slotClick(slotId, dragType, clickTypeIn, player);
	saveToNBT(player);
	return i;
}
 
Example 4
Project: MineCamera   File: ContainerPictureBook.java   View Source Code Vote up 6 votes
private void saveToNBT(EntityPlayer playerIn) {
	if (!playerIn.getEntityWorld().isRemote) {
		String listPidTotal="";
		for(int i=0;i<listPid.size();i++){
			listPidTotal+=listPid.get(i);
			if(i+1<listPid.size()){
				listPidTotal+="%,%";
			}
		}
		//System.out.println(listPid.size());
		ItemStack itemStackBook = playerIn.getActiveItemStack();
		if (itemStackBook != null) {
			NBTTagCompound nbt = new NBTTagCompound();
			nbt.setString("listPid", listPidTotal);
			nbt.setInteger("index", index);
			itemStackBook.setTagCompound(nbt);
		}
	}
}
 
Example 5
Project: MineCamera   File: EventLoader.java   View Source Code Vote up 6 votes
@SubscribeEvent
public void entityInteract(EntityInteract event) {
	if (event.getEntityPlayer().getEntityData().hasKey("renderViewCamera")) {
		event.setCanceled(true);
		if (event.getSide().isClient() && event.getHand().equals(EnumHand.MAIN_HAND)
				&& event.getItemStack() == null) {
			System.out.println("EntityInteract,HandType=" + event.getHand());
			ActiveTripod(Minecraft.getMinecraft().thePlayer.getName(),
					((EntityTripod) event.getWorld()
							.getEntityByID(event.getEntityPlayer().getEntityData().getInteger("renderViewCamera")))
									.getDelay());
		}
		return;
	}
	if (event.getTarget() instanceof EntityTripod) {
		Entity target = ((PlayerInteractEvent.EntityInteract) event).getTarget();
		EntityPlayer player = event.getEntityPlayer();
		if (!player.isSneaking()) {
			if (player.inventory.armorInventory[3] != null
					&& player.inventory.armorInventory[3].getItem() instanceof ItemGlassesHelmet) {
				if (player.getEntityWorld().isRemote) {
					// System.out.println("123");
					Minecraft.getMinecraft().setRenderViewEntity(target);
					Minecraft.getMinecraft().ingameGUI.setRecordPlaying(new TextComponentTranslation("chat.tripod.info"), false);
				}
				player.getEntityData().setInteger("renderViewCamera", target.getEntityId());
			}else if(!event.getWorld().isRemote&&event.getHand().equals(EnumHand.MAIN_HAND)){
				player.addChatComponentMessage(new TextComponentTranslation("chat.tripod.mustuseglass"));
			}
		} else {
			player.getEntityData().setInteger("usingGui", target.getEntityId());
			player.openGui(MineCamera.instance, GuiElementLoader.GUI_TRIPOD_CAMERA, target.getEntityWorld(),
					(int) target.posX, (int) target.posY, (int) target.posZ);
		}
	}
}
 
Example 6
Project: BaseClient   File: CommandBlockLogic.java   View Source Code Vote up 6 votes
public boolean tryOpenEditCommandBlock(EntityPlayer playerIn)
{
    if (!playerIn.capabilities.isCreativeMode)
    {
        return false;
    }
    else
    {
        if (playerIn.getEntityWorld().isRemote)
        {
            playerIn.openEditCommandBlock(this);
        }

        return true;
    }
}
 
Example 7
Project: MeeCreeps   File: EntityMeeCreeps.java   View Source Code Vote up 6 votes
@Override
    protected boolean processInteract(EntityPlayer player, EnumHand hand) {
        if (player.getEntityWorld().isRemote) {
//            player.openGui(MeeCreeps.instance, GuiProxy.GUI_MEECREEP_DISMISS, player.getEntityWorld(), (int) player.posX, (int) player.posY, (int) player.posZ);
            return true;
        } else {
            ServerActionManager manager = ServerActionManager.getManager();
            if (actionId != 0) {
                ActionOptions options = manager.getOptions(actionId);
                if (options != null) {
                    MeeCreepsMessages.INSTANCE.sendTo(new PacketActionOptionToClient(options, GuiProxy.GUI_MEECREEP_DISMISS), (EntityPlayerMP) player);
                    options.setPaused(true);
                }
            }
            return true;
        }
    }
 
Example 8
Project: Backmemed   File: CommandBlockBaseLogic.java   View Source Code Vote up 6 votes
public boolean tryOpenEditCommandBlock(EntityPlayer playerIn)
{
    if (!playerIn.canUseCommandBlock())
    {
        return false;
    }
    else
    {
        if (playerIn.getEntityWorld().isRemote)
        {
            playerIn.displayGuiEditCommandCart(this);
        }

        return true;
    }
}
 
Example 9
Project: DecompiledMinecraft   File: CommandBlockLogic.java   View Source Code Vote up 6 votes
public boolean tryOpenEditCommandBlock(EntityPlayer playerIn)
{
    if (!playerIn.capabilities.isCreativeMode)
    {
        return false;
    }
    else
    {
        if (playerIn.getEntityWorld().isRemote)
        {
            playerIn.openEditCommandBlock(this);
        }

        return true;
    }
}
 
Example 10
Project: Never-Enough-Currency   File: MessageSyncClearList.java   View Source Code Vote up 6 votes
@Override
public IMessage handleServerMessage(EntityPlayer player, MessageSyncClearList message, MessageContext ctx) {
	if ((player != null) && (message != null) && (ctx != null)) {
		EntityPlayer en = (EntityPlayer) player.getEntityWorld().getEntityByID(message.entityId);
		if (en != null) {
			if (player.getEntityId() == en.getEntityId() && en.getEntityWorld() != null && en.hasCapability(Currency.CART_DATA, null)) {
				CartCapability entityData = en.getCapability(Currency.CART_DATA, null);

				entityData.setCart(NonNullList.withSize(entityData.getSizeInventory(), ItemStack.EMPTY), true);
				List<Float> prices = Arrays.asList(new Float[25]);
				for (int i = 0; i < prices.size(); i++) {
					prices.set(i, (float) 0);
				}
			}
		}
	}
	return null;
}
 
Example 11
Project: Loot-Slash-Conquer   File: ItemTest.java   View Source Code Vote up 5 votes
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
   {
	if (!player.getEntityWorld().isRemote)
	{
        return EnumActionResult.SUCCESS;
	}
	
	return EnumActionResult.FAIL;
   }
 
Example 12
Project: MineCamera   File: ContainerCamera.java   View Source Code Vote up 5 votes
@Override
public void onContainerClosed(EntityPlayer playerIn) {
	super.onContainerClosed(playerIn);
	if(!playerIn.getEntityWorld().isRemote){
		saveToNBT(playerIn);
	}
}
 
Example 13
Project: Industrial-Foregoing   File: MobImprisonmentToolItem.java   View Source Code Vote up 5 votes
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (player.getEntityWorld().isRemote) return EnumActionResult.FAIL;
    if (!containsEntity(stack)) return EnumActionResult.FAIL;
    Entity entity = getEntityFromStack(stack, worldIn, true);
    BlockPos blockPos = pos.offset(facing);
    entity.setPositionAndRotation(blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5, 0, 0);
    stack.setTagCompound(new NBTTagCompound());
    player.setHeldItem(hand, stack);
    worldIn.spawnEntity(entity);
    if (entity instanceof EntityLiving) ((EntityLiving) entity).playLivingSound();
    return EnumActionResult.SUCCESS;
}
 
Example 14
Project: MeeCreeps   File: TeleportationTools.java   View Source Code Vote up 5 votes
public static void cancelPortalPair(EntityPlayer player, BlockPos selectedBlock) {
    World sourceWorld = player.getEntityWorld();
    TileEntity te = sourceWorld.getTileEntity(selectedBlock);
    if (te instanceof PortalTileEntity) {
        PortalTileEntity source = (PortalTileEntity) te;
        source.setTimeout(10);
    }
}
 
Example 15
Project: MeeCreeps   File: WorkerHelper.java   View Source Code Vote up 5 votes
public static BlockPos findSuitablePositionNearPlayer(@Nonnull EntityMeeCreeps meeCreep, @Nonnull EntityPlayer player, double distance) {
    Vec3d playerPos = player.getPositionVector();
    Vec3d entityPos = meeCreep.getPositionVector();

    if (entityPos.distanceTo(playerPos) < (distance * 1.2)) {
        // No need to move
        return meeCreep.getPosition();
    }

    double dx = playerPos.x - entityPos.x;
    double dy = playerPos.x - entityPos.x;
    double dz = playerPos.x - entityPos.x;
    Vec3d v = new Vec3d(-dx, -dy, -dz);
    v = v.normalize();
    Vec3d pos = new Vec3d(playerPos.x + v.x * distance, playerPos.y + v.y * distance, playerPos.z + v.z * distance);
    // First find a good spot at the specific location
    World world = player.getEntityWorld();

    float width = meeCreep.width;
    float eyeHeight = meeCreep.getEyeHeight();

    // First try on the prefered spot
    BlockPos p = scanSuitablePos(new BlockPos(pos.x, pos.y + .5, pos.z), world, width, eyeHeight);
    if (p != null) return p;
    // No good spot to stand on found. Try other spots around the prefered spot
    p = scanAround(pos, world, width, eyeHeight);
    if (p != null) return p;
    // No good spot to stand on found. Try other spots around the player
    p = scanAround(playerPos, world, width, eyeHeight);
    if (p != null) return p;

    // If all else fails we go stand where the player is
    return player.getPosition();
}
 
Example 16
Project: BaseClient   File: TileEntitySign.java   View Source Code Vote up 4 votes
public boolean executeCommand(final EntityPlayer playerIn)
{
    ICommandSender icommandsender = new ICommandSender()
    {
        public String getName()
        {
            return playerIn.getName();
        }
        public IChatComponent getDisplayName()
        {
            return playerIn.getDisplayName();
        }
        public void addChatMessage(IChatComponent component)
        {
        }
        public boolean canCommandSenderUseCommand(int permLevel, String commandName)
        {
            return permLevel <= 2;
        }
        public BlockPos getPosition()
        {
            return TileEntitySign.this.pos;
        }
        public Vec3 getPositionVector()
        {
            return new Vec3((double)TileEntitySign.this.pos.getX() + 0.5D, (double)TileEntitySign.this.pos.getY() + 0.5D, (double)TileEntitySign.this.pos.getZ() + 0.5D);
        }
        public World getEntityWorld()
        {
            return playerIn.getEntityWorld();
        }
        public Entity getCommandSenderEntity()
        {
            return playerIn;
        }
        public boolean sendCommandFeedback()
        {
            return false;
        }
        public void setCommandStat(CommandResultStats.Type type, int amount)
        {
            TileEntitySign.this.stats.func_179672_a(this, type, amount);
        }
    };

    for (int i = 0; i < this.signText.length; ++i)
    {
        ChatStyle chatstyle = this.signText[i] == null ? null : this.signText[i].getChatStyle();

        if (chatstyle != null && chatstyle.getChatClickEvent() != null)
        {
            ClickEvent clickevent = chatstyle.getChatClickEvent();

            if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
            {
                MinecraftServer.getServer().getCommandManager().executeCommand(icommandsender, clickevent.getValue());
            }
        }
    }

    return true;
}
 
Example 17
Project: Bewitchment   File: TileEntityGlyph.java   View Source Code Vote up 4 votes
public void startRitual(EntityPlayer player) {
	if (player.getEntityWorld().isRemote)
		return;
	List<EntityItem> itemsOnGround = getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(getPos()).grow(3, 0, 3));
	List<ItemStack> recipe = itemsOnGround.stream().map(i -> i.getItem()).collect(Collectors.toList());
	for (Ritual rit : Ritual.REGISTRY) { // Check every ritual
		if (rit.isValidInput(recipe, hasCircles(rit))) { // Check if circles and items match
			if (rit.isValid(player, world, pos, recipe)) { // Checks of extra conditions are met
				if (consumePower(rit.getRequiredStartingPower())) { // Check if there is enough starting power (and uses it in case there is)
					// The following block saves all the item used in the input inside the nbt
					// vvvvvv
					this.ritualData = new NBTTagCompound();
					NBTTagList itemsUsed = new NBTTagList();
					itemsOnGround.forEach(ei -> {
						NBTTagCompound item = new NBTTagCompound();
						ei.getItem().writeToNBT(item);
						itemsUsed.appendTag(item);
						ei.setDead();
					});
					ritualData.setTag("itemsUsed", itemsUsed);
					// ^^^^^

					// Sets the ritual up
					this.ritual = rit;
					this.entityPlayer = player.getPersistentID();
					this.cooldown = 1;
					ritual.onStarted(player, this, getWorld(), getPos(), ritualData);
					player.sendStatusMessage(new TextComponentTranslation("ritual." + rit.getRegistryName().toString().replace(':', '.') + ".name", new Object[0]), true);
					world.notifyBlockUpdate(getPos(), world.getBlockState(getPos()), world.getBlockState(getPos()), 3);
					markDirty();
					return;
				} else {
					player.sendStatusMessage(new TextComponentTranslation("ritual.failure.power", new Object[0]), true);
					return;
				}
			} else {
				player.sendStatusMessage(new TextComponentTranslation("ritual.failure.precondition", new Object[0]), true);
				return;
			}

		}
	}
	if (!itemsOnGround.isEmpty())
		player.sendStatusMessage(new TextComponentTranslation("ritual.failure.unknown", new Object[0]), true);
}
 
Example 18
Project: DecompiledMinecraft   File: TileEntitySign.java   View Source Code Vote up 4 votes
public boolean executeCommand(final EntityPlayer playerIn)
{
    ICommandSender icommandsender = new ICommandSender()
    {
        public String getName()
        {
            return playerIn.getName();
        }
        public IChatComponent getDisplayName()
        {
            return playerIn.getDisplayName();
        }
        public void addChatMessage(IChatComponent component)
        {
        }
        public boolean canCommandSenderUseCommand(int permLevel, String commandName)
        {
            return permLevel <= 2;
        }
        public BlockPos getPosition()
        {
            return TileEntitySign.this.pos;
        }
        public Vec3 getPositionVector()
        {
            return new Vec3((double)TileEntitySign.this.pos.getX() + 0.5D, (double)TileEntitySign.this.pos.getY() + 0.5D, (double)TileEntitySign.this.pos.getZ() + 0.5D);
        }
        public World getEntityWorld()
        {
            return playerIn.getEntityWorld();
        }
        public Entity getCommandSenderEntity()
        {
            return playerIn;
        }
        public boolean sendCommandFeedback()
        {
            return false;
        }
        public void setCommandStat(CommandResultStats.Type type, int amount)
        {
            TileEntitySign.this.stats.func_179672_a(this, type, amount);
        }
    };

    for (int i = 0; i < this.signText.length; ++i)
    {
        ChatStyle chatstyle = this.signText[i] == null ? null : this.signText[i].getChatStyle();

        if (chatstyle != null && chatstyle.getChatClickEvent() != null)
        {
            ClickEvent clickevent = chatstyle.getChatClickEvent();

            if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
            {
                MinecraftServer.getServer().getCommandManager().executeCommand(icommandsender, clickevent.getValue());
            }
        }
    }

    return true;
}
 
Example 19
Project: DecompiledMinecraft   File: TileEntitySign.java   View Source Code Vote up 4 votes
public boolean executeCommand(final EntityPlayer playerIn)
{
    ICommandSender icommandsender = new ICommandSender()
    {
        public String getName()
        {
            return playerIn.getName();
        }
        public IChatComponent getDisplayName()
        {
            return playerIn.getDisplayName();
        }
        public void addChatMessage(IChatComponent component)
        {
        }
        public boolean canCommandSenderUseCommand(int permLevel, String commandName)
        {
            return permLevel <= 2;
        }
        public BlockPos getPosition()
        {
            return TileEntitySign.this.pos;
        }
        public Vec3 getPositionVector()
        {
            return new Vec3((double)TileEntitySign.this.pos.getX() + 0.5D, (double)TileEntitySign.this.pos.getY() + 0.5D, (double)TileEntitySign.this.pos.getZ() + 0.5D);
        }
        public World getEntityWorld()
        {
            return playerIn.getEntityWorld();
        }
        public Entity getCommandSenderEntity()
        {
            return playerIn;
        }
        public boolean sendCommandFeedback()
        {
            return false;
        }
        public void setCommandStat(CommandResultStats.Type type, int amount)
        {
            TileEntitySign.this.stats.func_179672_a(this, type, amount);
        }
    };

    for (int i = 0; i < this.signText.length; ++i)
    {
        ChatStyle chatstyle = this.signText[i] == null ? null : this.signText[i].getChatStyle();

        if (chatstyle != null && chatstyle.getChatClickEvent() != null)
        {
            ClickEvent clickevent = chatstyle.getChatClickEvent();

            if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
            {
                MinecraftServer.getServer().getCommandManager().executeCommand(icommandsender, clickevent.getValue());
            }
        }
    }

    return true;
}
 
Example 20
Project: BaseClient   File: TileEntitySign.java   View Source Code Vote up 4 votes
public boolean executeCommand(final EntityPlayer playerIn)
{
    ICommandSender icommandsender = new ICommandSender()
    {
        public String getName()
        {
            return playerIn.getName();
        }
        public IChatComponent getDisplayName()
        {
            return playerIn.getDisplayName();
        }
        public void addChatMessage(IChatComponent component)
        {
        }
        public boolean canCommandSenderUseCommand(int permLevel, String commandName)
        {
            return permLevel <= 2;
        }
        public BlockPos getPosition()
        {
            return TileEntitySign.this.pos;
        }
        public Vec3 getPositionVector()
        {
            return new Vec3((double)TileEntitySign.this.pos.getX() + 0.5D, (double)TileEntitySign.this.pos.getY() + 0.5D, (double)TileEntitySign.this.pos.getZ() + 0.5D);
        }
        public World getEntityWorld()
        {
            return playerIn.getEntityWorld();
        }
        public Entity getCommandSenderEntity()
        {
            return playerIn;
        }
        public boolean sendCommandFeedback()
        {
            return false;
        }
        public void setCommandStat(CommandResultStats.Type type, int amount)
        {
            TileEntitySign.this.stats.func_179672_a(this, type, amount);
        }
    };

    for (int i = 0; i < this.signText.length; ++i)
    {
        ChatStyle chatstyle = this.signText[i] == null ? null : this.signText[i].getChatStyle();

        if (chatstyle != null && chatstyle.getChatClickEvent() != null)
        {
            ClickEvent clickevent = chatstyle.getChatClickEvent();

            if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
            {
                MinecraftServer.getServer().getCommandManager().executeCommand(icommandsender, clickevent.getValue());
            }
        }
    }

    return true;
}