Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Commit

Permalink
Add meta providers for several entity-capture items
Browse files Browse the repository at this point in the history
 - Cyclic's Monster Ball
 - Not Enough Wand's Capturing Wand
 - Industrial Foregoing's Mob Imprisonment Tool
 - Extra Utilities 2's Gold Lasso & Cursed Lasso

Fixes #185. There's most definitely not any other mods which add this
functionality, no sirree!
  • Loading branch information
SquidDev committed May 13, 2019
1 parent 0fc804a commit df371ff
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 5 deletions.
16 changes: 12 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ repositories {

maven { url 'http://chickenbones.net/maven/' } // CBMP
maven { url 'http://dvs1.progwml6.com/files/maven/' } // JEI + Tinker's
maven { url 'http://dyonovan.com/maven2/' } // Industrial Foregoing
maven { url 'http://maven.ic2.player.to/' } // IC2 + Forestry
maven { url 'https://dl.bintray.com/squiddev/maven/' } // ConfigGen (why do I use this still?)
maven { url 'https://maven.amadornes.com/' } // Multipart
maven { url 'https://maven.blamejared.com/' } // Botania
maven { url 'https://maven.covers1624.net/' } // CoFH
maven { url 'https://maven.k-4u.nl/' } // McJty's mods
maven { url 'https://maven.mcmoddev.com/' } // Tesla
maven { url 'https://maven.shadowfacts.net' } // Forgelin
maven { url 'https://maven.tterrag.com/' } // EnderCore
maven { url 'https://maven2.tterrag.com/' } // EnderIO
maven { url 'https://mod-buildcraft.com/maven/' } // Buildcraft
Expand All @@ -89,6 +91,7 @@ dependencies {
integrationMod "cofh:ThermalExpansion:1.12.2-5.5.3.41:universal"
integrationMod "cofh:ThermalFoundation:1.12.2-2.6.2.26:universal"
integrationMod "cofh:CoFHWorld:1.12.2-1.3.0.6:universal"
integrationMod("com.buuz135.industrial.IndustrialForegoing:industrialforegoing:1.12.2-1.5.13-136") { exclude group: "mezz.jei" }
compileOnly ("com.enderio:EnderIO:1.12.2-5.0.43") { transitive = false }
compileOnly "com.enderio.core:EnderCore:1.12.2-0.5.57" // EnderCore appears to crash in a development environment.
integrationMod("com.github.mcjty:mcjtylib:1.12-3.5.0") { transitive = false }
Expand All @@ -105,6 +108,7 @@ dependencies {
integrationMod "slimeknights:TConstruct:1.12.2-2.12.0.116"
integrationMod "slimeknights.mantle:Mantle:1.12-1.3.3.51"
integrationMod "vazkii.botania:Botania:r1.10-362.77"
integrationMod "net.ndrei:tesla-core-lib:1.12.2-1.0.15.16:deobf"

// All the Curse mods
integrationMod "baubles:Baubles:1.12:1.5.2"
Expand All @@ -115,6 +119,9 @@ dependencies {
integrationMod "roost:roost:1.12:1.3.0"
integrationMod "chickens:chickens:6.0.4"
integrationMod "hatchery:hatchery:1.12.2:2.2.1"
integrationMod "cyclic:Cyclic:1.12.2:1.19.9"
integrationMod "extra-utilities:extrautils2:1.12:1.9.9"
integrationMod "not-enough-wands:notenoughwands:1.12:1.8.1"

compileOnly('org.squiddev:ConfigGen:1.2.5') { exclude group: 'net.minecraftforge' }

Expand Down Expand Up @@ -172,9 +179,10 @@ curseforge {
}

task runTestServer(type: JavaExec) {
classpath = sourceSets.test.runtimeClasspath
main = "org.squiddev.plethora.boostrap.LaunchServer"
workingDir = "${project.projectDir}/test-files/server"
classpath = sourceSets.test.runtimeClasspath
main = "org.squiddev.plethora.boostrap.LaunchServer"
workingDir = "${project.projectDir}/test-files/server"
systemProperties = ["fml.queryResult": "confirm"]

workingDir.mkdirs()
workingDir.mkdirs()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.squiddev.plethora.integration.cyclic;

import com.lothrazar.cyclicmagic.item.mobcapture.ItemProjectileMagicNet;
import com.lothrazar.cyclicmagic.util.Const;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.passive.EntitySquid;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.squiddev.plethora.api.IWorldLocation;
import org.squiddev.plethora.api.Injects;
import org.squiddev.plethora.api.meta.IMetaProvider;
import org.squiddev.plethora.integration.ItemEntityStorageMetaProvider;
import org.squiddev.plethora.utils.WorldDummy;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;

import static com.lothrazar.cyclicmagic.item.mobcapture.ItemProjectileMagicNet.NBT_ENTITYID;

@Injects(Const.MODID)
public final class IntegrationCyclic {
public static final IMetaProvider<ItemStack> META_MONSTER_NET = new ItemEntityStorageMetaProvider<ItemProjectileMagicNet>(
"capturedEntity", ItemProjectileMagicNet.class,
"Provides the entity captured inside this monster net."
) {
@Nullable
@Override
protected Entity spawn(@Nonnull ItemStack stack, @Nonnull ItemProjectileMagicNet item, @Nonnull IWorldLocation location) {
NBTTagCompound entityData = stack.getTagCompound();
if (entityData == null || !entityData.hasKey(NBT_ENTITYID, Constants.NBT.TAG_STRING)) return null;
return EntityList.createEntityFromNBT(entityData, location.getWorld());
}

@Nonnull
@Override
protected Map<String, ?> getBasicDetails(@Nonnull ItemStack stack, @Nonnull ItemProjectileMagicNet item) {
return getBasicDetails(stack.getTagCompound());
}

@Nullable
@Override
public ItemStack getExample() {
Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(Const.MODID, "magic_net"));
if (!(item instanceof ItemProjectileMagicNet)) return null;

ItemStack stack = new ItemStack(item);
NBTTagCompound tag = new NBTTagCompound();
Entity entity = new EntitySquid(WorldDummy.INSTANCE);
entity.writeToNBT(tag);
tag.setString(NBT_ENTITYID, EntityList.getKey(entity.getClass()).toString());
stack.setTagCompound(tag);
return stack;
}
};

private IntegrationCyclic() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.squiddev.plethora.integration.extrautilities;

import com.rwtema.extrautils2.ExtraUtils2;
import com.rwtema.extrautils2.items.ItemGoldenLasso;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.passive.EntitySquid;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.Constants;
import org.squiddev.plethora.api.IWorldLocation;
import org.squiddev.plethora.api.Injects;
import org.squiddev.plethora.api.meta.IMetaProvider;
import org.squiddev.plethora.integration.ItemEntityStorageMetaProvider;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;

import static com.rwtema.extrautils2.items.ItemGoldenLasso.NBT_ANIMAL;

@Injects(ExtraUtils2.MODID)
public final class IntegrationExtraUtilities {
public static final IMetaProvider<ItemStack> META_MONSTER_NET = new ItemEntityStorageMetaProvider<ItemGoldenLasso>(
"capturedEntity", ItemGoldenLasso.class,
"Provides the entity captured inside this lasso."
) {
@Nullable
@Override
protected Entity spawn(@Nonnull ItemStack stack, @Nonnull ItemGoldenLasso item, @Nonnull IWorldLocation location) {
NBTTagCompound tag = stack.getTagCompound();
if (tag == null || !tag.hasKey(NBT_ANIMAL, Constants.NBT.TAG_COMPOUND)) return null;

NBTTagCompound entityData = tag.getCompoundTag(NBT_ANIMAL);
if (!entityData.hasKey("id", Constants.NBT.TAG_STRING)) return null;

return EntityList.createEntityFromNBT(entityData, location.getWorld());
}

@Nonnull
@Override
protected Map<String, ?> getBasicDetails(@Nonnull ItemStack stack, @Nonnull ItemGoldenLasso item) {
return getBasicDetails(stack.getTagCompound());
}

@Nonnull
@Override
public ItemStack getExample() {
return ItemGoldenLasso.newCraftingStack(EntitySquid.class);
}
};

private IntegrationExtraUtilities() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.squiddev.plethora.integration.industrialforegoing;

import com.buuz135.industrial.item.MobImprisonmentToolItem;
import com.buuz135.industrial.proxy.ItemRegistry;
import com.buuz135.industrial.utils.Reference;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.passive.EntitySquid;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import org.squiddev.plethora.api.IWorldLocation;
import org.squiddev.plethora.api.Injects;
import org.squiddev.plethora.api.meta.IMetaProvider;
import org.squiddev.plethora.integration.ItemEntityStorageMetaProvider;
import org.squiddev.plethora.utils.WorldDummy;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Map;

@Injects(Reference.MOD_ID)
public final class IntegrationIF {
public static final IMetaProvider<ItemStack> META_MOB_IMPRISONMENT = new ItemEntityStorageMetaProvider<MobImprisonmentToolItem>(
"capturedEntity", MobImprisonmentToolItem.class,
"Provides the entity captured inside this mob imprisonment tool."
) {
@Nullable
@Override
protected Entity spawn(@Nonnull ItemStack stack, @Nonnull MobImprisonmentToolItem item, @Nonnull IWorldLocation location) {
return item.containsEntity(stack) ? item.getEntityFromStack(stack, location.getWorld(), true) : null;
}

@Nonnull
@Override
protected Map<String, ?> getBasicDetails(@Nonnull ItemStack stack, @Nonnull MobImprisonmentToolItem item) {
return item.containsEntity(stack)
? getBasicDetails(new ResourceLocation(item.getID(stack)), stack.getTagCompound())
: Collections.emptyMap();
}

@Nonnull
@Override
public ItemStack getExample() {
ItemStack stack = new ItemStack(ItemRegistry.mobImprisonmentToolItem);
Entity entity = new EntitySquid(WorldDummy.INSTANCE);
NBTTagCompound tag = new NBTTagCompound();
tag.setString("entity", EntityList.getKey(entity).toString());
tag.setInteger("id", EntityList.getID(entity.getClass()));
entity.writeToNBT(tag);
stack.setTagCompound(tag);
return stack;
}
};

private IntegrationIF() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.squiddev.plethora.integration.notenoughwands;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntitySquid;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.common.registry.EntityEntry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import org.squiddev.plethora.api.IWorldLocation;
import org.squiddev.plethora.api.Injects;
import org.squiddev.plethora.api.meta.IMetaProvider;
import org.squiddev.plethora.integration.ItemEntityStorageMetaProvider;
import romelo333.notenoughwands.Items.CapturingWand;
import romelo333.notenoughwands.ModItems;
import romelo333.notenoughwands.NotEnoughWands;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Map;

@Injects(NotEnoughWands.MODID)
public final class IntegrationNEW {
public static final IMetaProvider<ItemStack> META_CAPTURING_WAND = new ItemEntityStorageMetaProvider<CapturingWand>(
"capturedEntity", CapturingWand.class,
"Provides the entity captured inside this capturing wand."
) {
@Nullable
@Override
protected Entity spawn(@Nonnull ItemStack stack, @Nonnull CapturingWand item, @Nonnull IWorldLocation location) {
NBTTagCompound tag = stack.getTagCompound();
if (tag == null || !tag.hasKey("type", Constants.NBT.TAG_STRING)) return null;

Class<? extends EntityLivingBase> type = getClass(tag.getString("type"));
if (type == null) return null;

EntityLivingBase entity;
try {
entity = type.getConstructor(World.class).newInstance(location.getWorld());
} catch (ReflectiveOperationException | RuntimeException e) {
return null;
}

entity.readEntityFromNBT(tag.getCompoundTag("mob"));
return entity;
}

@Nonnull
@Override
protected Map<String, ?> getBasicDetails(@Nonnull ItemStack stack, @Nonnull CapturingWand item) {
NBTTagCompound tag = stack.getTagCompound();
if (tag == null || !tag.hasKey("type", Constants.NBT.TAG_STRING)) return Collections.emptyMap();

Class<? extends EntityLivingBase> type = getClass(tag.getString("type"));
if (type == null) return Collections.emptyMap();

EntityEntry entry = EntityRegistry.getEntry(type);
if (entry == null) return Collections.emptyMap();

return getBasicDetails(entry.getRegistryName(), tag.getCompoundTag("mob"));
}

@Nullable
private Class<? extends EntityLivingBase> getClass(String type) {
try {
return Class.forName(type).asSubclass(EntityLivingBase.class);
} catch (ReflectiveOperationException ignored) {
return null;
}
}

@Nonnull
@Override
public ItemStack getExample() {
ItemStack stack = new ItemStack(ModItems.capturingWand);
NBTTagCompound tag = new NBTTagCompound();
tag.setString("type", EntitySquid.class.getName());
stack.setTagCompound(tag);
return stack;
}
};

private IntegrationNEW() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("inventories", function()

it("on a stick", function()
local inv = setup()
expect(inv.getItemMeta(1)):same {
expect(inv.getItemMeta(1)):matches {
name = "minecraft:stick", displayName = "Stick", rawName = "item.stick",
damage = 0, maxDamage = 0, count = 50, maxCount = 64,
ores = { stickWood = true }
Expand Down

0 comments on commit df371ff

Please sign in to comment.