Search in sources :

Example 16 with PlayerEntity

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

the class AgriWailaCropBlockInfoProvider method appendBody.

@Override
public void appendBody(List<ITextComponent> tooltip, IDataAccessor accessor, IPluginConfig config) {
    AgriApi.getCrop(accessor.getWorld(), accessor.getPosition()).ifPresent(crop -> {
        PlayerEntity player = accessor.getPlayer();
        // Add data including full genome if in creative mode
        if (player.getHeldItemMainhand().getItem() == AgriCraft.instance.getModItemRegistry().debugger) {
            crop.addDisplayInfo(tooltip::add);
            tooltip.add(AgriToolTips.GENOME);
            crop.getGenome().map(genome -> {
                genome.addDisplayInfo(tooltip::add);
                return true;
            }).orElseGet(() -> {
                tooltip.add(AgriToolTips.UNKNOWN);
                return false;
            });
        } else {
            // add crop data
            if (this.shouldAddInfo(player)) {
                crop.addDisplayInfo(tooltip::add);
            }
        }
    });
    AgriApi.getSoil(accessor.getWorld(), accessor.getPosition()).ifPresent(soil -> soil.addDisplayInfo(tooltip::add));
}
Also used : AgriCraft(com.infinityraider.agricraft.AgriCraft) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) IDataAccessor(mcp.mobius.waila.api.IDataAccessor) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BlockCropPlant(com.infinityraider.agricraft.content.core.BlockCropPlant) TileEntityCropPlant(com.infinityraider.agricraft.content.core.TileEntityCropPlant) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) AgriToolTips(com.infinityraider.agricraft.reference.AgriToolTips) IComponentProvider(mcp.mobius.waila.api.IComponentProvider) IPluginConfig(mcp.mobius.waila.api.IPluginConfig) TileEntity(net.minecraft.tileentity.TileEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 17 with PlayerEntity

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

the class MagnifyingGlassViewHandler method onPlayerTick.

@SuppressWarnings("unused")
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
    this.animationCounterPrev = this.animationCounter;
    if (this.isActive()) {
        // Check if the player is still holding the item and if not, deactivate
        if (this.getActiveHand() == null || !(this.getPlayer().getHeldItem(this.getActiveHand()).getItem() instanceof ItemMagnifyingGlass)) {
            this.active = false;
            this.endInspection();
            return;
        }
        // Increment animation counter
        if (this.animationCounter < ANIMATION_DURATION) {
            this.animationCounter += 1;
        } else {
            this.animationCounter = ANIMATION_DURATION;
        }
        if (this.isAnimationComplete()) {
            // Update inspected position
            this.checkInspectedPosition();
            // Tick inspector
            if (this.inspector != null && this.lastTarget != null) {
                World world = AgriCraft.instance.getClientWorld();
                PlayerEntity player = AgriCraft.instance.getClientPlayer();
                if (!this.lastTarget.onInspectionTick(world, this.inspector, player)) {
                    this.endInspection();
                }
            }
        }
    } else {
        // Decrement animation counter
        if (this.animationCounter > 0) {
            this.animationCounter -= 1;
        } else {
            this.animationCounter = 0;
            this.hand = null;
        }
    }
}
Also used : World(net.minecraft.world.World) ItemMagnifyingGlass(com.infinityraider.agricraft.content.tools.ItemMagnifyingGlass) AbstractClientPlayerEntity(net.minecraft.client.entity.player.AbstractClientPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 18 with PlayerEntity

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

the class VanillaSeedConversionHandler method runPlantingConversion.

protected boolean runPlantingConversion(World world, BlockPos pos, ItemStack stack, PlayerEntity player, Hand hand) {
    return !AgriCraft.instance.getConfig().convertSeedsOnlyInAnalyzer() && AgriApi.getGenomeAdapterizer().valueOf(stack).map(seed -> {
        // The player is attempting to plant a seed, convert it to an agricraft crop
        return AgriApi.getSoil(world, pos.down()).map(soil -> {
            // check if there are crop sticks above
            MutableBoolean consumed = new MutableBoolean(false);
            boolean cropSticks = AgriApi.getCrop(world, pos).map(crop -> {
                if (!crop.hasPlant() && !crop.isCrossCrop() && crop.plantGenome(seed, player)) {
                    if (player == null || !player.isCreative()) {
                        stack.shrink(1);
                        consumed.setValue(true);
                    }
                    if (player != null) {
                        player.swingArm(hand);
                    }
                }
                return true;
            }).orElse(false);
            // if there were crop sticks, return the result of the crop sticks action
            if (cropSticks) {
                return consumed.getValue();
            }
            // no crop sticks, try planting as a plant
            BlockState newState = AgriCraft.instance.getModBlockRegistry().crop_plant.getStateForPlacement(world, pos);
            if (newState != null && world.setBlockState(pos, newState, 11)) {
                boolean planted = AgriApi.getCrop(world, pos).map(crop -> crop.plantGenome(seed, player)).orElse(false);
                if (planted) {
                    // reduce stack size
                    if (player == null || !player.isCreative()) {
                        stack.shrink(1);
                    }
                    // return success
                    return true;
                } else {
                    world.setBlockState(pos, Blocks.AIR.getDefaultState());
                }
            }
            return false;
        }).orElse(false);
    }).orElse(false);
}
Also used : AgriCraft(com.infinityraider.agricraft.AgriCraft) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) Item(net.minecraft.item.Item) World(net.minecraft.world.World) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Sets(com.google.common.collect.Sets) Blocks(net.minecraft.block.Blocks) ItemStack(net.minecraft.item.ItemStack) TileEntitySeedAnalyzer(com.infinityraider.agricraft.content.core.TileEntitySeedAnalyzer) EventPriority(net.minecraftforge.eventbus.api.EventPriority) Event(net.minecraftforge.eventbus.api.Event) TileEntity(net.minecraft.tileentity.TileEntity) Hand(net.minecraft.util.Hand) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) BlockState(net.minecraft.block.BlockState) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) IAgriSeedItem(com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem) BlockState(net.minecraft.block.BlockState) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Example 19 with PlayerEntity

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

the class JsonFertilizer method applyFertilizer.

@Override
public ActionResultType applyFertilizer(World world, BlockPos pos, IAgriFertilizable target, ItemStack stack, Random random, @Nullable LivingEntity entity) {
    if (target instanceof IAgriPlantProvider) {
        IAgriCrop crop = ((IAgriCrop) target);
        String type = "neutral";
        for (int i = 0; i < this.potency; i++) {
            if (fertilizerEffect.isNegativelyAffected(crop.getPlant().getId())) {
                if (fertilizerEffect.canReduceGrowth() && random.nextBoolean()) {
                    type = "negative";
                    IAgriGrowthStage current = crop.getGrowthStage();
                    IAgriGrowthStage previous = current.getPreviousStage(crop, random);
                    if (current.equals(previous)) {
                        if (fertilizerEffect.canKillPlant()) {
                            crop.removeGenome();
                        }
                    } else {
                        crop.setGrowthStage(previous);
                    }
                }
            } else {
                if (crop.hasPlant() && this.fertilizerEffect.canFertilize(crop.getPlant().getId())) {
                    target.applyGrowthTick();
                    type = "positive";
                } else if (crop.isCrossCrop() && this.canTriggerMutation()) {
                    target.applyGrowthTick();
                    type = "positive";
                } else if (this.canTriggerWeeds()) {
                    target.applyGrowthTick();
                    type = "positive";
                }
            }
        }
        this.spawnParticles(world, pos, type, random);
        if ((entity instanceof PlayerEntity) && !(((PlayerEntity) entity).isCreative())) {
            stack.shrink(1);
        }
        return ActionResultType.SUCCESS;
    }
    return ActionResultType.FAIL;
}
Also used : IAgriPlantProvider(com.infinityraider.agricraft.api.v1.plant.IAgriPlantProvider) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 20 with PlayerEntity

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

the class MessageSyncResearchCapability method processMessage.

@Override
protected void processMessage(NetworkEvent.Context ctx) {
    PlayerEntity player = AgriCraft.instance.getClientPlayer();
    if (player != null && this.tag != null) {
        CapabilityResearchedPlants.getInstance().getCapability(player).ifPresent(impl -> {
            impl.readFromNBT(this.tag);
            impl.configureJei();
        });
    }
}
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