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);
}
}
}
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()));
}
}
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);
}
});
}
}
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));
}
});
}
}
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;
}
}
}
Aggregations