Skip to content

Commit

Permalink
Fix giants, equipping (partially)
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Mar 1, 2016
1 parent 7ad5f73 commit 5c5c7af
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
30 changes: 19 additions & 11 deletions src/main/java/net/citizensnpcs/editor/GenericEquipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class GenericEquipper implements Equipper {
@Override
public void equip(Player equipper, NPC toEquip) {
ItemStack hand = equipper.getItemInHand();
ItemStack hand = equipper.getInventory().getItemInMainHand();
Equipment trait = toEquip.getTrait(Equipment.class);
EquipmentSlot slot = EquipmentSlot.HAND;
Material type = hand == null ? Material.AIR : hand.getType();
Expand All @@ -27,41 +27,49 @@ public void equip(Player equipper, NPC toEquip) {
case GOLD_HELMET:
case IRON_HELMET:
case DIAMOND_HELMET:
if (!equipper.isSneaking())
if (!equipper.isSneaking()) {
slot = EquipmentSlot.HELMET;
}
break;
case LEATHER_CHESTPLATE:
case CHAINMAIL_CHESTPLATE:
case GOLD_CHESTPLATE:
case IRON_CHESTPLATE:
case DIAMOND_CHESTPLATE:
if (!equipper.isSneaking())
if (!equipper.isSneaking()) {
slot = EquipmentSlot.CHESTPLATE;
}
break;
case LEATHER_LEGGINGS:
case CHAINMAIL_LEGGINGS:
case GOLD_LEGGINGS:
case IRON_LEGGINGS:
case DIAMOND_LEGGINGS:
if (!equipper.isSneaking())
if (!equipper.isSneaking()) {
slot = EquipmentSlot.LEGGINGS;
}
break;
case LEATHER_BOOTS:
case CHAINMAIL_BOOTS:
case GOLD_BOOTS:
case IRON_BOOTS:
case DIAMOND_BOOTS:
if (!equipper.isSneaking())
if (!equipper.isSneaking()) {
slot = EquipmentSlot.BOOTS;
}
break;
case AIR:
for (int i = 0; i < 5; i++) {
if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) {
equipper.getWorld().dropItemNaturally(toEquip.getEntity().getLocation(), trait.get(i));
trait.set(i, null);
if (equipper.isSneaking()) {
for (int i = 0; i < 5; i++) {
if (trait.get(i) != null && trait.get(i).getType() != Material.AIR) {
equipper.getWorld().dropItemNaturally(toEquip.getEntity().getLocation(), trait.get(i));
trait.set(i, null);
}
}
Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_ALL_ITEMS_REMOVED, toEquip.getName());
} else {
return;
}
Messaging.sendTr(equipper, Messages.EQUIPMENT_EDITOR_ALL_ITEMS_REMOVED, toEquip.getName());
break;
default:
break;
Expand All @@ -79,7 +87,7 @@ public void equip(Player equipper, NPC toEquip) {
clone.setAmount(1);
trait.set(slot, clone);
hand.setAmount(hand.getAmount() - 1);
equipper.setItemInHand(hand);
equipper.getInventory().setItemInMainHand(hand);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ protected void L() {
}
}

@Override
public void M() {
super.M();
if (npc != null) {
npc.update();
}
}

@Override
public boolean n_() {
if (npc == null || !npc.isFlyable()) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/citizensnpcs/npc/entity/ShulkerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.EntityAIBodyControl;
import net.minecraft.server.v1_9_R1.EntityShulker;
import net.minecraft.server.v1_9_R1.IBlockData;
import net.minecraft.server.v1_9_R1.MinecraftKey;
Expand Down Expand Up @@ -180,6 +181,13 @@ public void m() {
}
}

@Override
public void n() {
if (npc == null) {
super.n();
}
}

@Override
public boolean n_() {
if (npc == null || !npc.isFlyable()) {
Expand All @@ -189,6 +197,11 @@ public boolean n_() {
}
}

@Override
protected EntityAIBodyControl s() {
return new EntityAIBodyControl(this);
}

@Override
public void setSize(float f, float f1) {
if (npc == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ protected void a(double d0, boolean flag, IBlockData block, BlockPosition blockp

@Override
public boolean a(EntityHuman entityhuman, EnumHand enumhand, ItemStack itemstack) {
return npc == null || !blockTrades ? super.a(entityhuman) : false; // block
// trades
return npc == null || !blockTrades ? super.a(entityhuman) : false; // block trades
}

@Override
Expand Down

0 comments on commit 5c5c7af

Please sign in to comment.