Search in sources :

Example 11 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project Overloaded by CJ-MC-Mods.

the class PlayerInterfaceRenderer method render.

@Override
public void render(@Nonnull TilePlayerInterface te, float v, @Nonnull MatrixStack matrixStack, @Nonnull IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
    UUID uuid = te.getPlacer();
    if (uuid == null)
        return;
    PlayerEntity player = te.getLevel().getPlayerByUUID(uuid);
    if (player == null) {
        if (!uuid.equals(uuidCache)) {
            uuidCache = uuid;
            CompoundNBT tag = new CompoundNBT();
            tag.putString("SkullOwner", uuid.toString());
            stackCache = new ItemStack(Items.PLAYER_HEAD, 1, tag);
        }
        renderItem(te, stackCache, matrixStack, iRenderTypeBuffer);
        return;
    }
    renderPlayer(te, player, matrixStack, iRenderTypeBuffer, combinedLightIn);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) UUID(java.util.UUID) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 12 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.

the class DebugModeIGrowable method debugActionBlockClicked.

@Override
public void debugActionBlockClicked(ItemStack stack, ItemUseContext context) {
    if (context.getWorld().isRemote) {
        return;
    }
    BlockPos pos = context.getPos();
    PlayerEntity player = context.getPlayer();
    World world = context.getWorld();
    // Start with the position of the block that was clicked on. '7' is gray. Btw, the chat font is not fixed width. :(
    StringBuilder outputRaw = new StringBuilder(String.format("`7%1$4d,%2$4d,%3$4d`r ", pos.getX(), pos.getY(), pos.getZ()));
    // Check if the clicked on block has the IGrowable interface.
    final IGrowable crop = WorldHelper.getBlock(world, pos, IGrowable.class).orElse(null);
    if (crop == null) {
        // If it does not, add a nicely formatted report, then skip onward.
        outputRaw.append(chatNotIG);
    } else if (world instanceof ServerWorld) {
        // Otherwise run the tests and record the results.
        BlockState state = world.getBlockState(pos);
        // canGrow
        outputRaw.append(crop.canGrow(world, pos, state, false) ? chatTrue : chatFalse);
        // canUseBonemeal
        outputRaw.append(crop.canUseBonemeal(world, world.rand, pos, state) ? chatTrue : chatFalse);
        // grow
        crop.grow((ServerWorld) world, world.rand, pos, state);
        // It's also helpful to also make clear what block was being tested.
        // '3' is dark aqua.
        outputRaw.append("`3");
        outputRaw.append(crop.toString().replaceFirst("Block", ""));
        outputRaw.append("`r");
    }
    // Ellipsis are added as a clue that there's more text.
    // '8' is dark gray.
    outputRaw.append(" `8[...]`r");
    // Create a hover box with explanatory information.
    StringTextComponent hoverComponent = new StringTextComponent(MessageUtil.colorize(chatInfo));
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent);
    // Turn the output String into a chat message.
    StringTextComponent outputComponent = new StringTextComponent(MessageUtil.colorize(outputRaw.toString()));
    // Add the hover box to the chat message.
    outputComponent.getStyle().setHoverEvent(hoverEvent);
    // Now send the completed chat message.
    player.sendMessage(outputComponent, Util.DUMMY_UUID);
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) HoverEvent(net.minecraft.util.text.event.HoverEvent) BlockState(net.minecraft.block.BlockState) IGrowable(net.minecraft.block.IGrowable) BlockPos(net.minecraft.util.math.BlockPos) StringTextComponent(net.minecraft.util.text.StringTextComponent) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 13 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.

the class ItemClipper method onItemUse.

@Nonnull
@Override
public ActionResultType onItemUse(@Nonnull ItemUseContext context) {
    World world = context.getWorld();
    if (world.isRemote()) {
        return ActionResultType.PASS;
    }
    BlockPos pos = context.getPos();
    ItemStack stack = context.getItem();
    PlayerEntity player = context.getPlayer();
    return AgriApi.getCrop(world, pos).map(crop -> {
        if (!crop.hasPlant() || !crop.getPlant().allowsClipping(crop.getGrowthStage(), stack, player)) {
            if (player != null) {
                player.sendMessage(AgriToolTips.MSG_CLIPPING_IMPOSSIBLE, player.getUniqueID());
            }
            return ActionResultType.FAIL;
        }
        if (MinecraftForge.EVENT_BUS.post(new AgriCropEvent.Clip.Pre(crop, stack, player))) {
            return ActionResultType.FAIL;
        }
        List<ItemStack> drops = Lists.newArrayList();
        crop.getPlant().getClipProducts(drops::add, stack, crop.getGrowthStage(), crop.getStats(), world.getRandom());
        crop.setGrowthStage(crop.getPlant().getInitialGrowthStage());
        crop.getPlant().onClipped(crop, stack, player);
        AgriCropEvent.Clip.Post event = new AgriCropEvent.Clip.Post(crop, stack, drops, player);
        MinecraftForge.EVENT_BUS.post(event);
        event.getDrops().forEach(crop::dropItem);
        return ActionResultType.SUCCESS;
    }).orElse(ActionResultType.FAIL);
}
Also used : AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) IAgriClipperItem(com.infinityraider.agricraft.api.v1.content.items.IAgriClipperItem) ItemUseContext(net.minecraft.item.ItemUseContext) ItemStack(net.minecraft.item.ItemStack) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) Lists(com.google.common.collect.Lists) AgriToolTips(com.infinityraider.agricraft.reference.AgriToolTips) AgriTabs(com.infinityraider.agricraft.content.AgriTabs) Names(com.infinityraider.agricraft.reference.Names) ItemBase(com.infinityraider.infinitylib.item.ItemBase) AgriCropEvent(com.infinityraider.agricraft.api.v1.event.AgriCropEvent) Nonnull(javax.annotation.Nonnull) ActionResultType(net.minecraft.util.ActionResultType) AgriCropEvent(com.infinityraider.agricraft.api.v1.event.AgriCropEvent) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Nonnull(javax.annotation.Nonnull)

Example 14 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.

the class ItemTrowel method tryNewPlant.

protected ActionResultType tryNewPlant(World world, BlockPos pos, ItemStack stack, @Nullable PlayerEntity player) {
    if (AgriCraft.instance.getConfig().allowPlantingOutsideCropSticks()) {
        BlockState newState = AgriCraft.instance.getModBlockRegistry().crop_plant.getStateForPlacement(world, pos);
        if (newState != null && world.setBlockState(pos, newState, 11)) {
            boolean success = AgriApi.getCrop(world, pos).map(crop -> {
                if (MinecraftForge.EVENT_BUS.post(new AgriCropEvent.Trowel.Pre(crop, stack, player))) {
                    return false;
                }
                return this.getGenome(stack).map(genome -> this.getGrowthStage(stack).map(stage -> {
                    boolean result = crop.plantGenome(genome, player) && this.setGrowthStage(crop, stage);
                    if (result) {
                        this.removePlant(stack);
                        MinecraftForge.EVENT_BUS.post(new AgriCropEvent.Trowel.Post(crop, stack, player));
                    }
                    return result;
                }).orElse(false)).orElse(false);
            }).orElse(false);
            if (success) {
                return ActionResultType.SUCCESS;
            } else {
                world.setBlockState(pos, Blocks.AIR.getDefaultState());
            }
        }
    }
    return ActionResultType.FAIL;
}
Also used : AgriNBT(com.infinityraider.agricraft.reference.AgriNBT) InfinityItemProperty(com.infinityraider.infinitylib.item.InfinityItemProperty) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) TileEntityCropSticks(com.infinityraider.agricraft.content.core.TileEntityCropSticks) NoPlant(com.infinityraider.agricraft.impl.v1.plant.NoPlant) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) CompoundNBT(net.minecraft.nbt.CompoundNBT) IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage) IAgriGenome(com.infinityraider.agricraft.api.v1.genetics.IAgriGenome) ItemUseContext(net.minecraft.item.ItemUseContext) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) AgriToolTips(com.infinityraider.agricraft.reference.AgriToolTips) Names(com.infinityraider.agricraft.reference.Names) ItemBase(com.infinityraider.infinitylib.item.ItemBase) IAgriTrowelItem(com.infinityraider.agricraft.api.v1.content.items.IAgriTrowelItem) BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) AgriCraft(com.infinityraider.agricraft.AgriCraft) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) ImmutableSet(com.google.common.collect.ImmutableSet) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Blocks(net.minecraft.block.Blocks) MinecraftForge(net.minecraftforge.common.MinecraftForge) AgriTabs(com.infinityraider.agricraft.content.AgriTabs) ResourceLocation(net.minecraft.util.ResourceLocation) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) AgriCropEvent(com.infinityraider.agricraft.api.v1.event.AgriCropEvent) ActionResultType(net.minecraft.util.ActionResultType) ClientWorld(net.minecraft.client.world.ClientWorld) BlockState(net.minecraft.block.BlockState) AgriCropEvent(com.infinityraider.agricraft.api.v1.event.AgriCropEvent)

Example 15 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project AgriCraft by AgriCraft.

the class JeiPlugin method onRuntimeAvailable.

@Override
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
    jei = jeiRuntime;
    if (AgriCraft.instance.getConfig().progressiveJEI()) {
        PlayerEntity player = AgriCraft.instance.getClientPlayer();
        AgriApi.getMutationRegistry().stream().forEach(mutation -> {
            if (CapabilityResearchedPlants.getInstance().isMutationResearched(player, mutation)) {
                unHideMutation(mutation);
            } else {
                hideMutation(mutation);
            }
        });
    }
}
Also used : PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

PlayerEntity (net.minecraft.entity.player.PlayerEntity)46 ItemStack (net.minecraft.item.ItemStack)22 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)19 World (net.minecraft.world.World)17 BlockPos (net.minecraft.util.math.BlockPos)16 CompoundNBT (net.minecraft.nbt.CompoundNBT)13 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)12 BlockState (net.minecraft.block.BlockState)10 ResourceLocation (net.minecraft.util.ResourceLocation)7 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)6 Nonnull (javax.annotation.Nonnull)6 AgriCraft (com.infinityraider.agricraft.AgriCraft)5 TileEntity (net.minecraft.tileentity.TileEntity)5 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)4 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)4 AgriTabs (com.infinityraider.agricraft.content.AgriTabs)4 Names (com.infinityraider.agricraft.reference.Names)4 ItemBase (com.infinityraider.infinitylib.item.ItemBase)4 Nullable (javax.annotation.Nullable)4 Blocks (net.minecraft.block.Blocks)4