From 103e4d35f57c5b858e4fcb11b80b16a0a0c2ac25 Mon Sep 17 00:00:00 2001 From: Sen Date: Thu, 20 Mar 2025 20:54:49 +0100 Subject: [PATCH] hovering, flying npc --- java/src/game/entity/npc/EntityFlyingNPC.java | 8 +++ .../game/entity/npc/EntityHoveringNPC.java | 56 ++++++++++++++++++- java/src/game/entity/npc/EntityNPC.java | 11 +++- java/src/game/gui/GuiConnect.java | 23 ++++++-- java/src/game/gui/world/GuiCreate.java | 31 ++++------ .../game/network/NetHandlerPlayServer.java | 8 +++ java/src/game/packet/CPacketAction.java | 2 + 7 files changed, 111 insertions(+), 28 deletions(-) diff --git a/java/src/game/entity/npc/EntityFlyingNPC.java b/java/src/game/entity/npc/EntityFlyingNPC.java index 2a26d9f..cf017cf 100755 --- a/java/src/game/entity/npc/EntityFlyingNPC.java +++ b/java/src/game/entity/npc/EntityFlyingNPC.java @@ -43,8 +43,16 @@ public abstract class EntityFlyingNPC extends EntityNPC { } + public boolean isFlying() { + return true; + } + public void moveEntityWithHeading(float strafe, float forward) { + if(this.isPlayer()) { + super.moveEntityWithHeading(strafe, forward); + return; + } if (this.isInLiquid()) { this.moveFlying(strafe, forward, 0.02F); diff --git a/java/src/game/entity/npc/EntityHoveringNPC.java b/java/src/game/entity/npc/EntityHoveringNPC.java index 377b20a..6a09843 100755 --- a/java/src/game/entity/npc/EntityHoveringNPC.java +++ b/java/src/game/entity/npc/EntityHoveringNPC.java @@ -2,6 +2,7 @@ package game.entity.npc; import game.entity.attributes.Attributes; import game.entity.types.EntityLiving; +import game.packet.CPacketAction; import game.world.World; public abstract class EntityHoveringNPC extends EntityNPC @@ -9,6 +10,8 @@ public abstract class EntityHoveringNPC extends EntityNPC private float heightOffset = 0.5F; private int heightOffsetUpdateTime; + private boolean serverHoverState; + public EntityHoveringNPC(World worldIn) { super(worldIn); @@ -33,6 +36,16 @@ public abstract class EntityHoveringNPC extends EntityNPC super.applyEntityAttributes(); this.getEntityAttribute(Attributes.FOLLOW_RANGE).setBaseValue(32.0D); } + + public boolean isHovering() + { + return this.getFlag(6); + } + + public void setHovering(boolean hover) + { + this.setFlag(6, hover); + } // protected void entityInit() // { @@ -77,11 +90,45 @@ public abstract class EntityHoveringNPC extends EntityNPC // return 1.0F; // } + public void onUpdateWalkingPlayer() + { + boolean flag = this.isHovering(); + + if (flag != this.serverHoverState) + { + if (flag) + { + this.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.START_HOVER)); + } + else + { + this.sendQueue.addToSendQueue(new CPacketAction(CPacketAction.Action.STOP_HOVER)); + } + + this.serverHoverState = flag; + } + + super.onUpdateWalkingPlayer(); + } + public void onLivingUpdate() { - if (!this.onGround && this.motionY < 0.0D) + if(this.sendQueue != null) { + if(this.gm.jump && this.gm.sprint && this.gm.moveForward == 0.0f && this.gm.moveStrafe == 0.0f) + this.setHovering(true); + if(this.isFlying() || (!this.gm.jump && this.gm.sneak && this.onGround)) + this.setHovering(false); + } + if (!this.onGround && this.motionY < 0.0D && (!this.isPlayer() || (!this.isFlying() && this.isHovering() && !this.jumping))) { - this.motionY *= 0.6D; + if(this.isPlayer() && this.isSneaking()) + this.motionY = -0.1D; + else + this.motionY *= 0.6D; + } + if (!this.onGround && this.isPlayer() && !this.isFlying() && !this.isSneaking() && this.isHovering()) + { + this.motionY = this.jumping ? 0.1D : -0.025D; } // if (this.worldObj.client) @@ -100,6 +147,11 @@ public abstract class EntityHoveringNPC extends EntityNPC super.onLivingUpdate(); } + protected float getJumpUpwardsMotion() + { + return !this.isPlayer() ? super.getJumpUpwardsMotion() : (super.getJumpUpwardsMotion()); + } + protected void updateAITasks() { // if (Config.blazeWaterDamage && this.isWet()) diff --git a/java/src/game/entity/npc/EntityNPC.java b/java/src/game/entity/npc/EntityNPC.java index 9fc4bc2..883a2fc 100755 --- a/java/src/game/entity/npc/EntityNPC.java +++ b/java/src/game/entity/npc/EntityNPC.java @@ -199,7 +199,7 @@ public abstract class EntityNPC extends EntityLiving public NetHandlerPlayServer connection; public NetHandlerPlayClient sendQueue; - private Game gm; + protected Game gm; public InventoryPlayer inventory; protected InventoryWarpChest warpChest; @@ -4634,4 +4634,13 @@ public abstract class EntityNPC extends EntityLiving } return super.getItem(); } + + public boolean isHovering() + { + return false; + } + + public void setHovering(boolean hover) + { + } } diff --git a/java/src/game/gui/GuiConnect.java b/java/src/game/gui/GuiConnect.java index 4fccfc7..2c8bf80 100644 --- a/java/src/game/gui/GuiConnect.java +++ b/java/src/game/gui/GuiConnect.java @@ -24,13 +24,18 @@ public class GuiConnect extends Gui implements Textbox.Callback { private Label userLabel; private Label passLabel; private Label accLabel; + private String lastAddr = ""; + private int lastPort = Config.PORT; + private String lastUser = ""; + private String lastPass = ""; + private String lastAcc = ""; public void init(int width, int height) { - this.addrBox = this.add(new Textbox(0, 20, 410, 24, 128, true, this, "")); - this.portBox = this.add(new Textbox(414, 20, 66, 24, 5, true, this, "")); - this.userBox = this.add(new Textbox(0, 70, 220, 24, NetHandlerPlayServer.MAX_USER_LENGTH, true, this, NetHandlerPlayServer.VALID_USER, "")); - this.passBox = this.add(new Textbox(0, 120, 480, 24, NetHandlerPlayServer.MAX_PASS_LENGTH, true, this, "")); - this.accBox = this.add(new Textbox(0, 170, 480, 24, NetHandlerPlayServer.MAX_PASS_LENGTH, true, this, "")); + this.addrBox = this.add(new Textbox(0, 20, 400, 24, 128, true, this, this.lastAddr)); + this.portBox = this.add(new Textbox(404, 20, 76, 24, 5, true, this, "" + this.lastPort)); + this.userBox = this.add(new Textbox(0, 70, 220, 24, NetHandlerPlayServer.MAX_USER_LENGTH, true, this, NetHandlerPlayServer.VALID_USER, this.lastUser)); + this.passBox = this.add(new Textbox(0, 120, 480, 24, NetHandlerPlayServer.MAX_PASS_LENGTH, true, this, this.lastPass)); + this.accBox = this.add(new Textbox(0, 170, 480, 24, NetHandlerPlayServer.MAX_PASS_LENGTH, true, this, this.lastAcc)); this.add(new ActButton(0, 220, 480, 24, new ActButton.Callback() { public void use(ActButton elem, ActButton.Mode action) { GuiConnect.this.connect(); @@ -63,7 +68,8 @@ public class GuiConnect extends Gui implements Textbox.Callback { } int port = -1; if(this.portBox.getText().isEmpty()) { - port = Config.PORT; + this.portLabel.setText(TextColor.RED + "Port"); + return; } else { try { @@ -83,6 +89,11 @@ public class GuiConnect extends Gui implements Textbox.Callback { } String pass = this.passBox.getText(); String acc = this.accBox.getText(); + this.lastAddr = addr; + this.lastPort = port; + this.lastUser = user; + this.lastPass = pass; + this.lastAcc = acc; this.gm.connect(addr, port, user, pass, acc); } diff --git a/java/src/game/gui/world/GuiCreate.java b/java/src/game/gui/world/GuiCreate.java index 56c9f2a..d4ca102 100755 --- a/java/src/game/gui/world/GuiCreate.java +++ b/java/src/game/gui/world/GuiCreate.java @@ -210,19 +210,20 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba UniverseRegistry.clear(); this.alreadyGenerated = false; this.dimension = Integer.MAX_VALUE; - this.createButton = this.add(new ActButton(width / 2 - 155, height - 28, 150, 20, (ActButton.Callback)this, "Neue Welt erstellen")); - this.add(new ActButton(width / 2 + 5, height - 28, 150, 20, (Gui)GuiWorlds.INSTANCE, "Abbrechen")); - this.dimButton = this.add(new ActButton(width / 2 - 155, 220, 310, 20, (ActButton.Callback)this, "")); - this.worldNameField = this.add(new Textbox(width / 2 - 100, 60, 200, 20, 256, true, this, GuiWorlds.VALID_FILE, "")); + this.createButton = this.add(new ActButton(0, 340, 160, 24, (ActButton.Callback)this, "Welt erstellen")); + this.add(new ActButton(164, 340, 160, 24, (Gui)GuiWorlds.INSTANCE, "Abbrechen")); + this.dimButton = this.add(new ActButton(0, 220, 324, 24, (ActButton.Callback)this, "")); + this.worldNameField = this.add(new Textbox(20, 40, 284, 24, 256, true, this, GuiWorlds.VALID_FILE, "")); this.worldNameField.setSelected(); - this.worldSeedField = this.add(new Textbox(width / 2 - 100, 136, 200, 20, 256, true, this, "")); - this.worldUserField = this.add(new Textbox(width / 2 - 100, 98, 200, 20, NetHandlerPlayServer.MAX_USER_LENGTH, true, this, NetHandlerPlayServer.VALID_USER, "")); + this.worldSeedField = this.add(new Textbox(20, 140, 284, 24, 256, true, this, "")); + this.worldUserField = this.add(new Textbox(20, 90, 284, 24, NetHandlerPlayServer.MAX_USER_LENGTH, true, this, NetHandlerPlayServer.VALID_USER, "")); this.createButton.enabled = false; - this.actionLabel = this.add(new Label(width / 2 - 100, 49, 200, 20, this.getFolderDesc(), true)); - this.userLabel = this.add(new Label(width / 2 - 100, 87, 200, 20, this.getUserDesc(), true)); - this.seed = this.add(new Label(width / 2 - 100, 125, 200, 20, "", true)); - this.decoded = this.add(new Label(width / 2 - 100, 160, 200, 20, "", true)); - this.descLines = this.add(new TransparentBox(width / 2 - 153, 242, 306, 160, "")); + this.actionLabel = this.add(new Label(20, 20, 284, 20, this.getFolderDesc(), true)); + this.userLabel = this.add(new Label(20, 70, 284, 20, this.getUserDesc(), true)); + this.seed = this.add(new Label(20, 120, 284, 20, "", true)); + this.decoded = this.add(new Label(20, 164, 284, 20, "", true)); + this.descLines = this.add(new TransparentBox(0, 244, 324, 160, "")); + this.shift(); this.setDimButton(); } @@ -302,14 +303,6 @@ public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callba } private String getFolderDesc() { -// FontRenderer.drawStringWithShadow("Startwert [" + this.seed + "]", this.width / 2 - 100, 125, -6250336); -// FontRenderer.drawStringWithShadow("Dekodiert: " + this.decoded, this.width / 2 - 100, 160, -6250336); -// FontRenderer.drawStringWithShadow(, this.width / 2 - 100, 49, -6250336); -// FontRenderer.drawStringWithShadow((this.worldUserField.getText().isEmpty() ? TextColor.DARK_RED : "") + "Spielername", this.width / 2 - 100, 87, -6250336); -// -// for(int z = 1; z < this.descLines.length; z++) { -// FontRenderer.drawStringWithShadow(this.descLines[z], this.width / 2 - 153, 242 + (z - 1) * (FontRenderer.FONT_HEIGHT + 1), -6250336); -// } return (this.worldNameField.getText().trim().isEmpty() || this.fileExists ? TextColor.DRED : "") + "Ordner der Welt" + (this.fileExists ? " - Existiert bereits" : ""); } diff --git a/java/src/game/network/NetHandlerPlayServer.java b/java/src/game/network/NetHandlerPlayServer.java index 7660eb2..40ad9ff 100755 --- a/java/src/game/network/NetHandlerPlayServer.java +++ b/java/src/game/network/NetHandlerPlayServer.java @@ -2551,6 +2551,14 @@ public class NetHandlerPlayServer extends NetHandler implements ICrafting, Scrip this.entity.setSprinting(false); break; + case START_HOVER: + this.entity.setHovering(true); + break; + + case STOP_HOVER: + this.entity.setHovering(false); + break; + // case STOP_SLEEPING: // this.playerEntity.wakeUpPlayer(); // this.hasMoved = false; diff --git a/java/src/game/packet/CPacketAction.java b/java/src/game/packet/CPacketAction.java index 0fefb23..9cf7671 100755 --- a/java/src/game/packet/CPacketAction.java +++ b/java/src/game/packet/CPacketAction.java @@ -62,6 +62,8 @@ public class CPacketAction implements Packet // STOP_SLEEPING, START_SPRINTING, STOP_SPRINTING, + START_HOVER, + STOP_HOVER, RIDING_JUMP, OPEN_INVENTORY, START_FLYING,