Jump to content

Having New Server problems with Time - Does not Tell Client to update variable.


Jade_Knightblazer

Recommended Posts

Seems what ever I do, I can't get time of day to work correctly.

 

Under my ClientTickHandler.

 

System.out.println(mc.theWorld.isDayLight()); is always true.

EntityPlayer.worldObj.isDayLight(); is always true.

 

Under my Custom Common Item.class:

 

onUpdate() Method:

 

System.out.println(world.isDayLight()); flips back and forth randomly true and false...

 

 

My goal is to have my iconIndex to switch to a different icon during the day, and change at night. However seems I can't get time to work :(

 

I have tried using Entity.worldObj, EntityPlayer.worldObj, World, mc.theWorld., mc.thPlayer.worldObj, ect.... still not correct time.

Link to comment
Share on other sites

The dial was a bad idea sadly, however I figured it out.

 

Time is not handled well on the client. Not sure why, but that is a no no.

 

Instead it must be aquired from the server so...

 

I made a static boolean in my mod_class.

public static boolean phantomClock;

 

Then in my clientTickHandler, under my tickInGame.

mod_AsgardShield.phantomClock = MinecraftServer.getServer().theWorldServer[0].isDaytime();

 

Finally under my Custom Common Item.class

    public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
    {
    	if ("phantom".equals(asgardShieldType))
    	{
    		if (mod_AsgardShield.phantomClock == true)
    		{
    			setIconIndex(36);
    		}
    		if (mod_AsgardShield.phantomClock == false)
    		{
    			setIconIndex(35);
    		}
    	}
    	
    }

 

This work the way I need it :)

 

Now important question tho. I had to import net.minecraft.server.MinecraftServer; to my clientTickHander.

 

Should I keep it that way? or create a serverTickHander and place my:

mod_AsgardShield.phantomClock = MinecraftServer.getServer().theWorldServer[0].isDaytime();

 

in there instead.

 

Nevermind, seems the client must have the server info to work correctly.

Link to comment
Share on other sites

Ok, ran into a problem with my Time clock thingy....

 

This code works 100% when running the client, however has a Null Pointer error if you try to connect to a server.

public void onTickInGame()
    {
        //System.out.println("onTickInGame");
        //TODO: Your Code Here
    	
    	Minecraft mc = FMLClientHandler.instance().getClient();
    	if (mc.thePlayer == null || mc.theWorld == null) return;
    	{
    		EntityPlayer p = mc.thePlayer;
    		
    		
    		//PhantomClock time.
    		mod_AsgardShield.playerGPS = p.dimension;
	mod_AsgardShield.phantomClock = MinecraftServer.getServer().theWorldServer[0].isDaytime();
    		

 

So I placed a Null catcher If statement to make sure the error doesn't crash the game. And then waits for the serverTickHander to do its job.

if (MinecraftServer.getServer() != null)
    		{
		mod_AsgardShield.phantomClock = MinecraftServer.getServer().theWorldServer[0].isDaytime();
    		}
    		if (MinecraftServer.getServer() == null)
    		{
    			//System.out.println("Server do your Job");
    		}

 

Now I created this for the my ServerTickHander. Which btw I hope I sliced it up correctly, since there is no template anywhere :(.

 

 

package mod_AsgardShield.common;

import java.util.EnumSet;
import java.util.Random;

import java.lang.Class;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Iterator;

import mod_AsgardShield.common.ItemAsgardShield;
import mod_AsgardShield.common.ItemZedSword;
import mod_AsgardShield.common.mod_AsgardShield;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.BaseMod;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.GuiScreen;
import net.minecraft.src.Item;
import net.minecraft.src.Potion;
import net.minecraft.src.PotionEffect;
import net.minecraft.src.ScaledResolution;
import net.minecraft.src.Vec3;

import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.server.FMLServerHandler;

public final class ServerTickHandlerAsgardShield implements ITickHandler
{
@Override
    public void tickStart(EnumSet<TickType> type, Object... tickData) {}

    @Override
    public void tickEnd(EnumSet<TickType> type, Object... tickData)
    {
        //if (type.equals(EnumSet.of(TickType.RENDER)))
        //{
            //onRenderTick();
        //}
        if (type.equals(EnumSet.of(TickType.SERVER)))
        {
            //GuiScreen guiscreen = Minecraft.getMinecraft().currentScreen;
            //if (guiscreen != null)
            //{
                //onTickInGUI(guiscreen);
            //} else {
                onTickInGame();
            //}
        }
    }

    @Override
    public EnumSet<TickType> ticks()
    {
        return EnumSet.of(TickType.RENDER, TickType.SERVER);
        // In my testing only RENDER, CLIENT, & PLAYER did anything on the client side.
        // Read 'cpw.mods.fml.common.TickType.java' for a full list and description of available types
    }

    @Override
    public String getLabel() { return null; }


   /* public void onRenderTick()
    {
    	Minecraft mc = FMLClientHandler.instance().getClient();
    	if (mc.thePlayer == null || mc.theWorld == null) return;
    	{
    		EntityPlayer p = mc.thePlayer;
    	
    		//System.out.println("onRenderTick");
    		//TODO: Your Code Here
    		
    		//FMLClientHandler.instance().getClient().fontRenderer.drawStringWithShadow("VC "+ItemAsgardShield.asgardShieldVanguardCountI, 0, 0, 16777215);
    		if (p.isBlocking() && ItemAsgardShield.asgardShieldActive == true && mc.playerController.isInCreativeMode() == false)
    		{
    			ScaledResolution var5 = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
    		    int var6 = var5.getScaledWidth();
    		    int var7 = var5.getScaledHeight();
    			int texture = mc.renderEngine.getTexture("/mod_AsgardShield/AsgardShieldTex/VCGauge.png");
    			mc.renderEngine.bindTexture(texture);
    			int VCCharge = (ItemAsgardShield.asgardShieldVanguardCountI * 16) - 16;
    			if(VCCharge < 0){VCCharge = 0;}
    			FMLClientHandler.instance().getClient().ingameGUI.drawTexturedModalRect(var6 / 2 - 8, var7 - 54, VCCharge, 0, 16, 16);
    		}
    	}
    }

    public void onTickInGUI(GuiScreen guiscreen)
    {
        //System.out.println("onTickInGUI");
        //TODO: Your Code Here
    }*/

    public void onTickInGame()
    {
        //System.out.println("onTickInGame");
        //TODO: Your Code Here
    	
    	MinecraftServer mcs = FMLServerHandler.instance().getServer();
    	if (mcs == null) return;
    	{
    		//PhantomClock time.
    		mod_AsgardShield.phantomClock = mcs.theWorldServer[0].isDaytime();
    	}
    	System.out.println(mod_AsgardShield.phantomClock);
    	
    	
    }
}

 

 

 

This part here is my server tick which tells my clock if its day or night.

    public void onTickInGame()
    {
        //System.out.println("onTickInGame");
        //TODO: Your Code Here
    	
    	MinecraftServer mcs = FMLServerHandler.instance().getServer();
    	if (mcs == null) return;
    	{
    		//PhantomClock time.
    		//mod_AsgardShield.playerGPS = p.dimension;
    		
    		//if (MinecraftServer.getServer() != null)
    		//{
		//mod_AsgardShield.phantomClock = MinecraftServer.getServer().theWorldServer[0].isDaytime();
    		//}
    		//if (MinecraftServer.getServer() == null)
    		//{
    			//System.out.println("need server info");
    		//}
    		mod_AsgardShield.phantomClock = mcs.theWorldServer[0].isDaytime();
    	}
    	System.out.println(mod_AsgardShield.phantomClock);
    	
    	
    }

 

Now this works for the server (By the readings isDaytime() returns correct true and false in the cmd prompt), however my mod_AsgardShield.phantomClock never gets updated by the Server, and sticks with clients preInt vaule. :(

 

SO... Server tells one thing, and the Client only knows the other.

 

I never messed with Server packets, what code would I use here?

Link to comment
Share on other sites

if you ever want to try for not using packets i think you can store the time var threw enchanting the item. Have it server side change its enchantment value and then client side read that value. The server should automatically update the items' enchantment to the client.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.