Jump to content

Recommended Posts

Posted

I have a problem whit getting the player position.

Sometimes its slipped away with -1 or +1 its tottally random.

Mostly in superflat worlds.

I make the following:

 

 

package fluffy.lantern.handler;

 

import java.util.EnumSet;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.entity.EntityClientPlayerMP;

import net.minecraft.client.gui.GuiScreen;

import net.minecraft.client.multiplayer.WorldClient;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

import fluffy.lantern.Lantern;

 

public class TickHandler implements ITickHandler

{

public static int lastPlayerX = 0;

public static int lastPlayerY = 0;

public static int lastPlayerZ = 0;

public static int lastPlayerX2 = 0;

public static int lastPlayerY2 = 0;

public static int lastPlayerZ2 = 0;

private int lastValue = 0;

private boolean lanternEquipped = false;

private boolean candleEquipped = false;

private boolean flashlightEquipped = false;

private boolean quickEquipped = false;

 

public static long numTicks = 0L;

 

private int raise = -8;

private int raise2 = -4;

 

public void tickStart(EnumSet<TickType> type, Object ... tickData)

{

numTicks++;

}

 

public void tickEnd(EnumSet<TickType> type, Object ... tickData)

{

if (type.equals(EnumSet.of(TickType.CLIENT)))

{

Minecraft mc = Minecraft.getMinecraft();

GuiScreen guiscreen = mc.currentScreen;

 

if (guiscreen == null)

{

if(this.lookForLantern(mc.thePlayer)){

this.onTickInGameBelt(mc);

}else{

this.onTickInGame(mc);

}

}

}

}

 

public EnumSet<TickType> ticks()

{

return EnumSet.of(TickType.CLIENT);

}

 

public String getLabel()

{

return null;

}

 

public void onTickInGame(Minecraft mc)

{

WorldClient world = mc.theWorld;

 

int playerPosX = (int)mc.thePlayer.posX;

int playerPosY = (int)mc.thePlayer.posY;

int playerPosZ = (int)mc.thePlayer.posZ;

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.lanternonItem.itemID)

{

if(lanternEquipped && raise != 0)

{

raise += 1;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {playerPosX, playerPosY, playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise});

this.lastPlayerX = playerPosX;

this.lastPlayerY = playerPosY;

this.lastPlayerZ = playerPosZ;

}

if(!lanternEquipped)

this.lanternEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.lanternonItem.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

 

if(lanternEquipped && raise != -8)

{

raise -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {playerPosX, playerPosY, playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise});

this.lastPlayerX = playerPosX;

this.lastPlayerY = playerPosY;

this.lastPlayerZ = playerPosZ;

}

}

 

if(lanternEquipped && raise == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ,});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.lanternEquipped = false;

}

}

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.candleonItem.itemID)

{

if(candleEquipped && raise2 != 0)

{

raise2 += 1;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || raise2 <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight2(new int[] {playerPosX, playerPosY, playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise2});

this.lastPlayerX = playerPosX;

this.lastPlayerY = playerPosY;

this.lastPlayerZ = playerPosZ;

}

if(!candleEquipped)

this.candleEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.candleonItem.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

if(candleEquipped && raise2 != -8)

{

raise2 -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise2 >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight2(new int[] {playerPosX, playerPosY, playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise2});

this.lastPlayerX = playerPosX;

this.lastPlayerY = playerPosY;

this.lastPlayerZ = playerPosZ;

}

}

 

if(candleEquipped && raise2 == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ,});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.candleEquipped = false;

}

}

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.flashlightOn.itemID)

{

int var5;

int value = 0;

 

if (Minecraft.getMinecraft().thePlayer.rayTrace(18.0D, 1.0F) != null)

{

int var9 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockX;

int var10 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockY;

int var11 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockZ;

var5 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).sideHit;

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.flashlightOn.itemID)

{

 

if (var5 == 0)

{

--var10;

}

else if (var5 == 1)

{

++var10;

}

else

{

if (var5 == 2)

{

--var11;

}

 

if (var5 == 3)

{

++var11;

}

 

if (var5 == 4)

{

--var9;

}

 

if (var5 == 5)

{

++var9;

}

}

 

if (Minecraft.getMinecraft().thePlayer.rayTrace(6.0D, 1.0F) != null)

{

value = 0;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(8.0D, 1.0F) != null)

{

value = -1;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(10.0D, 1.0F) != null)

{

value = -2;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(12.0D, 1.0F) != null)

{

value = -3;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(14.0D, 1.0F) != null)

{

value = -4;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(16.0D, 1.0F) != null)

{

value = -5;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(18.0D, 1.0F) != null)

{

value = -6;

}

 

if ((int)var9 != this.lastPlayerX2 || (int)var10 != this.lastPlayerY2 || (int)var11 != this.lastPlayerZ2 || (int)value != this.lastValue)

{

PacketHandlerClient.createAndSendPacketToServerLight3(new int[] {(int)var9, (int)var10, (int)var11, (int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2, (int)value});

 

this.lastValue = (int)value;

this.lastPlayerX2 = (int)var9;

this.lastPlayerY2 = (int)var10;

this.lastPlayerZ2 = (int)var11;

}

}

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(0.0D, 1.0F) == null)

{

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2});

this.lastPlayerX2 = 0;

this.lastPlayerY2 = 0;

this.lastPlayerZ2 = 0;

}

if(!flashlightEquipped)

this.flashlightEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.flashlightOn.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

if(flashlightEquipped){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2});

this.lastPlayerX2 = 0;

this.lastPlayerY2 = 0;

this.lastPlayerZ2 = 0;

this.flashlightEquipped = false;

}

}

 

if (lookForLantern(mc.thePlayer) == false){

if(quickEquipped && raise != -8)

{

raise -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {playerPosX, playerPosY, playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise});

this.lastPlayerX = playerPosX;

this.lastPlayerY = playerPosY;

this.lastPlayerZ = playerPosZ;

}

}

 

if(quickEquipped && raise == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ,});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.quickEquipped = false;

}

}

}

 

public void onTickInGameBelt(Minecraft mc)

{

WorldClient world = mc.theWorld;

 

int playerPosX = (int)mc.thePlayer.posX;

int playerPosY = (int)mc.thePlayer.posY;

int playerPosZ = (int)mc.thePlayer.posZ;

 

if (this.lookForLantern(mc.thePlayer))

{

if(quickEquipped && raise != 0)

{

raise += 2;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {playerPosX, playerPosY, playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise});

this.lastPlayerX = playerPosX;

this.lastPlayerY = playerPosY;

this.lastPlayerZ = playerPosZ;

}

 

if(!quickEquipped)

this.quickEquipped = true;

}

}

 

public static boolean lookForLantern(EntityClientPlayerMP player)

{

for (int i = 8; i < 9; ++i)

{

if (player.inventory.mainInventory != null && (player.inventory.mainInventory.itemID == Lantern.lanternonItem.itemID))

{

return true;

}

}

return false;

}

}

 

 

Posted

         int playerPosX = (int)mc.thePlayer.posX;
         int playerPosY = (int)mc.thePlayer.posY;
         int playerPosZ = (int)mc.thePlayer.posZ;

 

What did you think was going to happen when you truncated doubles down to ints?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I tryed that but no luck.

My new code:

 

 

package fluffy.lantern.handler;

 

import java.util.EnumSet;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.entity.EntityClientPlayerMP;

import net.minecraft.client.gui.GuiScreen;

import net.minecraft.client.multiplayer.WorldClient;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

import fluffy.lantern.Lantern;

 

public class TickHandler implements ITickHandler

{

private int lastPlayerX = 0;

private int lastPlayerY = 0;

private int lastPlayerZ = 0;

private int lastPlayerX2 = 0;

private int lastPlayerY2 = 0;

private int lastPlayerZ2 = 0;

private int lastValue = 0;

private boolean lanternEquipped = false;

private boolean candleEquipped = false;

private boolean flashlightEquipped = false;

private boolean quickEquipped = false;

 

public static long numTicks = 0L;

 

private int raise = -8;

private int raise2 = -4;

 

public void tickStart(EnumSet<TickType> type, Object ... tickData)

{

numTicks++;

}

 

public void tickEnd(EnumSet<TickType> type, Object ... tickData)

{

if (type.equals(EnumSet.of(TickType.CLIENT)))

{

Minecraft mc = Minecraft.getMinecraft();

GuiScreen guiscreen = mc.currentScreen;

 

if (guiscreen == null)

{

if(this.lookForLantern(mc.thePlayer)){

this.onTickInGameBelt(mc);

}else{

this.onTickInGame(mc);

}

}

}

}

 

public EnumSet<TickType> ticks()

{

return EnumSet.of(TickType.CLIENT);

}

 

public String getLabel()

{

return null;

}

 

public void onTickInGame(Minecraft mc)

{

WorldClient world = mc.theWorld;

 

double playerPosX = mc.thePlayer.posX;

    double playerPosY = mc.thePlayer.posY;

double playerPosZ = mc.thePlayer.posZ;

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.lanternonItem.itemID)

{

if(lanternEquipped && raise != 0)

{

raise += 1;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

if(!lanternEquipped)

this.lanternEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.lanternonItem.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

 

if(lanternEquipped && raise != -8)

{

raise -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

}

 

if(lanternEquipped && raise == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ,});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.lanternEquipped = false;

}

}

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.candleonItem.itemID)

{

if(candleEquipped && raise2 != 0)

{

raise2 += 1;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || raise2 <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight2(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise2});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

if(!candleEquipped)

this.candleEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.candleonItem.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

if(candleEquipped && raise2 != -8)

{

raise2 -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise2 >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight2(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise2});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

}

 

if(candleEquipped && raise2 == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ,});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.candleEquipped = false;

}

}

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.flashlightOn.itemID)

{

int var5;

int value = 0;

 

if (Minecraft.getMinecraft().thePlayer.rayTrace(18.0D, 1.0F) != null)

{

int var9 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockX;

int var10 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockY;

int var11 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockZ;

var5 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).sideHit;

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.flashlightOn.itemID)

{

 

if (var5 == 0)

{

--var10;

}

else if (var5 == 1)

{

++var10;

}

else

{

if (var5 == 2)

{

--var11;

}

 

if (var5 == 3)

{

++var11;

}

 

if (var5 == 4)

{

--var9;

}

 

if (var5 == 5)

{

++var9;

}

}

 

if (Minecraft.getMinecraft().thePlayer.rayTrace(6.0D, 1.0F) != null)

{

value = 0;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(8.0D, 1.0F) != null)

{

value = -1;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(10.0D, 1.0F) != null)

{

value = -2;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(12.0D, 1.0F) != null)

{

value = -3;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(14.0D, 1.0F) != null)

{

value = -4;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(16.0D, 1.0F) != null)

{

value = -5;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(18.0D, 1.0F) != null)

{

value = -6;

}

 

if ((int)var9 != this.lastPlayerX2 || (int)var10 != this.lastPlayerY2 || (int)var11 != this.lastPlayerZ2 || (int)value != this.lastValue)

{

PacketHandlerClient.createAndSendPacketToServerLight3(new int[] {(int)var9, (int)var10, (int)var11, (int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2, (int)value});

 

this.lastValue = (int)value;

this.lastPlayerX2 = (int)var9;

this.lastPlayerY2 = (int)var10;

this.lastPlayerZ2 = (int)var11;

}

}

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(0.0D, 1.0F) == null)

{

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2});

this.lastPlayerX2 = 0;

this.lastPlayerY2 = 0;

this.lastPlayerZ2 = 0;

}

if(!flashlightEquipped)

this.flashlightEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.flashlightOn.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

if(flashlightEquipped){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2});

this.lastPlayerX2 = 0;

this.lastPlayerY2 = 0;

this.lastPlayerZ2 = 0;

this.flashlightEquipped = false;

}

}

 

if (lookForLantern(mc.thePlayer) == false){

if(quickEquipped && raise != -8)

{

raise -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

}

 

if(quickEquipped && raise == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ,});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.quickEquipped = false;

}

}

}

 

public void onTickInGameBelt(Minecraft mc)

{

WorldClient world = mc.theWorld;

 

double playerPosX = (double)mc.thePlayer.posX;

double playerPosY = (double)mc.thePlayer.posY;

double playerPosZ = (double)mc.thePlayer.posZ;

 

if (this.lookForLantern(mc.thePlayer))

{

if(quickEquipped && raise != 0)

{

raise += 2;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, this.lastPlayerX, this.lastPlayerY, this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

 

if(!quickEquipped)

this.quickEquipped = true;

}

}

 

public static boolean lookForLantern(EntityClientPlayerMP player)

{

for (int i = 8; i < 9; ++i)

{

if (player.inventory.mainInventory != null && (player.inventory.mainInventory.itemID == Lantern.lanternonItem.itemID))

{

return true;

}

}

return false;

}

}

 

 

Posted

   private int lastPlayerX = 0;
   private int lastPlayerY = 0;
   private int lastPlayerZ = 0;
   private int lastPlayerX2 = 0;
   private int lastPlayerY2 = 0;
   private int lastPlayerZ2 = 0;

 

*Cough*

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Okey okey.

  private double lastPlayerX = 0;

  private double lastPlayerY = 0;

  private double lastPlayerZ = 0;

(X2, Y2, Z2 stay int because its for something else)

 

Where i use them i add a casting to(int) because i cant use double for some methods in my packethandler.

And its still not work.

Posted
Where i use them i add a casting to(int) because i cant use double for some methods in my packethandler.

 

Packets can handle floats.  Floats and doubles are convertible into each other.

 

Hmm.

Now I'm not sure.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Alright.

 

I don't know what the problem is.  I thought it was because of the truncates to integers, but that's not it.

 

I do not know what is wrong.  The problem may not even be in that class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Okey here is what related to my light system:

 

TickHandler:

 

 

package fluffy.lantern.handler;

 

import java.util.EnumSet;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.entity.EntityClientPlayerMP;

import net.minecraft.client.gui.GuiScreen;

import net.minecraft.client.multiplayer.WorldClient;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

import fluffy.lantern.Lantern;

 

public class TickHandler implements ITickHandler

{

private double lastPlayerX = 0;

private double lastPlayerY = 0;

private double lastPlayerZ = 0;

private int lastPlayerX2 = 0;

private int lastPlayerY2 = 0;

private int lastPlayerZ2 = 0;

private int lastValue = 0;

private boolean lanternEquipped = false;

private boolean candleEquipped = false;

private boolean flashlightEquipped = false;

private boolean quickEquipped = false;

 

public static long numTicks = 0L;

 

private int raise = -8;

private int raise2 = -4;

 

public void tickStart(EnumSet<TickType> type, Object ... tickData)

{

numTicks++;

}

 

public void tickEnd(EnumSet<TickType> type, Object ... tickData)

{

if (type.equals(EnumSet.of(TickType.CLIENT)))

{

Minecraft mc = Minecraft.getMinecraft();

GuiScreen guiscreen = mc.currentScreen;

 

if (guiscreen == null)

{

if(this.lookForLantern(mc.thePlayer)){

this.onTickInGameBelt(mc);

}else{

this.onTickInGame(mc);

}

}

}

}

 

public EnumSet<TickType> ticks()

{

return EnumSet.of(TickType.CLIENT);

}

 

public String getLabel()

{

return null;

}

 

public void onTickInGame(Minecraft mc)

{

WorldClient world = mc.theWorld;

 

double playerPosX = mc.thePlayer.posX;

    double playerPosY = mc.thePlayer.posY;

double playerPosZ = mc.thePlayer.posZ;

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.lanternonItem.itemID)

{

if(lanternEquipped && raise != 0)

{

raise += 1;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

if(!lanternEquipped)

this.lanternEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.lanternonItem.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

 

if(lanternEquipped && raise != -8)

{

raise -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

}

 

if(lanternEquipped && raise == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.lanternEquipped = false;

}

}

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.candleonItem.itemID)

{

if(candleEquipped && raise2 != 0)

{

raise2 += 1;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || raise2 <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight2(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise2});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

if(!candleEquipped)

this.candleEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.candleonItem.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

if(candleEquipped && raise2 != -8)

{

raise2 -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise2 >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight2(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise2});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

}

 

if(candleEquipped && raise2 == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.candleEquipped = false;

}

}

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.flashlightOn.itemID)

{

int var5;

int value = 0;

 

if (Minecraft.getMinecraft().thePlayer.rayTrace(18.0D, 1.0F) != null)

{

int var9 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockX;

int var10 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockY;

int var11 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockZ;

var5 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).sideHit;

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.flashlightOn.itemID)

{

 

if (var5 == 0)

{

--var10;

}

else if (var5 == 1)

{

++var10;

}

else

{

if (var5 == 2)

{

--var11;

}

 

if (var5 == 3)

{

++var11;

}

 

if (var5 == 4)

{

--var9;

}

 

if (var5 == 5)

{

++var9;

}

}

 

if (Minecraft.getMinecraft().thePlayer.rayTrace(6.0D, 1.0F) != null)

{

value = 0;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(8.0D, 1.0F) != null)

{

value = -1;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(10.0D, 1.0F) != null)

{

value = -2;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(12.0D, 1.0F) != null)

{

value = -3;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(14.0D, 1.0F) != null)

{

value = -4;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(16.0D, 1.0F) != null)

{

value = -5;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(18.0D, 1.0F) != null)

{

value = -6;

}

 

if ((int)var9 != this.lastPlayerX2 || (int)var10 != this.lastPlayerY2 || (int)var11 != this.lastPlayerZ2 || (int)value != this.lastValue)

{

PacketHandlerClient.createAndSendPacketToServerLight3(new int[] {(int)var9, (int)var10, (int)var11, (int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2, (int)value});

 

this.lastValue = (int)value;

this.lastPlayerX2 = (int)var9;

this.lastPlayerY2 = (int)var10;

this.lastPlayerZ2 = (int)var11;

}

}

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(0.0D, 1.0F) == null)

{

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2});

this.lastPlayerX2 = 0;

this.lastPlayerY2 = 0;

this.lastPlayerZ2 = 0;

}

if(!flashlightEquipped)

this.flashlightEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.flashlightOn.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

if(flashlightEquipped){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2});

this.lastPlayerX2 = 0;

this.lastPlayerY2 = 0;

this.lastPlayerZ2 = 0;

this.flashlightEquipped = false;

}

}

 

if (lookForLantern(mc.thePlayer) == false){

if(quickEquipped && raise != -8)

{

raise -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

}

 

if(quickEquipped && raise == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.quickEquipped = false;

}

}

}

 

public void onTickInGameBelt(Minecraft mc)

{

WorldClient world = mc.theWorld;

 

double playerPosX = mc.thePlayer.posX;

double playerPosY = mc.thePlayer.posY;

double playerPosZ = mc.thePlayer.posZ;

 

if (this.lookForLantern(mc.thePlayer))

{

if(quickEquipped && raise != 0)

{

raise += 2;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

 

if(!quickEquipped)

this.quickEquipped = true;

}

}

 

public static boolean lookForLantern(EntityClientPlayerMP player)

{

for (int i = 8; i < 9; ++i)

{

if (player.inventory.mainInventory != null && (player.inventory.mainInventory.itemID == Lantern.lanternonItem.itemID))

{

return true;

}

}

return false;

}

}

 

[/spoler]

 

PacketHandler:

[spoler]

package fluffy.lantern.handler;

 

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.IOException;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.multiplayer.WorldClient;

import net.minecraft.network.INetworkManager;

import net.minecraft.network.packet.Packet250CustomPayload;

import net.minecraft.world.EnumSkyBlock;

import cpw.mods.fml.common.network.IPacketHandler;

import cpw.mods.fml.common.network.PacketDispatcher;

import cpw.mods.fml.common.network.Player;

import fluffy.lantern.Lantern;

import fluffy.lantern.blocks.LanternOn;

 

public class PacketHandlerClient implements IPacketHandler

{

public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player playerEntity)

{

DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));

if (packet.channel.equals("Lantern"))

{

char packetType = 90;

 

try

{

packetType = inputStream.readChar();

}

 

catch (IOException var7)

{

var7.printStackTrace();

}

 

switch (packetType)

{

case 68:

this.handlePacketDark(packet, inputStream);

break;

 

case 76:

this.handlePacketLight(packet, inputStream);

break;

 

case 78:

this.handlePacketLight2(packet, inputStream);

break;

 

case 80:

this.handlePacketLight3(packet, inputStream);

break;

 

case 86:

this.handlePacketLanternSetting(packet, inputStream);

break;

 

default:

}

}

}

 

private void handlePacketLight(Packet250CustomPayload packet, DataInputStream inputStream)

{

int x;

int y;

int z;

int oldX;

int oldY;

int oldZ;

int raise;

 

try

{

x = inputStream.readInt();

y = inputStream.readInt();

z = inputStream.readInt();

oldX = inputStream.readInt();

oldY = inputStream.readInt();

oldZ = inputStream.readInt();

raise = inputStream.readInt();

}

catch (IOException var10)

{

var10.printStackTrace();

return;

}

 

WorldClient world = Minecraft.getMinecraft().theWorld;

 

world.setLightValue(EnumSkyBlock.Block, x , y, z, Lantern.instance.getLanternLightValue() + raise);

 

if(x != oldX || y != oldY || z != oldZ){

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, oldX, oldY, oldZ);

}

 

world.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);

world.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);

world.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);

world.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);

world.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);

world.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);

}

 

private void handlePacketLight2(Packet250CustomPayload packet, DataInputStream inputStream)

{

int x;

int y;

int z;

int oldX;

int oldY;

int oldZ;

int raise2;

 

try

{

x = inputStream.readInt();

y = inputStream.readInt();

z = inputStream.readInt();

oldX = inputStream.readInt();

oldY = inputStream.readInt();

oldZ = inputStream.readInt();

raise2 = inputStream.readInt();

}

catch (IOException var10)

{

var10.printStackTrace();

return;

}

 

WorldClient world = Minecraft.getMinecraft().theWorld;

 

world.setLightValue(EnumSkyBlock.Block, x, y, z, Lantern.instance.getCandleLightValue() + raise2);

 

if(x != oldX || y != oldY || z != oldZ){

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, oldX, oldY, oldZ);

}

 

world.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);

world.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);

world.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);

world.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);

world.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);

world.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);

 

}

 

private void handlePacketLight3(Packet250CustomPayload packet, DataInputStream inputStream)

{

int var9;

int var10;

int var11;

int oldX2;

int oldY2;

int oldZ2;

int value;

try{

 

var9 = inputStream.readInt();

var10 = inputStream.readInt();

var11 = inputStream.readInt();

oldX2 = inputStream.readInt();

oldY2 = inputStream.readInt();

oldZ2 = inputStream.readInt();

value = inputStream.readInt();

 

 

}catch(IOException var12){

var12.printStackTrace();

return;

}

 

Minecraft.getMinecraft().theWorld.setLightValue(EnumSkyBlock.Block, var9, var10, var11, Lantern.instance.flashLightValue + value);

if(var9 != oldX2 || var10 != oldY2 || var11 != oldZ2){

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, oldX2, oldY2, oldZ2);

}

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9, var10 + 1, var11);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9, var10 - 1, var11);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9 - 1, var10, var11);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9 + 1, var10, var11);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9, var10, var11 - 1);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9, var10, var11 + 1);

}

 

 

private void handlePacketDark(Packet250CustomPayload packet, DataInputStream inputStream)

{

int x;

int y;

int z;

 

try

{

x = inputStream.readInt();

y = inputStream.readInt();

z = inputStream.readInt();

}

catch (IOException var10)

{

var10.printStackTrace();

return;

}

 

WorldClient world = Minecraft.getMinecraft().theWorld;

 

for (int i = -2; i < 2; ++i)

{

for (int j = -2; j < 2; ++j)

{

for (int k = -2; k < 2; ++k)

{

world.updateLightByType(EnumSkyBlock.Block, x + i, y + j, z + k);

}

}

}

}

 

private void handlePacketLanternSetting(Packet250CustomPayload packet, DataInputStream inputStream)

{

byte newLanternLightValue;

byte newCandleLightValue;

byte newFlashLightValue;

 

try

{

newLanternLightValue = inputStream.readByte();

newCandleLightValue = inputStream.readByte();

newFlashLightValue = inputStream.readByte();

}

catch (IOException var7)

{

var7.printStackTrace();

return;

}

 

Lantern.instance.setLanternLightValue(newLanternLightValue);

Lantern.instance.setCandleLightValue(newCandleLightValue);

Lantern.instance.setFlashLightValue(newFlashLightValue);

 

Lantern.lanternOn.setLightValue((float)newLanternLightValue / 15F);

Lantern.candleOn.setLightValue((float)newCandleLightValue / 15F);

}

 

public static void createAndSendPacketToServerDark(int[] data)

{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

DataOutputStream outputStream = new DataOutputStream(bos);

 

try

{

outputStream.writeChar(68);

outputStream.writeInt(data[0]);

outputStream.writeInt(data[1]);

outputStream.writeInt(data[2]);

}

catch (Exception var4)

{

var4.printStackTrace();

}

 

Packet250CustomPayload packet = new Packet250CustomPayload();

packet.channel = "Lantern";

packet.data = bos.toByteArray();

packet.length = bos.size();

PacketDispatcher.sendPacketToServer(packet);

}

 

public static void createAndSendPacketToServerLight(int[] data)

{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

DataOutputStream outputStream = new DataOutputStream(bos);

 

try

{

outputStream.writeChar(76);

outputStream.writeInt(data[0]);

outputStream.writeInt(data[1]);

outputStream.writeInt(data[2]);

outputStream.writeInt(data[3]);

outputStream.writeInt(data[4]);

outputStream.writeInt(data[5]);

outputStream.writeInt(data[6]);

}

catch (Exception var4)

{

var4.printStackTrace();

}

 

Packet250CustomPayload packet = new Packet250CustomPayload();

packet.channel = "Lantern";

packet.data = bos.toByteArray();

packet.length = bos.size();

PacketDispatcher.sendPacketToServer(packet);

}

public static void createAndSendPacketToServerLight2(int[] data)

{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

DataOutputStream outputStream = new DataOutputStream(bos);

 

try

{

outputStream.writeChar(78);

outputStream.writeInt(data[0]);

outputStream.writeInt(data[1]);

outputStream.writeInt(data[2]);

outputStream.writeInt(data[3]);

outputStream.writeInt(data[4]);

outputStream.writeInt(data[5]);

outputStream.writeInt(data[6]);

}

catch (Exception var4)

{

var4.printStackTrace();

}

 

Packet250CustomPayload packet = new Packet250CustomPayload();

packet.channel = "Lantern";

packet.data = bos.toByteArray();

packet.length = bos.size();

PacketDispatcher.sendPacketToServer(packet);

}

public static void createAndSendPacketToServerLight3(int[] data)

{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

DataOutputStream outputStream = new DataOutputStream(bos);

 

try

{

outputStream.writeChar(80);

outputStream.writeInt(data[0]);

outputStream.writeInt(data[1]);

outputStream.writeInt(data[2]);

outputStream.writeInt(data[3]);

outputStream.writeInt(data[4]);

outputStream.writeInt(data[5]);

outputStream.writeInt(data[6]);

}

catch (Exception var4)

{

var4.printStackTrace();

}

 

Packet250CustomPayload packet = new Packet250CustomPayload();

packet.channel = "Lantern";

packet.data = bos.toByteArray();

packet.length = bos.size();

PacketDispatcher.sendPacketToServer(packet);

}

}

[/spoler]

 

Thats it no other class touches it!

Posted

Hi

 

EntityLivingBase.getPosition(partialTick) can be useful to get the position during rendering.

 

I don't really understand the symptoms of your problem, but I think a couple of breakpoints in your debugger should be able to solve it very quickly.

 

When you say "it is random", is that really true?

 

I.e. if you stop moving, does it flick around between -1 and +1?

 

If you move a small amount, does it jump to +1, move a bit more and jump to +0, move a bit more and jump to -1, or similar?

 

I gather that you want an integer ("block") position instead of the player's double position?  if so, beware that casting to int discards the fraction, so negative numbers will go up but positive numbers will go down, which I don't think is what you want.  You need Math.floor().

 

-TGG

Posted

Okey so my problem:

I have a method where a light gets emitted where the player stands.(Dynamic light)

In Default world its sometimes under the player sometimes slipped to X+1 or -1 ore the same on Y.

In Flat world its never place the lght under the player.

Yes its random. Sometimes work sometimes not.

Its not flickering bettween positions its just like a ghost player.

 

In my previous comment i failed to use spoiler so my 2 code again:

 

TickHander:

 

 

package fluffy.lantern.handler;

 

import java.util.EnumSet;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.entity.EntityClientPlayerMP;

import net.minecraft.client.gui.GuiScreen;

import net.minecraft.client.multiplayer.WorldClient;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

import fluffy.lantern.Lantern;

 

public class TickHandler implements ITickHandler

{

private double lastPlayerX = 0;

private double lastPlayerY = 0;

private double lastPlayerZ = 0;

private int lastPlayerX2 = 0;

private int lastPlayerY2 = 0;

private int lastPlayerZ2 = 0;

private int lastValue = 0;

private boolean lanternEquipped = false;

private boolean candleEquipped = false;

private boolean flashlightEquipped = false;

private boolean quickEquipped = false;

 

public static long numTicks = 0L;

 

private int raise = -8;

private int raise2 = -4;

 

public void tickStart(EnumSet<TickType> type, Object ... tickData)

{

numTicks++;

}

 

public void tickEnd(EnumSet<TickType> type, Object ... tickData)

{

if (type.equals(EnumSet.of(TickType.CLIENT)))

{

Minecraft mc = Minecraft.getMinecraft();

GuiScreen guiscreen = mc.currentScreen;

 

if (guiscreen == null)

{

if(this.lookForLantern(mc.thePlayer)){

this.onTickInGameBelt(mc);

}else{

this.onTickInGame(mc);

}

}

}

}

 

public EnumSet<TickType> ticks()

{

return EnumSet.of(TickType.CLIENT);

}

 

public String getLabel()

{

return null;

}

 

public void onTickInGame(Minecraft mc)

{

WorldClient world = mc.theWorld;

 

double playerPosX = mc.thePlayer.posX;

    double playerPosY = mc.thePlayer.posY;

double playerPosZ = mc.thePlayer.posZ;

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.lanternonItem.itemID)

{

if(lanternEquipped && raise != 0)

{

raise += 1;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

if(!lanternEquipped)

this.lanternEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.lanternonItem.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

 

if(lanternEquipped && raise != -8)

{

raise -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

}

 

if(lanternEquipped && raise == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.lanternEquipped = false;

}

}

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.candleonItem.itemID)

{

if(candleEquipped && raise2 != 0)

{

raise2 += 1;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || raise2 <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight2(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise2});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

if(!candleEquipped)

this.candleEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.candleonItem.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

if(candleEquipped && raise2 != -8)

{

raise2 -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise2 >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight2(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise2});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

}

 

if(candleEquipped && raise2 == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.candleEquipped = false;

}

}

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.flashlightOn.itemID)

{

int var5;

int value = 0;

 

if (Minecraft.getMinecraft().thePlayer.rayTrace(18.0D, 1.0F) != null)

{

int var9 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockX;

int var10 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockY;

int var11 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).blockZ;

var5 = Minecraft.getMinecraft().thePlayer.rayTrace(200.0D, 1.0F).sideHit;

 

if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID == Lantern.flashlightOn.itemID)

{

 

if (var5 == 0)

{

--var10;

}

else if (var5 == 1)

{

++var10;

}

else

{

if (var5 == 2)

{

--var11;

}

 

if (var5 == 3)

{

++var11;

}

 

if (var5 == 4)

{

--var9;

}

 

if (var5 == 5)

{

++var9;

}

}

 

if (Minecraft.getMinecraft().thePlayer.rayTrace(6.0D, 1.0F) != null)

{

value = 0;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(8.0D, 1.0F) != null)

{

value = -1;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(10.0D, 1.0F) != null)

{

value = -2;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(12.0D, 1.0F) != null)

{

value = -3;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(14.0D, 1.0F) != null)

{

value = -4;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(16.0D, 1.0F) != null)

{

value = -5;

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(18.0D, 1.0F) != null)

{

value = -6;

}

 

if ((int)var9 != this.lastPlayerX2 || (int)var10 != this.lastPlayerY2 || (int)var11 != this.lastPlayerZ2 || (int)value != this.lastValue)

{

PacketHandlerClient.createAndSendPacketToServerLight3(new int[] {(int)var9, (int)var10, (int)var11, (int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2, (int)value});

 

this.lastValue = (int)value;

this.lastPlayerX2 = (int)var9;

this.lastPlayerY2 = (int)var10;

this.lastPlayerZ2 = (int)var11;

}

}

}

else if (Minecraft.getMinecraft().thePlayer.rayTrace(0.0D, 1.0F) == null)

{

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2});

this.lastPlayerX2 = 0;

this.lastPlayerY2 = 0;

this.lastPlayerZ2 = 0;

}

if(!flashlightEquipped)

this.flashlightEquipped = true;

}else if (mc.thePlayer.inventory.getCurrentItem() != null && mc.thePlayer.inventory.getCurrentItem().itemID != Lantern.flashlightOn.itemID || mc.thePlayer.inventory.getCurrentItem() == null){

if(flashlightEquipped){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int)lastPlayerX2, (int)lastPlayerY2, (int)lastPlayerZ2});

this.lastPlayerX2 = 0;

this.lastPlayerY2 = 0;

this.lastPlayerZ2 = 0;

this.flashlightEquipped = false;

}

}

 

if (lookForLantern(mc.thePlayer) == false){

if(quickEquipped && raise != -8)

{

raise -= 1;

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise >= -8)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

}

 

if(quickEquipped && raise == -8){

PacketHandlerClient.createAndSendPacketToServerDark(new int[] {(int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ});

this.lastPlayerX = 0;

this.lastPlayerY = 0;

this.lastPlayerZ = 0;

this.quickEquipped = false;

}

}

}

 

public void onTickInGameBelt(Minecraft mc)

{

WorldClient world = mc.theWorld;

 

double playerPosX = mc.thePlayer.posX;

double playerPosY = mc.thePlayer.posY;

double playerPosZ = mc.thePlayer.posZ;

 

if (this.lookForLantern(mc.thePlayer))

{

if(quickEquipped && raise != 0)

{

raise += 2;

}

 

if (playerPosX != this.lastPlayerX || playerPosY != this.lastPlayerY || playerPosZ != this.lastPlayerZ || this.raise <= 0)

{

PacketHandlerClient.createAndSendPacketToServerLight(new int[] {(int) playerPosX, (int) playerPosY, (int) playerPosZ, (int) this.lastPlayerX, (int) this.lastPlayerY, (int) this.lastPlayerZ, this.raise});

this.lastPlayerX = (int) playerPosX;

this.lastPlayerY = (int) playerPosY;

this.lastPlayerZ = (int) playerPosZ;

}

 

if(!quickEquipped)

this.quickEquipped = true;

}

}

 

public static boolean lookForLantern(EntityClientPlayerMP player)

{

for (int i = 8; i < 9; ++i)

{

if (player.inventory.mainInventory != null && (player.inventory.mainInventory.itemID == Lantern.lanternonItem.itemID))

{

return true;

}

}

return false;

}

}

 

 

 

PacketHandlerClient:

 

 

package fluffy.lantern.handler;

 

import java.io.ByteArrayInputStream;

import java.io.ByteArrayOutputStream;

import java.io.DataInputStream;

import java.io.DataOutputStream;

import java.io.IOException;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.multiplayer.WorldClient;

import net.minecraft.network.INetworkManager;

import net.minecraft.network.packet.Packet250CustomPayload;

import net.minecraft.world.EnumSkyBlock;

import cpw.mods.fml.common.network.IPacketHandler;

import cpw.mods.fml.common.network.PacketDispatcher;

import cpw.mods.fml.common.network.Player;

import fluffy.lantern.Lantern;

import fluffy.lantern.blocks.LanternOn;

 

public class PacketHandlerClient implements IPacketHandler

{

public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player playerEntity)

{

DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));

if (packet.channel.equals("Lantern"))

{

char packetType = 90;

 

try

{

packetType = inputStream.readChar();

}

 

catch (IOException var7)

{

var7.printStackTrace();

}

 

switch (packetType)

{

case 68:

this.handlePacketDark(packet, inputStream);

break;

 

case 76:

this.handlePacketLight(packet, inputStream);

break;

 

case 78:

this.handlePacketLight2(packet, inputStream);

break;

 

case 80:

this.handlePacketLight3(packet, inputStream);

break;

 

case 86:

this.handlePacketLanternSetting(packet, inputStream);

break;

 

default:

}

}

}

 

private void handlePacketLight(Packet250CustomPayload packet, DataInputStream inputStream)

{

int x;

int y;

int z;

int oldX;

int oldY;

int oldZ;

int raise;

 

try

{

x = inputStream.readInt();

y = inputStream.readInt();

z = inputStream.readInt();

oldX = inputStream.readInt();

oldY = inputStream.readInt();

oldZ = inputStream.readInt();

raise = inputStream.readInt();

}

catch (IOException var10)

{

var10.printStackTrace();

return;

}

 

WorldClient world = Minecraft.getMinecraft().theWorld;

 

world.setLightValue(EnumSkyBlock.Block, x , y, z, Lantern.instance.getLanternLightValue() + raise);

 

if(x != oldX || y != oldY || z != oldZ){

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, oldX, oldY, oldZ);

}

 

world.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);

world.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);

world.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);

world.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);

world.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);

world.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);

}

 

private void handlePacketLight2(Packet250CustomPayload packet, DataInputStream inputStream)

{

int x;

int y;

int z;

int oldX;

int oldY;

int oldZ;

int raise2;

 

try

{

x = inputStream.readInt();

y = inputStream.readInt();

z = inputStream.readInt();

oldX = inputStream.readInt();

oldY = inputStream.readInt();

oldZ = inputStream.readInt();

raise2 = inputStream.readInt();

}

catch (IOException var10)

{

var10.printStackTrace();

return;

}

 

WorldClient world = Minecraft.getMinecraft().theWorld;

 

world.setLightValue(EnumSkyBlock.Block, x, y, z, Lantern.instance.getCandleLightValue() + raise2);

 

if(x != oldX || y != oldY || z != oldZ){

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, oldX, oldY, oldZ);

}

 

world.updateLightByType(EnumSkyBlock.Block, x + 1, y, z);

world.updateLightByType(EnumSkyBlock.Block, x - 1, y, z);

world.updateLightByType(EnumSkyBlock.Block, x, y + 1, z);

world.updateLightByType(EnumSkyBlock.Block, x, y - 1, z);

world.updateLightByType(EnumSkyBlock.Block, x, y, z + 1);

world.updateLightByType(EnumSkyBlock.Block, x, y, z - 1);

 

}

 

private void handlePacketLight3(Packet250CustomPayload packet, DataInputStream inputStream)

{

int var9;

int var10;

int var11;

int oldX2;

int oldY2;

int oldZ2;

int value;

try{

 

var9 = inputStream.readInt();

var10 = inputStream.readInt();

var11 = inputStream.readInt();

oldX2 = inputStream.readInt();

oldY2 = inputStream.readInt();

oldZ2 = inputStream.readInt();

value = inputStream.readInt();

 

 

}catch(IOException var12){

var12.printStackTrace();

return;

}

 

Minecraft.getMinecraft().theWorld.setLightValue(EnumSkyBlock.Block, var9, var10, var11, Lantern.instance.flashLightValue + value);

if(var9 != oldX2 || var10 != oldY2 || var11 != oldZ2){

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, oldX2, oldY2, oldZ2);

}

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9, var10 + 1, var11);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9, var10 - 1, var11);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9 - 1, var10, var11);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9 + 1, var10, var11);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9, var10, var11 - 1);

Minecraft.getMinecraft().theWorld.updateLightByType(EnumSkyBlock.Block, var9, var10, var11 + 1);

}

 

 

private void handlePacketDark(Packet250CustomPayload packet, DataInputStream inputStream)

{

int x;

int y;

int z;

 

try

{

x = inputStream.readInt();

y = inputStream.readInt();

z = inputStream.readInt();

}

catch (IOException var10)

{

var10.printStackTrace();

return;

}

 

WorldClient world = Minecraft.getMinecraft().theWorld;

 

for (int i = -2; i < 2; ++i)

{

for (int j = -2; j < 2; ++j)

{

for (int k = -2; k < 2; ++k)

{

world.updateLightByType(EnumSkyBlock.Block, x + i, y + j, z + k);

}

}

}

}

 

private void handlePacketLanternSetting(Packet250CustomPayload packet, DataInputStream inputStream)

{

byte newLanternLightValue;

byte newCandleLightValue;

byte newFlashLightValue;

 

try

{

newLanternLightValue = inputStream.readByte();

newCandleLightValue = inputStream.readByte();

newFlashLightValue = inputStream.readByte();

}

catch (IOException var7)

{

var7.printStackTrace();

return;

}

 

Lantern.instance.setLanternLightValue(newLanternLightValue);

Lantern.instance.setCandleLightValue(newCandleLightValue);

Lantern.instance.setFlashLightValue(newFlashLightValue);

 

Lantern.lanternOn.setLightValue((float)newLanternLightValue / 15F);

Lantern.candleOn.setLightValue((float)newCandleLightValue / 15F);

}

 

public static void createAndSendPacketToServerDark(int[] data)

{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

DataOutputStream outputStream = new DataOutputStream(bos);

 

try

{

outputStream.writeChar(68);

outputStream.writeInt(data[0]);

outputStream.writeInt(data[1]);

outputStream.writeInt(data[2]);

}

catch (Exception var4)

{

var4.printStackTrace();

}

 

Packet250CustomPayload packet = new Packet250CustomPayload();

packet.channel = "Lantern";

packet.data = bos.toByteArray();

packet.length = bos.size();

PacketDispatcher.sendPacketToServer(packet);

}

 

public static void createAndSendPacketToServerLight(int[] data)

{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

DataOutputStream outputStream = new DataOutputStream(bos);

 

try

{

outputStream.writeChar(76);

outputStream.writeInt(data[0]);

outputStream.writeInt(data[1]);

outputStream.writeInt(data[2]);

outputStream.writeInt(data[3]);

outputStream.writeInt(data[4]);

outputStream.writeInt(data[5]);

outputStream.writeInt(data[6]);

}

catch (Exception var4)

{

var4.printStackTrace();

}

 

Packet250CustomPayload packet = new Packet250CustomPayload();

packet.channel = "Lantern";

packet.data = bos.toByteArray();

packet.length = bos.size();

PacketDispatcher.sendPacketToServer(packet);

}

public static void createAndSendPacketToServerLight2(int[] data)

{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

DataOutputStream outputStream = new DataOutputStream(bos);

 

try

{

outputStream.writeChar(78);

outputStream.writeInt(data[0]);

outputStream.writeInt(data[1]);

outputStream.writeInt(data[2]);

outputStream.writeInt(data[3]);

outputStream.writeInt(data[4]);

outputStream.writeInt(data[5]);

outputStream.writeInt(data[6]);

}

catch (Exception var4)

{

var4.printStackTrace();

}

 

Packet250CustomPayload packet = new Packet250CustomPayload();

packet.channel = "Lantern";

packet.data = bos.toByteArray();

packet.length = bos.size();

PacketDispatcher.sendPacketToServer(packet);

}

public static void createAndSendPacketToServerLight3(int[] data)

{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

DataOutputStream outputStream = new DataOutputStream(bos);

 

try

{

outputStream.writeChar(80);

outputStream.writeInt(data[0]);

outputStream.writeInt(data[1]);

outputStream.writeInt(data[2]);

outputStream.writeInt(data[3]);

outputStream.writeInt(data[4]);

outputStream.writeInt(data[5]);

outputStream.writeInt(data[6]);

}

catch (Exception var4)

{

var4.printStackTrace();

}

 

Packet250CustomPayload packet = new Packet250CustomPayload();

packet.channel = "Lantern";

packet.data = bos.toByteArray();

packet.length = bos.size();

PacketDispatcher.sendPacketToServer(packet);

}

}

 

 

Posted

if (player.inventory.mainInventory != null && (player.inventory.mainInventory.itemID == Lantern.lanternonItem.itemID))

That shouldn't compile.

 

Also, you have a client tick handler and a client packet handler. Where is the server packet handler ?

Posted

ClientPacketHandler:

Sends packet to server to other player see light and force other players for the server config.

 

ServerPacketHandler:

Gets the config option and send it to players.

Key handler and item change stuff.

 

BUT i tryed it in without packets(only TickHandler) and its still slipped.

So they aren't be the problem.

Posted

Hi

 

I would suggest you take a step back and first of all try to implement your dynamic lighting just on the client.  (And actually I think there's a good chance you don't need any custom packets at all, because the vanilla automatically synchronises the position and look  of other players as well as the item they're holding.  If you want items eg in the hotbar to also be effective, you can just send a packet every time the player equips/unequips, you don't need to send a packet every time they move as well)

 

i.e.  In your client tickhandler, just read the player position and update the dynamic lighting.  Once you've got that working you can progress to the more complicated stuff.

 

-TGG

 

 

Posted

The only problem is im tryed that.

With pakts, without pakets it dosen't metter.

I gonna implement EntityPlayer to my tick handler somehow and see that helps or not.

Mc.thePlayer can be the problem since its only EntityClientPlayerMP.

Posted

Okey i tested again only TickHandler and the resoults:

Default world: Light under the player(not on all biomes/height level)

Flat world: Light slipped away as hell.

 

I think thats going to be a Forge/Minecraft bug.

Posted

I made a dummy dynamic light for testing reasons.

PLAYER ticking CLIENT registration.

 

Resoults:

Default: Almost 80% under player!

Flat: Still slipped very badly.

 

TestTickHandler:

 

 

package fluffy.lantern.handler;

import java.util.EnumSet;

 

import net.minecraft.block.Block;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.world.EnumSkyBlock;

import cpw.mods.fml.common.ITickHandler;

import cpw.mods.fml.common.TickType;

public class TestTickHandler implements ITickHandler

{

private final EnumSet<TickType> ticksToGet;

 

private static int lastX = 0;

private static int lastY = 0;

private static int lastZ = 0;

 

 

public TestTickHandler(EnumSet<TickType> ticksToGet)

{

this.ticksToGet = ticksToGet;

}

 

@Override

public void tickStart(EnumSet<TickType> type, Object... tickData)

{

playerTick((EntityPlayer)tickData[0]);

}

@Override

public void tickEnd(EnumSet<TickType> type, Object... tickData)

{

}

@Override

public EnumSet<TickType> ticks()

{

return ticksToGet;

}

@Override

public String getLabel()

{

return "TutorialPlayerTick";

}

 

public static void playerTick(EntityPlayer player)

{

if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().itemID == Block.torchWood.blockID){

 

int x = (int)player.posX;

int y = (int)player.posY;

int z = (int)player.posZ;

 

if(x != lastX || y != lastY || z != lastZ)

{

player.worldObj.setLightValue(EnumSkyBlock.Block, x, y, z, 14);

 

player.worldObj.updateLightByType(EnumSkyBlock.Block, lastX, lastY, lastZ);

 

player.worldObj.updateLightByType(EnumSkyBlock.Block, x+1, y, z);

player.worldObj.updateLightByType(EnumSkyBlock.Block, x-1, y, z);

player.worldObj.updateLightByType(EnumSkyBlock.Block, x, y+1, z);

player.worldObj.updateLightByType(EnumSkyBlock.Block, x, y-1, z);

player.worldObj.updateLightByType(EnumSkyBlock.Block, x, y, z+1);

player.worldObj.updateLightByType(EnumSkyBlock.Block, x, y, z-1);

 

lastX = x;

lastY = y;

lastZ = z;

}

 

}else if((player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().itemID != Block.torchWood.blockID) || (player.getCurrentEquippedItem() == null))

{

player.worldObj.updateLightByType(EnumSkyBlock.Block, lastX, lastY, lastZ);

 

lastX = 0;

lastY = 0;

lastZ = 0;

}

}

}

 

 

Posted

You are still directly casting doubles to int... that has been pointed out earlier to be the major culprit of your problem (most probably).

Try something like this:

int x = (int) Math.floor(player.posX);
// etc.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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