Search in sources :

Example 6 with ServerPlayerEntity

use of net.minecraft.entity.player.ServerPlayerEntity in project Bookshelf by Darkhax-Minecraft.

the class CommandHand method hand.

private int hand(CommandContext<CommandSource> context) throws CommandSyntaxException {
    final OutputType type = context.getArgument("type", OutputType.class);
    final ServerPlayerEntity player = context.getSource().getPlayerOrException();
    final String outputText = type.converter.apply(player.getMainHandItem());
    final ITextComponent component = TextComponentUtils.wrapInSquareBrackets(new StringTextComponent(outputText).withStyle((style) -> {
        return style.withColor(TextFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, outputText)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent("chat.copy.click"))).withInsertion(outputText);
    }));
    context.getSource().sendSuccess(component, false);
    return 0;
}
Also used : JsonObject(com.google.gson.JsonObject) VanillaIngredientSerializer(net.minecraftforge.common.crafting.VanillaIngredientSerializer) Serializers(net.darkhax.bookshelf.serialization.Serializers) ClickEvent(net.minecraft.util.text.event.ClickEvent) Function(java.util.function.Function) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) StringTextComponent(net.minecraft.util.text.StringTextComponent) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) CommandContext(com.mojang.brigadier.context.CommandContext) TextFormatting(net.minecraft.util.text.TextFormatting) NBTIngredient(net.minecraftforge.common.crafting.NBTIngredient) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandSource(net.minecraft.command.CommandSource) TextComponentUtils(net.minecraft.util.text.TextComponentUtils) HoverEvent(net.minecraft.util.text.event.HoverEvent) StringJoiner(java.util.StringJoiner) ResourceLocation(net.minecraft.util.ResourceLocation) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Commands(net.minecraft.command.Commands) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 7 with ServerPlayerEntity

use of net.minecraft.entity.player.ServerPlayerEntity in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerRespawn.

@SubscribeEvent
public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
    World world = event.getPlayer().getEntityWorld();
    PlayerEntity player = event.getPlayer();
    PlayerInventory playerInventory = player.inventory;
    if (!world.isRemote) {
        ItemStack mirrorStack = ItemStack.EMPTY;
        for (int i = 0; i < playerInventory.getSizeInventory(); i++) {
            ItemStack stack = playerInventory.getStackInSlot(i);
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                mirrorStack = stack;
                break;
            }
        }
        if (!mirrorStack.isEmpty()) {
            if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
                CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
                if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                    DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                    if (spawnDimension != null && player.dimension != spawnDimension) {
                        MinecraftServer server = world.getServer();
                        if (server != null) {
                            BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                            ((ServerPlayerEntity) player).teleport(server.getWorld(spawnDimension), spawnPoint.getX() + 0.5D, spawnPoint.getY(), spawnPoint.getZ() + 0.5D, player.rotationYaw, player.rotationPitch);
                        }
                    }
                }
            }
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PlayerInventory(net.minecraft.entity.player.PlayerInventory) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)7 ItemStack (net.minecraft.item.ItemStack)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Container (net.minecraft.inventory.container.Container)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 NetworkEvent (net.minecraftforge.fml.network.NetworkEvent)2 IGuiButtonSensitive (com.bluepowermod.client.gui.IGuiButtonSensitive)1 JsonObject (com.google.gson.JsonObject)1 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 Random (java.util.Random)1 StringJoiner (java.util.StringJoiner)1 Function (java.util.function.Function)1 Nullable (javax.annotation.Nullable)1 Serializers (net.darkhax.bookshelf.serialization.Serializers)1 CommandSource (net.minecraft.command.CommandSource)1 Commands (net.minecraft.command.Commands)1 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 ICraftingRecipe (net.minecraft.item.crafting.ICraftingRecipe)1