use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class InteractionVisualizerAPI method createArmorStandItemHoldingObject.
/**
* Create a fake armorstand for holding mini items at the given location.
* DOES NOT SPAWN THE ARMORSTAND.
*
* @return The InteractionVisualizer ArmorStand object created.
*/
public static ArmorStand createArmorStandItemHoldingObject(Location location) {
Vector vector = rotateVectorAroundY(location.clone().getDirection().normalize().multiply(0.19), -100).add(location.clone().getDirection().normalize().multiply(-0.11));
ArmorStand stand = new ArmorStand(location.add(vector));
setStand(stand, location.getYaw());
return stand;
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class FurnaceDisplay method onBreakFurnace.
@EventHandler(priority = EventPriority.MONITOR)
public void onBreakFurnace(TileEntityRemovedEvent event) {
Block block = event.getBlock();
if (!furnaceMap.containsKey(block)) {
return;
}
Map<String, Object> map = furnaceMap.get(block);
if (map.get("Item") instanceof Item) {
Item item = (Item) map.get("Item");
PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
}
if (map.get("Stand") instanceof ArmorStand) {
ArmorStand stand = (ArmorStand) map.get("Stand");
PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
}
furnaceMap.remove(block);
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class GrindstoneDisplay method spawnArmorStands.
public Map<String, ArmorStand> spawnArmorStands(Player player, Block block) {
// .add(0.68, 0.600781, 0.35)
Map<String, ArmorStand> map = new HashMap<>();
Location loc = block.getLocation().clone().add(0.5, 0.600781, 0.5);
ArmorStand center = new ArmorStand(loc);
float yaw = getCardinalDirection(player);
center.setRotation(yaw, center.getLocation().getPitch());
setStand(center);
center.setCustomName("IV.Grindstone.Center");
Vector vector = rotateVectorAroundY(center.getLocation().clone().getDirection().normalize().multiply(0.19), -100).add(center.getLocation().clone().getDirection().normalize().multiply(-0.11));
ArmorStand middle = new ArmorStand(loc.clone().add(vector));
setStand(middle, yaw);
ArmorStand slot0 = new ArmorStand(middle.getLocation().clone().add(rotateVectorAroundY(center.getLocation().clone().getDirection().normalize().multiply(0.2), -90)));
setStand(slot0, yaw + 20);
ArmorStand slot1 = new ArmorStand(middle.getLocation().clone().add(rotateVectorAroundY(center.getLocation().clone().getDirection().normalize().multiply(0.2), 90)));
setStand(slot1, yaw - 20);
map.put("0", slot0);
map.put("1", slot1);
PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMSTAND, KEY), slot0);
PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMSTAND, KEY), slot1);
return map;
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class GrindstoneDisplay method onCloseGrindstone.
@EventHandler
public void onCloseGrindstone(InventoryCloseEvent event) {
if (event.getView().getTopInventory() == null) {
return;
}
try {
if (event.getView().getTopInventory().getLocation() == null) {
return;
}
} catch (Exception | AbstractMethodError e) {
return;
}
if (event.getView().getTopInventory().getLocation().getBlock() == null) {
return;
}
Block block = event.getView().getTopInventory().getLocation().getBlock();
if (!openedGrindstone.containsKey(block)) {
return;
}
Map<String, Object> map = openedGrindstone.get(block);
if (!map.get("Player").equals(event.getPlayer())) {
return;
}
for (int i = 0; i <= 2; i++) {
if (!(map.get(String.valueOf(i)) instanceof String)) {
Object entity = map.get(String.valueOf(i));
if (entity instanceof Item) {
PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), (Item) entity);
} else if (entity instanceof ArmorStand) {
PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), (ArmorStand) entity);
}
}
}
openedGrindstone.remove(block);
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class GrindstoneDisplay method process.
@Override
public void process(Player player) {
if (VanishUtils.isVanished(player)) {
return;
}
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
return;
}
if (player.getOpenInventory().getTopInventory().getLocation() == null) {
return;
}
if (!LocationUtils.isLoaded(player.getOpenInventory().getTopInventory().getLocation())) {
return;
}
if (player.getOpenInventory().getTopInventory().getLocation().getBlock() == null) {
return;
}
if (!player.getOpenInventory().getTopInventory().getLocation().getBlock().getType().equals(Material.GRINDSTONE)) {
return;
}
InventoryView view = player.getOpenInventory();
Block block = view.getTopInventory().getLocation().getBlock();
Location loc = block.getLocation();
if (!openedGrindstone.containsKey(block)) {
Map<String, Object> map = new HashMap<>();
map.put("Player", player);
map.put("2", "N/A");
map.putAll(spawnArmorStands(player, block));
openedGrindstone.put(block, map);
}
Map<String, Object> map = openedGrindstone.get(block);
if (!map.get("Player").equals(player)) {
return;
}
ItemStack[] items = new ItemStack[] { view.getItem(0), view.getItem(1) };
if (view.getItem(2) != null) {
ItemStack itemstack = view.getItem(2);
if (itemstack == null || itemstack.getType().equals(Material.AIR)) {
itemstack = null;
}
Item item = null;
if (map.get("2") instanceof String) {
if (itemstack != null) {
item = new Item(loc.clone().add(0.5, 1.2, 0.5));
item.setItemStack(itemstack);
item.setVelocity(new Vector(0, 0, 0));
item.setPickupDelay(32767);
item.setGravity(false);
map.put("2", item);
PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item);
PacketManager.updateItem(item);
} else {
map.put("2", "N/A");
}
} else {
item = (Item) map.get("2");
if (itemstack != null) {
if (!item.getItemStack().equals(itemstack)) {
item.setItemStack(itemstack);
PacketManager.updateItem(item);
}
} else {
map.put("2", "N/A");
PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
}
}
}
for (int i = 0; i < 2; i++) {
ArmorStand stand = (ArmorStand) map.get(String.valueOf(i));
ItemStack item = items[i];
if (item == null || item.getType().equals(Material.AIR)) {
item = null;
}
if (item != null) {
boolean changed = true;
if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.BLOCK) && !standMode(stand).equals(MaterialMode.BLOCK)) {
toggleStandMode(stand, "Block");
} else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.TOOL) && !standMode(stand).equals(MaterialMode.TOOL)) {
toggleStandMode(stand, "Tool");
} else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.ITEM) && !standMode(stand).equals(MaterialMode.ITEM)) {
toggleStandMode(stand, "Item");
} else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.STANDING) && !standMode(stand).equals(MaterialMode.STANDING)) {
toggleStandMode(stand, "Standing");
} else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.LOWBLOCK) && !standMode(stand).equals(MaterialMode.LOWBLOCK)) {
toggleStandMode(stand, "LowBlock");
} else {
changed = false;
}
if (!item.getType().equals(stand.getItemInMainHand().getType())) {
changed = true;
stand.setItemInMainHand(item);
}
if (changed) {
PacketManager.updateArmorStand(stand);
}
} else {
if (!stand.getItemInMainHand().getType().equals(Material.AIR)) {
stand.setItemInMainHand(new ItemStack(Material.AIR));
PacketManager.updateArmorStand(stand);
}
}
}
}
Aggregations