Java Code Examples for net.minecraftforge.fml.common.gameevent.TickEvent.Phase#END

The following examples show how to use net.minecraftforge.fml.common.gameevent.TickEvent.Phase#END . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventsClient.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@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);
            }
        }
    }

}
 
Example 2
Source File: DebugUtil.java    From EnderZoo with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onPlayerTickClient(PlayerTickEvent evt) {
  if (evt.side != Side.CLIENT || evt.phase != Phase.END) {
    return;
  }
  RayTraceResult mo = Minecraft.getMinecraft().objectMouseOver;
  if (mo != null && mo.entityHit != null && mo.entityHit instanceof EntityLivingBase) {
    EntityLivingBase el = (EntityLivingBase) mo.entityHit;
    if (el != lastMouseOver) {
      double baseAttack = 0;
      double attack = 0;
      IAttributeInstance damAtt = el.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.ATTACK_DAMAGE);
      if (damAtt != null) {
        baseAttack = damAtt.getBaseValue();
        attack = damAtt.getAttributeValue();
      }
      System.out.println("DebugUtil.onPlayerTickClient: Health: " + el.getMaxHealth() + " Base Damage: " + baseAttack + " Damage: " + attack);
    }
    lastMouseOver = el;
  } else {
    lastMouseOver = null;
  }

}
 
Example 3
Source File: ClientStateMachine.java    From malmo with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example 4
Source File: BleachHack.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
  public void onTick(TickEvent.ClientTickEvent event) {
if (!(event.phase == Phase.END)) return;

try {
	ModuleManager.onUpdate();
  		ModuleManager.updateKeys();
  		
  		if (Minecraft.getInstance().player.ticksExisted % 100 == 0) {
  			fileReader.saveModules();
  			fileReader.saveSettings();
  			fileReader.saveClickGui();
  		}
  		
  		BleachQueue.nextQueue();
  	} catch (Exception e) {}
  }
 
Example 5
Source File: DelayedActionTickHandler.java    From OpenModsLib with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldTick(WorldTickEvent evt) {
	if (evt.side == Side.SERVER && evt.phase == Phase.END) {
		int worldId = evt.world.provider.getDimension();
		Queue<Runnable> callbacks = getWorldQueue(worldId);

		Runnable callback;
		while ((callback = callbacks.poll()) != null) {
			callback.run();
		}
	}
}
 
Example 6
Source File: CCCEventHandler.java    From CodeChickenCore with MIT License 5 votes vote down vote up
@SubscribeEvent
public void clientTick(TickEvent.ClientTickEvent event) {
    if(event.phase == Phase.END) {
        CCUpdateChecker.tick();
        renderTime++;
    }
}
 
Example 7
Source File: EventHandler.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onPostServerTick(ServerTickEvent event){
    if(event.phase == Phase.END) {
        RailNetworkManager.getServerInstance().onPostServerTick();
        ChunkLoadManager.INSTANCE.update();
    }
}
 
Example 8
Source File: ClientRenderHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent event)
{

	if(event.phase == Phase.START)
	{
		if(ClientRenderHandler.IsGeneratingFirstIsland)
		{
			Minecraft.getMinecraft().skipRenderWorld = true;
			skipRender = true;
		}
		else
		{
			skipRender = false;
		}
	}
	if(event.phase == Phase.END)
	{
		if(skipRender && ClientRenderHandler.IsGeneratingFirstIsland)
		{
			String gen = Core.translate("gui.generatingmapmessage");
			FontRenderer renderer = Minecraft.getMinecraft().fontRenderer;
			ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
			int sizeX = Minecraft.getMinecraft().displayWidth/2;
			int sizeY = Minecraft.getMinecraft().displayHeight/2;

			renderer.drawString(gen, sizeX/2 - (renderer.getStringWidth(gen) / 2)+1, sizeY/2+1, Color.black.getRGB());
			renderer.drawString(gen, sizeX/2 - (renderer.getStringWidth(gen) / 2), sizeY/2, Color.white.getRGB());
			Minecraft.getMinecraft().skipRenderWorld = false;
			skipRender = false;
		}
	}
}
 
Example 9
Source File: ClientHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@SubscribeEvent
public void tickEvent(TickEvent.ClientTickEvent event) {
    if (event.phase == Phase.END) {
        return;
    }

    Minecraft mc = Minecraft.getMinecraft();
    if (mc.world != null) {
        if (loadWorld(mc.world)) {
            NEIClientConfig.setHasSMPCounterPart(false);
            NEIClientConfig.setInternalEnabled(false);

            if (!Minecraft.getMinecraft().isSingleplayer() && ClientUtils.inWorld())//wait for server to initiate in singleplayer
            {
                NEIClientConfig.loadWorld("remote/" + ClientUtils.getServerIP().replace(':', '~'));
            }
        }

        if (!NEIClientConfig.isEnabled()) {
            return;
        }

        KeyManager.tickKeyStates();

        if (mc.currentScreen == null) {
            NEIController.processCreativeCycling(mc.player.inventory);
        }
    }

    GuiScreen gui = mc.currentScreen;
    if (gui != lastGui) {
        if (gui instanceof GuiMainMenu) {
            lastworld = null;
        } else if (gui instanceof GuiWorldSelection) {
            NEIClientConfig.reloadSaves();
        }
    }
    lastGui = gui;
}
 
Example 10
Source File: CableTickHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onTick(TickEvent.ServerTickEvent tick) {
	try {
		if(tick.phase == Phase.END) {
			NetworkRegistry.dataNetwork.tickAllNetworks();
			NetworkRegistry.energyNetwork.tickAllNetworks();
			NetworkRegistry.liquidNetwork.tickAllNetworks();
		}
	} catch (ConcurrentModificationException e) {
		e.printStackTrace();
	}
}
 
Example 11
Source File: ClientHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@SubscribeEvent
public void tickEvent(TickEvent.ClientTickEvent event) {
    if(event.phase == Phase.END)
        return;

    Minecraft mc = Minecraft.getMinecraft();
    if(mc.theWorld != null) {
        if(loadWorld(mc.theWorld)) {
            NEIClientConfig.setHasSMPCounterPart(false);
            NEIClientConfig.setInternalEnabled(false);

            if (!Minecraft.getMinecraft().isSingleplayer())//wait for server to initiate in singleplayer
                NEIClientConfig.loadWorld("remote/" + ClientUtils.getServerIP().replace(':', '~'));
        }

        if (!NEIClientConfig.isEnabled())
            return;

        KeyManager.tickKeyStates();

        NEIController.updateUnlimitedItems(mc.thePlayer.inventory);
        if (mc.currentScreen == null)
            NEIController.processCreativeCycling(mc.thePlayer.inventory);

        updateMagnetMode(mc.theWorld, mc.thePlayer);
    }

    GuiScreen gui = mc.currentScreen;
    if (gui != lastGui) {
        if (gui instanceof GuiMainMenu)
            lastworld = null;
        else if (gui instanceof GuiSelectWorld)
            NEIClientConfig.reloadSaves();
    }
    lastGui = gui;
}
 
Example 12
Source File: MagnetModeHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@SubscribeEvent
@SideOnly (Side.CLIENT)
public void clientTickEvent(TickEvent.ClientTickEvent event) {

    if (event.phase == Phase.END || Minecraft.getMinecraft().world == null) {
        return;
    }
    if (!NEIClientConfig.isMagnetModeEnabled()) {
        return;
    }
    EntityPlayer player = Minecraft.getMinecraft().player;

    Iterator<EntityItem> iterator = clientMagnetItems.iterator();
    while (iterator.hasNext()) {
        EntityItem item = iterator.next();
        if (item.cannotPickup()) {
            continue;
        }
        if (item.isDead) {
            iterator.remove();
        }
        if (item.getEntityData().getBoolean("PreventRemoteMovement")) {
            continue;
        }
        if (!NEIClientUtils.canItemFitInInventory(player, item.getItem())) {
            continue;
        }
        double dx = player.posX - item.posX;
        double dy = player.posY + player.getEyeHeight() - item.posY;
        double dz = player.posZ - item.posZ;
        double absxz = Math.sqrt(dx * dx + dz * dz);
        double absy = Math.abs(dy);
        if (absxz > DISTANCE_XZ || absy > DISTANCE_Y) {
            continue;
        }

        if (absxz > 1) {
            dx /= absxz;
            dz /= absxz;
        }

        if (absy > 1) {
            dy /= absy;
        }

        double vx = item.motionX + SPEED_XZ * dx;
        double vy = item.motionY + SPEED_Y * dy;
        double vz = item.motionZ + SPEED_XZ * dz;

        double absvxz = Math.sqrt(vx * vx + vz * vz);
        double absvy = Math.abs(vy);

        double rationspeedxz = absvxz / MAX_SPEED_XZ;
        if (rationspeedxz > 1) {
            vx /= rationspeedxz;
            vz /= rationspeedxz;
        }

        double rationspeedy = absvy / MAX_SPEED_Y;
        if (rationspeedy > 1) {
            vy /= rationspeedy;
        }

        if (absvxz < 0.2 && absxz < 0.2) {
            item.setDead();
        }

        item.setVelocity(vx, vy, vz);
    }
}
 
Example 13
Source File: ClientHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@SubscribeEvent
public void tickEvent(TickEvent.RenderTickEvent event) {
    if(event.phase == Phase.END && NEIClientConfig.isEnabled())
        HUDRenderer.renderOverlay();
}
 
Example 14
Source File: JEIProxy.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@SubscribeEvent
public void tickEvent(ClientTickEvent event) {
    if (event.phase == Phase.END) {
        extraAreasCache = null;
    }
}
 
Example 15
Source File: ServerStateMachine.java    From malmo with MIT License 4 votes vote down vote up
@Override
protected void onServerTick(ServerTickEvent ev)
{
    if (this.missionHasEnded)
        return;	// In case we get in here after deciding the mission is over.
    
    if (!ServerStateMachine.this.checkWatchList())
        onError(null);  // We've lost a connection - abort the mission.

    if (ev.phase == Phase.START)
    {
        // Measure our performance - especially useful if we've been overclocked.
        if (this.secondStartTimeMs == 0)
            this.secondStartTimeMs = System.currentTimeMillis();

        long timeNow = System.currentTimeMillis();
        if (timeNow - this.secondStartTimeMs > 1000)
        {
            long targetTicks = 1000 / TimeHelper.serverTickLength;
            if (this.tickCount < targetTicks)
                System.out.println("Warning: managed " + this.tickCount + "/" + targetTicks + " ticks this second.");
            this.secondStartTimeMs = timeNow;
            this.tickCount = 0;
        }
        this.tickCount++;
    }

	MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();

    if (ev.phase == Phase.END && getHandlers() != null && getHandlers().worldDecorator != null)
    {
        World world = server.getEntityWorld();
        getHandlers().worldDecorator.update(world);
    }

    if (ev.phase == Phase.END)
    {
        if (getHandlers() != null && getHandlers().quitProducer != null && getHandlers().quitProducer.doIWantToQuit(currentMissionInit()))
        {
            ServerStateMachine.this.quitCode = getHandlers().quitProducer.getOutcome();
            onMissionEnded(true);
        }
        else if (this.runningAgents.isEmpty())
        {
            ServerStateMachine.this.quitCode = "All agents finished";
            onMissionEnded(true);
        }
        // We need to make sure we keep the weather within mission parameters.
        // We set the weather just after building the world, but it's not a permanent setting,
        // and apparently there is a known bug in Minecraft that means the weather sometimes changes early.
        // To get around this, we reset it periodically.
        if (server.getTickCounter() % 500 == 0)
        {
            EnvironmentHelper.setMissionWeather(currentMissionInit(), server.getEntityWorld().getWorldInfo());
        }
    }
}
 
Example 16
Source File: ClientStateMachine.java    From malmo with MIT License 4 votes vote down vote up
@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);
    }
}
 
Example 17
Source File: CyberwareMenuHandler.java    From Cyberware with MIT License 4 votes vote down vote up
@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();
		}
		
	}
}