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