mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Allow /npc equip to work with Striders, fix a bug with /npc look
This commit is contained in:
parent
3ba991e1fc
commit
a16226ccaf
@ -100,7 +100,11 @@ public class EquipmentEditor extends Editor {
|
||||
private static final Map<EntityType, Equipper> EQUIPPERS = Maps.newEnumMap(EntityType.class);
|
||||
|
||||
static {
|
||||
EQUIPPER_GUIS.put(EntityType.PIG, PigEquipperGUI.class);
|
||||
EQUIPPER_GUIS.put(EntityType.PIG, SteerableEquipperGUI.class);
|
||||
try {
|
||||
EQUIPPER_GUIS.put(EntityType.valueOf("STRIDER"), SteerableEquipperGUI.class);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
}
|
||||
EQUIPPER_GUIS.put(EntityType.ENDERMAN, EndermanEquipperGUI.class);
|
||||
EQUIPPERS.put(EntityType.SHEEP, new SheepEquipper());
|
||||
EQUIPPERS.put(EntityType.HORSE, new HorseEquipper());
|
||||
|
@ -33,7 +33,7 @@ import net.citizensnpcs.trait.Saddle;
|
||||
compatMaterial = { "BARRIER", "FIRE" },
|
||||
title = "<4>Unused") },
|
||||
value = "xxx")
|
||||
public class PigEquipperGUI extends InventoryMenuPage {
|
||||
public class SteerableEquipperGUI extends InventoryMenuPage {
|
||||
@InjectContext
|
||||
private NPC npc;
|
||||
@MenuSlot(slot = { 0, 1 })
|
@ -1,6 +1,7 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.Steerable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
@ -8,6 +9,7 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
/**
|
||||
* Persists saddle metadata.
|
||||
@ -16,9 +18,9 @@ import net.citizensnpcs.api.trait.TraitName;
|
||||
*/
|
||||
@TraitName("saddle")
|
||||
public class Saddle extends Trait implements Toggleable {
|
||||
private boolean pig;
|
||||
@Persist("")
|
||||
private boolean saddle;
|
||||
private boolean steerable;
|
||||
|
||||
public Saddle() {
|
||||
super("saddle");
|
||||
@ -26,24 +28,27 @@ public class Saddle extends Trait implements Toggleable {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (pig && npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked())))
|
||||
if (steerable && npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked()))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpawn() {
|
||||
if (npc.getEntity() instanceof Pig) {
|
||||
((Pig) npc.getEntity()).setSaddle(saddle);
|
||||
pig = true;
|
||||
} else
|
||||
pig = false;
|
||||
if (Util.optionalEntitySet("PIG", "STRIDER").contains(npc.getEntity().getType())) {
|
||||
steerable = true;
|
||||
updateSaddleState();
|
||||
} else {
|
||||
steerable = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean toggle() {
|
||||
saddle = !saddle;
|
||||
if (pig)
|
||||
((Pig) npc.getEntity()).setSaddle(saddle);
|
||||
if (steerable) {
|
||||
updateSaddleState();
|
||||
}
|
||||
return saddle;
|
||||
}
|
||||
|
||||
@ -52,7 +57,22 @@ public class Saddle extends Trait implements Toggleable {
|
||||
return "Saddle{" + saddle + "}";
|
||||
}
|
||||
|
||||
private void updateSaddleState() {
|
||||
if (SUPPORT_STEERABLE) {
|
||||
try {
|
||||
((Steerable) npc.getEntity()).setSaddle(saddle);
|
||||
} catch (Throwable t) {
|
||||
SUPPORT_STEERABLE = false;
|
||||
((Pig) npc.getEntity()).setSaddle(saddle);
|
||||
}
|
||||
} else {
|
||||
((Pig) npc.getEntity()).setSaddle(saddle);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean useSaddle() {
|
||||
return saddle;
|
||||
}
|
||||
|
||||
private static boolean SUPPORT_STEERABLE = true;
|
||||
}
|
@ -68,7 +68,7 @@ public class PlayerLookControl {
|
||||
|
||||
protected float getXRotD() {
|
||||
double var0 = this.tx - this.a.getX();
|
||||
double var2 = this.ty - this.a.getEyeY();
|
||||
double var2 = this.ty - (this.a.getY() + this.a.getEyeY());
|
||||
double var4 = this.tz - this.a.getZ();
|
||||
double var6 = Mth.sqrt((float) (var0 * var0 + var4 * var4));
|
||||
return (float) (-(Mth.atan2(var2, var6) * 57.2957763671875D));
|
||||
|
Loading…
Reference in New Issue
Block a user