cleanup player controller var names

This commit is contained in:
Sen 2025-05-25 15:38:12 +02:00
parent 64b256c713
commit 2bc84f0c66

View file

@ -25,46 +25,46 @@ import common.world.World;
public class PlayerController {
private final Client gm;
private final ClientPlayer netClientHandler;
private BlockPos currentBlock = new BlockPos(-1, -1, -1);
private ItemStack currentItemHittingBlock;
private float curBlockDamageMP;
private float stepSoundTickCounter;
private int blockHitDelay;
private boolean isHittingBlock;
private boolean noclip;
private int currentPlayerItem;
private final ClientPlayer handler;
private BlockPos position = new BlockPos(-1, -World.MAX_SIZE_Y - 1, -1);
private ItemStack stack;
private float damage;
private float stepCounter;
private int delay;
private boolean hitting;
private int lastSelected;
private boolean interacting;
public PlayerController(Client gmIn, ClientPlayer netHandler) {
this.gm = gmIn;
this.netClientHandler = netHandler;
public PlayerController(Client gm, ClientPlayer handler) {
this.gm = gm;
this.handler = handler;
}
public boolean onPlayerDestroyBlock(BlockPos pos, Facing side) {
World world = this.gm.world;
State iblockstate = world.getState(pos);
Block block1 = iblockstate.getBlock();
State state = world.getState(pos);
Block block = state.getBlock();
if(block1 == Blocks.air) {
if(block == Blocks.air) {
return false;
}
else {
world.playAuxSFX(2001, pos, BlockRegistry.getStateId(iblockstate));
world.playAuxSFX(2001, pos, BlockRegistry.getStateId(state));
boolean flag = world.setBlockToAir(pos);
if(flag) {
block1.onBlockDestroyedByPlayer(world, pos, iblockstate);
block.onBlockDestroyedByPlayer(world, pos, state);
}
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
this.position = new BlockPos(this.position.getX(), -1, this.position.getZ());
ItemStack itemstack1 = this.gm.player.getCurrentEquippedItem();
ItemStack stack = this.gm.player.getCurrentEquippedItem();
if(itemstack1 != null) {
itemstack1.onBlockDestroyed(world, block1, pos, this.gm.player);
if(stack != null) {
stack.onBlockDestroyed(world, block, pos, this.gm.player);
if(itemstack1.stackSize == 0) {
if(stack.stackSize == 0) {
this.gm.player.destroyCurrentEquippedItem();
}
}
@ -73,41 +73,41 @@ public class PlayerController {
}
}
public boolean clickBlock(BlockPos loc, Facing face) {
if(!World.isValidXZ(loc)) {
public boolean clickBlock(BlockPos pos, Facing face) {
if(!World.isValidXZ(pos)) {
return false;
}
else {
ItemStack stack = this.gm.player.getHeldItem();
if(stack != null && stack.getItem().onAction(stack, this.gm.player, this.gm.world, ItemControl.PRIMARY, loc)) {
if(stack != null && stack.getItem().onAction(stack, this.gm.player, this.gm.world, ItemControl.PRIMARY, pos)) {
this.interacting = true;
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face));
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, pos, face));
return true;
}
if(!this.isHittingBlock || !this.isHittingPosition(loc)) {
if(this.isHittingBlock) {
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.currentBlock, face));
if(!this.hitting || !this.isHittingPosition(pos)) {
if(this.hitting) {
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.position, face));
}
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, loc, face));
Block block1 = this.gm.world.getState(loc).getBlock();
boolean flag = block1 != Blocks.air;
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.START_DESTROY_BLOCK, pos, face));
Block block = this.gm.world.getState(pos).getBlock();
boolean flag = block != Blocks.air;
if(flag && this.curBlockDamageMP == 0.0F) {
block1.onBlockClicked(this.gm.world, loc, this.gm.player);
if(flag && this.damage == 0.0F) {
block.onBlockClicked(this.gm.world, pos, this.gm.player);
}
if(flag && block1.getPlayerRelativeBlockHardness(this.gm.player, this.gm.player.worldObj, loc) >= 1.0F) {
this.onPlayerDestroyBlock(loc, face);
this.blockHitDelay = 3;
if(flag && block.getPlayerRelativeBlockHardness(this.gm.player, this.gm.player.worldObj, pos) >= 1.0F) {
this.onPlayerDestroyBlock(pos, face);
this.delay = 3;
}
else {
this.isHittingBlock = true;
this.currentBlock = loc;
this.currentItemHittingBlock = this.gm.player.getHeldItem();
this.curBlockDamageMP = 0.0F;
this.stepSoundTickCounter = 0.0F;
this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
this.hitting = true;
this.position = pos;
this.stack = this.gm.player.getHeldItem();
this.damage = 0.0F;
this.stepCounter = 0.0F;
this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.position, (int)(this.damage * 10.0F) - 1);
}
}
@ -116,11 +116,11 @@ public class PlayerController {
}
public void resetBlockRemoving() {
if(this.isHittingBlock) {
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.currentBlock, Facing.DOWN));
this.isHittingBlock = false;
this.curBlockDamageMP = 0.0F;
this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.currentBlock, -1);
if(this.hitting) {
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.ABORT_DESTROY_BLOCK, this.position, Facing.DOWN));
this.hitting = false;
this.damage = 0.0F;
this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.position, -1);
}
}
@ -128,123 +128,123 @@ public class PlayerController {
this.interacting = false;
}
public boolean onPlayerDamageBlock(BlockPos posBlock, Facing directionFacing) {
public boolean onPlayerDamageBlock(BlockPos pos, Facing face) {
if(this.interacting)
return false;
this.syncCurrentPlayItem();
if(this.blockHitDelay > 0) {
--this.blockHitDelay;
if(this.delay > 0) {
--this.delay;
return true;
}
else if(this.isHittingPosition(posBlock)) {
Block block = this.gm.world.getState(posBlock).getBlock();
else if(this.isHittingPosition(pos)) {
Block block = this.gm.world.getState(pos).getBlock();
if(block == Blocks.air) {
this.isHittingBlock = false;
this.hitting = false;
return false;
}
else {
this.curBlockDamageMP += block.getPlayerRelativeBlockHardness(this.gm.player, this.gm.player.worldObj, posBlock);
this.damage += block.getPlayerRelativeBlockHardness(this.gm.player, this.gm.player.worldObj, pos);
if(this.stepSoundTickCounter % 4.0F == 0.0F && block.sound.getStepSound() != null) {
if(this.stepCounter % 4.0F == 0.0F && block.sound.getStepSound() != null) {
this.gm.getSoundManager().playSound(new PositionedSound(block.sound.getStepSound(), 0.25F,
(float)posBlock.getX() + 0.5F, (float)posBlock.getY() + 0.5F, (float)posBlock.getZ() + 0.5F));
(float)pos.getX() + 0.5F, (float)pos.getY() + 0.5F, (float)pos.getZ() + 0.5F));
}
++this.stepSoundTickCounter;
++this.stepCounter;
if(this.curBlockDamageMP >= 1.0F) {
this.isHittingBlock = false;
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.STOP_DESTROY_BLOCK, posBlock, directionFacing));
this.onPlayerDestroyBlock(posBlock, directionFacing);
this.curBlockDamageMP = 0.0F;
this.stepSoundTickCounter = 0.0F;
this.blockHitDelay = 5;
if(this.damage >= 1.0F) {
this.hitting = false;
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.STOP_DESTROY_BLOCK, pos, face));
this.onPlayerDestroyBlock(pos, face);
this.damage = 0.0F;
this.stepCounter = 0.0F;
this.delay = 5;
}
this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
this.gm.world.sendBlockBreakProgress(this.gm.player.getId(), this.position, (int)(this.damage * 10.0F) - 1);
return true;
}
}
else {
return this.clickBlock(posBlock, directionFacing);
return this.clickBlock(pos, face);
}
}
public void updateController() {
this.syncCurrentPlayItem();
if(this.netClientHandler.getNetworkManager().isChannelOpen()) {
this.netClientHandler.getNetworkManager().processReceivedPackets();
if(this.handler.getNetworkManager().isChannelOpen()) {
this.handler.getNetworkManager().processReceivedPackets();
}
else {
this.netClientHandler.getNetworkManager().checkDisconnected();
this.handler.getNetworkManager().checkDisconnected();
}
}
private boolean isHittingPosition(BlockPos pos) {
ItemStack itemstack = this.gm.player.getHeldItem();
boolean flag = this.currentItemHittingBlock == null && itemstack == null;
ItemStack stack = this.gm.player.getHeldItem();
boolean flag = this.stack == null && stack == null;
if(this.currentItemHittingBlock != null && itemstack != null) {
flag = itemstack.getItem() == this.currentItemHittingBlock.getItem()
&& ItemStack.areItemStackTagsEqual(itemstack, this.currentItemHittingBlock)
&& (itemstack.isItemStackDamageable() || itemstack.getMetadata() == this.currentItemHittingBlock.getMetadata());
if(this.stack != null && stack != null) {
flag = stack.getItem() == this.stack.getItem()
&& ItemStack.areItemStackTagsEqual(stack, this.stack)
&& (stack.isItemStackDamageable() || stack.getMetadata() == this.stack.getMetadata());
}
return pos.equals(this.currentBlock) && flag;
return pos.equals(this.position) && flag;
}
private void syncCurrentPlayItem() {
int i = this.gm.player.inventory.currentItem;
int slot = this.gm.player.inventory.currentItem;
if(i != this.currentPlayerItem) {
this.currentPlayerItem = i;
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ITEMSLOT, this.currentPlayerItem));
if(slot != this.lastSelected) {
this.lastSelected = slot;
this.handler.addToSendQueue(new CPacketAction(CPacketAction.Action.SET_ITEMSLOT, this.lastSelected));
}
}
public boolean onPlayerRightClick(EntityNPC player, WorldClient worldIn, ItemStack heldStack, BlockPos hitPos, Facing side, Vec3 hitVec) {
public boolean onPlayerRightClick(EntityNPC player, WorldClient world, ItemStack stack, BlockPos pos, Facing side, Vec3 hit) {
this.syncCurrentPlayItem();
float f = (float)(hitVec.xCoord - (double)hitPos.getX());
float f1 = (float)(hitVec.yCoord - (double)hitPos.getY());
float f2 = (float)(hitVec.zCoord - (double)hitPos.getZ());
float f = (float)(hit.xCoord - (double)pos.getX());
float f1 = (float)(hit.yCoord - (double)pos.getY());
float f2 = (float)(hit.zCoord - (double)pos.getZ());
boolean flag = false;
if(!World.isValidXZ(hitPos)) {
if(!World.isValidXZ(pos)) {
return false;
}
else {
if(heldStack == null || !heldStack.getItem().onAction(heldStack, player, worldIn, ItemControl.SECONDARY, hitPos)) {
State iblockstate = worldIn.getState(hitPos);
if(stack == null || !stack.getItem().onAction(stack, player, world, ItemControl.SECONDARY, pos)) {
State iblockstate = world.getState(pos);
if((!player.isSneaking() || player.getHeldItem() == null)
&& iblockstate.getBlock().onBlockActivated(worldIn, hitPos, iblockstate, player, side, f, f1, f2)) {
&& iblockstate.getBlock().onBlockActivated(world, pos, iblockstate, player, side, f, f1, f2)) {
flag = true;
}
if(!flag && heldStack != null && heldStack.getItem() instanceof ItemBlock) {
ItemBlock itemblock = (ItemBlock)heldStack.getItem();
if(!flag && stack != null && stack.getItem() instanceof ItemBlock) {
ItemBlock itemblock = (ItemBlock)stack.getItem();
if(!itemblock.canPlaceBlockOnSide(worldIn, hitPos, side, player, heldStack)) {
if(!itemblock.canPlaceBlockOnSide(world, pos, side, player, stack)) {
return false;
}
}
}
else {
heldStack.getItem().onItemUse(heldStack, player, worldIn, hitPos, side, f, f1, f2);
stack.getItem().onItemUse(stack, player, world, pos, side, f, f1, f2);
flag = true;
}
this.netClientHandler.addToSendQueue(new CPacketPlace(hitPos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));
this.handler.addToSendQueue(new CPacketPlace(pos, side.getIndex(), player.inventory.getCurrentItem(), f, f1, f2));
if(!flag) {
if(heldStack == null) {
if(stack == null) {
return false;
}
else {
return heldStack.onItemUse(player, worldIn, hitPos, side, f, f1, f2);
return stack.onItemUse(player, world, pos, side, f, f1, f2);
}
}
else {
@ -253,17 +253,17 @@ public class PlayerController {
}
}
public boolean sendUseItem(EntityNPC playerIn, World worldIn, ItemStack itemStackIn) {
public boolean sendUseItem(EntityNPC player, World world, ItemStack stack) {
this.syncCurrentPlayItem();
this.netClientHandler.addToSendQueue(new CPacketPlace(playerIn.inventory.getCurrentItem()));
int i = itemStackIn.stackSize;
ItemStack itemstack = itemStackIn.useItemRightClick(worldIn, playerIn);
this.handler.addToSendQueue(new CPacketPlace(player.inventory.getCurrentItem()));
int size = stack.stackSize;
ItemStack changed = stack.useItemRightClick(world, player);
if(itemstack != itemStackIn || itemstack != null && itemstack.stackSize != i) {
playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = itemstack;
if(changed != stack || changed != null && changed.stackSize != size) {
player.inventory.mainInventory[player.inventory.currentItem] = changed;
if(itemstack.stackSize == 0) {
playerIn.inventory.mainInventory[playerIn.inventory.currentItem] = null;
if(changed.stackSize == 0) {
player.inventory.mainInventory[player.inventory.currentItem] = null;
}
return true;
@ -273,42 +273,42 @@ public class PlayerController {
}
}
public EntityNPC createPlayerEntity(WorldClient worldIn, int type) {
EntityNPC player = (EntityNPC)EntityRegistry.createEntityByID(type, worldIn);
player.setClientPlayer(this.netClientHandler);
public EntityNPC createPlayerEntity(WorldClient world, int type) {
EntityNPC player = (EntityNPC)EntityRegistry.createEntityByID(type, world);
player.setClientPlayer(this.handler);
return player;
}
public void attackEntity(EntityNPC playerIn, Entity targetEntity) {
public void attackEntity(EntityNPC player, Entity target) {
this.syncCurrentPlayItem();
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ATTACK, targetEntity.getId()));
playerIn.attackTargetEntityWithCurrentItem(targetEntity);
this.handler.addToSendQueue(new CPacketAction(CPacketAction.Action.ATTACK, target.getId()));
player.attackTargetEntityWithCurrentItem(target);
}
public boolean interactWithEntitySendPacket(EntityNPC playerIn, Entity targetEntity) {
public boolean interactWithEntitySendPacket(EntityNPC player, Entity target) {
this.syncCurrentPlayItem();
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.INTERACT, targetEntity.getId()));
return playerIn.interactWith(targetEntity);
this.handler.addToSendQueue(new CPacketAction(CPacketAction.Action.INTERACT, target.getId()));
return player.interactWith(target);
}
public ItemStack windowClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityNPC playerIn) {
short short1 = playerIn.openContainer.getNextTransactionID(playerIn.inventory);
ItemStack itemstack = playerIn.openContainer.slotClick(slotId, mouseButtonClicked, mode, playerIn);
this.netClientHandler.addToSendQueue(new CPacketClick(windowId, slotId, mouseButtonClicked, mode, itemstack, short1));
return itemstack;
public ItemStack windowClick(int window, int slot, int button, int mode, EntityNPC player) {
short id = player.openContainer.getNextTransactionID(player.inventory);
ItemStack stack = player.openContainer.slotClick(slot, button, mode, player);
this.handler.addToSendQueue(new CPacketClick(window, slot, button, mode, stack, id));
return stack;
}
public void sendEnchantPacket(int windowID, int button) {
this.netClientHandler.addToSendQueue(new CPacketAction(CPacketAction.Action.ENCHANT_ITEM, windowID | (button << 8)));
public void sendEnchantPacket(int window, int button) {
this.handler.addToSendQueue(new CPacketAction(CPacketAction.Action.ENCHANT_ITEM, window | (button << 8)));
}
public void onStoppedUsingItem(EntityNPC playerIn) {
public void onStoppedUsingItem(EntityNPC player) {
this.syncCurrentPlayItem();
this.netClientHandler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Facing.DOWN));
playerIn.stopUsingItem();
this.handler.addToSendQueue(new CPacketBreak(CPacketBreak.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, Facing.DOWN));
player.stopUsingItem();
}
public boolean getIsHittingBlock() {
return this.isHittingBlock;
return this.hitting;
}
}