mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 22:27:32 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
c3651fd6f7
411 files changed
+8252
-2458
No files matched your search
@@ -53,6 +53,10 @@ public class SyncController {
|
||||
|
||||
public static boolean DEBUG_SYNC_LOGGING = false;
|
||||
|
||||
private static final EnumMap<EnumSyncType, SyncCacheEntry> cacheEntries = new EnumMap<>(EnumSyncType.class);
|
||||
private static final ConcurrentHashMap<UUID, PlayerSyncState> playerSyncState = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
private static void debug(String message, Object... args) {
|
||||
if (DEBUG_SYNC_LOGGING) {
|
||||
System.out.println("[SyncController] " + String.format(message, args));
|
||||
@@ -71,10 +75,10 @@ public class SyncController {
|
||||
EnumSyncType.MAGIC_CYCLE
|
||||
};
|
||||
|
||||
private static final EnumMap<EnumSyncType, SyncCacheEntry> CACHE_ENTRIES = new EnumMap<>(EnumSyncType.class);
|
||||
private static final ConcurrentHashMap<UUID, PlayerSyncState> PLAYER_SYNC_STATE = new ConcurrentHashMap<>();
|
||||
public static void load() {
|
||||
cacheEntries.clear();
|
||||
playerSyncState.clear();
|
||||
|
||||
static {
|
||||
registerCache(EnumSyncType.FACTION, SyncController::factionsNBT);
|
||||
registerCache(EnumSyncType.DIALOG_CATEGORY, SyncController::dialogCategoriesNBT);
|
||||
registerCache(EnumSyncType.QUEST_CATEGORY, SyncController::questCategoriesNBT);
|
||||
@@ -87,14 +91,14 @@ public class SyncController {
|
||||
}
|
||||
|
||||
public static void syncPlayer(EntityPlayerMP player) {
|
||||
syncPlayer(player, true);
|
||||
SyncController.syncPlayerInternal(player, true);
|
||||
}
|
||||
|
||||
private static void syncPlayer(EntityPlayerMP player, boolean includePostPackets) {
|
||||
PlayerSyncState state = PLAYER_SYNC_STATE.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new);
|
||||
private static void syncPlayerInternal(EntityPlayerMP player, boolean includePostPackets) {
|
||||
PlayerSyncState state = playerSyncState.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new);
|
||||
|
||||
for (EnumSyncType type : LOGIN_SYNC_TYPES) {
|
||||
SyncCacheEntry entry = CACHE_ENTRIES.get(type);
|
||||
SyncCacheEntry entry = cacheEntries.get(type);
|
||||
if (entry == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -123,7 +127,7 @@ public class SyncController {
|
||||
}
|
||||
|
||||
public static void beginLogin(EntityPlayerMP player) {
|
||||
PLAYER_SYNC_STATE.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new);
|
||||
playerSyncState.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new);
|
||||
PacketHandler.Instance.sendToPlayer(
|
||||
new LoginPacket(getServerCacheKey(), getServerRevisionSnapshot()),
|
||||
player
|
||||
@@ -137,7 +141,7 @@ public class SyncController {
|
||||
Map<EnumSyncType, Integer> clientRevisions
|
||||
) {
|
||||
String currentServerKey = getServerCacheKey();
|
||||
PlayerSyncState state = PLAYER_SYNC_STATE.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new);
|
||||
PlayerSyncState state = playerSyncState.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new);
|
||||
|
||||
if (!currentServerKey.equals(serverKey)) {
|
||||
state.reset();
|
||||
@@ -175,7 +179,7 @@ public class SyncController {
|
||||
private static EnumMap<EnumSyncType, Integer> getServerRevisionSnapshot() {
|
||||
EnumMap<EnumSyncType, Integer> snapshot = new EnumMap<>(EnumSyncType.class);
|
||||
for (EnumSyncType type : LOGIN_SYNC_TYPES) {
|
||||
SyncCacheEntry entry = CACHE_ENTRIES.get(type);
|
||||
SyncCacheEntry entry = cacheEntries.get(type);
|
||||
if (entry != null) {
|
||||
snapshot.put(type, entry.getRevisionValue());
|
||||
}
|
||||
@@ -199,7 +203,7 @@ public class SyncController {
|
||||
}
|
||||
|
||||
public static int getCurrentRevision(EnumSyncType type) {
|
||||
SyncCacheEntry entry = CACHE_ENTRIES.get(type);
|
||||
SyncCacheEntry entry = cacheEntries.get(type);
|
||||
return entry == null ? -1 : entry.getRevisionValue();
|
||||
}
|
||||
|
||||
@@ -792,11 +796,11 @@ public class SyncController {
|
||||
}
|
||||
|
||||
private static void registerCache(EnumSyncType type, Supplier<NBTTagCompound> supplier) {
|
||||
CACHE_ENTRIES.put(type, new SyncCacheEntry(type, supplier));
|
||||
cacheEntries.put(type, new SyncCacheEntry(type, supplier));
|
||||
}
|
||||
|
||||
private static CachedSyncPayload rebuildNow(EnumSyncType type) {
|
||||
SyncCacheEntry entry = CACHE_ENTRIES.get(type);
|
||||
SyncCacheEntry entry = cacheEntries.get(type);
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -808,7 +812,7 @@ public class SyncController {
|
||||
EnumSet<EnumSyncType> targets = getInvalidationTargets(type);
|
||||
EnumMap<EnumSyncType, Integer> revisions = new EnumMap<>(EnumSyncType.class);
|
||||
for (EnumSyncType target : targets) {
|
||||
SyncCacheEntry entry = CACHE_ENTRIES.get(target);
|
||||
SyncCacheEntry entry = cacheEntries.get(target);
|
||||
if (entry != null) {
|
||||
int newRevision = entry.invalidate();
|
||||
revisions.put(target, newRevision);
|
||||
@@ -848,7 +852,7 @@ public class SyncController {
|
||||
if (revision < 0) {
|
||||
return;
|
||||
}
|
||||
for (PlayerSyncState state : PLAYER_SYNC_STATE.values()) {
|
||||
for (PlayerSyncState state : playerSyncState.values()) {
|
||||
state.updateRevision(type, revision);
|
||||
}
|
||||
}
|
||||
@@ -857,7 +861,7 @@ public class SyncController {
|
||||
if (revisions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (PlayerSyncState state : PLAYER_SYNC_STATE.values()) {
|
||||
for (PlayerSyncState state : playerSyncState.values()) {
|
||||
for (Map.Entry<EnumSyncType, Integer> entry : revisions.entrySet()) {
|
||||
state.updateRevision(entry.getKey(), entry.getValue());
|
||||
}
|
||||
@@ -939,6 +943,12 @@ public class SyncController {
|
||||
return revision;
|
||||
}
|
||||
|
||||
private synchronized void reset() {
|
||||
dirty = true;
|
||||
payload = null;
|
||||
revision = 0;
|
||||
}
|
||||
|
||||
private static byte[][] splitIntoChunks(byte[] payload) {
|
||||
int totalSize = payload.length;
|
||||
int chunkCount = (totalSize + LargeAbstractPacket.CHUNK_SIZE - 1) / LargeAbstractPacket.CHUNK_SIZE;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package kamkeel.npcs.network.packets.player;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import kamkeel.npcs.network.LargeAbstractPacket;
|
||||
@@ -52,7 +50,6 @@ public class SaveBookPacket extends LargeAbstractPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
|
||||
int x = data.readInt(), y = data.readInt(), z = data.readInt();
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import kamkeel.npcs.command.CommandKamkeel;
|
||||
import kamkeel.npcs.command.profile.CommandProfile;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
||||
import kamkeel.npcs.developer.Developer;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
@@ -310,6 +311,7 @@ public class CustomNpcs {
|
||||
ScriptController.HasStart = true;
|
||||
ServerCloneController.Instance = new ServerCloneController();
|
||||
ServerTagMapController.Instance = new ServerTagMapController();
|
||||
SyncController.load();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import noppes.npcs.roles.JobSpawner;
|
||||
import noppes.npcs.roles.RoleBank;
|
||||
import noppes.npcs.roles.RoleCompanion;
|
||||
import noppes.npcs.roles.RoleFollower;
|
||||
import noppes.npcs.roles.RoleMount;
|
||||
import noppes.npcs.roles.RolePostman;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
import noppes.npcs.roles.RoleTransporter;
|
||||
@@ -196,7 +197,11 @@ public class DataAdvanced {
|
||||
if (EnumRoleType.values().length <= i) {
|
||||
i -= 2;
|
||||
}
|
||||
role = EnumRoleType.values()[i];
|
||||
EnumRoleType newRole = EnumRoleType.values()[i];
|
||||
if (npc.roleInterface instanceof RoleMount && newRole != EnumRoleType.Mount) {
|
||||
((RoleMount) npc.roleInterface).onDisable();
|
||||
}
|
||||
role = newRole;
|
||||
if (role == EnumRoleType.None)
|
||||
npc.roleInterface = null;
|
||||
else if (role == EnumRoleType.Bank && !(npc.roleInterface instanceof RoleBank))
|
||||
@@ -211,6 +216,8 @@ public class DataAdvanced {
|
||||
npc.roleInterface = new RoleTransporter(npc);
|
||||
else if (role == EnumRoleType.Companion && !(npc.roleInterface instanceof RoleCompanion))
|
||||
npc.roleInterface = new RoleCompanion(npc);
|
||||
else if (role == EnumRoleType.Mount && !(npc.roleInterface instanceof RoleMount))
|
||||
npc.roleInterface = new RoleMount(npc);
|
||||
}
|
||||
|
||||
public void setJob(int i) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
@@ -546,7 +547,7 @@ public class ScriptPlayerEventHandler {
|
||||
if (event.source.getEntity() instanceof EntityPlayerMP) {
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) event.source.getEntity());
|
||||
float attackAmount = event.ammount;
|
||||
if (ConfigMain.AttributesEnabled)
|
||||
if (ConfigMain.AttributesEnabled && !DBCAddon.IsAvailable())
|
||||
attackAmount = AttributeAttackUtil.calculateOutgoing((EntityPlayer) event.source.getEntity(), attackAmount);
|
||||
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.AttackEvent pevent1 = new noppes.npcs.scripted.event.player.PlayerEvent.AttackEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.source.getEntity()), event.entityLiving, attackAmount, event.source);
|
||||
@@ -565,7 +566,7 @@ public class ScriptPlayerEventHandler {
|
||||
boolean cancel = event.isCanceled();
|
||||
Entity source = NoppesUtilServer.GetDamageSource(event.source);
|
||||
// Player to Player Interaction
|
||||
if (ConfigMain.AttributesEnabled) {
|
||||
if (ConfigMain.AttributesEnabled && !DBCAddon.IsAvailable()) {
|
||||
if (event.entityLiving instanceof EntityPlayerMP && source instanceof EntityPlayerMP) {
|
||||
event.ammount = AttributeAttackUtil.calculateDamagePlayerToPlayer((EntityPlayer) source, (EntityPlayer) event.entityLiving, event.ammount);
|
||||
} else if (!(event.entityLiving instanceof EntityNPCInterface) && source instanceof EntityPlayer) {
|
||||
|
||||
@@ -70,7 +70,6 @@ public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements GuiYesNo
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int i, int j, int k) {
|
||||
;
|
||||
super.mouseClicked(i, j, k);
|
||||
if (k == 0 && playerScroll != null)
|
||||
playerScroll.mouseClicked(i, j, k);
|
||||
@@ -132,11 +131,10 @@ public class GuiNpcManagePlayerData extends GuiNPCInterface2 implements GuiYesNo
|
||||
}
|
||||
if (id == 1) {
|
||||
PacketClient.sendClient(new PlayerDataMapRegenPacket());
|
||||
close();
|
||||
}
|
||||
} else {
|
||||
displayGuiScreen(this);
|
||||
}
|
||||
|
||||
displayGuiScreen(this);
|
||||
}
|
||||
|
||||
// IScrollData interface.
|
||||
|
||||
@@ -15,7 +15,9 @@ import noppes.npcs.client.gui.util.IGuiData;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.constants.EnumCombatPolicy;
|
||||
import noppes.npcs.constants.EnumNavType;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.RoleMount;
|
||||
|
||||
public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IGuiData {
|
||||
private DataAI ai;
|
||||
@@ -44,7 +46,12 @@ public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IG
|
||||
addLabel(new GuiNpcLabel(10, "ai.avoidwater", guiLeft + 150, guiTop + 17));
|
||||
addButton(new GuiNpcButton(5, guiLeft + 230, guiTop + 10, 60, 20, new String[]{"gui.no", "gui.yes"}, npc.ais.avoidsWater ? 1 : 0));
|
||||
addLabel(new GuiNpcLabel(11, "ai.return", guiLeft + 150, guiTop + 40));
|
||||
addButton(new GuiNpcButton(6, guiLeft + 230, guiTop + 35, 60, 20, new String[]{"gui.no", "gui.yes"}, npc.ais.returnToStart ? 1 : 0));
|
||||
int returnValue = npc.ais.returnToStart ? 1 : 0;
|
||||
if (npc.advanced.role == EnumRoleType.Mount && npc.roleInterface instanceof RoleMount) {
|
||||
returnValue = ((RoleMount) npc.roleInterface).getReturnToStartPreference() ? 1 : 0;
|
||||
}
|
||||
addButton(new GuiNpcButton(6, guiLeft + 230, guiTop + 35, 60, 20, new String[]{"gui.no", "gui.yes"}, returnValue));
|
||||
getButton(6).setEnabled(npc.advanced.role != EnumRoleType.Mount);
|
||||
addLabel(new GuiNpcLabel(17, "ai.leapattarget", guiLeft + 150, guiTop + 65));
|
||||
addButton(new GuiNpcButton(15, guiLeft + 230, guiTop + 60, 60, 20, new String[]{"gui.no", "ai.jump", "ai.pounce"}, npc.ais.leapType));
|
||||
addLabel(new GuiNpcLabel(15, "ai.indirect", guiLeft + 150, guiTop + 90));
|
||||
@@ -132,7 +139,13 @@ public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IG
|
||||
} else if (button.id == 5) {
|
||||
npc.setAvoidWater(button.getValue() == 1);
|
||||
} else if (button.id == 6) {
|
||||
ai.returnToStart = (button.getValue() == 1);
|
||||
if (npc.advanced.role == EnumRoleType.Mount && npc.roleInterface instanceof RoleMount) {
|
||||
((RoleMount) npc.roleInterface).setReturnToStartPreference(button.getValue() == 1);
|
||||
ai.returnToStart = false;
|
||||
initGui();
|
||||
} else {
|
||||
ai.returnToStart = (button.getValue() == 1);
|
||||
}
|
||||
} else if (button.id == 7) {
|
||||
ai.canSwim = (button.getValue() == 1);
|
||||
} else if (button.id == 9) {
|
||||
|
||||
@@ -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,130 @@
|
||||
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);
|
||||
y += 24;
|
||||
addJumpRow(3, "role.mount.jumpheight", role.getJumpStrength(), y);
|
||||
y += 24;
|
||||
|
||||
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));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 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, 15.0F, 1.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 == 4) {
|
||||
role.resetOffsets();
|
||||
initGui();
|
||||
} else if (guibutton.id == 5 && guibutton instanceof GuiNpcButton) {
|
||||
role.setSprintAllowed(((GuiNpcButton) guibutton).getValue() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
case 3:
|
||||
role.setJumpStrength(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();
|
||||
case 3:
|
||||
return role.getJumpStrength();
|
||||
default:
|
||||
return 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
if (role != null) {
|
||||
PacketClient.sendClient(new RoleSavePacket(role.writeToNBT(new NBTTagCompound())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,6 +219,9 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if(GuiNpcTextField.activeTextfield != null)
|
||||
GuiNpcTextField.unfocus();
|
||||
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
displayGuiScreen(null);
|
||||
mc.setIngameFocus();
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class GuiNPCInterface2 extends GuiNPCInterface {
|
||||
xSize = 420;
|
||||
ySize = 200;
|
||||
menu = new GuiNpcMenu(this, activeMenu, npc);
|
||||
|
||||
closeOnEsc = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.client.renderer.entity.RenderBiped;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
@@ -229,7 +230,8 @@ public class RenderNPCHumanMale extends RenderNPCInterface {
|
||||
GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
|
||||
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glScalef(-var6, -var6, var6);
|
||||
} else if (itemstack2.getItem() instanceof ItemBow && (customRenderer == null || pluginMod)) {
|
||||
} else if ((itemstack2.getItem() != null && itemstack2.getItem() == Items.bow) ||
|
||||
(itemstack2.getItem() instanceof ItemBow && (customRenderer == null || pluginMod))) {
|
||||
var6 = 0.625F;
|
||||
GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
|
||||
GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
|
||||
@@ -322,7 +324,8 @@ public class RenderNPCHumanMale extends RenderNPCInterface {
|
||||
GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
|
||||
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
|
||||
GL11.glScalef(var6, -var6, var6);
|
||||
} else if (itemstack2.getItem() instanceof ItemBow && (customRenderer == null || pluginMod)) {
|
||||
} else if ((itemstack2.getItem() != null && itemstack2.getItem() == Items.bow) ||
|
||||
(itemstack2.getItem() instanceof ItemBow && (customRenderer == null || pluginMod))) {
|
||||
var6 = 0.625F;
|
||||
GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
|
||||
GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
|
||||
|
||||
@@ -2,5 +2,5 @@ package noppes.npcs.constants;
|
||||
|
||||
public enum EnumRoleType {
|
||||
|
||||
None, Trader, Follower, Bank, Transporter, Postman, Companion
|
||||
None, Trader, Follower, Bank, Transporter, Postman, Companion, Mount
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
|
||||
@Override
|
||||
public boolean isTerminated() {
|
||||
return terminateWhen != null && terminateWhen.apply(this);
|
||||
return checkTermination();
|
||||
}
|
||||
|
||||
public void inheritedTick() {
|
||||
@@ -107,10 +107,10 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
checkCount++;
|
||||
|
||||
Runnable execute = () -> {
|
||||
if (condition != null && condition.apply(this))
|
||||
if (evaluatePredicate(condition, "Condition"))
|
||||
executeTask();
|
||||
|
||||
if (isTerminated()) {
|
||||
if (checkTermination()) {
|
||||
if (onTermination != null)
|
||||
executeOnTermination();
|
||||
markDone();
|
||||
@@ -153,6 +153,32 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
manager.LOGGER.log("Finished executing onTermination task", this);
|
||||
}
|
||||
|
||||
private boolean checkTermination() {
|
||||
return evaluatePredicate(terminateWhen, "Termination condition");
|
||||
}
|
||||
|
||||
private boolean evaluatePredicate(Function<IAction, Boolean> predicate, String name) {
|
||||
if (predicate == null)
|
||||
return false;
|
||||
|
||||
Boolean result;
|
||||
try {
|
||||
result = predicate.apply(this);
|
||||
} catch (Throwable t) {
|
||||
manager.LOGGER.error(name + " of " + this + " threw an exception:", t);
|
||||
markDone();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
if (manager.inDebugMode())
|
||||
manager.LOGGER.log(name + " returned null; treating as false", this);
|
||||
return false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return String.format("%s [queue='%s', scheduled=%s, done=%s, paused=%s, updateEvery=%s, duration=%d/%d, count=%d/%d, checks=%d/%d, taskExecuted=%s, threaded=%s]", getIdentifier(), getQueueName(),
|
||||
|
||||
@@ -40,7 +40,10 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
|
||||
super.onLivingUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveEntityWithHeading(float p_70612_1_, float p_70612_2_) {
|
||||
if (handleMountedMovement(p_70612_1_, p_70612_2_))
|
||||
return;
|
||||
if (!this.canFly() || this.hurtTime != 0 || !this.canBreathe()) {
|
||||
super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
|
||||
return;
|
||||
@@ -92,4 +95,46 @@ public abstract class EntityNPCFlying extends EntityNPCInterface {
|
||||
this.limbSwingAmount += (distance - this.limbSwingAmount) * 0.4F;
|
||||
this.limbSwing += this.limbSwingAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doMountedMovement(float strafe, float forward, float moveSpeed) {
|
||||
if (!this.canFly() || this.hurtTime != 0 || !this.canBreathe()) {
|
||||
super.doMountedMovement(strafe, forward, moveSpeed);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean aboveLimit = false;
|
||||
double heightOffGround = this.posY - this.worldObj.getTopSolidOrLiquidBlock((int) this.posX, (int) this.posZ);
|
||||
if (heightOffGround < 0) {
|
||||
Vec3 pos = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
|
||||
Vec3 posLimit = Vec3.createVectorHelper(this.posX, this.posY - this.ais.flyHeightLimit, this.posZ);
|
||||
MovingObjectPosition mob = this.worldObj.rayTraceBlocks(pos, posLimit, true);
|
||||
if (mob == null || mob.typeOfHit == MovingObjectPosition.MovingObjectType.MISS) {
|
||||
aboveLimit = true;
|
||||
}
|
||||
} else if (heightOffGround > this.ais.flyHeightLimit) {
|
||||
aboveLimit = true;
|
||||
}
|
||||
if (aboveLimit && this.ais.hasFlyLimit || (heightOffGround < Math.ceil(this.height) && this.motionY == 0)) {
|
||||
this.flyLimitAllow = false;
|
||||
if (!this.getNavigator().noPath() && this.motionY > 0) {
|
||||
this.motionY = 0;
|
||||
} else {
|
||||
super.doMountedMovement(strafe, forward, moveSpeed);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.flyLimitAllow = true;
|
||||
|
||||
double d3 = this.motionY;
|
||||
super.doMountedMovement(strafe, forward, moveSpeed);
|
||||
this.motionY = d3;
|
||||
|
||||
if (this.getNavigator().noPath()) {
|
||||
this.motionY = -Math.abs(this.ais.flyGravity);
|
||||
}
|
||||
|
||||
this.updateLimbSwing();
|
||||
this.velocityChanged = true;
|
||||
}
|
||||
}
|
||||
@@ -65,8 +65,10 @@ import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
@@ -152,6 +154,7 @@ import noppes.npcs.roles.JobFollower;
|
||||
import noppes.npcs.roles.JobInterface;
|
||||
import noppes.npcs.roles.RoleCompanion;
|
||||
import noppes.npcs.roles.RoleFollower;
|
||||
import noppes.npcs.roles.RoleMount;
|
||||
import noppes.npcs.roles.RoleInterface;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.entity.ScriptNpc;
|
||||
@@ -208,6 +211,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
|
||||
public ResourceLocation textureLocation = null;
|
||||
|
||||
private Entity lastRider;
|
||||
|
||||
public EnumAnimation currentAnimation = EnumAnimation.NONE;
|
||||
|
||||
public int npcVersion = VersionCompatibility.ModRev;
|
||||
@@ -468,6 +473,8 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
|
||||
super.onLivingUpdate();
|
||||
|
||||
handleMountRiderState();
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
if (roleInterface != null) {
|
||||
roleInterface.clientUpdate();
|
||||
@@ -1478,10 +1485,14 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
this.spawnExplosionParticle();
|
||||
delete();
|
||||
} else {
|
||||
if (this.riddenByEntity != null)
|
||||
if (this.riddenByEntity != null) {
|
||||
stabilizeDismountedRider(this.riddenByEntity);
|
||||
this.riddenByEntity.mountEntity(null);
|
||||
haltMountedMotion();
|
||||
}
|
||||
if (this.ridingEntity != null)
|
||||
this.mountEntity(null);
|
||||
lastRider = null;
|
||||
setHealth(-1);
|
||||
setSprinting(false);
|
||||
getNavigator().clearPathEntity();
|
||||
@@ -1753,6 +1764,11 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
roleInterface.writeToNBT(bard);
|
||||
compound.setTag("Companion", bard);
|
||||
}
|
||||
if (advanced.role == EnumRoleType.Mount) {
|
||||
NBTTagCompound mount = new NBTTagCompound();
|
||||
roleInterface.writeToNBT(mount);
|
||||
compound.setTag("Mount", mount);
|
||||
}
|
||||
|
||||
if (this instanceof EntityCustomNpc) {
|
||||
compound.setTag("ModelData", ((EntityCustomNpc) this).modelData.writeToNBT());
|
||||
@@ -1790,6 +1806,10 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
NBTTagCompound companion = compound.getCompoundTag("Companion");
|
||||
roleInterface.readFromNBT(companion);
|
||||
}
|
||||
if (advanced.role == EnumRoleType.Mount) {
|
||||
NBTTagCompound mount = compound.getCompoundTag("Mount");
|
||||
roleInterface.readFromNBT(mount);
|
||||
}
|
||||
if (this instanceof EntityCustomNpc) {
|
||||
((EntityCustomNpc) this).modelData.readFromNBT(compound.getCompoundTag("ModelData"));
|
||||
}
|
||||
@@ -2056,15 +2076,132 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveEntityWithHeading(float p_70612_1_, float p_70612_2_) {
|
||||
public void moveEntityWithHeading(float strafe, float forward) {
|
||||
if (handleMountedMovement(strafe, forward)) {
|
||||
return;
|
||||
}
|
||||
double d0 = this.posX;
|
||||
double d1 = this.posY;
|
||||
double d2 = this.posZ;
|
||||
super.moveEntityWithHeading(p_70612_1_, p_70612_2_);
|
||||
super.moveEntityWithHeading(strafe, forward);
|
||||
if (advanced.role == EnumRoleType.Companion && !isRemote())
|
||||
((RoleCompanion) roleInterface).addMovementStat(this.posX - d0, this.posY - d1, this.posZ - d2);
|
||||
}
|
||||
|
||||
protected boolean handleMountedMovement(float strafe, float forward) {
|
||||
if (advanced.role != EnumRoleType.Mount || !(roleInterface instanceof RoleMount))
|
||||
return false;
|
||||
if (riddenByEntity != null && !(riddenByEntity instanceof EntityPlayer)) {
|
||||
riddenByEntity.mountEntity(null);
|
||||
return false;
|
||||
}
|
||||
if (!(riddenByEntity instanceof EntityPlayer))
|
||||
return false;
|
||||
|
||||
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);
|
||||
this.renderYawOffset = this.rotationYaw;
|
||||
this.rotationYawHead = this.rotationYaw;
|
||||
|
||||
float controlledStrafe = rider.moveStrafing * 0.5F;
|
||||
float controlledForward = rider.moveForward;
|
||||
if (controlledForward <= 0.0F) {
|
||||
controlledForward *= 0.25F;
|
||||
}
|
||||
|
||||
float moveSpeed = Math.max(0.1F, getSpeed());
|
||||
boolean riderSprinting = rider.isSprinting() && mount.isSprintAllowed();
|
||||
if (riderSprinting) {
|
||||
moveSpeed *= 1.2F;
|
||||
}
|
||||
|
||||
if (!mount.isSprintAllowed() && rider.isSprinting()) {
|
||||
rider.setSprinting(false);
|
||||
}
|
||||
|
||||
this.setSprinting(riderSprinting);
|
||||
this.stepHeight = 1.0F;
|
||||
this.jumpMovementFactor = moveSpeed * 0.1F;
|
||||
|
||||
this.getNavigator().clearPathEntity();
|
||||
this.setAttackTarget(null);
|
||||
this.setRevengeTarget(null);
|
||||
|
||||
this.fallDistance = 0.0F;
|
||||
rider.fallDistance = 0.0F;
|
||||
|
||||
applyMountedVerticalMotion(rider, moveSpeed, controlledForward);
|
||||
doMountedMovement(controlledStrafe, controlledForward, moveSpeed);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doMountedMovement(float strafe, float forward, float moveSpeed) {
|
||||
this.moveStrafing = strafe;
|
||||
this.moveForward = forward;
|
||||
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;
|
||||
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 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;
|
||||
this.velocityChanged = true;
|
||||
} else {
|
||||
float pitch = rider.rotationPitch;
|
||||
if (pitch < -10F) {
|
||||
this.motionY = vertical;
|
||||
} else if (pitch > 10F) {
|
||||
this.motionY = -vertical;
|
||||
} else if (!this.onGround) {
|
||||
this.motionY *= 0.6D;
|
||||
}
|
||||
}
|
||||
} else if (rider.isJumping && this.onGround) {
|
||||
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;
|
||||
if (forward > 0.0F) {
|
||||
float yawRadians = this.rotationYaw * (float) Math.PI / 180.0F;
|
||||
double boost = 0.4D * forward;
|
||||
this.motionX += -MathHelper.sin(yawRadians) * boost;
|
||||
this.motionZ += MathHelper.cos(yawRadians) * boost;
|
||||
}
|
||||
ForgeHooks.onLivingJump(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowLeashing() {
|
||||
return false;
|
||||
@@ -2075,6 +2212,101 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRiderPosition() {
|
||||
if (advanced.role == EnumRoleType.Mount && roleInterface instanceof RoleMount && riddenByEntity != null) {
|
||||
RoleMount mount = (RoleMount) roleInterface;
|
||||
double scale = Math.max(0.1D, this.display.modelSize / 5.0D);
|
||||
Vec3 seat = Vec3.createVectorHelper(mount.getOffsetX(), 0.0D, mount.getOffsetZ() + (0.8D * scale));
|
||||
seat.rotateAroundY((float) Math.toRadians(-this.renderYawOffset));
|
||||
double px = this.posX + seat.xCoord;
|
||||
double py = this.posY + this.getMountedYOffset() + riddenByEntity.getYOffset() + mount.getOffsetY();
|
||||
double pz = this.posZ + seat.zCoord;
|
||||
|
||||
riddenByEntity.setPosition(px, py, pz);
|
||||
|
||||
if (riddenByEntity instanceof EntityLivingBase) {
|
||||
EntityLivingBase rider = (EntityLivingBase) riddenByEntity;
|
||||
rider.prevRotationPitch = rider.rotationPitch;
|
||||
rider.prevRotationYaw = rider.rotationYaw;
|
||||
rider.prevRenderYawOffset = this.renderYawOffset;
|
||||
rider.renderYawOffset = this.renderYawOffset;
|
||||
rider.prevRotationYawHead = this.renderYawOffset;
|
||||
rider.rotationYawHead = this.renderYawOffset;
|
||||
}
|
||||
} else {
|
||||
super.updateRiderPosition();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMountRiderState() {
|
||||
if (worldObj.isRemote) {
|
||||
if (advanced.role != EnumRoleType.Mount || !(roleInterface instanceof RoleMount)) {
|
||||
lastRider = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (advanced.role != EnumRoleType.Mount || !(roleInterface instanceof RoleMount)) {
|
||||
lastRider = null;
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
haltMountedMotion();
|
||||
}
|
||||
lastRider = currentRider;
|
||||
}
|
||||
}
|
||||
|
||||
private void stabilizeDismountedRider(Entity rider) {
|
||||
boolean wasOnGround = rider.onGround;
|
||||
double previousMotionX = rider.motionX;
|
||||
double previousMotionY = rider.motionY;
|
||||
double previousMotionZ = rider.motionZ;
|
||||
float previousFall = rider.fallDistance;
|
||||
|
||||
if (wasOnGround) {
|
||||
rider.motionX = 0.0D;
|
||||
rider.motionY = 0.0D;
|
||||
rider.motionZ = 0.0D;
|
||||
rider.fallDistance = 0.0F;
|
||||
rider.onGround = true;
|
||||
} else {
|
||||
rider.motionX = previousMotionX;
|
||||
rider.motionY = previousMotionY;
|
||||
rider.motionZ = previousMotionZ;
|
||||
rider.fallDistance = previousFall;
|
||||
}
|
||||
|
||||
rider.velocityChanged = true;
|
||||
}
|
||||
|
||||
private void haltMountedMotion() {
|
||||
this.motionX = 0.0D;
|
||||
this.motionY = 0.0D;
|
||||
this.motionZ = 0.0D;
|
||||
this.velocityChanged = true;
|
||||
this.isAirBorne = false;
|
||||
this.setSprinting(false);
|
||||
this.moveForward = 0.0F;
|
||||
this.moveStrafing = 0.0F;
|
||||
this.setAIMoveSpeed(0.0F);
|
||||
this.limbSwingAmount = 0.0F;
|
||||
this.limbSwing = 0.0F;
|
||||
this.getNavigator().clearPathEntity();
|
||||
}
|
||||
|
||||
// Model Types: 0: Steve 64x32, 1: Steve 64x64, 2: Alex 64x64
|
||||
public int getModelType() {
|
||||
return this.display.modelType;
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
package noppes.npcs.roles;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
|
||||
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);
|
||||
this.storedReturnToStart = npc.ais.returnToStart;
|
||||
npc.ais.returnToStart = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setFloat("MountOffsetX", offsetX);
|
||||
compound.setFloat("MountOffsetY", offsetY);
|
||||
compound.setFloat("MountOffsetZ", offsetZ);
|
||||
compound.setBoolean("MountReturnFlag", storedReturnToStart);
|
||||
compound.setFloat("MountJumpStrength", jumpStrength);
|
||||
compound.setBoolean("MountAllowSprint", allowSprint);
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
setOffsetX(compound.getFloat("MountOffsetX"));
|
||||
setOffsetY(compound.getFloat("MountOffsetY"));
|
||||
setOffsetZ(compound.getFloat("MountOffsetZ"));
|
||||
if (compound.hasKey("MountReturnFlag")) {
|
||||
storedReturnToStart = compound.getBoolean("MountReturnFlag");
|
||||
} 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interact(EntityPlayer player) {
|
||||
if (player == null || npc.worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
if (npc.riddenByEntity != null && npc.riddenByEntity != player) {
|
||||
return;
|
||||
}
|
||||
if (player.ridingEntity != null && player.ridingEntity != npc) {
|
||||
player.mountEntity(null);
|
||||
}
|
||||
player.fallDistance = 0.0F;
|
||||
npc.fallDistance = 0.0F;
|
||||
player.mountEntity(npc);
|
||||
npc.getNavigator().clearPathEntity();
|
||||
npc.setAttackTarget(null);
|
||||
npc.setRevengeTarget(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean aiShouldExecute() {
|
||||
if (npc.ais.returnToStart) {
|
||||
storedReturnToStart = true;
|
||||
npc.ais.returnToStart = false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setOffsetX(float value) {
|
||||
this.offsetX = clamp(value);
|
||||
}
|
||||
|
||||
public void setOffsetY(float value) {
|
||||
this.offsetY = clamp(value);
|
||||
}
|
||||
|
||||
public void setOffsetZ(float value) {
|
||||
this.offsetZ = clamp(value);
|
||||
}
|
||||
|
||||
public float getOffsetX() {
|
||||
return offsetX;
|
||||
}
|
||||
|
||||
public float getOffsetY() {
|
||||
return offsetY;
|
||||
}
|
||||
|
||||
public float getOffsetZ() {
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean getReturnToStartPreference() {
|
||||
return storedReturnToStart;
|
||||
}
|
||||
|
||||
private float clamp(float value) {
|
||||
return ValueUtil.clamp(value, -5.0F, 5.0F);
|
||||
}
|
||||
|
||||
public void resetOffsets() {
|
||||
offsetX = 0.0F;
|
||||
offsetY = 0.0F;
|
||||
offsetZ = 0.0F;
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
npc.ais.returnToStart = storedReturnToStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete() {
|
||||
onDisable();
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import noppes.npcs.controllers.data.DialogOption;
|
||||
import noppes.npcs.controllers.data.Line;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.RoleMount;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.constants.AnimationType;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
@@ -269,13 +270,20 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
* @param bo Whether or not the npc will try to return to his home position
|
||||
*/
|
||||
public void setReturnToHome(boolean bo) {
|
||||
npc.ais.returnToStart = bo;
|
||||
if (npc.advanced.role == EnumRoleType.Mount && npc.roleInterface instanceof RoleMount) {
|
||||
((RoleMount) npc.roleInterface).setReturnToStartPreference(bo);
|
||||
} else {
|
||||
npc.ais.returnToStart = bo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Whether or not the npc returns home
|
||||
*/
|
||||
public boolean getReturnToHome() {
|
||||
if (npc.advanced.role == EnumRoleType.Mount && npc.roleInterface instanceof RoleMount) {
|
||||
return ((RoleMount) npc.roleInterface).getReturnToStartPreference();
|
||||
}
|
||||
return npc.ais.returnToStart;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user