下面列出了怎么用net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent的API类实例代码及写法,或者点击链接到github查看源代码。
@SubscribeEvent
public void onClientTick(ClientTickEvent event) {
if (getWorld() == null || getLocalPlayer() == null) {
reset();
return;
}
switch (event.phase) {
case START: {
if (originalIndex != -1 && resetCondition.test(ticksElapsed)) {
resetSelected();
}
if (ticksElapsed != -1) {
++ticksElapsed;
}
break;
}
}
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onClientTickEvent(ClientTickEvent event) {
Minecraft mc = Minecraft.getMinecraft();
if (mc.world != null) {
if (!mc.isGamePaused()) {
WorldPhysObjectManager manager = ValkyrienSkiesMod.VS_PHYSICS_MANAGER
.getManagerForWorld(mc.world);
if (event.phase == Phase.END) {
for (PhysicsWrapperEntity wrapper : manager.physicsEntities) {
wrapper.getPhysicsObject().onPostTickClient();
}
EntityDraggable.tickAddedVelocityForWorld(mc.world);
}
}
}
}
@Override
public void onClientTick(TickEvent.ClientTickEvent ev)
{
// Check to see whether anything has caused us to abort - if so, go to the abort state.
if (inAbortState())
episodeHasCompleted(ClientState.MISSION_ABORTED);
if (ev.phase == Phase.END)
episodeHasCompleted(ClientState.CREATING_NEW_WORLD);
if (++totalTicks > WAIT_MAX_TICKS)
{
String msg = "Too long waiting for server episode to close.";
TCPUtils.Log(Level.SEVERE, msg);
episodeHasCompletedWithErrors(ClientState.ERROR_TIMED_OUT_WAITING_FOR_EPISODE_CLOSE, msg);
}
}
@SubscribeEvent
public static void clientTick(ClientTickEvent event) {
EntityPlayer e = Minecraft.getMinecraft().player;
if(e != null && e.world != null && !Minecraft.getMinecraft().isGamePaused()) {
Particle particle = new ParticleBasic(e.world, e.posX + (Math.random() - 0.5F), e.posY + 3, e.posZ + (Math.random() - 0.5F), 0.0F, 1000.0F, 0.0F, DabSquirrels.dab, 1F);
Minecraft.getMinecraft().effectRenderer.addEffect(particle);
}
}
@SubscribeEvent
public void onClientTick(ClientTickEvent ev) {
if (isDead) {
deadTicks++;
if (deadTicks > delay.getAsInteger()) {
deadTicks = 0;
isDead = false;
getLocalPlayer().respawnPlayer();
}
}
}
@SubscribeEvent
void onTick(ClientTickEvent event) {
switch (event.phase) {
case START:
MC.gameSettings.limitFramerate = getFps();
break;
case END:
default:
break;
}
}
@SubscribeEvent
public void onClientTick(ClientTickEvent event) {
if (getWorld() == null || getLocalPlayer() == null) {
return;
}
if (event.phase == TickEvent.Phase.START) {
getWorld()
.loadedEntityList
.stream()
.filter(EntityItem.class::isInstance)
.map(EntityItem.class::cast)
.forEach(Entity::setDead);
}
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void overlayPre(ClientTickEvent event)
{
if (event.phase == Phase.START && Minecraft.getMinecraft() != null && Minecraft.getMinecraft().thePlayer != null)
{
EntityPlayer e = Minecraft.getMinecraft().thePlayer;
HashMultimap<String, AttributeModifier> multimap = HashMultimap.<String, AttributeModifier>create();
multimap.put(SharedMonsterAttributes.MOVEMENT_SPEED.getAttributeUnlocalizedName(), new AttributeModifier(speedId, "Missing leg speed", -100F, 0));
e.getAttributeMap().removeAttributeModifiers(multimap);
}
}
@SubscribeEvent
public void onClientTick(ClientTickEvent event) {
World world = Minecraft.getMinecraft().world;
if (world == null) {
// There's no world, so there's nothing to run.
return;
}
// Pretend this is the world tick, because diesieben07 doesn't want WorldClient to make world tick events.
switch (event.phase) {
case START:
// Nothing for now
for (PhysicsWrapperEntity wrapper : ValkyrienSkiesMod.VS_PHYSICS_MANAGER
.getManagerForWorld(world)
.getTickablePhysicsEntities()) {
// This is necessary because Minecraft will run a raytrace right after this
// event to determine what the player is looking at for interaction purposes.
// That raytrace will use the render transform, so we must have the render
// transform set to a partialTick of 1.0.
wrapper.getPhysicsObject().getShipTransformationManager()
.updateRenderTransform(1.0);
}
break;
case END:
// Tick the IShipManager on the world client.
IHasShipManager shipManager = (IHasShipManager) world;
shipManager.getManager().tick();
break;
}
}
@Override
public void onClientTick(TickEvent.ClientTickEvent ev)
{
// Check to see whether anything has caused us to abort - if so, go to the abort state.
if (inAbortState())
episodeHasCompleted(ClientState.MISSION_ABORTED);
if (++totalTicks > WAIT_MAX_TICKS)
{
String msg = "Too long waiting for world to be created.";
TCPUtils.Log(Level.SEVERE, msg);
episodeHasCompletedWithErrors(ClientState.ERROR_TIMED_OUT_WAITING_FOR_WORLD_CREATE, msg);
}
}
@Override
public void onClientTick(TickEvent.ClientTickEvent ev)
{
// Check to see whether anything has caused us to abort - if so, go to the abort state.
if (inAbortState())
episodeHasCompleted(ClientState.MISSION_ABORTED);
++totalTicks;
}
@Override
public void onClientTick(ClientTickEvent event)
{
if (!this.aborting)
episodeHasCompleted(ClientState.WAITING_FOR_SERVER_MISSION_END);
if (++totalTicks > WAIT_MAX_TICKS)
{
String msg = "Too long waiting for server to end mission.";
TCPUtils.Log(Level.SEVERE, msg);
episodeHasCompletedWithErrors(ClientState.ERROR_TIMED_OUT_WAITING_FOR_MISSION_END, msg);
}
}
@SubscribeEvent
public void onClientTick(ClientTickEvent ev)
{
if (ev.phase == Phase.START)
{
// Track average client ticks per second:
this.clientTickMonitor.beat();
}
}
@SubscribeEvent
public void onTickClientTick(ClientTickEvent event) {
items.removeIf(Task::execute);
}
@SubscribeEvent
public void onTick(ClientTickEvent event) {
if (!Phase.START.equals(event.phase) || getLocalPlayer() == null) {
return;
}
// only process when a gui isn't opened by the player
if (MC.currentScreen != null && no_gui.get()) {
return;
}
if (tasks.isEmpty()) {
final List<InvItem> slots = LocalPlayerInventory.getSlotStorageInventory();
tasks =
LocalPlayerInventory.getHotbarInventory()
.stream()
.filter(InvItem::nonNull)
.filter(this::isMonitoring)
.filter(item -> !isAboveThreshold(item))
.filter(item ->
slots
.stream()
.filter(this::isMonitoring)
.filter(inv -> !inv.isItemDamageable() || isAboveThreshold(inv))
.anyMatch(item::isItemsEqual)
)
.max(Comparator.comparingInt(LocalPlayerInventory::getHotbarDistance))
.map(hotbarItem ->
TaskChain.<Runnable>builder()
.then(() -> {
// pick up item
verifyHotbar(hotbarItem);
click(
slots
.stream()
.filter(InvItem::nonNull)
.filter(this::isMonitoring)
.filter(hotbarItem::isItemsEqual)
.filter(inv -> !inv.isDamageable() || isAboveThreshold(inv))
.max(Comparator.comparingInt(this::getDamageOrCount))
.orElseThrow(RuntimeException::new),
0,
ClickType.PICKUP
);
})
.then(() -> {
// place item into hotbar
verifyHotbar(hotbarItem);
click(hotbarItem, 0, ClickType.PICKUP);
})
.then(this::tryPlacingHeldItem)
.build())
.orElse(TaskChain.empty());
}
// process the next click task
int n = 0;
while (processing(n++) && tasks.hasNext()) {
try {
tasks.next().run();
} catch (Throwable t) {
tasks = TaskChain.singleton(this::tryPlacingHeldItem);
}
}
++tickCount;
}
@SubscribeEvent
public void onTick(ClientTickEvent event) {
if (getWorld() == null || getLocalPlayer() == null || running) {
return;
}
switch (event.phase) {
case END: {
Chunk chunk = getWorld().getChunkFromBlockCoords(getLocalPlayer().getPosition());
if (chunk.isEmpty()) {
return;
}
ChunkPos pos = chunk.getPos();
if (!pos.equals(current) || (timer.isStarted() && timer.hasTimeElapsed(1000L))) {
// chunk changed, don't show diff between different chunks
if (current != null && !pos.equals(current)) {
size = previousSize = 0L;
}
current = pos;
running = true;
// process size calculation on another thread
Executors.defaultThreadFactory()
.newThread(
() -> {
try {
final NBTTagCompound root = new NBTTagCompound();
NBTTagCompound level = new NBTTagCompound();
root.setTag("Level", level);
root.setInteger("DataVersion", 1337);
try {
// this should be done on the main mc thread but it works 99% of the
// time outside it
AnvilChunkLoader loader = new AnvilChunkLoader(DUMMY, null);
Methods.AnvilChunkLoader_writeChunkToNBT.invoke(
loader, chunk, getWorld(), level);
} catch (Throwable t) {
size = -1L;
previousSize = 0L;
return; // couldn't save chunk
}
DataOutputStream compressed =
new DataOutputStream(
new BufferedOutputStream(
new DeflaterOutputStream(new ByteArrayOutputStream(8096))));
try {
CompressedStreamTools.write(root, compressed);
previousSize = size;
size = compressed.size();
} catch (IOException e) {
size = -1L;
previousSize = 0L;
}
} finally {
timer.start();
running = false;
}
})
.start();
}
break;
}
default:
break;
}
}
@SubscribeEvent
public void handleWorldTick2(ClientTickEvent event) {
TaskRunner.run();
}
@SubscribeEvent
public void tick(ClientTickEvent event)
{
if(event.phase == Phase.START)
{
if (!KeyBinds.menu.isPressed() && mc.currentScreen == null && wasInScreen > 0)
{
KeyConflictContext inGame = KeyConflictContext.IN_GAME;
mc.gameSettings.keyBindForward.setKeyConflictContext(inGame);
mc.gameSettings.keyBindLeft.setKeyConflictContext(inGame);
mc.gameSettings.keyBindBack.setKeyConflictContext(inGame);
mc.gameSettings.keyBindRight.setKeyConflictContext(inGame);
mc.gameSettings.keyBindJump.setKeyConflictContext(inGame);
mc.gameSettings.keyBindSneak.setKeyConflictContext(inGame);
mc.gameSettings.keyBindSprint.setKeyConflictContext(inGame);
if (wasSprinting)
{
mc.thePlayer.setSprinting(wasSprinting);
}
wasInScreen--;
}
}
if(event.phase == Phase.END)
{
if (mc.thePlayer != null && mc.currentScreen == null)
{
ICyberwareUserData data = CyberwareAPI.getCapability(mc.thePlayer);
for (int keyCode : data.getHotkeys())
{
if (isPressed(data, keyCode))
{
pressed.add(keyCode);
if (!lastPressed.contains(keyCode))
{
ClientUtils.useActiveItemClient(mc.thePlayer, data.getHotkey(keyCode));
}
}
}
lastPressed = pressed;
pressed = new ArrayList<Integer>();
}
if (mc.thePlayer != null && CyberwareAPI.getCapability(mc.thePlayer).getNumActiveItems() > 0 && KeyBinds.menu.isPressed() && mc.currentScreen == null)
{
KeyConflictContext gui = KeyConflictContext.GUI;
mc.gameSettings.keyBindForward.setKeyConflictContext(gui);
mc.gameSettings.keyBindLeft.setKeyConflictContext(gui);
mc.gameSettings.keyBindBack.setKeyConflictContext(gui);
mc.gameSettings.keyBindRight.setKeyConflictContext(gui);
mc.gameSettings.keyBindJump.setKeyConflictContext(gui);
mc.gameSettings.keyBindSneak.setKeyConflictContext(gui);
mc.gameSettings.keyBindSprint.setKeyConflictContext(gui);
mc.displayGuiScreen(new GuiCyberwareMenu());
CyberwareAPI.getCapability(mc.thePlayer).setOpenedRadialMenu(true);
CyberwarePacketHandler.INSTANCE.sendToServer(new OpenRadialMenuPacket());
wasInScreen = 5;
}
else if (wasInScreen > 0 && mc.currentScreen instanceof GuiCyberwareMenu)
{
wasSprinting = mc.thePlayer.isSprinting();
}
}
}
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent ev)
{
// Use the client tick to ensure we regularly update our state (from the client thread)
updateState();
}
@Override
public void onClientTick(TickEvent.ClientTickEvent ev) throws Exception
{
checkForMissionCommand();
}
@Override
public void onClientTick(TickEvent.ClientTickEvent ev)
{
// Check to see whether anything has caused us to abort - if so, go to the abort state.
if (inAbortState())
episodeHasCompleted(ClientState.MISSION_ABORTED);
// We need to make sure that both the client and server have paused,
// otherwise we are still susceptible to the "Holder Lookups" hang.
// Since the server sets its pause state in response to the client's pause state,
// and it only performs this check once, at the top of its tick method,
// to be sure that the server has had time to set the flag correctly we need to make sure
// that at least one server tick method has *started* since the flag was set.
// We can't do this by catching the onServerTick events, since we don't receive them when the game is paused.
// The following code makes use of the fact that the server both locks and empties the server's futureQueue,
// every time through the server tick method.
// This locking means that if the client - which needs to wait on the lock -
// tries to add an event to the queue in response to an event on the queue being executed,
// the newly added event will have to happen in a subsequent tick.
if ((Minecraft.getMinecraft().isGamePaused() || Minecraft.getMinecraft().player == null) && ev != null && ev.phase == Phase.END && this.clientTickCount == this.serverTickCount && this.clientTickCount <= 2)
{
this.clientTickCount++; // Increment our count, and wait for the server to catch up.
Minecraft.getMinecraft().getIntegratedServer().addScheduledTask(new Runnable()
{
public void run()
{
// Increment the server count.
PauseOldServerEpisode.this.serverTickCount++;
}
});
}
if (this.serverTickCount > 2) {
episodeHasCompleted(ClientState.CLOSING_OLD_SERVER);
} else if (++totalTicks > WAIT_MAX_TICKS) {
String msg = "Too long waiting for server episode to pause.";
TCPUtils.Log(Level.SEVERE, msg);
episodeHasCompletedWithErrors(ClientState.ERROR_TIMED_OUT_WAITING_FOR_EPISODE_PAUSE, msg);
}
}
@SubscribeEvent
public void onPreClientTick(ClientTickEvent event){
if(event.phase == Phase.START) {
RailNetworkManager.getClientInstance().onPreClientTick();
}
}
@SubscribeEvent
public void tickEvent(ClientTickEvent event) {
if (event.phase == Phase.END) {
extraAreasCache = null;
}
}
/** Subclass should overrride this to act on client ticks.
* @throws Exception */
protected void onClientTick(ClientTickEvent ev) throws Exception {}