Search in sources :

Example 21 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project AgriCraft by AgriCraft.

the class ItemToolTipHandler method addSeedBagTooltip.

/**
 * Adds tooltips to the seed bag (we must do this here to avoid the enchantment tool tip)
 */
@SubscribeEvent
@SuppressWarnings("unused")
public void addSeedBagTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.getItemStack();
    if (stack.getItem() instanceof ItemSeedBag) {
        ItemSeedBag bag = (ItemSeedBag) stack.getItem();
        ItemSeedBag.Contents contents = bag.getContents(stack);
        if (bag.isActivated(stack)) {
            // Remove previous tooltip
            if (event.getToolTip().size() > 0) {
                ITextComponent name = event.getToolTip().get(0);
                event.getToolTip().clear();
                event.getToolTip().add(name);
            }
            // Description
            event.getToolTip().add(AgriToolTips.SEED_BAG_ACTIVE);
            event.getToolTip().add(AgriToolTips.EMPTY_LINE);
            // Contents
            if (contents.getPlant().isPlant()) {
                event.getToolTip().add(new StringTextComponent("").appendSibling(AgriToolTips.SEED_BAG_CONTENTS).appendSibling(new StringTextComponent(" " + contents.getCount() + " ")).appendSibling(contents.getPlant().getSeedName()));
            } else {
                event.getToolTip().add(AgriToolTips.SEED_BAG_EMPTY);
            }
            // Sorter
            event.getToolTip().add(new StringTextComponent("").appendSibling(AgriToolTips.SEED_BAG_SORTER).appendSibling(new StringTextComponent(" ")).appendSibling(contents.getSorter().getName()));
            event.getToolTip().add(AgriToolTips.EMPTY_LINE);
            // Usage
            if (ModuleKeyboard.getInstance().isKeyPressed(Minecraft.getInstance().gameSettings.keyBindSneak)) {
                event.getToolTip().add(new StringTextComponent("").mergeStyle(TextFormatting.DARK_GRAY).appendSibling(AgriToolTips.SEED_BAG_MAIN_HAND));
                event.getToolTip().add(new StringTextComponent("").mergeStyle(TextFormatting.DARK_GRAY).appendSibling(AgriToolTips.SEED_BAG_OFF_HAND));
                event.getToolTip().add(new StringTextComponent("").mergeStyle(TextFormatting.DARK_GRAY).appendSibling(AgriToolTips.SEED_BAG_SCROLLING));
            } else {
                event.getToolTip().add(new StringTextComponent("").mergeStyle(TextFormatting.DARK_GRAY).appendSibling(AgriToolTips.SNEAK_INFO));
            }
        } else {
            event.getToolTip().add(AgriToolTips.SEED_BAG_INACTIVE_1);
            event.getToolTip().add(AgriToolTips.SEED_BAG_INACTIVE_2);
        }
    }
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) ItemSeedBag(com.infinityraider.agricraft.content.tools.ItemSeedBag) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 22 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project AgriCraft by AgriCraft.

the class GeneAnimalAttractant method onCropGrowthTick.

@SubscribeEvent
@SuppressWarnings("unused")
public void onCropGrowthTick(AgriCropEvent.Grow.General.Post event) {
    if (event.getCrop().world() != null && event.getCrop().hasPlant() && event.getCrop().isMature()) {
        BlockPos min = event.getCrop().getPosition().add(-RANGE, -RANGE, -RANGE);
        BlockPos max = event.getCrop().getPosition().add(RANGE, RANGE, RANGE);
        AxisAlignedBB range = new AxisAlignedBB(min, max);
        event.getCrop().world().getEntitiesWithinAABB(this.clazz, range, (entity) -> true).stream().map(entity -> CapabilityEatCropGoal.getInstance().getCropEatGoal(entity)).filter(Objects::nonNull).filter(goal -> goal.isSuitableTarget(event.getCrop())).forEach(goal -> goal.addPotentialTarget(event.getCrop()));
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) AgriNBT(com.infinityraider.agricraft.reference.AgriNBT) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) CompoundNBT(net.minecraft.nbt.CompoundNBT) IFormattableTextComponent(net.minecraft.util.text.IFormattableTextComponent) Random(java.util.Random) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) EntityHelper(com.infinityraider.infinitylib.utility.EntityHelper) Goal(net.minecraft.entity.ai.goal.Goal) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) MobEntity(net.minecraft.entity.MobEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) 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) Tuple(net.minecraft.util.Tuple) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Consumer(java.util.function.Consumer) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) List(java.util.List) Vector3f(net.minecraft.util.math.vector.Vector3f) AgriGenePair(com.infinityraider.agricraft.impl.v1.genetics.AgriGenePair) AgriCropEvent(com.infinityraider.agricraft.api.v1.event.AgriCropEvent) com.infinityraider.agricraft.api.v1.genetics(com.infinityraider.agricraft.api.v1.genetics) CapabilityEatCropGoal(com.infinityraider.agricraft.capability.CapabilityEatCropGoal) Objects(java.util.Objects) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 23 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project AgriCraft by AgriCraft.

the class BotanyPotsHandler method onCropGrowth.

// Fertility checks and weeds
@SuppressWarnings("unused")
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onCropGrowth(PotGrowCropEvent.Pre event) {
    if (event.getBotanyPot().getCrop() instanceof AgriCropInfo) {
        event.getBotanyPot().getCapability(CropCapability.getCapability()).ifPresent(crop -> {
            boolean cancel;
            if (AgriCraft.instance.getConfig().allowBotanyPotsWeeds() && CropHelper.rollForWeedAction(crop)) {
                // Weed tick, run weed logic
                cancel = true;
                if (!crop.hasWeeds()) {
                    CropHelper.spawnWeeds(crop);
                } else {
                    if (crop instanceof BotanyPotAgriCropInstance.Impl) {
                        BotanyPotAgriCropInstance.Impl cropImpl = (BotanyPotAgriCropInstance.Impl) crop;
                        if (cropImpl.incrementWeedCounter(event.getCurrentAmount())) {
                            if (AgriCraft.instance.getConfig().allowLethalWeeds()) {
                                event.setAmount(-1);
                                if (event.getBotanyPot().getCurrentGrowthTicks() <= 0) {
                                    event.getBotanyPot().setCrop(null, ItemStack.EMPTY);
                                }
                            }
                        }
                    }
                }
            } else {
                // Plant tick, run fertility checks
                cancel = false;
                IAgriGrowthResponse response = crop.getFertilityResponse();
                if (response.killInstantly()) {
                    event.getBotanyPot().setCrop(null, ItemStack.EMPTY);
                    response.onPlantKilled(crop);
                    cancel = true;
                } else if (response.isLethal()) {
                    event.setAmount(-1);
                    if (event.getBotanyPot().getCurrentGrowthTicks() <= 0) {
                        event.getBotanyPot().setCrop(null, ItemStack.EMPTY);
                        cancel = true;
                    }
                } else {
                    cancel = !response.isFertile();
                }
            }
            if (cancel) {
                event.setAmount(0);
                event.setCanceled(true);
                event.setResult(Event.Result.DENY);
            }
        });
    }
}
Also used : IAgriGrowthResponse(com.infinityraider.agricraft.api.v1.requirement.IAgriGrowthResponse) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 24 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project AgriCraft by AgriCraft.

the class BotanyPotsHandler method onLookUp.

// Stats and seed conversion
@SubscribeEvent
@SuppressWarnings("unused")
public void onLookUp(LookupEvent.Crop event) {
    if (event.getCurrentLookup() instanceof AgriCropInfo) {
        event.setLookup(((AgriCropInfo) event.getCurrentLookup()).withStats(event.getItemStack()));
    } else {
        if (!AgriCraft.instance.getConfig().overrideVanillaFarming()) {
            return;
        }
        if (VanillaSeedConversionHandler.getInstance().isException(event.getItemStack())) {
            return;
        }
        AgriApi.getGenomeAdapterizer().valueOf(event.getItemStack()).ifPresent(genome -> {
            ItemStack seedStack = genome.toSeedStack();
            CropInfo info = BotanyPotHelper.getCropForItem(seedStack);
            if (info instanceof AgriCropInfo) {
                event.setLookup(((AgriCropInfo) info).withStats(seedStack));
                AgriCraft.instance.queueTask(() -> event.getBotanyPot().setCrop(info, seedStack));
            }
        });
    }
}
Also used : CropInfo(net.darkhax.botanypots.crop.CropInfo) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 25 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent 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)

Aggregations

SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)87 PlayerEntity (net.minecraft.entity.player.PlayerEntity)18 ItemStack (net.minecraft.item.ItemStack)17 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)11 ResourceLocation (net.minecraft.util.ResourceLocation)10 World (net.minecraft.world.World)8 Player (net.minecraft.world.entity.player.Player)8 BlockPos (net.minecraft.util.math.BlockPos)7 Entity (net.minecraft.world.entity.Entity)7 ItemStack (net.minecraft.world.item.ItemStack)7 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 Minecraft (net.minecraft.client.Minecraft)5 BlockPos (net.minecraft.core.BlockPos)5 ServerPlayer (net.minecraft.server.level.ServerPlayer)5 StringTextComponent (net.minecraft.util.text.StringTextComponent)5 Item (net.minecraft.world.item.Item)5 BlockItem (net.minecraft.item.BlockItem)4 ResourceLocation (net.minecraft.resources.ResourceLocation)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)4