This repository has been archived by the owner on Aug 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add meta providers for several entity-capture items
- 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
Showing
6 changed files
with
279 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/org/squiddev/plethora/integration/cyclic/IntegrationCyclic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...main/java/org/squiddev/plethora/integration/extrautilities/IntegrationExtraUtilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/squiddev/plethora/integration/industrialforegoing/IntegrationIF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/java/org/squiddev/plethora/integration/notenoughwands/IntegrationNEW.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters