Search in sources :

Example 41 with PlayerEntity

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

the class GuiPlugin method onSeedAnalyzerRightClick.

public void onSeedAnalyzerRightClick(PlayerInteractEvent.RightClickBlock event) {
    BlockPos pos = event.getPos();
    BlockState state = event.getWorld().getBlockState(pos);
    if (event.getPlayer().isSneaking()) {
        return;
    }
    if (state.getBlock() != AgriCraft.instance.getModBlockRegistry().seed_analyzer.getBlock()) {
        return;
    }
    event.setCancellationResult(ActionResultType.SUCCESS);
    event.setCanceled(true);
    if (event.getPlayer().world.isRemote) {
        return;
    }
    INamedContainerProvider containerProvider = new INamedContainerProvider() {

        @Nonnull
        @Override
        public ITextComponent getDisplayName() {
            return new TranslationTextComponent("screen.agricraft.seed_analyzer");
        }

        @Override
        public Container createMenu(int id, @Nonnull PlayerInventory playerInventory, @Nonnull PlayerEntity player) {
            return new SeedAnalyzerContainer(id, event.getWorld(), playerInventory, pos);
        }
    };
    NetworkHooks.openGui((ServerPlayerEntity) event.getPlayer(), containerProvider, pos);
}
Also used : BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) SeedAnalyzerContainer(com.infinityraider.agricraft.plugins.agrigui.analyzer.SeedAnalyzerContainer) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) INamedContainerProvider(net.minecraft.inventory.container.INamedContainerProvider) PlayerInventory(net.minecraft.entity.player.PlayerInventory) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 42 with PlayerEntity

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

the class ItemDynamicAgriSeed method onItemUse.

@Nonnull
@Override
public ActionResultType onItemUse(@Nonnull ItemUseContext context) {
    World world = context.getWorld();
    BlockPos pos = context.getPos();
    TileEntity tile = world.getTileEntity(pos);
    ItemStack stack = context.getItem();
    PlayerEntity player = context.getPlayer();
    // If crop sticks were clicked, attempt to plant the seed
    if (tile instanceof TileEntityCropSticks) {
        return this.attemptSeedPlant((TileEntityCropSticks) tile, stack, player);
    }
    // If a soil was clicked, check the block on top of the soil and handle accordingly
    return AgriApi.getSoil(world, pos).map(soil -> {
        BlockPos up = pos.up();
        TileEntity above = world.getTileEntity(up);
        // There are currently crop sticks on the soil, attempt to plant on the crop sticks
        if (above instanceof TileEntityCropSticks) {
            return this.attemptSeedPlant((TileEntityCropSticks) above, stack, player);
        }
        // There are currently no crop sticks, check if the place is suitable and plant the plant directly
        if (above == null && AgriCraft.instance.getConfig().allowPlantingOutsideCropSticks()) {
            BlockState newState = AgriCraft.instance.getModBlockRegistry().crop_plant.getStateForPlacement(world, up);
            if (newState != null && world.setBlockState(up, newState, 11)) {
                boolean success = AgriApi.getCrop(world, up).map(crop -> this.getGenome(context.getItem()).map(genome -> crop.plantGenome(genome, player)).map(result -> {
                    if (result) {
                        // consume item
                        if (player == null || !player.isCreative()) {
                            stack.shrink(1);
                        }
                    }
                    return result;
                }).orElse(false)).orElse(false);
                if (success) {
                    return ActionResultType.SUCCESS;
                } else {
                    world.setBlockState(up, Blocks.AIR.getDefaultState());
                }
            }
        }
        // Neither alternative option was successful, delegate the call to the super method
        return super.onItemUse(context);
    }).orElse(super.onItemUse(context));
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) NoPlant(com.infinityraider.agricraft.impl.v1.plant.NoPlant) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) CompoundNBT(net.minecraft.nbt.CompoundNBT) IAgriGenome(com.infinityraider.agricraft.api.v1.genetics.IAgriGenome) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) IWorldReader(net.minecraft.world.IWorldReader) ItemUseContext(net.minecraft.item.ItemUseContext) ITextComponent(net.minecraft.util.text.ITextComponent) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) Names(com.infinityraider.agricraft.reference.Names) ItemBase(com.infinityraider.infinitylib.item.ItemBase) NonNullList(net.minecraft.util.NonNullList) BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IAgriSeedItem(com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem) AgriCraft(com.infinityraider.agricraft.AgriCraft) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Blocks(net.minecraft.block.Blocks) List(java.util.List) AgriTabs(com.infinityraider.agricraft.content.AgriTabs) ItemGroup(net.minecraft.item.ItemGroup) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) ActionResultType(net.minecraft.util.ActionResultType) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Nonnull(javax.annotation.Nonnull)

Example 43 with PlayerEntity

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

the class BlockGreenHouseAirRenderer method render.

@SubscribeEvent
@SuppressWarnings("unused")
public void render(RenderWorldLastEvent event) {
    PlayerEntity player = AgriCraft.instance.getClientPlayer();
    ItemStack stack = player.getHeldItemMainhand();
    if (stack.getItem() != AgriCraft.instance.getModItemRegistry().debugger) {
        return;
    }
    if (AgriCraft.instance.getModItemRegistry().debugger.getDebugMode(stack) instanceof DebugModeGreenHouse) {
        this.highlightGreenHouseAirBlocks(player.getEntityWorld(), player.getPosition(), event.getMatrixStack());
    }
}
Also used : DebugModeGreenHouse(com.infinityraider.agricraft.util.debug.DebugModeGreenHouse) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 44 with PlayerEntity

use of net.minecraft.entity.player.PlayerEntity in project Geolosys by oitsjustjose.

the class ManualGifting method onPlayerJoin.

@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
    if (!CommonConfig.GIVE_MANUAL_TO_NEW.get()) {
        return;
    }
    PlayerEntity player = event.getPlayer();
    IDepositCapability geolosysCap = event.getEntity().getEntityWorld().getCapability(GeolosysAPI.GEOLOSYS_WORLD_CAPABILITY).orElse(null);
    if (geolosysCap == null) {
        return;
    }
    if (!geolosysCap.hasPlayerReceivedManual(player.getUniqueID())) {
        ItemHandlerHelper.giveItemToPlayer(player, PatchouliAPI.get().getBookStack(new ResourceLocation(Constants.MODID, "field_manual")));
        geolosysCap.setPlayerReceivedManual(player.getUniqueID());
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) IDepositCapability(com.oitsjustjose.geolosys.common.world.capability.IDepositCapability) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 45 with PlayerEntity

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

the class PlayerAngleLocker method storePlayerAngles.

public static void storePlayerAngles() {
    PlayerEntity player = AgriCraft.instance.getClientPlayer();
    yaw = player.rotationYaw;
    yawCamera = player.cameraYaw;
    yawOffset = player.renderYawOffset;
    yawHead = player.rotationYawHead;
    pitch = player.rotationPitch;
}
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