@Override public Set<org.getspout.spoutapi.material.Block> getModifiedBlocks() { // hit cache first if (cachedBlockData != null) { return cachedBlockData; } Set<org.getspout.spoutapi.material.Block> modified = new HashSet<org.getspout.spoutapi.material.Block>(); TLongFloatIterator i = originalFriction.iterator(); while (i.hasNext()) { i.advance(); int id = TIntPairHashSet.longToKey1(i.key()); int data = TIntPairHashSet.longToKey2(i.key()); org.getspout.spoutapi.material.Block block = MaterialData.getBlock(id, (short) data); if (block != null) { modified.add(block); } } i = originalHardness.iterator(); while (i.hasNext()) { i.advance(); int id = TIntPairHashSet.longToKey1(i.key()); int data = TIntPairHashSet.longToKey2(i.key()); org.getspout.spoutapi.material.Block block = MaterialData.getBlock(id, (short) data); if (block != null) { modified.add(block); } } TIntIntIterator j = originalLight.iterator(); while (j.hasNext()) { j.advance(); org.getspout.spoutapi.material.Block block = MaterialData.getBlock(j.key()); if (block != null) { modified.add(block); } } TIntByteIterator k = originalOpacity.iterator(); while (k.hasNext()) { k.advance(); org.getspout.spoutapi.material.Block block = MaterialData.getBlock(k.key()); if (block != null) { modified.add(block); } } cachedBlockData = modified; // save to cache return modified; }
public Ingredient(String ingredient, UltraItems instance) throws Exception { this.ingredient = ingredient; plugin = instance; String[] item = null; try { item = ingredient.split("[:,;-]"); if (item.length >= 1) { itemid = Integer.decode(item[0]); if (item.length >= 2) { itemdata = Integer.decode(item[1]); if (item.length >= 3) { amount = Integer.decode(item[2]); } } } material = MaterialData.getMaterial(itemid, getData()); } catch (Exception e) { if (plugin.itemManager.getItem(ingredient) != null) { material = plugin.itemManager.getItem(ingredient).getCustomItem(); itemid = material.getRawId(); itemdata = material.getRawData(); } } if (material == null) { throw new DataFormatException("Ingredient \"" + ingredient + "\" doesn't exist"); } }
@Override public EnumAnimation c_(ItemStack itemstack) { CustomItem item = MaterialData.getCustomItem(itemstack.getData()); if (item instanceof Food) { return EnumAnimation.EAT; } return super.c_(itemstack); }
@Override public ItemStack b(ItemStack itemstack, World world, EntityHuman entityhuman) { CustomItem item = MaterialData.getCustomItem(itemstack.getData()); if (item instanceof Food) { --itemstack.count; entityhuman.getFoodData().eat(((Food) item).getHungerRestored(), 0.6F); } return itemstack; }
private void disperseDrops( final Player cause, final Sprout sprout, final Block block, final boolean bonus) { if (cause != null && cause.getGameMode() == GameMode.CREATIVE) { return; } if (!sprout.isFullyGrown()) { return; } final Collection<Drop> drops = sprout.getDrops(); for (Drop drop : drops) { final org.getspout.spoutapi.material.Material customMaterial = MaterialData.getCustomItem(drop.getName()); if (customMaterial == null) { final Material material = Material.getMaterial(drop.getName().toUpperCase()); if (material == null) { continue; } final ItemStack stack = new ItemStack(material, drop.getAmount()); block.getWorld().dropItemNaturally(block.getLocation(), stack); } else { final SpoutItemStack spoutStack = new SpoutItemStack(customMaterial, drop.getAmount()); block.getWorld().dropItemNaturally(block.getLocation(), spoutStack); } } if (bonus) { final Collection<Drop> bonusDrops = sprout.getBonus(); for (Drop drop : bonusDrops) { final org.getspout.spoutapi.material.Material customMaterial = MaterialData.getCustomItem(drop.getName()); if (customMaterial == null) { final Material material = Material.getMaterial(drop.getName().toUpperCase()); if (material == null) { continue; } final ItemStack stack = new ItemStack(material, drop.getAmount()); block.getWorld().dropItemNaturally(block.getLocation(), stack); } else { final SpoutItemStack spoutStack = new SpoutItemStack(customMaterial, drop.getAmount()); block.getWorld().dropItemNaturally(block.getLocation(), spoutStack); } } } }
@Override public ItemStack a(ItemStack itemstack, World world, EntityHuman entityhuman) { CustomItem item = MaterialData.getCustomItem(itemstack.getData()); if (item instanceof Food) { Bukkit.getScheduler() .scheduleSyncDelayedTask(Spout.getInstance(), new FoodUpdate(entityhuman, itemstack), 2); } return itemstack; }
@Override public void remove(org.getspout.spoutapi.material.Material material) { ItemStack[] items = getContents(); for (int i = 0; i < items.length; i++) { if (items[i] != null && MaterialData.getMaterial(items[i].getTypeId(), items[i].getDurability()) == material) { clear(i); } } }
private void updateBlockAttributes(int id, short data) { org.getspout.spoutapi.material.Block block = MaterialData.getBlock(id, data); if (block != null) { cachedBlockData = null; HashSet<org.getspout.spoutapi.material.Block> toUpdate = new HashSet<org.getspout.spoutapi.material.Block>(1); toUpdate.add(block); SpoutPacket updatePacket = new PacketBlockData(toUpdate); for (SpoutPlayer player : SpoutManager.getOnlinePlayers()) { if (player.isSpoutCraftEnabled()) player.sendPacket(updatePacket); } } }
public GenericCustomItem(Plugin plugin, String name) { super( name, 318, mm.registerCustomItemName(plugin, plugin.getDescription().getName() + "." + name)); this.fullName = plugin.getDescription().getName() + "." + name; this.customId = mm.registerCustomItemName(plugin, fullName); this.plugin = plugin; this.setName(name); MaterialData.addCustomItem(this); for (SpoutPlayer player : Spout.getServer().getOnlinePlayers()) { player.sendPacket(this); } }
@Override public void remove(org.bukkit.Material material) { ItemStack[] items = getContents(); for (int i = 0; i < items.length; i++) { if (items[i] == null) { continue; } org.getspout.spoutapi.material.Material myMat = MaterialData.getMaterial(items[i].getTypeId(), items[i].getDurability()); if (myMat instanceof CustomItem || myMat instanceof Tool || myMat instanceof CustomBlock) { continue; } if (items[i].getType() == material) { clear(i); } } }
private void disperseSeeds(final Player cause, final Sprout sprout, final Block block) { if (cause != null && cause.getGameMode() == GameMode.CREATIVE) { return; } final String seedName = sprout.getItemSource(); final org.getspout.spoutapi.material.Material customMaterial = MaterialData.getCustomItem(seedName); if (customMaterial == null) { final Material material = Material.getMaterial(seedName); if (material == null) { return; } final ItemStack stack = new ItemStack(material); // TODO Configurable amounts block.getWorld().dropItemNaturally(block.getLocation(), stack); } else { final SpoutItemStack spoutStack = new SpoutItemStack(customMaterial); block.getWorld().dropItemNaturally(block.getLocation(), spoutStack); } }
public static void checkblock(String type, CustomBlockDesign item) { for (int rpc = 1; rpc < 10; ++rpc) { if (Configuration.block.contains( "Custom " + type + "." + item.getName() + ".shaped recipe" + rpc)) { int amount = Configuration.block.getInt( "Custom " + type + "." + item.getName() + ".shaped recipe" + rpc + ".amount"); List list = Configuration.block.getList( "Custom " + type + "." + item.getName() + ".shaped recipe" + rpc + ".ingredients"); int customId = 0; Iterator keys = list.iterator(); String[] row1 = keys.next().toString().split(","); String[] row2 = keys.next().toString().split(","); String[] row3 = keys.next().toString().split(","); String srow1 = ""; String srow2 = ""; String srow3 = ""; ItemStack result = new SpoutItemStack(item, amount); recipe = new SpoutShapedRecipe(result); recipe.shape("ghi", "def", "abc"); char letter = 0; for (int count = 0; count < 3; count++) { if (row1[count].contains(":")) { if (count == 0) { row1dv1 = row1[count].split(":"); } else if (count == 1) { row1dv2 = row1[count].split(":"); } else if (count == 2) { row1dv3 = row1[count].split(":"); } } } for (int count = 0; count < 3; count++) { if (row2[count].contains(":")) { if (count == 0) { row2dv1 = row2[count].split(":"); } else if (count == 1) { row2dv2 = row2[count].split(":"); } else if (count == 2) { row2dv3 = row2[count].split(":"); } } } for (int count = 0; count < 3; count++) { if (row3[count].contains(":")) { if (count == 0) { row3dv1 = row3[count].split(":"); } else if (count == 1) { row3dv2 = row3[count].split(":"); } else if (count == 2) { row3dv3 = row3[count].split(":"); } } } for (int rowi = 0; rowi < 3; ++rowi) { if (rowi == 0) { for (i = 0; i < 3; ) { if (i == 0) { letter = 'a'; rowletter = "a"; } else if (i == 1) { letter = 'b'; rowletter = "b"; } else if (i == 2) { letter = 'c'; rowletter = "c"; } if (row1[i] != "-") { try { if (i == 0) { if (row1dv1 != null) { recipe.setIngredient( letter, MaterialData.getMaterial( Integer.parseInt(row1dv1[0]), Short.parseShort(row1dv1[1]))); srow1 = srow1 + rowletter; } else { recipe.setIngredient( letter, MaterialData.getMaterial(Integer.parseInt(row1[i]))); srow1 = srow1 + rowletter; } } else if (i == 1) { if (row1dv2 != null) { recipe.setIngredient( letter, MaterialData.getMaterial( Integer.parseInt(row1dv2[0]), Short.parseShort(row1dv2[1]))); srow1 = srow1 + rowletter; } else { recipe.setIngredient( letter, MaterialData.getMaterial(Integer.parseInt(row1[i]))); srow1 = srow1 + rowletter; } } else { if (row1dv3 != null) { recipe.setIngredient( letter, MaterialData.getMaterial( Integer.parseInt(row1dv3[0]), Short.parseShort(row1dv3[1]))); srow1 = srow1 + rowletter; } else { recipe.setIngredient( letter, MaterialData.getMaterial(Integer.parseInt(row1[i]))); srow1 = srow1 + rowletter; } } } catch (NumberFormatException e) { for (GenericCustomItem itemcheck : Hashmaps.customitemsmap.values()) { if (itemcheck.getName().equals(row1[i])) { customId = itemcheck.getCustomId(); srow1 = srow1 + rowletter; } } for (CustomOresDesign block : Hashmaps.customoresmap.values()) { if (block.getName().equals(row1[i])) { customId = block.getCustomId(); srow1 = srow1 + rowletter; } } for (GenericCustomTool toolcheck : Hashmaps.customtoolsmap.values()) { if (toolcheck.getName().equals(row1[i])) { customId = toolcheck.getCustomId(); srow1 = srow1 + rowletter; } } for (GenericCustomFood foodcheck : Hashmaps.customfoodmap.values()) { if (foodcheck.getName().equals(row1[i])) { customId = foodcheck.getCustomId(); srow1 = srow1 + rowletter; } } recipe.setIngredient(letter, MaterialData.getCustomItem(customId)); } } else { srow1 = srow1 + " "; } ++i; } } else if (rowi == 1) { for (int i = 0; i < 3; ) { if (i == 0) { letter = 'd'; rowletter = "d"; } else if (i == 1) { letter = 'e'; rowletter = "e"; } else if (i == 2) { letter = 'f'; rowletter = "f"; } if (row2[i] != "-") { try { if (i == 0) { if (row2dv1 != null) { recipe.setIngredient( letter, MaterialData.getMaterial( Integer.parseInt(row2dv1[0]), Short.parseShort(row2dv1[1]))); srow2 = srow2 + rowletter; } else { recipe.setIngredient( letter, MaterialData.getMaterial(Integer.parseInt(row2[i]))); srow2 = srow2 + rowletter; } } else if (i == 1) { if (row2dv2 != null) { recipe.setIngredient( letter, MaterialData.getMaterial( Integer.parseInt(row2dv2[0]), Short.parseShort(row2dv2[1]))); srow2 = srow2 + rowletter; } else { recipe.setIngredient( letter, MaterialData.getMaterial(Integer.parseInt(row2[i]))); srow2 = srow2 + rowletter; } } else { if (row2dv3 != null) { recipe.setIngredient( letter, MaterialData.getMaterial( Integer.parseInt(row2dv3[0]), Short.parseShort(row2dv3[1]))); srow2 = srow2 + rowletter; } else { recipe.setIngredient( letter, MaterialData.getMaterial(Integer.parseInt(row2[i]))); srow2 = srow2 + rowletter; } } } catch (NumberFormatException e) { for (GenericCustomItem itemcheck : Hashmaps.customitemsmap.values()) { if (itemcheck.getName().equals(row2[i])) { customId = itemcheck.getCustomId(); srow2 = srow2 + rowletter; } } for (CustomOresDesign block : Hashmaps.customoresmap.values()) { if (block.getName().equals(row2[i])) { customId = block.getCustomId(); srow2 = srow2 + rowletter; } } for (GenericCustomTool toolcheck : Hashmaps.customtoolsmap.values()) { if (toolcheck.getName().equals(row2[i])) { customId = toolcheck.getCustomId(); srow2 = srow2 + rowletter; } } for (GenericCustomFood foodcheck : Hashmaps.customfoodmap.values()) { if (foodcheck.getName().equals(row2[i])) { customId = foodcheck.getCustomId(); srow2 = srow2 + rowletter; } } recipe.setIngredient(letter, MaterialData.getCustomItem(customId)); } } else { srow2 = srow2 + " "; } ++i; } } else if (rowi == 2) { for (int i = 0; i < 3; ) { if (i == 0) { letter = 'g'; rowletter = "g"; } else if (i == 1) { letter = 'h'; rowletter = "h"; } else if (i == 2) { letter = 'i'; rowletter = "i"; } if (row3[i] != "-") { try { if (i == 0) { if (row3dv1 != null) { recipe.setIngredient( letter, MaterialData.getMaterial( Integer.parseInt(row3dv1[0]), Short.parseShort(row3dv1[1]))); srow3 = srow3 + rowletter; } else { recipe.setIngredient( letter, MaterialData.getMaterial(Integer.parseInt(row3[i]))); srow3 = srow3 + rowletter; } } else if (i == 1) { if (row3dv2 != null) { recipe.setIngredient( letter, MaterialData.getMaterial( Integer.parseInt(row3dv2[0]), Short.parseShort(row3dv2[1]))); srow3 = srow3 + rowletter; } else { recipe.setIngredient( letter, MaterialData.getMaterial(Integer.parseInt(row3[i]))); srow3 = srow3 + rowletter; } } else { if (row3dv3 != null) { recipe.setIngredient( letter, MaterialData.getMaterial( Integer.parseInt(row3dv3[0]), Short.parseShort(row3dv3[1]))); srow3 = srow3 + rowletter; } else { recipe.setIngredient( letter, MaterialData.getMaterial(Integer.parseInt(row3[i]))); srow3 = srow3 + rowletter; } } } catch (NumberFormatException e) { for (GenericCustomItem itemcheck : Hashmaps.customitemsmap.values()) { if (itemcheck.getName().equals(row3[i])) { customId = itemcheck.getCustomId(); srow3 = srow3 + rowletter; } } for (CustomOresDesign block : Hashmaps.customores) { if (block.getName().equals(row3[i])) { customId = block.getCustomId(); srow3 = srow3 + rowletter; } } for (GenericCustomTool toolcheck : Hashmaps.customtoolsmap.values()) { if (toolcheck.getName().equals(row3[i])) { customId = toolcheck.getCustomId(); srow3 = srow3 + rowletter; } } for (GenericCustomFood foodcheck : Hashmaps.customfoodmap.values()) { if (foodcheck.getName().equals(row3[i])) { customId = foodcheck.getCustomId(); srow3 = srow3 + rowletter; } } recipe.setIngredient(letter, MaterialData.getCustomItem(customId)); } } else { srow3 = srow3 + " "; } ++i; } } } recipe.shape(srow1, srow2, srow3); SpoutManager.getMaterialManager().registerSpoutRecipe(recipe); System.out.println( "[RpgEssentials] Added shaped recipe " + rpc + " for: " + item.getName()); } if (Configuration.block.contains( "Custom " + type + "." + item.getName() + ".furnace recipe" + rpc)) { int amount = Configuration.block.getInt( "Custom " + type + "." + item.getName() + ".furnace recipe" + rpc + ".amount"); String ingredientraw = Configuration.block.getString( "Custom " + type + "." + item.getName() + ".furnace recipe" + rpc + ".ingredient"); int customId = 0; ItemStack result = new SpoutItemStack(item, amount); try { int ingredient = Integer.parseInt(ingredientraw); FurnaceRecipes.NewFurnaceRecipe(result, ingredient); } catch (NumberFormatException e) { CustomOresDesign test1 = Hashmaps.customoresmap.get(ingredientraw); GenericCustomItem test2 = Hashmaps.customitemsmap.get(ingredientraw); GenericCustomTool test3 = Hashmaps.customtoolsmap.get(ingredientraw); if (test1 != null) { FurnaceRecipes.CustomOreFurnaceRecipe(result, Material.STONE, test1); } else if (test2 != null) { FurnaceRecipes.CustomItemFurnaceRecipe(result, Material.FLINT, test2); } else { FurnaceRecipes.CustomToolFurnaceRecipe(result, Material.FLINT, test3); } } } } }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { // Prevent trampling switch (event.getAction()) { case PHYSICAL: final Block top = event.getClickedBlock().getRelative((BlockFace.UP)); if (plugin .getWorldRegistry() .contains(top.getWorld().getName(), top.getX(), top.getY(), top.getZ())) { event.setCancelled(true); break; } case RIGHT_CLICK_BLOCK: // Exit this method if player clicking on chest, door, button, etc. switch (event.getClickedBlock().getType()) { case CHEST: case WOOD_BUTTON: case STONE_BUTTON: case WOOD_DOOR: case IRON_DOOR: case IRON_DOOR_BLOCK: case FENCE_GATE: case BREWING_STAND: case FURNACE: case BURNING_FURNACE: return; } final Player interacter = event.getPlayer(); final ItemStack held = event.getItem(); if (held == null) { return; } final Block interacted = event.getClickedBlock(); final SpoutItemStack stack = new SpoutItemStack(held); final String name; // Grab the material's name if (stack.isCustomItem()) { name = stack.getMaterial().getNotchianName(); } else { name = held.getType().name(); } // Fertilizer logic final Sprout dispersed = plugin .getWorldRegistry() .get( interacted.getWorld().getName(), interacted.getX(), interacted.getY(), interacted.getZ()); if (dispersed != null && !((SimpleSprout) dispersed).isOnLastStage() && dispersed.getVariables().allowFertilization()) { final Stage current = dispersed.getCurrentStage(); final Fertilizer fertilizer; if (current == null) { fertilizer = dispersed.getFertilizerSource(); } else { fertilizer = current.getFertilizer(); } boolean toContinue = false; // Bonemeal if ((fertilizer.getName().equals("bonemeal") && name.equals("INK_SACK"))) { toContinue = true; // Custom Block } else if (fertilizer.getName().endsWith(name)) { toContinue = true; // Material } else if (fertilizer.getName().equals(name.toLowerCase())) { toContinue = true; } if (!toContinue) { return; } event.setCancelled(true); Stage stage; org.getspout.spoutapi.material.Material customMaterial; Material material; // Stage 0 if (current == null) { stage = dispersed.getStage(1); customMaterial = MaterialData.getCustomBlock(stage.getName()); material = Material.getMaterial(stage.getName().toUpperCase()); if (customMaterial == null) { if (material == null) { return; } } // Grow to stage 1 ((SimpleSprout) dispersed).grow(stage); if (customMaterial != null) { ((SpoutBlock) interacted).setCustomBlock((CustomBlock) customMaterial); } else { ((SpoutBlock) interacted).setCustomBlock(null); interacted.setType(material); } } else { stage = ((SimpleSprout) dispersed).getNextStage(); if (stage == null) { return; } customMaterial = MaterialData.getCustomBlock(stage.getName()); material = Material.getMaterial(stage.getName().toUpperCase()); if (customMaterial == null) { if (material == null) { return; } } ((SimpleSprout) dispersed).incrementFertilizerCount(stage); if (((SimpleSprout) dispersed).getFertilizerCount(stage) >= fertilizer.getAmount()) { if (customMaterial != null) { ((SpoutBlock) interacted).setCustomBlock((CustomBlock) customMaterial); } else { ((SpoutBlock) interacted).setCustomBlock(null); interacted.setType(material); } ((SimpleSprout) dispersed).grow(stage); } if (((SimpleSprout) dispersed).isOnLastStage()) { ((SimpleSprout) dispersed).setFullyGrown(true); final SaveThread thread = ((SaveThread) ThreadRegistry.get(interacted.getWorld().getName())); if (thread != null) { thread.add(interacted.getLocation(), (SimpleSprout) dispersed); } } } decrementInventory(interacter, interacter.getItemInHand()); } else { // Non-fertilizer logic final Sprout sprout = plugin.getSproutRegistry().find(name); if (sprout == null) { return; } event.setCancelled(true); // Block face logic. TODO Customizable? if (event.getBlockFace() != BlockFace.UP) { return; } // Soil logic org.getspout.spoutapi.material.Material customMaterial = MaterialData.getCustomItem(sprout.getPlacementSource()); Material material = Material.getMaterial(sprout.getPlacementSource().toUpperCase()); if (customMaterial == null || !(((SpoutBlock) interacted).getBlockType() instanceof CustomBlock) || !((CustomBlock) ((SpoutBlock) interacted).getBlockType()) .getFullName() .equalsIgnoreCase(customMaterial.getName())) { if (material == null || !interacted.getType().equals(material)) { return; } } final Block where = interacted.getRelative(BlockFace.UP); // Make sure where we are setting the block won't be already obstructed. if (where.getType() != Material.AIR) { return; } // Handle Jobs Integration Calls if (SproutConfiguration.jobsEnabled) { if (!Jobs.hasRequiredJobAndLevel( event.getPlayer(), "Farmer", sprout.getMinimumLevelRequired())) { event .getPlayer() .sendMessage( ChatColor.DARK_AQUA + "[Sprout]" + ChatColor.WHITE + " Planting this seed requires the job " + ChatColor.GOLD + "[Farmer]" + ChatColor.WHITE + ", at level " + ChatColor.GOLD + sprout.getMinimumLevelRequired() + ChatColor.WHITE + " or higher."); return; } // Planting experience within jobs is handled by block place of the vanilla block of // "CROP" } final Sprout toInject = cloner.deepClone(sprout); plugin .getWorldRegistry() .add(where.getWorld().getName(), where.getX(), where.getY(), where.getZ(), toInject); final SaveThread thread = ((SaveThread) ThreadRegistry.get(where.getWorld().getName())); if (thread != null) { thread.add(where.getLocation(), (SimpleSprout) toInject); } // Set material if (stack.isCustomItem()) { final CustomBlock block = MaterialData.getCustomBlock(sprout.getBlockSource()); ((SpoutBlock) where).setCustomBlock(block); interacter.playSound(interacter.getLocation(), Sound.DIG_GRASS, 1.0F, 0.7936508F); decrementInventory(interacter, held); } // Handle Jobs Integration Calls if (SproutConfiguration.jobsEnabled) { JobsWorker.jobsPlace(event.getPlayer(), where); } } } }