Jump to content

Recommended Posts

Posted

I have a dynamic light mod its works well but when i get the player coords its not under the player.

Thanks for helping me!

My 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;

}

}

 

 

 

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.