use of org.bukkit.inventory.ShapelessRecipe in project Essentials by drtshock.
the class Commandcondense method getStackOnRecipeMatch.
private Collection<ItemStack> getStackOnRecipeMatch(final Recipe recipe, final ItemStack stack) {
final Collection<ItemStack> inputList;
if (recipe instanceof ShapedRecipe) {
ShapedRecipe sRecipe = (ShapedRecipe) recipe;
inputList = sRecipe.getIngredientMap().values();
} else if (recipe instanceof ShapelessRecipe) {
ShapelessRecipe slRecipe = (ShapelessRecipe) recipe;
inputList = slRecipe.getIngredientList();
} else {
return null;
}
boolean match = true;
Iterator<ItemStack> iter = inputList.iterator();
while (iter.hasNext()) {
ItemStack inputSlot = iter.next();
if (inputSlot == null) {
iter.remove();
continue;
}
if (inputSlot.getDurability() == Short.MAX_VALUE) {
inputSlot.setDurability((short) 0);
}
if (!inputSlot.isSimilar(stack)) {
match = false;
}
}
if (match) {
return inputList;
}
return null;
}
use of org.bukkit.inventory.ShapelessRecipe in project Dragonet-Legacy by DragonetMC.
the class CraftingDataPacket method encode.
@Override
public void encode() {
enchants = 0;
try {
setChannel(NetworkChannel.CHANNEL_WORLD_EVENTS);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PEBinaryWriter writer = new PEBinaryWriter(bos);
writer.writeByte((byte) (this.pid() & 0xFF));
for (Object o : recipies) {
if (Recipe.class.isAssignableFrom(o.getClass())) {
Recipe r = (Recipe) o;
if (ShapelessRecipe.class.isInstance(r)) {
writer.writeInt(ENTRY_SHAPELESS);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(((ShapelessRecipe) r).getIngredientList().size());
for (ItemStack stack : ((ShapelessRecipe) r).getIngredientList()) {
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(stack));
}
ewriter.writeInt(1);
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(r.getResult()));
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
} else if (FurnaceRecipe.class.isInstance(r)) {
FurnaceRecipe f = (FurnaceRecipe) r;
if (f.getResult().getDurability() != 0) {
writer.writeInt(ENTRY_FURNACE_DATA);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(f.getInput().getTypeId() << 16 | f.getInput().getDurability());
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(f.getResult()));
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
} else {
writer.writeInt(ENTRY_FURNACE);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(f.getInput().getTypeId());
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(f.getResult()));
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
}
} else if (ShapedRecipe.class.isInstance(r)) {
ShapedRecipe sr = (ShapedRecipe) r;
writer.writeInt(ENTRY_SHAPED);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(sr.getShape()[0].length());
ewriter.writeInt(sr.getShape().length);
for (int pos = 0; pos > sr.getShape()[0].length(); pos++) {
for (String line : sr.getShape()) {
ItemStack stack = sr.getIngredientMap().get(line.charAt(pos));
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(stack));
}
}
ewriter.writeInt(1);
PEInventorySlot.writeSlot(ewriter, PEInventorySlot.fromItemStack(sr.getResult()));
long mostUUID = sr.getResult().getTypeId() << 32 | sr.getResult().getDurability() << 16 | (sr.getResult().getAmount() & 0xFFFF);
UUID uid = new UUID(mostUUID, mostUUID);
ewriter.writeUUID(uid);
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
} else {
writer.writeInt(-1);
writer.writeInt(0);
}
} else if (Enchantment.class.isAssignableFrom(o.getClass())) {
Enchantment e = (Enchantment) o;
writer.writeInt(ENTRY_ENCHANT);
ByteArrayOutputStream ebos = new ByteArrayOutputStream();
PEBinaryWriter ewriter = new PEBinaryWriter(ebos);
/* Write data */
{
ewriter.writeInt(enchants);
enchants++;
ewriter.writeInt(e.getId());
//HACK: Always return this.
ewriter.writeInt(e.getMaxLevel());
//HACK: Always 1 for now. TO BE FIXED!
ewriter.writeInt(1);
ewriter.writeString(e.getName());
}
writer.writeInt(ebos.toByteArray().length);
writer.write(ebos.toByteArray());
}
}
writer.writeInt(recipies.size());
this.setData(bos.toByteArray());
} catch (IOException e) {
}
}
Aggregations