public boolean testCondition(Random rand, LootContext context) { Entity entity = context.getEntity(this.target); if (entity == null) { return false; } else { for (EntityProperty entityproperty : this.properties) { if (!entityproperty.testProperty(rand, entity)) { return false; } } return true; } }
public void serialize(JsonObject json, EntityHasProperty value, JsonSerializationContext context) { JsonObject jsonobject = new JsonObject(); for (EntityProperty entityproperty : value.properties) { EntityProperty.Serializer<EntityProperty> serializer = EntityPropertyManager.<EntityProperty>getSerializerFor(entityproperty); jsonobject.add(serializer.getName().toString(), serializer.serialize(entityproperty, context)); } json.add("properties", jsonobject); json.add("entity", context.serialize(value.target)); }
public EntityHasProperty deserialize(JsonObject json, JsonDeserializationContext context) { Set<Entry<String, JsonElement>> set = JsonUtils.getJsonObject(json, "properties").entrySet(); EntityProperty[] aentityproperty = new EntityProperty[set.size()]; int i = 0; for (Entry<String, JsonElement> entry : set) { aentityproperty[i++] = EntityPropertyManager.getSerializerForName(new ResourceLocation((String)entry.getKey())).deserialize((JsonElement)entry.getValue(), context); } return new EntityHasProperty(aentityproperty, (LootContext.EntityTarget)JsonUtils.deserializeClass(json, "entity", context, LootContext.EntityTarget.class)); }
private static void replaceCookedWithCharred(LootPool targetPool, Item targetItem, ItemStack replacementStack, int minCount, int maxCount) { List<LootFunction> charredFunctions = Lists.newArrayList(); if(replacementStack.getItemDamage() != 0) charredFunctions.add(LootUtil.createSetMetadata(replacementStack.getItemDamage())); if(replacementStack.getTagCompound() != null) charredFunctions.add(LootUtil.createSetNBT(replacementStack.getTagCompound())); charredFunctions.add(LootUtil.createCountFunction(minCount, maxCount)); charredFunctions.add(LootUtil.createLootingFunc(0, 1)); LootCondition notOnFire = new EntityHasProperty(new EntityProperty[] {new EntityOnFire(false)}, EntityTarget.THIS); LootCondition onFire = new EntityHasProperty(new EntityProperty[] {new EntityOnFire(true)}, EntityTarget.THIS); targetPool.removeEntry(targetItem.getRegistryName().toString()); targetPool.addEntry(new LootEntryItem(targetItem, 1, 1, new LootFunction[] {LootUtil.createCountFunction(1, 3), LootUtil.createLootingFunc(0, 1)}, new LootCondition[] {notOnFire}, targetItem.getRegistryName().toString())); targetPool.addEntry(new LootEntryItem(replacementStack.getItem(), 1, 1, charredFunctions.toArray(new LootFunction[charredFunctions.size()]), new LootCondition[] {onFire}, ModMain.MODID + ":charred_+" + targetItem.getRegistryName().getResourcePath().toString())); }
private void removeSmeltFunction(LootPool pool, Item targetItem, Item replacement, int minCount, int maxCount) { LootCondition notOnFire = new EntityHasProperty(new EntityProperty[] {new EntityOnFire(false)}, EntityTarget.THIS); LootCondition onFire = new EntityHasProperty(new EntityProperty[] {new EntityOnFire(true)}, EntityTarget.THIS); pool.removeEntry(targetItem.getRegistryName().toString()); pool.addEntry(new LootEntryItem(targetItem, 1, 1, new LootFunction[] {LootUtil.createCountFunction(1, 3), LootUtil.createLootingFunc(0, 1)}, new LootCondition[] {notOnFire}, targetItem.getRegistryName().toString())); pool.addEntry(new LootEntryItem(replacement, 1, 1, new LootFunction[] {LootUtil.createCountFunction(1, 3), LootUtil.createLootingFunc(0, 1)}, new LootCondition[] {onFire}, replacement.getRegistryName().toString())); }
public EntityHasProperty(EntityProperty[] propertiesIn, LootContext.EntityTarget targetIn) { this.properties = propertiesIn; this.target = targetIn; }