001/* 002 * This file is part of Baritone. 003 * 004 * Baritone is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU Lesser General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * Baritone is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU Lesser General Public License for more details. 013 * 014 * You should have received a copy of the GNU Lesser General Public License 015 * along with Baritone. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package baritone.api.event.events; 019 020import baritone.api.event.events.type.EventState; 021import net.minecraft.client.Minecraft; 022 023import java.util.function.BiFunction; 024 025/** 026 * Called on and after each game tick of the primary {@link Minecraft} instance and dispatched to all Baritone 027 * instances. 028 * <p> 029 * When {@link #state} is {@link EventState#PRE}, the event is being called just prior to when the current in-game 030 * screen is ticked. When {@link #state} is {@link EventState#POST}, the event is being called at the very end 031 * of the {@link Minecraft#runTick()} method. 032 */ 033public final class TickEvent { 034 035 private static int overallTickCount; 036 037 private final EventState state; 038 private final Type type; 039 private final int count; 040 041 public TickEvent(EventState state, Type type, int count) { 042 this.state = state; 043 this.type = type; 044 this.count = count; 045 } 046 047 public int getCount() { 048 return count; 049 } 050 051 public Type getType() { 052 return type; 053 } 054 055 public EventState getState() { 056 return state; 057 } 058 059 public static synchronized BiFunction<EventState, Type, TickEvent> createNextProvider() { 060 final int count = overallTickCount++; 061 return (state, type) -> new TickEvent(state, type, count); 062 } 063 064 public enum Type { 065 /** 066 * When guarantees can be made about 067 * the game state and in-game variables. 068 */ 069 IN, 070 /** 071 * No guarantees can be made about the game state. 072 * This probably means we are at the main menu. 073 */ 074 OUT, 075 } 076}