mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-16 20:31:30 +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);
|
private static final Map<EntityType, Equipper> EQUIPPERS = Maps.newEnumMap(EntityType.class);
|
||||||
|
|
||||||
static {
|
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);
|
EQUIPPER_GUIS.put(EntityType.ENDERMAN, EndermanEquipperGUI.class);
|
||||||
EQUIPPERS.put(EntityType.SHEEP, new SheepEquipper());
|
EQUIPPERS.put(EntityType.SHEEP, new SheepEquipper());
|
||||||
EQUIPPERS.put(EntityType.HORSE, new HorseEquipper());
|
EQUIPPERS.put(EntityType.HORSE, new HorseEquipper());
|
||||||
|
@ -33,7 +33,7 @@ import net.citizensnpcs.trait.Saddle;
|
|||||||
compatMaterial = { "BARRIER", "FIRE" },
|
compatMaterial = { "BARRIER", "FIRE" },
|
||||||
title = "<4>Unused") },
|
title = "<4>Unused") },
|
||||||
value = "xxx")
|
value = "xxx")
|
||||||
public class PigEquipperGUI extends InventoryMenuPage {
|
public class SteerableEquipperGUI extends InventoryMenuPage {
|
||||||
@InjectContext
|
@InjectContext
|
||||||
private NPC npc;
|
private NPC npc;
|
||||||
@MenuSlot(slot = { 0, 1 })
|
@MenuSlot(slot = { 0, 1 })
|
@ -1,6 +1,7 @@
|
|||||||
package net.citizensnpcs.trait;
|
package net.citizensnpcs.trait;
|
||||||
|
|
||||||
import org.bukkit.entity.Pig;
|
import org.bukkit.entity.Pig;
|
||||||
|
import org.bukkit.entity.Steerable;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
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.persistence.Persist;
|
||||||
import net.citizensnpcs.api.trait.Trait;
|
import net.citizensnpcs.api.trait.Trait;
|
||||||
import net.citizensnpcs.api.trait.TraitName;
|
import net.citizensnpcs.api.trait.TraitName;
|
||||||
|
import net.citizensnpcs.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persists saddle metadata.
|
* Persists saddle metadata.
|
||||||
@ -16,9 +18,9 @@ import net.citizensnpcs.api.trait.TraitName;
|
|||||||
*/
|
*/
|
||||||
@TraitName("saddle")
|
@TraitName("saddle")
|
||||||
public class Saddle extends Trait implements Toggleable {
|
public class Saddle extends Trait implements Toggleable {
|
||||||
private boolean pig;
|
|
||||||
@Persist("")
|
@Persist("")
|
||||||
private boolean saddle;
|
private boolean saddle;
|
||||||
|
private boolean steerable;
|
||||||
|
|
||||||
public Saddle() {
|
public Saddle() {
|
||||||
super("saddle");
|
super("saddle");
|
||||||
@ -26,24 +28,27 @@ public class Saddle extends Trait implements Toggleable {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
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);
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSpawn() {
|
public void onSpawn() {
|
||||||
if (npc.getEntity() instanceof Pig) {
|
if (Util.optionalEntitySet("PIG", "STRIDER").contains(npc.getEntity().getType())) {
|
||||||
((Pig) npc.getEntity()).setSaddle(saddle);
|
steerable = true;
|
||||||
pig = true;
|
updateSaddleState();
|
||||||
} else
|
} else {
|
||||||
pig = false;
|
steerable = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean toggle() {
|
public boolean toggle() {
|
||||||
saddle = !saddle;
|
saddle = !saddle;
|
||||||
if (pig)
|
if (steerable) {
|
||||||
((Pig) npc.getEntity()).setSaddle(saddle);
|
updateSaddleState();
|
||||||
|
}
|
||||||
return saddle;
|
return saddle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +57,22 @@ public class Saddle extends Trait implements Toggleable {
|
|||||||
return "Saddle{" + saddle + "}";
|
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() {
|
public boolean useSaddle() {
|
||||||
return saddle;
|
return saddle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean SUPPORT_STEERABLE = true;
|
||||||
}
|
}
|
@ -68,7 +68,7 @@ public class PlayerLookControl {
|
|||||||
|
|
||||||
protected float getXRotD() {
|
protected float getXRotD() {
|
||||||
double var0 = this.tx - this.a.getX();
|
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 var4 = this.tz - this.a.getZ();
|
||||||
double var6 = Mth.sqrt((float) (var0 * var0 + var4 * var4));
|
double var6 = Mth.sqrt((float) (var0 * var0 + var4 * var4));
|
||||||
return (float) (-(Mth.atan2(var2, var6) * 57.2957763671875D));
|
return (float) (-(Mth.atan2(var2, var6) * 57.2957763671875D));
|
||||||
|
Loading…
Reference in New Issue
Block a user