Ok Having issues. First off when debugging to see if force reading the nbt would work. It replaced the skeleton spawner however it only did that if the xyz arguments matched. So what do I do?
Second Issue to get it working with the itemstack. It doesn't replace the block for one thing and I can't get it to check the nbt beecause, I don't know what to put for the second argument. This below here is my current code setup. I also Have a 3d issue with this how do I read the nbt as an itemstack? If I change it to write to nbt component it adds another nbt data value for the already tagged spawner. So if I get the key with the itemstack how do I applay this to read nbt from the tile entity?
public class SilkSpawners {
public static TileEntity var1;
public static int varmeta;
public static TileEntity varTile_nbt_read;
//@SideOnly(Side.SERVER)
// private static TIntObjectMap<Map<ChunkPosition, TileEntity>> feild = new TIntObjectHashMap<>();
// WorldProvider#dimensionId field
// (first is chunkposition tileentity ("key") )
//String name = countryNames.get("IT");
@SubscribeEvent
public void BlockEvent(BreakEvent event)
{
System.out.println("Var1 before set");
System.out.println(var1);
if (!event.world.isRemote)
{
if (event.block instanceof BlockMobSpawner)
{
if (heldItem1 != null && heldItem1.getItem().getHarvestLevel(heldItem1, "pickaxe") > 0 && EnchantmentHelper.getSilkTouchModifier(event1.harvester))
{
Block block = Blocks.mob_spawner;
NBTTagCompound BlockEntityTag = new NBTTagCompound();
NBTTagCompound var_nbt = new NBTTagCompound(); // Write the TileEntity to NBT
var1.writeToNBT(var_nbt);
System.out.println("vAAAAAAAAAAAAAAAAAAAAR !!!!!!!!!!!!!!!!!! 1");
System.out.println(var_nbt);
final ItemStack droppedItem = new ItemStack(block); // Create an ItemStack of the Block
final ItemStack MetaBlock = new ItemStack(block, 1, varmeta);
droppedItem.setTagInfo("BlockEntityTag", var_nbt); // Store the TileEntity data in the ItemStack
//droppedItem.writeToNBT(var_nbt); ebuger
MetaBlock.setTagInfo("BlockEntityTag", var_nbt); // Store the TileEntity data in the ItemStack
event1.drops.add(droppedItem); // Add the ItemStack to the drops list
System.out.println("drooooooooooooooooooooooop");
System.out.println(droppedItem);
//event1.drops.clear();
//var1 = null; //resets var1 to null and is ready for the next instance
// if necessary feild.clear();
}
}
}
}
@SubscribeEvent
public void BlockEvent (PlaceEvent event2)
{
if (!event2.world.isRemote)
{
if (event2.placedBlock == Blocks.mob_spawner)
{
if (event2.itemInHand != null && event2.itemInHand.hasTagCompound() );
{
Ok Having issues. First off when debugging to see if force reading the nbt would work. It replaced the skeleton spawner however it only did that if the xyz arguments matched. So what do I do?
Looking at the 1.10.2 version of ItemBlock, it seems I oversimplified the process of transferring the data from the ItemStack's NBT to the TileEntity.
What you actually need to do is the following:
Write the in-world TileEntity to NBT (TileEntity#writeToNBT), we'll call this tileNBT.
Create a copy of this compound tag (NBTTagCompound#copy), we'll call this originalTileNBT.
Get the "BlockEntityTag" compound tag from the ItemStack's stack compound tag, we'll call this itemNBT.
Call tileNBT.merge(itemNBT) to merge itemNBT into tileNBT.
Set the "x", "y" and "z" values of tileNBT to the coordinates that the block is being placed at.
If tileNBT isn't equal to originalTileNBT, call TileEntity#readFromNBT with tileNBT and then call TileEntity#markDirty.
Keep in mind that only ops in creative mode can do this for mob spawners, command blocks and signs in 1.10.2. Do you want any player to be able to place these mob spawners?
You can then use NBTTagCompound#hasKey(String, int) to check if the compound tag has a key (the first argument) with the specified tag type (the second argument, use the constants from Constants.NBT).
In future, please use Gist or Pastebin to post logs/crash reports (if applicable) and code with syntax highlighting. To get syntax highlighting on Gist, give each file the appropriate extension (.java for Java code). To get syntax highlighting on Pastebin, select the language from the dropdown at the bottom of the page.
It's much easier to read code with proper formatting and syntax highlighting.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Detailed Explination On Why Players Must Get Spawners And Place Them:
I will use .java for pastebin or gist? Yes I want any player to pick up a mob spawner that is the point of silk spawners. I will then go from this mod when it is finished with nie compatibility and make more dungeons such as creeper , cavespider, witherskeletons , and enderman spwawners. Or if I figure out that list thing with nie then I can get a random mob from the list and apply it's tile entity data somehow?
So once player has found the rare creeper spawner (I am pretty sure they use to spawn in creeper dungeons in alpha or beta) then I would like them to take that silk pick and harvest it. Take it back to their base surround it with obsidian or bedrock(if they have my enhanced vanilla already made mod). It seems I have alot more re-writing of silk spawners base then realized (not messing with nie just yet it's complicated and I want a working base method first). I will try this tomorrow and may have to implement java hash map but, I doubt this.
Call tileNBT.merge(itemNBT) to merge itemNBT into tileNBT.
Set the "x", "y" and "z" values of tileNBT to the coordinates that the block is being placed at.
tileNBT.merge isn't an option in 1.7.10 and haven't heard of it for 1.8.9 what do you mean by this.
Set x,y,z cord. Ok how Do I edit this? Do I edit it with a section of nbt and how do you do that?
You know... if I were you, instead of a Map storing a dimension id AND another Map, I would make an inner class to easily store those values. Something like this:
public static class DimensionalPos
{
public final int dimId, x, y, z;
public DimensionalPos(int parDim, int parX, int parY, int parZ)
{
this.dimId = parDim;
this.x = parX;
this.y = parY;
this.z = parZ;
}
// added after Choonster's suggestion below
@Override
public boolean equals(Object o)
{
if(o instanceof DimensionalPos)
{
DimensionalPos d = (DimensionalPos)o;
return d.dimId == this.dimId && d.x == this.x && d.y == this.y && d.z == this.z;
}
return false;
}
}
In the block break event, I would store a new DimensionalPos in a regular HashMap<DimensionalPos, TileEntity> that has the location of the spawner as the key and the TileEntity as the value.
That is more reliable than a single static TileEntity because, on slow servers with multiple players, 2 spawners may be broken in the time it takes to fire the harvest drops event.
Also, using a Map lets you remove the TileEntity from the Map after use. If you use a single static TileEntity, you have to remember to set it to null after use (and then add null-checks all over) so players don't get a spawner when the code fails to set a valid TileEntity.
In short, be safe and use a Map, even if it's harder.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
tileNBT.merge isn't an option in 1.7.10 and haven't heard of it for 1.8.9 what do you mean by this.
Since it doesn't exist in 1.7.10, you'll need to implement it yourself. Look at the NBTTagCompound class in 1.8.9+ to see how it's implemented.
Set x,y,z cord. Ok how Do I edit this? Do I edit it with a section of nbt and how do you do that?
Use the setter methods of NBTTagCompound to set the values.
The inner class suggested by sky_01 would be simpler to use than nested maps, but you'd need to override Object#equals and Object#hashCode for it to work properly as the key of a HashMap. I suggest looking at how ChunkCoordinates implements these methods.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
This is getting to complex for 1.7.10 It is starting to sound like writing my own api and backporting nbt features from 1.8 to 1.7.10. I will try it but, if it fails I will just only have the mod working for nie for 1.7.10 and you said it should work in 1.8+ already so It's updating time soon. I have made a forum with it. Me and my team have worked hard on finding and fixing bugs and also made the configuration file. two lines of configing but, that is all you need. You can adjust the minimum harvest level and adjust (true / false) whether or not golden pickaxe with silk touch will always harvest spawners regardless of minimum harvest level being set above the golden pickaxe.
i am trying to make this work with another mod that uses its own blocks and i am useing a array list to store he value but it keeps crashing with index out of bounds exceptions when breaking a block other than the seccond one on the array list
public class aoa {
public static TileEntity var1;
public static int varmeta;
public static TileEntity varTile_nbt_read;
public static String a;
public static Block block;
public static String n = "nevermine";
public static int q = 0;
@SubscribeEvent
public void yourPlayerHarvestEvent(HarvestDropsEvent event1)
{
if(!event1.world.isRemote)
{
if(!(event1.harvester == null))
{
System.out.println(event1.block);
ArrayList<String> list = new ArrayList<String>();
aoaArray.al(list);
Iterator<String> it = list.iterator();
while (it.hasNext())
{
block = GameRegistry.findBlock(n,it.next());
if(block == (event1.block))
{
a = list.get(q);
Choonster Could you please tell me how to get around this?
The method getEntityNameToSpawn() from the type MobSpawnerBaseLogic is not visible
I got that error when trying to get mobspawnerbaselogic getenitytyname because, the string is private. How else can i get the entity name using 1.8+ code?
Started 1.8.9 updating and I am having some issues.
Set the "x", "y" and "z" values of tileNBT to the coordinates that the block is being placed at.
It already does that for me by itself but, I want to set the x y z cords upon block breaking to 0 0 0 so the blocks will stack once in my inventory how do I do this. Once that is fixed and you answer me on how to get entity name to spawn for nie I can release 1.8 and 1.8.9 ports of the mod.
Choonster Could you please tell me how to get around this?
The method getEntityNameToSpawn() from the type MobSpawnerBaseLogic is not visible
I got that error when trying to get mobspawnerbaselogic getenitytyname because, the string is private. How else can i get the entity name using 1.8+ code?
You'll need to use reflection to call it.
Now that I look at the spawner code more closely, a single spawner can spawn multiple types of entities. You should only use an NEI-compatible (metadata-based) spawner if MobSpawnerBaseLogic#getRandomEntity returns null and the MobSpawnerBaseLogic#minecartToSpawn list is empty (these are both private, you'll need to use reflection to access them); else use an NBT-based spawner.
Despite the name, MobSpawnerBaseLogic#minecartToSpawn can be used for any type of entity; not just minecarts.
To access a private field or method using reflection, call ReflectionHelper#findField or ReflectionHelper#findMethod and store the resulting Field/Method object in a private static final field (the instance argument of ReflectionHelper#findMethod is unused, just pass null). Use Field#get to get the current value of a field, passing the instance to get it from as the argument. Use Method#invoke to call a method, passing the instance to call it on and the arguments to pass to it as arguments.
You must use the MCP and SRG names of a Minecraft field/method when accessing it via reflection. MCPBot can give you this information. Fields/methods added by Forge or other non-Minecraft code only have a single name, so just use this when accessing them via reflection.
It already does that for me by itself but, I want to set the x y z cords upon block breaking to 0 0 0 so the blocks will stack once in my inventory how do I do this. Once that is fixed and you answer me on how to get entity name to spawn for nie I can release 1.8 and 1.8.9 ports of the mod.
Simply call NBTTagCompound#setInteger or NBTTagCompound#removeTag for each coordinate tag after writing the spawner to NBT, before you add it to the ItemStack's NBT.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thanks now the item stacks. So since .haseffect isn't what you recommend what should I use to scan for the nbt value in the block break event? Also that method is undefined for 1.8 + so I would love a response please.
Use EnchantmentHelper.getSilkTouchModifier to check if an entity's held item has Silk Touch on it.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
It makes it have the argument in their of the player and then upon block break of the mobspawner it disappears and is still their. I need to detect it from nbt. Could you please tell me how to do this?
It makes it have the argument in their of the player and then upon block break of the mobspawner it disappears and is still their. I need to detect it from nbt. Could you please tell me how to do this?
EnchantmentHelper already reads the ItemStack's NBT to determine which enchantments it has.
Post your current code (using Gist/Pastebin).
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
This works because, I am only setting the metadata for nei based on what the name was and the fact that I am only doing this for block harvest method. I then found the tile entity data and it had that and I looked at base mob spawner logic to find out how it got it's name. It seemed to be buried and my previous attempts failed because, the string had " " without the space and the rest of the code wouldn't work. So I decided to take a look and see how minecraft gets the name without the " ". (I knew this from debugging with the console). Then I found the process and executed it. lol lol no java complicated reflections when A that would slow the system down and B I am lazy.
I also found another thing out today. Minecraft reads things not on "BlockEntityTag" but, on "EntityId" tag. Meaning I can finally probably make nbt work without nei.
I have figured out the enchantment issues. I was using .haseffect(33) when it only checked if it was enchanted meaning it wasn't silk spawners if you had a gold pickaxe it was enchanted spawners. It aslo caused the xp to not drop because, it was enchanted. So I found out my mistake was not putting event.getplayer() rather then setting a variable / feild to define what the player was. Forge didn't recognize that the player was in the event resaulting in a crash. So here is the code for 1.7 fix will find code easily for 1.8+ or at leas I should.
I still need help figuring out the xp. I found some stuff out but, it doesn't seem to help when setxptodrop(0) does nothing and forge seems to want to do nothing.
Ok So I got the blocks to stack and read nbt without nei and that part works. I need to know how to replace the title name on the Item based on the entity name. How Do I do this? I can grab the entity name had to do this for the work around in nie I just need to know how to set the tag so it displays as entityname + Monster Spawner.
Fixed crash report with event handlers. I have know clue why it was erroring that the itemstack was null but, it didn't want to return / cancel the event if the terms were untrue. So I had to make several return methods for the even harvest handlers and also had to make two more return methods for placement of the block so it would be stabilized.
Ok Having issues. First off when debugging to see if force reading the nbt would work. It replaced the skeleton spawner however it only did that if the xyz arguments matched. So what do I do?
Code:http://pastebin.com/8e4q2HqY
Debug Logger Test. Doesn't Replace pig with skele because, xyz arguments are not the same.
Second Issue to get it working with the itemstack. It doesn't replace the block for one thing and I can't get it to check the nbt beecause, I don't know what to put for the second argument. This below here is my current code setup. I also Have a 3d issue with this how do I read the nbt as an itemstack? If I change it to write to nbt component it adds another nbt data value for the already tagged spawner. So if I get the key with the itemstack how do I applay this to read nbt from the tile entity?
package com.EvilNotch.SilkSpawners;
import java.util.HashMap;
import java.util.Map;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockMobSpawner;
import net.minecraft.block.BlockSand;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
import net.minecraftforge.event.world.BlockEvent.PlaceEvent;
public class SilkSpawners {
public static TileEntity var1;
public static int varmeta;
public static TileEntity varTile_nbt_read;
//@SideOnly(Side.SERVER)
// private static TIntObjectMap<Map<ChunkPosition, TileEntity>> feild = new TIntObjectHashMap<>();
// WorldProvider#dimensionId field
// (first is chunkposition tileentity ("key") )
//String name = countryNames.get("IT");
@SubscribeEvent
public void BlockEvent(BreakEvent event)
{
System.out.println("Var1 before set");
System.out.println(var1);
if (!event.world.isRemote)
{
if (event.block instanceof BlockMobSpawner)
{
if (event.world.getTileEntity(event.x, event.y, event.z) instanceof TileEntityMobSpawner);
{
ItemStack heldItem = event.getPlayer().getCurrentEquippedItem();
if (heldItem != null && heldItem.getItem().getHarvestLevel(heldItem, "pickaxe") > 0)
{
var1 = event.world.getTileEntity(event.x, event.y, event.z);
event.world.removeTileEntity(event.x, event.y, event.z);
varmeta = event.world.getBlockMetadata(event.x, event.y, event.z);
System.out.println("Varmeeeeeeeeeeeeeeeeeeeeeta");
System.out.println(varmeta);
}
}
}
}
}
// world.getProvider().getDimensionId() world.getTileEntity()
@SubscribeEvent
public void yourPlayerHarvestEvent(HarvestDropsEvent event1)
{
if(!event1.world.isRemote)
{
if (event1.block instanceof BlockMobSpawner)
{
ItemStack heldItem1 = event1.harvester.getCurrentEquippedItem();
if (heldItem1 != null && heldItem1.getItem().getHarvestLevel(heldItem1, "pickaxe") > 0 && EnchantmentHelper.getSilkTouchModifier(event1.harvester))
{
Block block = Blocks.mob_spawner;
NBTTagCompound BlockEntityTag = new NBTTagCompound();
NBTTagCompound var_nbt = new NBTTagCompound(); // Write the TileEntity to NBT
var1.writeToNBT(var_nbt);
System.out.println("vAAAAAAAAAAAAAAAAAAAAR !!!!!!!!!!!!!!!!!! 1");
System.out.println(var_nbt);
final ItemStack droppedItem = new ItemStack(block); // Create an ItemStack of the Block
final ItemStack MetaBlock = new ItemStack(block, 1, varmeta);
droppedItem.setTagInfo("BlockEntityTag", var_nbt); // Store the TileEntity data in the ItemStack
//droppedItem.writeToNBT(var_nbt); ebuger
MetaBlock.setTagInfo("BlockEntityTag", var_nbt); // Store the TileEntity data in the ItemStack
event1.drops.add(droppedItem); // Add the ItemStack to the drops list
System.out.println("drooooooooooooooooooooooop");
System.out.println(droppedItem);
//event1.drops.clear();
//var1 = null; //resets var1 to null and is ready for the next instance
// if necessary feild.clear();
}
}
}
}
@SubscribeEvent
public void BlockEvent (PlaceEvent event2)
{
if (!event2.world.isRemote)
{
if (event2.placedBlock == Blocks.mob_spawner)
{
if (event2.itemInHand != null && event2.itemInHand.hasTagCompound() );
{
System.out.println("ItemInHand");
System.out.println(event2.itemInHand);
ItemStack varhand = event2.itemInHand;
varhand.getTagCompound();
System.out.println("NBT Compound");
System.out.println(varhand.getTagCompound() );
NBTTagCompound handNBT = new NBTTagCompound();
varhand.writeToNBT(handNBT);
varTile_nbt_read = event2.world.getTileEntity(event2.x, event2.y, event2.z);
varTile_nbt_read.readFromNBT(handNBT);
System.out.println("HandNBT");
System.out.println(handNBT);
}
}
}
}
}
if (handNBT.hasKey("BlockEntityTag", 0))
{
}
Which thing? You can get the MobSpawnerBaseLogic from the TileEntityMobSpawner by calling TileEntityMobSpawner#func_145881_a.
Looking at the 1.10.2 version of ItemBlock, it seems I oversimplified the process of transferring the data from the ItemStack's NBT to the TileEntity.
What you actually need to do is the following:
Keep in mind that only ops in creative mode can do this for mob spawners, command blocks and signs in 1.10.2. Do you want any player to be able to place these mob spawners?
In future, please use Gist or Pastebin to post logs/crash reports (if applicable) and code with syntax highlighting. To get syntax highlighting on Gist, give each file the appropriate extension (.java for Java code). To get syntax highlighting on Pastebin, select the language from the dropdown at the bottom of the page.
It's much easier to read code with proper formatting and syntax highlighting.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Detailed Explination On Why Players Must Get Spawners And Place Them:
I will use .java for pastebin or gist? Yes I want any player to pick up a mob spawner that is the point of silk spawners. I will then go from this mod when it is finished with nie compatibility and make more dungeons such as creeper , cavespider, witherskeletons , and enderman spwawners. Or if I figure out that list thing with nie then I can get a random mob from the list and apply it's tile entity data somehow?
So once player has found the rare creeper spawner (I am pretty sure they use to spawn in creeper dungeons in alpha or beta) then I would like them to take that silk pick and harvest it. Take it back to their base surround it with obsidian or bedrock(if they have my enhanced vanilla already made mod). It seems I have alot more re-writing of silk spawners base then realized (not messing with nie just yet it's complicated and I want a working base method first). I will try this tomorrow and may have to implement java hash map but, I doubt this.
tileNBT.merge isn't an option in 1.7.10 and haven't heard of it for 1.8.9 what do you mean by this.
Set x,y,z cord. Ok how Do I edit this? Do I edit it with a section of nbt and how do you do that?
You know... if I were you, instead of a Map storing a dimension id AND another Map, I would make an inner class to easily store those values. Something like this:
In the block break event, I would store a new DimensionalPos in a regular HashMap<DimensionalPos, TileEntity> that has the location of the spawner as the key and the TileEntity as the value.
That is more reliable than a single static TileEntity because, on slow servers with multiple players, 2 spawners may be broken in the time it takes to fire the harvest drops event.
Also, using a Map lets you remove the TileEntity from the Map after use. If you use a single static TileEntity, you have to remember to set it to null after use (and then add null-checks all over) so players don't get a spawner when the code fails to set a valid TileEntity.
In short, be safe and use a Map, even if it's harder.
Since it doesn't exist in 1.7.10, you'll need to implement it yourself. Look at the NBTTagCompound class in 1.8.9+ to see how it's implemented.
Use the setter methods of NBTTagCompound to set the values.
The inner class suggested by sky_01 would be simpler to use than nested maps, but you'd need to override Object#equals and Object#hashCode for it to work properly as the key of a HashMap. I suggest looking at how ChunkCoordinates implements these methods.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/mods-discussion/2720122-silk-spawners-not-enough-items-support#c1
Working Dev Version 1.7.10 NEI Add on for Silk Spawners has a config for harvest level
themodpackmaker and I Are A Team
This is getting to complex for 1.7.10 It is starting to sound like writing my own api and backporting nbt features from 1.8 to 1.7.10. I will try it but, if it fails I will just only have the mod working for nie for 1.7.10 and you said it should work in 1.8+ already so It's updating time soon. I have made a forum with it. Me and my team have worked hard on finding and fixing bugs and also made the configuration file. two lines of configing but, that is all you need. You can adjust the minimum harvest level and adjust (true / false) whether or not golden pickaxe with silk touch will always harvest spawners regardless of minimum harvest level being set above the golden pickaxe.
He Wrote Most Of The Code So You Know
i am trying to make this work with another mod that uses its own blocks and i am useing a array list to store he value but it keeps crashing with index out of bounds exceptions when breaking a block other than the seccond one on the array list
the code is here
package com.EvilNotch.SilkSpawners.modsupport;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;
import com.EvilNotch.SilkSpawners.config;
import com.EvilNotch.SilkSpawners.modsupport.arraylist.aoaArray;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockMobSpawner;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.world.World;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
public class aoa {
public static TileEntity var1;
public static int varmeta;
public static TileEntity varTile_nbt_read;
public static String a;
public static Block block;
public static String n = "nevermine";
public static int q = 0;
@SubscribeEvent
public void yourPlayerHarvestEvent(HarvestDropsEvent event1)
{
if(!event1.world.isRemote)
{
if(!(event1.harvester == null))
{
System.out.println(event1.block);
ArrayList<String> list = new ArrayList<String>();
aoaArray.al(list);
Iterator<String> it = list.iterator();
while (it.hasNext())
{
block = GameRegistry.findBlock(n,it.next());
if(block == (event1.block))
{
a = list.get(q);
}
q = q + 1;
System.out.println(q);
System.out.println(a);
}
System.out.println(a);
if (event1.block == GameRegistry.findBlock(n, a) )
{
ItemStack heldItem1 = event1.harvester.getCurrentEquippedItem();
if (heldItem1 != null && heldItem1.getItem().getHarvestLevel(heldItem1, "pickaxe") >= config.harvestlevel && EnchantmentHelper.getSilkTouchModifier(event1.harvester) || config.GoldenPickaxeAlwaysEnabled == true && heldItem1.getItem() == Items.golden_pickaxe && heldItem1.hasEffect(33) )
{
ItemStack aoa = new ItemStack(GameRegistry.findBlock(n, a) );
event1.drops.add(aoa);
}
}
}
}
}
}
um make a new form for this. Call it How Do I Get Block From An Array List from another mod.
Choonster Could you please tell me how to get around this?
The method getEntityNameToSpawn() from the type MobSpawnerBaseLogic is not visible
I got that error when trying to get mobspawnerbaselogic getenitytyname because, the string is private. How else can i get the entity name using 1.8+ code?
Started 1.8.9 updating and I am having some issues.
It already does that for me by itself but, I want to set the x y z cords upon block breaking to 0 0 0 so the blocks will stack once in my inventory how do I do this. Once that is fixed and you answer me on how to get entity name to spawn for nie I can release 1.8 and 1.8.9 ports of the mod.
While your reading this I am unable to disable another mods xp value here http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/modification-development/2720449-how-to-disable-xp-from-modded-block-drops-forge
You'll need to use reflection to call it.
Now that I look at the spawner code more closely, a single spawner can spawn multiple types of entities. You should only use an NEI-compatible (metadata-based) spawner if MobSpawnerBaseLogic#getRandomEntity returns null and the MobSpawnerBaseLogic#minecartToSpawn list is empty (these are both private, you'll need to use reflection to access them); else use an NBT-based spawner.
Despite the name, MobSpawnerBaseLogic#minecartToSpawn can be used for any type of entity; not just minecarts.
To access a private field or method using reflection, call ReflectionHelper#findField or ReflectionHelper#findMethod and store the resulting Field/Method object in a private static final field (the instance argument of ReflectionHelper#findMethod is unused, just pass null). Use Field#get to get the current value of a field, passing the instance to get it from as the argument. Use Method#invoke to call a method, passing the instance to call it on and the arguments to pass to it as arguments.
You must use the MCP and SRG names of a Minecraft field/method when accessing it via reflection. MCPBot can give you this information. Fields/methods added by Forge or other non-Minecraft code only have a single name, so just use this when accessing them via reflection.
Simply call NBTTagCompound#setInteger or NBTTagCompound#removeTag for each coordinate tag after writing the spawner to NBT, before you add it to the ItemStack's NBT.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thanks now the item stacks. So since .haseffect isn't what you recommend what should I use to scan for the nbt value in the block break event? Also that method is undefined for 1.8 + so I would love a response please.
Use EnchantmentHelper.getSilkTouchModifier to check if an entity's held item has Silk Touch on it.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
It makes it have the argument in their of the player and then upon block break of the mobspawner it disappears and is still their. I need to detect it from nbt. Could you please tell me how to do this?
EnchantmentHelper already reads the ItemStack's NBT to determine which enchantments it has.
Post your current code (using Gist/Pastebin).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
rip comment. Made some mistakes or further explained below.
Edit since the name from getlogic name was a private sting and I had incomplete information to work with I decided to make a work around for nei.
This works because, I am only setting the metadata for nei based on what the name was and the fact that I am only doing this for block harvest method. I then found the tile entity data and it had that and I looked at base mob spawner logic to find out how it got it's name. It seemed to be buried and my previous attempts failed because, the string had " " without the space and the rest of the code wouldn't work. So I decided to take a look and see how minecraft gets the name without the " ". (I knew this from debugging with the console). Then I found the process and executed it. lol lol no java complicated reflections when A that would slow the system down and B I am lazy.
I also found another thing out today. Minecraft reads things not on "BlockEntityTag" but, on "EntityId" tag. Meaning I can finally probably make nbt work without nei.
I have figured out the enchantment issues. I was using .haseffect(33) when it only checked if it was enchanted meaning it wasn't silk spawners if you had a gold pickaxe it was enchanted spawners. It aslo caused the xp to not drop because, it was enchanted. So I found out my mistake was not putting event.getplayer() rather then setting a variable / feild to define what the player was. Forge didn't recognize that the player was in the event resaulting in a crash. So here is the code for 1.7 fix will find code easily for 1.8+ or at leas I should.
I still need help figuring out the xp. I found some stuff out but, it doesn't seem to help when setxptodrop(0) does nothing and forge seems to want to do nothing.
Ok So I got the blocks to stack and read nbt without nei and that part works. I need to know how to replace the title name on the Item based on the entity name. How Do I do this? I can grab the entity name had to do this for the work around in nie I just need to know how to set the tag so it displays as entityname + Monster Spawner.
Edit
Fixed crash report with event handlers. I have know clue why it was erroring that the itemstack was null but, it didn't want to return / cancel the event if the terms were untrue. So I had to make several return methods for the even harvest handlers and also had to make two more return methods for placement of the block so it would be stabilized.