Skip to content

Commit

Permalink
Add mechanism dNPC.item_type
Browse files Browse the repository at this point in the history
An equivalent to /npc item
  • Loading branch information
mcmonkey4eva committed Sep 24, 2014
1 parent 549a122 commit 1605f97
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dMaterial.java
Expand Up @@ -623,6 +623,14 @@ public String name() {
return material.name();
}


public Byte getData(byte fallback) {
if (data == null)
return fallback;
else
return data;
}

public Byte getData() {
return data;
}
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dNPC.java
Expand Up @@ -24,6 +24,9 @@
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.trait.Equipment;
import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.npc.entity.nonliving.FallingBlockController;
import net.citizensnpcs.npc.entity.nonliving.ItemController;
import net.citizensnpcs.npc.entity.nonliving.ItemFrameController;
import net.citizensnpcs.trait.Anchors;
import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Poses;
Expand All @@ -32,10 +35,12 @@

import net.minecraft.server.v1_7_R4.EntityLiving;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftLivingEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
Expand Down Expand Up @@ -970,6 +975,37 @@ public void adjust(Mechanism mechanism) {
getCitizen().getTrait(Owner.class).setOwner(value.asString());
}

// <--[mechanism]
// @object dNPC
// @name item_type
// @input dItem
// @description
// Sets the item type of the item.
// @tags
// None
// -->
if (mechanism.matches("item_type") && mechanism.requireObject(dItem.class)) {
dItem item = mechanism.getValue().asType(dItem.class);
Material mat = item.getMaterial().getMaterial();
int data = item.getMaterial().getData((byte)0);
switch (getEntity().getType()) {
case DROPPED_ITEM:
((org.bukkit.entity.Item) getEntity()).getItemStack().setType(mat);
((ItemController.ItemNPC) getEntity()).setType(mat, data);
break;
case ITEM_FRAME:
((ItemFrame) getEntity()).getItem().setType(mat);
((ItemFrameController.ItemFrameNPC) getEntity()).setType(mat, data);
break;
case FALLING_BLOCK:
((FallingBlockController.FallingBlockNPC) getEntity()).setType(mat, data);
break;
default:
dB.echoError("NPC is the not an item type!");
break;
}
}

// <--[mechanism]
// @object dNPC
// @name spawn
Expand Down

0 comments on commit 1605f97

Please sign in to comment.