use of net.minecraft.world.IWorldNameable in project Railcraft by Railcraft.
the class ItemNotepad method onItemUse.
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (Game.isClient(world))
return EnumActionResult.SUCCESS;
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null) {
if (// COPY
player.isSneaking()) {
EnumMap<Contents, NBTTagCompound> contents = new EnumMap<Contents, NBTTagCompound>(Contents.class);
for (Contents contentType : Contents.VALUES) {
NBTTagCompound data = contentType.copy(tileEntity);
if (data != null)
contents.put(contentType, data);
}
if (contents.isEmpty()) {
//TODO: Fix in 1.8 to use getDisplayName
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.copy.fail");
} else {
setContents(stack, contents);
if (tileEntity instanceof IWorldNameable)
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.copy", tileEntity.getDisplayName());
stack.damageItem(1, player);
}
} else // PASTE
{
EnumMap<Contents, NBTTagCompound> contents = getContents(stack);
if (contents.isEmpty()) {
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.empty");
} else {
PasteMode pasteMode = getPasteMode(stack);
boolean pasted = false;
for (Map.Entry<Contents, NBTTagCompound> entry : getContents(stack).entrySet()) {
if (pasteMode.allows(entry.getKey()))
pasted |= entry.getKey().paste(tileEntity, entry.getValue());
}
if (pasted) {
if (tileEntity instanceof IWorldNameable)
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.paste", tileEntity.getDisplayName());
} else
//TODO: Fix in 1.8 to use getDisplayName
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.paste.fail");
}
}
}
return EnumActionResult.SUCCESS;
}
use of net.minecraft.world.IWorldNameable in project SpongeCommon by SpongePowered.
the class DisplayNameDataProcessor method from.
@Override
public Optional<DisplayNameData> from(DataHolder holder) {
if (holder instanceof Entity) {
@Nullable Text displayName = ((IMixinEntity) holder).getDisplayNameText();
if (displayName != null) {
return Optional.of(new SpongeDisplayNameData(displayName));
}
return Optional.empty();
} else if (holder instanceof ItemStack) {
ItemStack stack = (ItemStack) holder;
if (!stack.hasDisplayName()) {
return Optional.empty();
}
if (stack.getItem() == Items.WRITTEN_BOOK) {
final NBTTagCompound compound = stack.getTagCompound();
if (compound == null) {
// The book wasn't initialized.
return Optional.empty();
}
return Optional.of(new SpongeDisplayNameData(SpongeTexts.fromLegacy(compound.getString(NbtDataUtil.ITEM_BOOK_TITLE))));
}
final NBTTagCompound compound = ((ItemStack) holder).getSubCompound(NbtDataUtil.ITEM_DISPLAY);
if (compound != null && compound.hasKey(NbtDataUtil.ITEM_DISPLAY_NAME, NbtDataUtil.TAG_STRING)) {
return Optional.of(new SpongeDisplayNameData(SpongeTexts.fromLegacy(compound.getString(NbtDataUtil.ITEM_DISPLAY_NAME))));
}
return Optional.empty();
} else if (holder instanceof IWorldNameable) {
if (((IWorldNameable) holder).hasCustomName()) {
final String customName = ((IWorldNameable) holder).getName();
final DisplayNameData data = new SpongeDisplayNameData(SpongeTexts.fromLegacy(customName));
return Optional.of(data);
}
return Optional.empty();
}
return Optional.empty();
}
use of net.minecraft.world.IWorldNameable in project takumicraft by TNTModders.
the class BlockTakumiMonsterBomb method harvestBlock.
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) {
if (te instanceof IWorldNameable && ((IWorldNameable) te).hasCustomName()) {
player.addStat(StatList.getBlockStats(this));
player.addExhaustion(0.005F);
if (worldIn.isRemote) {
return;
}
int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
Item item = this.getItemDropped(state, worldIn.rand, i);
if (item == Items.AIR) {
return;
}
ItemStack itemstack = new ItemStack(item, this.quantityDropped(worldIn.rand));
itemstack.setStackDisplayName(((IWorldNameable) te).getName());
spawnAsEntity(worldIn, pos, itemstack);
} else {
super.harvestBlock(worldIn, player, pos, state, null, stack);
}
}
use of net.minecraft.world.IWorldNameable in project Railcraft by Railcraft.
the class ItemNotepad method onItemUse.
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (Game.isClient(world))
return EnumActionResult.SUCCESS;
ItemStack stack = player.getHeldItem(hand);
TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity != null) {
if (// COPY
player.isSneaking()) {
EnumMap<Contents, NBTTagCompound> contents = new EnumMap<>(Contents.class);
for (Contents contentType : Contents.VALUES) {
NBTTagCompound data = contentType.copy(tileEntity);
if (data != null)
contents.put(contentType, data);
}
if (contents.isEmpty()) {
// TODO: Fix in 1.8 to use getDisplayName
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.copy.fail");
} else {
setContents(stack, contents);
if (tileEntity instanceof IWorldNameable)
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.copy", tileEntity.getDisplayName());
stack.damageItem(1, player);
}
} else // PASTE
{
EnumMap<Contents, NBTTagCompound> contents = getContents(stack);
if (contents.isEmpty()) {
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.empty");
} else {
PasteMode pasteMode = getPasteMode(stack);
boolean pasted = getContents(stack).entrySet().stream().filter(entry -> pasteMode.allows(entry.getKey())).map(entry -> entry.getKey().paste(tileEntity, entry.getValue())).reduce(false, (a, b) -> a || b);
if (pasted) {
if (tileEntity instanceof IWorldNameable)
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.paste", tileEntity.getDisplayName());
} else
ChatPlugin.sendLocalizedChatFromServer(player, "item.railcraft.tool.notepad.action.paste.fail", tileEntity.getDisplayName());
}
}
}
return EnumActionResult.SUCCESS;
}
Aggregations