mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 06:07:27 +00:00
Restrict mount riders and expose jump controls
This commit is contained in:
1 parent
b035f4e188
commit
bed60002c3
19 files changed
+130
-18
No files matched your search
@@ -38,10 +38,16 @@ public class GuiNpcMount extends GuiNPCInterface2 implements ITextfieldListener
|
||||
addOffsetRow(1, "role.mount.offsety", role.getOffsetY(), y);
|
||||
y += 24;
|
||||
addOffsetRow(2, "role.mount.offsetz", role.getOffsetZ(), y);
|
||||
y += 24;
|
||||
addJumpRow(3, "role.mount.jumpheight", role.getJumpStrength(), y);
|
||||
y += 24;
|
||||
|
||||
addButton(new GuiNpcButton(3, guiLeft + 4, y + 26, 80, 20, "role.mount.reset"));
|
||||
addLabel(new GuiNpcLabel(5, "role.mount.sprint", guiLeft + 4, y + 5));
|
||||
addButton(new GuiNpcButton(5, guiLeft + 140, y, 60, 20, new String[]{"gui.no", "gui.yes"}, role.isSprintAllowed() ? 1 : 0));
|
||||
|
||||
GuiNpcLabel speedLabel = new GuiNpcLabel(4, "", guiLeft + 4, y + 6);
|
||||
addButton(new GuiNpcButton(4, guiLeft + 4, y + 30, 80, 20, "role.mount.reset"));
|
||||
|
||||
GuiNpcLabel speedLabel = new GuiNpcLabel(6, "", guiLeft + 4, y + 56);
|
||||
speedLabel.label = StatCollector.translateToLocalFormatted("role.mount.walkspeed", npc.ais.getWalkingSpeed());
|
||||
addLabel(speedLabel);
|
||||
}
|
||||
@@ -54,6 +60,14 @@ public class GuiNpcMount extends GuiNPCInterface2 implements ITextfieldListener
|
||||
addTextField(field);
|
||||
}
|
||||
|
||||
private void addJumpRow(int id, String translationKey, float value, int y) {
|
||||
addLabel(new GuiNpcLabel(id, translationKey, guiLeft + 4, y + 5));
|
||||
GuiNpcTextField field = new GuiNpcTextField(id, this, guiLeft + 140, y, 80, 20, format(value));
|
||||
field.floatsOnly = true;
|
||||
field.setMinMaxDefaultFloat(0.1F, 3.0F, 1.0F);
|
||||
addTextField(field);
|
||||
}
|
||||
|
||||
private String format(float value) {
|
||||
return String.format(Locale.ROOT, "%.2f", value);
|
||||
}
|
||||
@@ -62,9 +76,11 @@ public class GuiNpcMount extends GuiNPCInterface2 implements ITextfieldListener
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (role == null)
|
||||
return;
|
||||
if (guibutton.id == 3) {
|
||||
if (guibutton.id == 4) {
|
||||
role.resetOffsets();
|
||||
initGui();
|
||||
} else if (guibutton.id == 5 && guibutton instanceof GuiNpcButton) {
|
||||
role.setSprintAllowed(((GuiNpcButton) guibutton).getValue() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +99,9 @@ public class GuiNpcMount extends GuiNPCInterface2 implements ITextfieldListener
|
||||
case 2:
|
||||
role.setOffsetZ(value);
|
||||
break;
|
||||
case 3:
|
||||
role.setJumpStrength(value);
|
||||
break;
|
||||
}
|
||||
textfield.setText(format(valueForField(textfield.id)));
|
||||
}
|
||||
@@ -95,6 +114,8 @@ public class GuiNpcMount extends GuiNPCInterface2 implements ITextfieldListener
|
||||
return role.getOffsetY();
|
||||
case 2:
|
||||
return role.getOffsetZ();
|
||||
case 3:
|
||||
return role.getJumpStrength();
|
||||
default:
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
@@ -2091,10 +2091,15 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
protected boolean handleMountedMovement(float strafe, float forward) {
|
||||
if (advanced.role != EnumRoleType.Mount || !(roleInterface instanceof RoleMount))
|
||||
return false;
|
||||
if (!(riddenByEntity instanceof EntityLivingBase))
|
||||
if (riddenByEntity != null && !(riddenByEntity instanceof EntityPlayer)) {
|
||||
riddenByEntity.mountEntity(null);
|
||||
return false;
|
||||
}
|
||||
if (!(riddenByEntity instanceof EntityPlayer))
|
||||
return false;
|
||||
|
||||
EntityLivingBase rider = (EntityLivingBase) riddenByEntity;
|
||||
RoleMount mount = (RoleMount) roleInterface;
|
||||
EntityPlayer rider = (EntityPlayer) riddenByEntity;
|
||||
this.prevRotationYaw = this.rotationYaw = rider.rotationYaw;
|
||||
this.rotationPitch = rider.rotationPitch * 0.5F;
|
||||
this.setRotation(this.rotationYaw, this.rotationPitch);
|
||||
@@ -2108,11 +2113,16 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
}
|
||||
|
||||
float moveSpeed = Math.max(0.1F, getSpeed());
|
||||
if (rider.isSprinting()) {
|
||||
boolean riderSprinting = rider.isSprinting() && mount.isSprintAllowed();
|
||||
if (riderSprinting) {
|
||||
moveSpeed *= 1.2F;
|
||||
}
|
||||
|
||||
this.setSprinting(rider.isSprinting());
|
||||
if (!mount.isSprintAllowed() && rider.isSprinting()) {
|
||||
rider.setSprinting(false);
|
||||
}
|
||||
|
||||
this.setSprinting(riderSprinting);
|
||||
this.stepHeight = 1.0F;
|
||||
this.jumpMovementFactor = moveSpeed * 0.1F;
|
||||
|
||||
@@ -2135,21 +2145,33 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
if (!worldObj.isRemote) {
|
||||
this.setAIMoveSpeed(moveSpeed);
|
||||
super.moveEntityWithHeading(strafe, forward);
|
||||
this.prevLimbSwingAmount = this.limbSwingAmount;
|
||||
double deltaX = this.posX - this.prevPosX;
|
||||
double deltaZ = this.posZ - this.prevPosZ;
|
||||
float limbSwingSpeed = MathHelper.sqrt_double(deltaX * deltaX + deltaZ * deltaZ) * 4.0F;
|
||||
if (limbSwingSpeed > 1.0F) {
|
||||
limbSwingSpeed = 1.0F;
|
||||
}
|
||||
this.limbSwingAmount += (limbSwingSpeed - this.limbSwingAmount) * 0.4F;
|
||||
this.limbSwing += this.limbSwingAmount;
|
||||
}
|
||||
|
||||
this.prevLimbSwingAmount = this.limbSwingAmount;
|
||||
double deltaX = this.posX - this.prevPosX;
|
||||
double deltaZ = this.posZ - this.prevPosZ;
|
||||
if (worldObj.isRemote && deltaX * deltaX + deltaZ * deltaZ < 1.0E-6D) {
|
||||
deltaX = this.motionX;
|
||||
deltaZ = this.motionZ;
|
||||
}
|
||||
float limbSwingSpeed = MathHelper.sqrt_double(deltaX * deltaX + deltaZ * deltaZ) * 4.0F;
|
||||
if (limbSwingSpeed > 1.0F) {
|
||||
limbSwingSpeed = 1.0F;
|
||||
}
|
||||
this.limbSwingAmount += (limbSwingSpeed - this.limbSwingAmount) * 0.4F;
|
||||
this.limbSwing += this.limbSwingAmount;
|
||||
}
|
||||
|
||||
protected void applyMountedVerticalMotion(EntityLivingBase rider, float moveSpeed, float forward) {
|
||||
if (!(roleInterface instanceof RoleMount)) {
|
||||
return;
|
||||
}
|
||||
RoleMount mount = (RoleMount) roleInterface;
|
||||
double jumpFactor = MathHelper.clamp_double(mount.getJumpStrength(), 0.1D, 3.0D);
|
||||
|
||||
if (canFly()) {
|
||||
double vertical = Math.max(0.1D, moveSpeed * 0.6D);
|
||||
double verticalBase = Math.max(0.1D, moveSpeed * 0.6D);
|
||||
double vertical = MathHelper.clamp_double(verticalBase * jumpFactor, 0.05D, 2.0D);
|
||||
if (rider.isJumping) {
|
||||
this.motionY = Math.min(this.motionY + vertical, vertical);
|
||||
this.isAirBorne = true;
|
||||
@@ -2165,7 +2187,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
}
|
||||
}
|
||||
} else if (rider.isJumping && this.onGround) {
|
||||
double jumpVelocity = MathHelper.clamp_double(0.4D + moveSpeed * 1.5D, 0.4D, 0.9D);
|
||||
double baseVelocity = MathHelper.clamp_double(0.4D + moveSpeed * 1.5D, 0.2D, 1.2D);
|
||||
double jumpVelocity = MathHelper.clamp_double(baseVelocity * jumpFactor, 0.2D, 2.0D);
|
||||
this.motionY = jumpVelocity;
|
||||
this.isAirBorne = true;
|
||||
this.velocityChanged = true;
|
||||
@@ -2230,6 +2253,13 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
}
|
||||
|
||||
Entity currentRider = this.riddenByEntity;
|
||||
if (currentRider != null && !(currentRider instanceof EntityPlayer)) {
|
||||
Entity dismount = currentRider;
|
||||
dismount.mountEntity(null);
|
||||
stabilizeDismountedRider(dismount);
|
||||
haltMountedMotion();
|
||||
currentRider = null;
|
||||
}
|
||||
if (currentRider != lastRider) {
|
||||
if (lastRider != null) {
|
||||
stabilizeDismountedRider(lastRider);
|
||||
|
||||
@@ -10,7 +10,12 @@ public class RoleMount extends RoleInterface {
|
||||
private float offsetX;
|
||||
private float offsetY;
|
||||
private float offsetZ;
|
||||
private static final float MIN_JUMP_STRENGTH = 0.1F;
|
||||
private static final float MAX_JUMP_STRENGTH = 3.0F;
|
||||
|
||||
private boolean storedReturnToStart;
|
||||
private float jumpStrength = 1.0F;
|
||||
private boolean allowSprint = true;
|
||||
|
||||
public RoleMount(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
@@ -24,6 +29,8 @@ public class RoleMount extends RoleInterface {
|
||||
compound.setFloat("MountOffsetY", offsetY);
|
||||
compound.setFloat("MountOffsetZ", offsetZ);
|
||||
compound.setBoolean("MountReturnFlag", storedReturnToStart);
|
||||
compound.setFloat("MountJumpStrength", jumpStrength);
|
||||
compound.setBoolean("MountAllowSprint", allowSprint);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -37,6 +44,12 @@ public class RoleMount extends RoleInterface {
|
||||
} else {
|
||||
storedReturnToStart = npc.ais.returnToStart;
|
||||
}
|
||||
if (compound.hasKey("MountJumpStrength")) {
|
||||
setJumpStrength(compound.getFloat("MountJumpStrength"));
|
||||
} else {
|
||||
jumpStrength = 1.0F;
|
||||
}
|
||||
allowSprint = !compound.hasKey("MountAllowSprint") || compound.getBoolean("MountAllowSprint");
|
||||
npc.ais.returnToStart = false;
|
||||
}
|
||||
|
||||
@@ -92,6 +105,22 @@ public class RoleMount extends RoleInterface {
|
||||
return offsetZ;
|
||||
}
|
||||
|
||||
public void setJumpStrength(float value) {
|
||||
this.jumpStrength = ValueUtil.clamp(value, MIN_JUMP_STRENGTH, MAX_JUMP_STRENGTH);
|
||||
}
|
||||
|
||||
public float getJumpStrength() {
|
||||
return jumpStrength;
|
||||
}
|
||||
|
||||
public void setSprintAllowed(boolean allowSprint) {
|
||||
this.allowSprint = allowSprint;
|
||||
}
|
||||
|
||||
public boolean isSprintAllowed() {
|
||||
return allowSprint;
|
||||
}
|
||||
|
||||
public void setReturnToStartPreference(boolean value) {
|
||||
this.storedReturnToStart = value;
|
||||
npc.ais.returnToStart = false;
|
||||
|
||||
Reference in new issue
Block a user