use of lumien.randomthings.tileentity.TileEntityEnderMailbox in project Random-Things by lumien231.
the class BlockEnderMailbox method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (!worldIn.isRemote) {
ItemStack heldItem = playerIn.getHeldItemMainhand();
if (playerIn.isSneaking() && heldItem.getItem() == ModItems.enderLetter) {
NBTTagCompound compound;
if ((compound = heldItem.getTagCompound()) != null) {
if (compound.hasKey("receiver") && !compound.getBoolean("received")) {
GameProfile playerProfile = worldIn.getMinecraftServer().getPlayerProfileCache().getGameProfileForUsername(compound.getString("receiver"));
if (playerProfile != null && playerProfile.getId() != null) {
EnderMailboxInventory mailboxInventory = EnderLetterHandler.get(worldIn).getOrCreateInventoryForPlayer(playerProfile.getId());
for (int slot = 0; slot < mailboxInventory.getSizeInventory(); slot++) {
if (mailboxInventory.getStackInSlot(slot).isEmpty()) {
ItemStack sendingLetter = heldItem.copy();
heldItem.shrink(1);
sendingLetter.getTagCompound().setBoolean("received", true);
sendingLetter.getTagCompound().setString("sender", playerIn.getGameProfile().getName());
mailboxInventory.setInventorySlotContents(slot, sendingLetter);
playerIn.world.playSound(null, pos, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, 1, 1);
return true;
}
}
playerIn.sendMessage(new TextComponentTranslation("item.enderLetter.noSpace").setStyle(new Style().setColor(TextFormatting.DARK_PURPLE)));
} else {
playerIn.sendMessage(new TextComponentTranslation("item.enderLetter.noPlayer", compound.getString("receiver")).setStyle(new Style().setColor(TextFormatting.DARK_PURPLE)));
}
}
}
return true;
}
TileEntityEnderMailbox te = (TileEntityEnderMailbox) worldIn.getTileEntity(pos);
if (te.getOwner() != null) {
if (te.getOwner().equals(playerIn.getGameProfile().getId())) {
playerIn.openGui(RandomThings.instance, GuiIds.ENDER_MAILBOX, worldIn, pos.getX(), pos.getY(), pos.getZ());
} else {
playerIn.sendMessage(new TextComponentTranslation("block.enderMailbox.owner").setStyle(new Style().setColor(TextFormatting.RED)));
}
}
}
return true;
}
use of lumien.randomthings.tileentity.TileEntityEnderMailbox in project Random-Things by lumien231.
the class BlockEnderMailbox method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()).withProperty(ACTIVE, false), 2);
if (!worldIn.isRemote && placer instanceof EntityPlayer) {
TileEntityEnderMailbox te = (TileEntityEnderMailbox) worldIn.getTileEntity(pos);
te.setOwner(((EntityPlayer) placer).getGameProfile().getId());
}
}
Aggregations