cleanup player controller comments
This commit is contained in:
parent
d41ad4db01
commit
2cf7f0036d
1 changed files with 21 additions and 259 deletions
|
@ -43,77 +43,8 @@ public class PlayerController
|
||||||
this.netClientHandler = netHandler;
|
this.netClientHandler = netHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void clickBlockCreative(Game gmIn, PlayerController playerController, BlockPos pos, Facing facing)
|
|
||||||
// {
|
|
||||||
// if (!gmIn.theWorld.extinguishFire(gmIn.thePlayer, pos, facing))
|
|
||||||
// {
|
|
||||||
// playerController.onPlayerDestroyBlock(pos, facing);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void setPlayerCapabilities()
|
|
||||||
// {
|
|
||||||
// this.gm.thePlayer.flying &= this.gm.thePlayer.hasEffect(Potion.flying) || this.gm.thePlayer.noclip;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public boolean isNoclip()
|
|
||||||
// {
|
|
||||||
// return this.gm.thePlayer.capabilities.noClip;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void setNoclip(boolean noclip)
|
|
||||||
// {
|
|
||||||
// this.noclip = noclip;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void setCheat(boolean cheat)
|
|
||||||
// {
|
|
||||||
// this.cheat = cheat;
|
|
||||||
// this.setPlayerCapabilities();
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// public boolean shouldDrawHUD()
|
|
||||||
// {
|
|
||||||
// return !this.creative;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when a player completes the destruction of a block
|
|
||||||
*/
|
|
||||||
public boolean onPlayerDestroyBlock(BlockPos pos, Facing side)
|
public boolean onPlayerDestroyBlock(BlockPos pos, Facing side)
|
||||||
{
|
{
|
||||||
// if (this.gamemode.isAdventure())
|
|
||||||
// {
|
|
||||||
// if (this.gamemode == Gamemode.SPECTATOR)
|
|
||||||
// {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!this.gm.thePlayer.isAllowEdit())
|
|
||||||
// {
|
|
||||||
// Block block = this.gm.theWorld.getBlockState(pos).getBlock();
|
|
||||||
// ItemStack itemstack = this.gm.thePlayer.getCurrentEquippedItem();
|
|
||||||
//
|
|
||||||
// if (itemstack == null)
|
|
||||||
// {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (!itemstack.canDestroy(block))
|
|
||||||
// {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (this.gm.thePlayer.getHeldItem() != null && !this.gm.thePlayer.getHeldItem().getItem().canBreakBlocks())
|
|
||||||
// {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
World world = this.gm.world;
|
World world = this.gm.world;
|
||||||
State iblockstate = world.getState(pos);
|
State iblockstate = world.getState(pos);
|
||||||
Block block1 = iblockstate.getBlock();
|
Block block1 = iblockstate.getBlock();
|
||||||
|
@ -134,8 +65,6 @@ public class PlayerController
|
||||||
|
|
||||||
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
|
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
|
||||||
|
|
||||||
// if (!this.creative)
|
|
||||||
// {
|
|
||||||
ItemStack itemstack1 = this.gm.player.getCurrentEquippedItem();
|
ItemStack itemstack1 = this.gm.player.getCurrentEquippedItem();
|
||||||
|
|
||||||
if (itemstack1 != null)
|
if (itemstack1 != null)
|
||||||
|
@ -147,42 +76,13 @@ public class PlayerController
|
||||||
this.gm.player.destroyCurrentEquippedItem();
|
this.gm.player.destroyCurrentEquippedItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the player is hitting a block with an item.
|
|
||||||
*/
|
|
||||||
public boolean clickBlock(BlockPos loc, Facing face)
|
public boolean clickBlock(BlockPos loc, Facing face)
|
||||||
{
|
{
|
||||||
// if (this.gamemode.isAdventure())
|
|
||||||
// {
|
|
||||||
// if (this.gamemode == Gamemode.SPECTATOR)
|
|
||||||
// {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!this.gm.thePlayer.isAllowEdit())
|
|
||||||
// {
|
|
||||||
// Block block = this.gm.theWorld.getBlockState(loc).getBlock();
|
|
||||||
// ItemStack itemstack = this.gm.thePlayer.getCurrentEquippedItem();
|
|
||||||
//
|
|
||||||
// if (itemstack == null)
|
|
||||||
// {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (!itemstack.canDestroy(block))
|
|
||||||
// {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (!World.isValidXZ(loc))
|
if (!World.isValidXZ(loc))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -195,13 +95,6 @@ public class PlayerController
|
||||||
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face));
|
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// if (this.creative)
|
|
||||||
// {
|
|
||||||
// this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face));
|
|
||||||
// clickBlockCreative(this.gm, this, loc, face);
|
|
||||||
// this.blockHitDelay = 5;
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
if (!this.isHittingBlock || !this.isHittingPosition(loc))
|
if (!this.isHittingBlock || !this.isHittingPosition(loc))
|
||||||
{
|
{
|
||||||
if (this.isHittingBlock)
|
if (this.isHittingBlock)
|
||||||
|
@ -221,8 +114,7 @@ public class PlayerController
|
||||||
if (flag && block1.getPlayerRelativeBlockHardness(this.gm.player, this.gm.player.worldObj, loc) >= 1.0F)
|
if (flag && block1.getPlayerRelativeBlockHardness(this.gm.player, this.gm.player.worldObj, loc) >= 1.0F)
|
||||||
{
|
{
|
||||||
this.onPlayerDestroyBlock(loc, face);
|
this.onPlayerDestroyBlock(loc, face);
|
||||||
// if(this.cheat && block1.getPlayerRelativeBlockHardness(this.gm.thePlayer, this.gm.thePlayer.worldObj, loc) < 1.0F)
|
this.blockHitDelay = 3;
|
||||||
this.blockHitDelay = 3;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -239,9 +131,6 @@ public class PlayerController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets current block damage and isHittingBlock
|
|
||||||
*/
|
|
||||||
public void resetBlockRemoving()
|
public void resetBlockRemoving()
|
||||||
{
|
{
|
||||||
if (this.isHittingBlock)
|
if (this.isHittingBlock)
|
||||||
|
@ -269,13 +158,6 @@ public class PlayerController
|
||||||
--this.blockHitDelay;
|
--this.blockHitDelay;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// else if (this.creative && World.isValidXZ(posBlock))
|
|
||||||
// {
|
|
||||||
// this.blockHitDelay = 5;
|
|
||||||
// this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, posBlock, directionFacing));
|
|
||||||
// clickBlockCreative(this.gm, this, posBlock, directionFacing);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
else if (this.isHittingPosition(posBlock))
|
else if (this.isHittingPosition(posBlock))
|
||||||
{
|
{
|
||||||
Block block = this.gm.world.getState(posBlock).getBlock();
|
Block block = this.gm.world.getState(posBlock).getBlock();
|
||||||
|
@ -316,14 +198,6 @@ public class PlayerController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * player reach distance = 4F
|
|
||||||
// */
|
|
||||||
// public float getBlockReachDistance()
|
|
||||||
// {
|
|
||||||
// return ;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void updateController()
|
public void updateController()
|
||||||
{
|
{
|
||||||
this.syncCurrentPlayItem();
|
this.syncCurrentPlayItem();
|
||||||
|
@ -351,9 +225,6 @@ public class PlayerController
|
||||||
return pos.equals(this.currentBlock) && flag;
|
return pos.equals(this.currentBlock) && flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Syncs the current player item with the server
|
|
||||||
*/
|
|
||||||
private void syncCurrentPlayItem()
|
private void syncCurrentPlayItem()
|
||||||
{
|
{
|
||||||
int i = this.gm.player.inventory.currentItem;
|
int i = this.gm.player.inventory.currentItem;
|
||||||
|
@ -380,11 +251,9 @@ public class PlayerController
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(heldStack == null || !heldStack.getItem().onAction(heldStack, player, worldIn, ItemControl.SECONDARY, hitPos)) {
|
if(heldStack == null || !heldStack.getItem().onAction(heldStack, player, worldIn, ItemControl.SECONDARY, hitPos)) {
|
||||||
// if (this.gamemode != Gamemode.SPECTATOR)
|
|
||||||
// {
|
|
||||||
State iblockstate = worldIn.getState(hitPos);
|
State iblockstate = worldIn.getState(hitPos);
|
||||||
|
|
||||||
if ((!player.isSneaking() || player.getHeldItem() == null) // && (player.getHeldItem() == null || !player.getHeldItem().getItem().ignoresBlocks())
|
if ((!player.isSneaking() || player.getHeldItem() == null)
|
||||||
&& iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2))
|
&& iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2))
|
||||||
{
|
{
|
||||||
flag = true;
|
flag = true;
|
||||||
|
@ -399,7 +268,6 @@ public class PlayerController
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
heldStack.getItem().onItemUse(heldStack, player, worldIn, hitPos, side, f, f1, f2);
|
heldStack.getItem().onItemUse(heldStack, player, worldIn, hitPos, side, f, f1, f2);
|
||||||
|
@ -408,21 +276,12 @@ public class PlayerController
|
||||||
|
|
||||||
this.netClientHandler.addToSendQueue(new CPacketPlace(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));
|
this.netClientHandler.addToSendQueue(new CPacketPlace(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));
|
||||||
|
|
||||||
if (!flag) // && this.gamemode != Gamemode.SPECTATOR)
|
if (!flag)
|
||||||
{
|
{
|
||||||
if (heldStack == null)
|
if (heldStack == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// else if (this.creative)
|
|
||||||
// {
|
|
||||||
// int i = heldStack.getMetadata();
|
|
||||||
// int j = heldStack.stackSize;
|
|
||||||
// boolean flag1 = heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
|
|
||||||
// heldStack.setItemDamage(i);
|
|
||||||
// heldStack.stackSize = j;
|
|
||||||
// return flag1;
|
|
||||||
// }
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
|
return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
|
||||||
|
@ -435,38 +294,28 @@ public class PlayerController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Notifies the server of things like consuming food, etc...
|
|
||||||
*/
|
|
||||||
public boolean sendUseItem(EntityNPC playerIn, World worldIn, ItemStack itemStackIn)
|
public boolean sendUseItem(EntityNPC playerIn, World worldIn, ItemStack itemStackIn)
|
||||||
{
|
{
|
||||||
// if (this.gamemode == Gamemode.SPECTATOR)
|
this.syncCurrentPlayItem();
|
||||||
// {
|
this.netClientHandler.addToSendQueue(new CPacketPlace(playerIn.inventory.getCurrentItem()));
|
||||||
// return false;
|
int i = itemStackIn.stackSize;
|
||||||
// }
|
ItemStack itemstack = itemStackIn.useItemRightClick(worldIn, playerIn);
|
||||||
// else
|
|
||||||
// {
|
|
||||||
this.syncCurrentPlayItem();
|
|
||||||
this.netClientHandler.addToSendQueue(new CPacketPlace(playerIn.inventory.getCurrentItem()));
|
|
||||||
int i = itemStackIn.stackSize;
|
|
||||||
ItemStack itemstack = itemStackIn.useItemRightClick(worldIn, playerIn);
|
|
||||||
|
|
||||||
if (itemstack != itemStackIn || itemstack != null && itemstack.stackSize != i)
|
if (itemstack != itemStackIn || itemstack != null && itemstack.stackSize != i)
|
||||||
|
{
|
||||||
|
playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = itemstack;
|
||||||
|
|
||||||
|
if (itemstack.stackSize == 0)
|
||||||
{
|
{
|
||||||
playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = itemstack;
|
playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
|
||||||
|
|
||||||
if (itemstack.stackSize == 0)
|
|
||||||
{
|
|
||||||
playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return true;
|
||||||
return false;
|
}
|
||||||
}
|
else
|
||||||
// }
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityNPC createPlayerEntity(WorldClient worldIn, int type)
|
public EntityNPC createPlayerEntity(WorldClient worldIn, int type)
|
||||||
|
@ -476,48 +325,20 @@ public class PlayerController
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Attacks an entity
|
|
||||||
*/
|
|
||||||
public void attackEntity(EntityNPC playerIn, Entity targetEntity)
|
public void attackEntity(EntityNPC playerIn, Entity targetEntity)
|
||||||
{
|
{
|
||||||
this.syncCurrentPlayItem();
|
this.syncCurrentPlayItem();
|
||||||
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ATTACK, targetEntity.getId()));
|
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ATTACK, targetEntity.getId()));
|
||||||
|
|
||||||
// if (this.gamemode != Gamemode.SPECTATOR)
|
|
||||||
// {
|
|
||||||
playerIn.attackTargetEntityWithCurrentItem(targetEntity);
|
playerIn.attackTargetEntityWithCurrentItem(targetEntity);
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Send packet to server - player is interacting with another entity (left click)
|
|
||||||
*/
|
|
||||||
public boolean interactWithEntitySendPacket(EntityNPC playerIn, Entity targetEntity)
|
public boolean interactWithEntitySendPacket(EntityNPC playerIn, Entity targetEntity)
|
||||||
{
|
{
|
||||||
this.syncCurrentPlayItem();
|
this.syncCurrentPlayItem();
|
||||||
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.INTERACT, targetEntity.getId()));
|
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.INTERACT, targetEntity.getId()));
|
||||||
return /* this.gamemode != Gamemode.SPECTATOR && */ playerIn.interactWith(targetEntity);
|
return playerIn.interactWith(targetEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Return true when the player rightclick on an entity
|
|
||||||
// *
|
|
||||||
// * @param player The player's instance
|
|
||||||
// * @param entityIn The entity clicked
|
|
||||||
// * @param movingObject The object clicked
|
|
||||||
// */
|
|
||||||
// public boolean isPlayerRightClickingOnEntity(EntityNPC player, Entity entityIn, MovingObjectPosition movingObject)
|
|
||||||
// {
|
|
||||||
// this.syncCurrentPlayItem();
|
|
||||||
// Vec3 vec3 = new Vec3(movingObject.hitVec.xCoord - entityIn.posX, movingObject.hitVec.yCoord - entityIn.posY, movingObject.hitVec.zCoord - entityIn.posZ);
|
|
||||||
// this.netClientHandler.addToSendQueue(new C02PacketUseEntity(entityIn, vec3));
|
|
||||||
// return this.gamemode != Gamemode.SPECTATOR && entityIn.interactAt(player, vec3);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles slot clicks sends a packet to the server.
|
|
||||||
*/
|
|
||||||
public ItemStack windowClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityNPC playerIn)
|
public ItemStack windowClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityNPC playerIn)
|
||||||
{
|
{
|
||||||
short short1 = playerIn.openContainer.getNextTransactionID(playerIn.inventory);
|
short short1 = playerIn.openContainer.getNextTransactionID(playerIn.inventory);
|
||||||
|
@ -526,36 +347,11 @@ public class PlayerController
|
||||||
return itemstack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* GuiEnchantment uses this during multiplayer to tell PlayerControllerMP to send a packet indicating the
|
|
||||||
* enchantment action the player has taken.
|
|
||||||
*
|
|
||||||
* @param windowID The ID of the current window
|
|
||||||
* @param button The button id (enchantment selected)
|
|
||||||
*/
|
|
||||||
public void sendEnchantPacket(int windowID, int button)
|
public void sendEnchantPacket(int windowID, int button)
|
||||||
{
|
{
|
||||||
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ENCHANT_ITEM, windowID | (button << 8)));
|
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ENCHANT_ITEM, windowID | (button << 8)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Used in PlayerControllerMP to update the server with an ItemStack in a slot.
|
|
||||||
// */
|
|
||||||
// public void sendCheatPacket(ItemStack itemStackIn, boolean full)
|
|
||||||
// {
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Sends a Packet107 to the server to drop the item on the ground
|
|
||||||
// */
|
|
||||||
// public void sendPacketDropItem(ItemStack itemStackIn)
|
|
||||||
// {
|
|
||||||
// if (this.creative && itemStackIn != null)
|
|
||||||
// {
|
|
||||||
// this.netClientHandler.addToSendQueue(new CPacketCreative(-1, itemStackIn));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void onStoppedUsingItem(EntityNPC playerIn)
|
public void onStoppedUsingItem(EntityNPC playerIn)
|
||||||
{
|
{
|
||||||
this.syncCurrentPlayItem();
|
this.syncCurrentPlayItem();
|
||||||
|
@ -563,40 +359,6 @@ public class PlayerController
|
||||||
playerIn.stopUsingItem();
|
playerIn.stopUsingItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Checks if the player is not creative, used for checking if it should break a block instantly
|
|
||||||
// */
|
|
||||||
// public boolean isNotCreative()
|
|
||||||
// {
|
|
||||||
// return !this.creative;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * returns true if player is in creative mode
|
|
||||||
// */
|
|
||||||
// public boolean isCreative()
|
|
||||||
// {
|
|
||||||
// return this.creative;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Checks if the player is riding a horse, used to chose the GUI to open
|
|
||||||
// */
|
|
||||||
// public boolean isRidingHorse()
|
|
||||||
// {
|
|
||||||
// return ;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public Gamemode getGamemode()
|
|
||||||
// {
|
|
||||||
// return this.gamemode;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return isHittingBlock
|
|
||||||
*/
|
|
||||||
public boolean getIsHittingBlock()
|
public boolean getIsHittingBlock()
|
||||||
{
|
{
|
||||||
return this.isHittingBlock;
|
return this.isHittingBlock;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue