I am trying to make a mod starting with 1.7.10 and going to 1.8.9 later. I am trying to get forge harvest method to drop the current spawners meta data with modded ids supported. Currently I am unable to get a custom meta data without specifying and then that is just one metadata I want it to be whatever the spawner meta data is(aka only pig spawners). here is my code for 1.7.10 if you have advice for 1.7.10 or 1.8.9 I can probably figure it out. This event is in my handler and is registered in my mainjava.java file. I currently know it works because, I got wool with specific meta data from the spawners on a test(changed the block to wool and 1 count then changed event1.blockmetadata to 7
also have enderportal frame dropping to. again here is my 1.7.10 faulty code
@SubscribeEvent
public void yourPlayerHarvestEvent(HarvestDropsEvent event1)
{
if (event1.block instanceof BlockMobSpawner)
{
ItemStack test = event1.harvester.getCurrentEquippedItem();
event1.drops.clear();
if (test != null)
{
if (test.getItem().getHarvestLevel(test, "pickaxe") > 0 && EnchantmentHelper.getSilkTouchModifier(event1.harvester))
{
event1.drops.add(new ItemStack(Blocks.mob_spawner, 1, event1.blockMetadata));
}
}
}
}
}
actually it's not metadata I found out there are more then 16 states for spawners. I need a way to grab and return the tile entity data from vanilla and moded spawners that extends spawners how do I do that?
actually it's not metadata I found out there are more then 16 states for spawners. I need a way to grab and return the tile entity data from vanilla and moded spawners that extends spawners how do I do that?
The event object contains the World and BlockPos from which you can get the tile entity.
When a block is broken, the TileEntity is removed from the world before BlockEvent.HarvestDropsEvent is called unless the block specifically delays it (which mob spawners don't).
A slightly hacky way around this is to subscribe to BlockEvent.BreakEvent, check if the player has the correct tool (i.e. a pickaxe with silk touch) and then store the TileEntity. In BlockEvent.HarvestDropsEvent, retrieve the TileEntity, remove it from storage and then add an ItemStack with the appropriate NBT to the drops list. Only do this on the server.
To store the TileEntity, I recommend creating a TIntObjectMap<Map<BlockPos, TileEntity>> (use the hash implementation of each map interface). Use the dimension ID as the key for the outer map and the position as the key for the inner map.
You may want to remove any invalid TileEntities (TileEntity#isInvalid) at the end of your BlockEvent.HarvestDropsEvent handler to prevent memory leaks.
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.
So confused could you write the code fore me? I don't know what to do. I couldn't get past the item stack so the rest of the code is errored. Also How do I get your method to work without having the dimension id thing? I want it to work in any dimension.
@SubscribeEvent
public <BlockPos, TileEntity> void yourPlayerHarvestEvent(BlockEvent.BreakEvent event1)
{
if (event1.block instanceof BlockMobSpawner)
{
TIntObjectMap<Map<BlockPos, TileEntity>>
TileCode = (TIntObjectMap<Map<BlockPos, TileEntity>>) Blocks.mob_spawner, TileEntity;
//Item stack is errored
ItemStack test = TileCode;
event1.drops.clear();
if (test != null)
{
if (test.getItem().getHarvestLevel(test, "pickaxe") > 0 && EnchantmentHelper.getSilkTouchModifier(event1.harvester))
{
event1.drops.add(new ItemStack(Blocks.mob_spawner, 1, event1.blockMetadata));
}
}
}
}
}
I'm not going to write the code for you, but I will give you a more detailed description of what to do. If you know Java (a prerequisite for writing a mod), you should be able to understand this.
The dimension ID is required for this to work in multiple dimensions. The spawner at 0,1,0 in dimension 0 isn't the same as the spawner at 0,1,0 in dimension 1, so you need to store these separately.
You need to store the TIntObjectMap<Map<BlockPos, TileEntity>> as a field in your event handler class (setting it to an instance of TIntObjectHashMap<Map<BlockPos, TileEntity>>) and only access it on the server.
In your BlockEvent.BreakEvent handler, do the following:
Check if the event is being fired on the server (World#isRemote). If it's not, return from the method.
Check if the block that was broken is a mob spawner, the TileEntity at the block's position (World#getTileEntity) was an instance of TileEntityMobSpawner and the player had the correct tool (a pickaxe with Silk Touch). If this isn't the case, return from the method.
Get the Map<BlockPos, TileEntity> for the dimension the block was broken in from the TIntObjectMap. If it doesn't exist, create a new HashMap<BlockPos, TileEntity> and store it in the TIntObjectMap, using the dimension ID as the key.
Get the TileEntity at the block's position and store it in the Map, using the block's position as the key.
In your BlockEvent.HarvestDropsEvent handler, do the following:
Check if the event is being fired on the server (World#isRemote). If it's not, return from the method.
Check if the block that was broken is a mob spawner and the player had the correct tool (a pickaxe with Silk Touch). If this isn't the case, return from the method.
Get the Map<BlockPos, TileEntity> for the dimension the block was broken in from the TIntObjectMap. If it doesn't exist, return from the method.
Get the TileEntity at the block's position from the Map. If it isn't an instance of TileEntityMobSpawner, return from the method.
Create an ItemStack with the appropriate NBT and add it to the drops list.
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.
Also, make sure BlockEvent.BreakEvent#harvester (BlockEvent.BreakEvent#getHarvester() in 1.8+) is not null or explosions will crash your game when you access the ItemStack. I learned that the hard way
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
I don't know how to do this. what is the hash map implementation interface? where is the outer map and BlockPos Isn't recognized nor is TIleEntity. Dimension id can I use the generic term to grab the id so it's not only working for the overworld or vanilla ids?
TIntObjectMap <Isthisout<isthisin>isthisout> what is going on here.
To store the TileEntity, I recommend creating a TIntObjectMap> (use the hash implementation of each map interface). Use the dimension ID as the key for the outer map and the position as the key for the inner map.
What do you mean by this? So TIntObjectMap<Map<BlockPos, TileEntity>> instance of TIntObjectHashMap<Map<BlockPos, TileEntity>> this is confusing. What event handler break, drop, harvest or just at the top of the class. Question how does the hashmap actually store the tileentity data if it's not instanceof BlockMobSpawner ?
You need to store the TIntObjectMap> as a field in your event handler class (setting it to an instance of TIntObjectHashMap>) and only access it on the server.
A TIntObjectMap is a map with integer keys (the dimension ID) and object values (the per-dimension map). The generic type argument is the value type. TIntObjectHashMap is an implementation of this interface (the hash implementation I was talking about). This is the outer map.
A Map is a map with object keys (the block position) and object values (the TileEntity). The generic type arguments are the key and value type. HashMap is an implementation of this interface (the hash implementation I was talking about). This is the per-dimension map.
You need to create a field of type TIntObjectMap<Map<BlockPos, TileEntity>> in your event handler class and set it to a new instance of TIntObjectHashMap<Map<BlockPos, TileEntity>>.
The map will only store data that you put in it. If you only put TileEntityMobSpawner objects in it, it will only store TileEntityMobSpawner objects.
BlockPos only exists in 1.8+. In 1.7.10, you can use ChunkPosition instead.
To get the dimension ID, get the WorldProvider from the World#provider field and the dimension ID from the WorldProvider#dimensionId field (1.7.10) or the WorldProvider#getDimensionId method (1.8.9).
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.
Alright after guessing around reading your thing guesing around and then reading this website I think I got it. Could you tell me if this is correct? It shows no errors. Map is java.util import the tintobjecthashmap is it's own inport and the rest is minecraft inports.
Edit the second map is the outer map so where do I put the dimension id? Also How does this work is it creating a new hashmap for each new tile entity id or each new tile entity?
See how to use a Map or About the Map Interface. I haven't used that particular Map, but I believe you call feild.put with the dimension id and a new HashMap that contains the ChunkPosition and TileEntity, which is also added by calling the put function on that hash map.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
TIntObjectMap is the type of the field, TIntObjectHashMap is the type of the field's value. This is the outer map and uses the dimension ID as the key and the per-dimension map of positions and TileEntity objects.
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.
Keep getting stuck before the fun happens. It keeps erroring World getSpawnerWorld(). Your #thing didn't work. I have tried referring to the fieldSpawner that I created but, that didn't seem to help. So this tells me
if (event.block instanceof BlockMobSpawner, getSpawnerWorld)
Check if the block that was broken is a mob spawner, the TileEntity at the block's position (World#getTileEntity) was an instance of TileEntityMobSpawner and the player had the correct tool (a pickaxe with Silk Touch). If this isn't the case,
The code you posted isn't valid Java. You must have a solid understanding of Java and OO programming in general before you can make a mod.
I can't teach you Java.
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.
I was confused because, you made it sound like to use instance of mobspawner , tileentity data. So I tried that. I know enough java to get the job done I just would like to understand what you meant. I didn't know if you wanted me using the feild or the function inside TileEntityMobSpawner.class which was World getSpawnerWorld()
I took intro to computer programming so I know the basics and have studied java some as well
Get the World from the event. Use World#getTileEntity to get the TileEntity at the block's position and then check if it's an instance of TileEntityMobSpawner.
You don't need to use TileEntityMobSpawner#getSpawnerWorld.
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.
I am trying to make a mod starting with 1.7.10 and going to 1.8.9 later. I am trying to get forge harvest method to drop the current spawners meta data with modded ids supported. Currently I am unable to get a custom meta data without specifying and then that is just one metadata I want it to be whatever the spawner meta data is(aka only pig spawners). here is my code for 1.7.10 if you have advice for 1.7.10 or 1.8.9 I can probably figure it out. This event is in my handler and is registered in my mainjava.java file. I currently know it works because, I got wool with specific meta data from the spawners on a test(changed the block to wool and 1 count then changed event1.blockmetadata to 7
also have enderportal frame dropping to. again here is my 1.7.10 faulty code
Anyone have any ideas maybe I am missing code to grab the blocks metadata so it returns pigspawner
You can use the BlockState that comes with the event to get the metadata.
Putting the CENDENT back in transcendent!
actually it's not metadata I found out there are more then 16 states for spawners. I need a way to grab and return the tile entity data from vanilla and moded spawners that extends spawners how do I do that?
The event object contains the World and BlockPos from which you can get the tile entity.
Putting the CENDENT back in transcendent!
I am trying to get to get the right tile entity data upon block break method how would I combine the two events into one?
When a block is broken, the TileEntity is removed from the world before BlockEvent.HarvestDropsEvent is called unless the block specifically delays it (which mob spawners don't).
A slightly hacky way around this is to subscribe to BlockEvent.BreakEvent, check if the player has the correct tool (i.e. a pickaxe with silk touch) and then store the TileEntity. In BlockEvent.HarvestDropsEvent, retrieve the TileEntity, remove it from storage and then add an ItemStack with the appropriate NBT to the drops list. Only do this on the server.
To store the TileEntity, I recommend creating a TIntObjectMap<Map<BlockPos, TileEntity>> (use the hash implementation of each map interface). Use the dimension ID as the key for the outer map and the position as the key for the inner map.
You may want to remove any invalid TileEntities (TileEntity#isInvalid) at the end of your BlockEvent.HarvestDropsEvent handler to prevent memory leaks.
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.
So confused could you write the code fore me? I don't know what to do. I couldn't get past the item stack so the rest of the code is errored. Also How do I get your method to work without having the dimension id thing? I want it to work in any dimension.
Still need help how do you use the hashmap ?
I'm not going to write the code for you, but I will give you a more detailed description of what to do. If you know Java (a prerequisite for writing a mod), you should be able to understand this.
The dimension ID is required for this to work in multiple dimensions. The spawner at 0,1,0 in dimension 0 isn't the same as the spawner at 0,1,0 in dimension 1, so you need to store these separately.
You need to store the TIntObjectMap<Map<BlockPos, TileEntity>> as a field in your event handler class (setting it to an instance of TIntObjectHashMap<Map<BlockPos, TileEntity>>) and only access it on the server.
In your BlockEvent.BreakEvent handler, do the following:
In your BlockEvent.HarvestDropsEvent handler, do the following:
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.
Also, make sure BlockEvent.BreakEvent#harvester (BlockEvent.BreakEvent#getHarvester() in 1.8+) is not null or explosions will crash your game when you access the ItemStack. I learned that the hard way
I don't know how to do this. what is the hash map implementation interface? where is the outer map and BlockPos Isn't recognized nor is TIleEntity. Dimension id can I use the generic term to grab the id so it's not only working for the overworld or vanilla ids?
TIntObjectMap <Isthisout<isthisin>isthisout> what is going on here.
What do you mean by this? So TIntObjectMap<Map<BlockPos, TileEntity>> instance of TIntObjectHashMap<Map<BlockPos, TileEntity>> this is confusing. What event handler break, drop, harvest or just at the top of the class. Question how does the hashmap actually store the tileentity data if it's not instanceof BlockMobSpawner ?
A TIntObjectMap is a map with integer keys (the dimension ID) and object values (the per-dimension map). The generic type argument is the value type. TIntObjectHashMap is an implementation of this interface (the hash implementation I was talking about). This is the outer map.
A Map is a map with object keys (the block position) and object values (the TileEntity). The generic type arguments are the key and value type. HashMap is an implementation of this interface (the hash implementation I was talking about). This is the per-dimension map.
You need to create a field of type TIntObjectMap<Map<BlockPos, TileEntity>> in your event handler class and set it to a new instance of TIntObjectHashMap<Map<BlockPos, TileEntity>>.
The map will only store data that you put in it. If you only put TileEntityMobSpawner objects in it, it will only store TileEntityMobSpawner objects.
BlockPos only exists in 1.8+. In 1.7.10, you can use ChunkPosition instead.
To get the dimension ID, get the WorldProvider from the World#provider field and the dimension ID from the WorldProvider#dimensionId field (1.7.10) or the WorldProvider#getDimensionId method (1.8.9).
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.
Alright after guessing around reading your thing guesing around and then reading this website I think I got it. Could you tell me if this is correct? It shows no errors. Map is java.util import the tintobjecthashmap is it's own inport and the rest is minecraft inports.
Edit the second map is the outer map so where do I put the dimension id? Also How does this work is it creating a new hashmap for each new tile entity id or each new tile entity?
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.BlockMobSpawner;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.ChunkPosition;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
private TIntObjectMap<Map<ChunkPosition , TileEntity>> feild = new TIntObjectHashMap<Map<ChunkPosition, TileEntity>>();
See how to use a Map or About the Map Interface. I haven't used that particular Map, but I believe you call feild.put with the dimension id and a new HashMap that contains the ChunkPosition and TileEntity, which is also added by calling the put function on that hash map.
TIntObjectMap is the type of the field, TIntObjectHashMap is the type of the field's value. This is the outer map and uses the dimension ID as the key and the per-dimension map of positions and TileEntity objects.
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.
Keep getting stuck before the fun happens. It keeps erroring World getSpawnerWorld(). Your #thing didn't work. I have tried referring to the fieldSpawner that I created but, that didn't seem to help. So this tells me
The code you posted isn't valid Java. You must have a solid understanding of Java and OO programming in general before you can make a mod.
I can't teach you Java.
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.
I was confused because, you made it sound like to use instance of mobspawner , tileentity data. So I tried that. I know enough java to get the job done I just would like to understand what you meant. I didn't know if you wanted me using the feild or the function inside TileEntityMobSpawner.class which was World getSpawnerWorld()
I took intro to computer programming so I know the basics and have studied java some as well
Get the World from the event. Use World#getTileEntity to get the TileEntity at the block's position and then check if it's an instance of TileEntityMobSpawner.
You don't need to use TileEntityMobSpawner#getSpawnerWorld.
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.