mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 21:32:19 +00:00
Add mount role for NPCs with rider controls
This commit is contained in:
1 parent
082d22ba6e
commit
11e326de48
23 files changed
+476
-6
No files matched your search
@@ -25,6 +25,7 @@ import noppes.npcs.client.gui.roles.GuiNpcFollowerJob;
|
||||
import noppes.npcs.client.gui.roles.GuiNpcGuard;
|
||||
import noppes.npcs.client.gui.roles.GuiNpcHealer;
|
||||
import noppes.npcs.client.gui.roles.GuiNpcSpawner;
|
||||
import noppes.npcs.client.gui.roles.GuiNpcMount;
|
||||
import noppes.npcs.client.gui.roles.GuiNpcTransporter;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface2;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
@@ -47,7 +48,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
|
||||
super.initGui();
|
||||
int y = guiTop + 10;
|
||||
this.addButton(new GuiNpcButton(3, guiLeft + 85 + 160, y, 52, 20, "selectServer.edit"));
|
||||
this.addButton(new GuiNpcButton(8, guiLeft + 85, y, 155, 20, new String[]{"role.none", "role.trader", "role.follower", "role.bank", "role.transporter", "role.mailman", NoppesStringUtils.translate("role.companion", "(WIP)")}, npc.advanced.role.ordinal()));
|
||||
this.addButton(new GuiNpcButton(8, guiLeft + 85, y, 155, 20, new String[]{"role.none", "role.trader", "role.follower", "role.bank", "role.transporter", "role.mailman", NoppesStringUtils.translate("role.companion", "(WIP)"), "role.mount"}, npc.advanced.role.ordinal()));
|
||||
getButton(3).setEnabled(npc.advanced.role != EnumRoleType.None && npc.advanced.role != EnumRoleType.Postman);
|
||||
|
||||
this.addButton(new GuiNpcButton(4, guiLeft + 85 + 160, y += 22, 52, 20, "selectServer.edit"));
|
||||
@@ -148,6 +149,8 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
|
||||
displayGuiScreen(new GuiNpcTransporter(npc));
|
||||
else if (npc.advanced.role == EnumRoleType.Companion)
|
||||
displayGuiScreen(new GuiNpcCompanion(npc));
|
||||
else if (npc.advanced.role == EnumRoleType.Mount)
|
||||
displayGuiScreen(new GuiNpcMount(npc));
|
||||
} else if (compound.hasKey("JobData")) {
|
||||
if (npc.jobInterface != null)
|
||||
npc.jobInterface.readFromNBT(compound);
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package noppes.npcs.client.gui.roles;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.role.RoleSavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface2;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.RoleMount;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class GuiNpcMount extends GuiNPCInterface2 implements ITextfieldListener {
|
||||
|
||||
private final RoleMount role;
|
||||
|
||||
public GuiNpcMount(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
this.role = npc.roleInterface instanceof RoleMount ? (RoleMount) npc.roleInterface : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
if (role == null) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
int y = guiTop + 6;
|
||||
addOffsetRow(0, "role.mount.offsetx", role.getOffsetX(), y);
|
||||
y += 24;
|
||||
addOffsetRow(1, "role.mount.offsety", role.getOffsetY(), y);
|
||||
y += 24;
|
||||
addOffsetRow(2, "role.mount.offsetz", role.getOffsetZ(), y);
|
||||
|
||||
addButton(new GuiNpcButton(3, guiLeft + 4, y + 26, 80, 20, "role.mount.reset"));
|
||||
|
||||
GuiNpcLabel speedLabel = new GuiNpcLabel(4, "", guiLeft + 4, y + 6);
|
||||
speedLabel.label = StatCollector.translateToLocalFormatted("role.mount.walkspeed", npc.ais.getWalkingSpeed());
|
||||
addLabel(speedLabel);
|
||||
}
|
||||
|
||||
private void addOffsetRow(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(-5.0F, 5.0F, 0.0F);
|
||||
addTextField(field);
|
||||
}
|
||||
|
||||
private String format(float value) {
|
||||
return String.format(Locale.ROOT, "%.2f", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (role == null)
|
||||
return;
|
||||
if (guibutton.id == 3) {
|
||||
role.resetOffsets();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textfield) {
|
||||
if (role == null)
|
||||
return;
|
||||
float value = textfield.isFloat() ? textfield.getFloat() : 0.0F;
|
||||
switch (textfield.id) {
|
||||
case 0:
|
||||
role.setOffsetX(value);
|
||||
break;
|
||||
case 1:
|
||||
role.setOffsetY(value);
|
||||
break;
|
||||
case 2:
|
||||
role.setOffsetZ(value);
|
||||
break;
|
||||
}
|
||||
textfield.setText(format(valueForField(textfield.id)));
|
||||
}
|
||||
|
||||
private float valueForField(int id) {
|
||||
switch (id) {
|
||||
case 0:
|
||||
return role.getOffsetX();
|
||||
case 1:
|
||||
return role.getOffsetY();
|
||||
case 2:
|
||||
return role.getOffsetZ();
|
||||
default:
|
||||
return 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
if (role != null) {
|
||||
PacketClient.sendClient(new RoleSavePacket(role.writeToNBT(new NBTTagCompound())));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user