I have a Question. I have a few generated Structures that I have created. However, since Entities don't spawn in them, I thought of resorting to One-use Spawners. The problem is, how would this be resolved? I want the Spawners to load in the Mobs when approached at a certain distance, but, again, not sure how to do it. Here is the Basic Code I came up with for the Block:
[/p]
[p]package com.stormarmory;[/p]
[p]import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;[/p]
[p]public class BlockMobSpawner
extends BlockContainer
{
public BlockMobSpawner()
{
super(Material.rock);
}
public int idDropped(int par1, Random par2Random, int par3)
{
return 0;
}
public int quantityDropped(Random par1Random)
{
return 0;
}
public boolean isOpaqueCube()
{
return false;
}
public IIcon getIcon(int i, int j)
{
return Blocks.mob_spawner.getIcon(i, j);
}
public TileEntity createNewTileEntity(World var1, int var2)
{
return null; //Mob Spawner would go here
}
}[/p]
[p]
If your entity is set to never despawn, you can just spawn it when you generate the structure.
Something else that I've done is spawn the entity when a chest is opened. For that, you can use an event and then you would need to make sure it is the right chest that was opened. Another way to do it is have a custom chest.
I've never tried to make a mob spawner just spawn one entity though.
Actually, I just now found out that I could actually use Spawners from NEI to generate in my Structures. The Problem is, that they turn into a Pig Spawner whenever the Structure Generates. Here is the Code I used for the Structure, notice the Metadata I used for the Spawner is akin to my Entity's Mob ID.
[/p]
[p]ackage com.stormarmory.structures;[/p]
[p]import java.util.Random;[/p]
[p]import com.stormarmory.blocks.MBlocks;[/p]
[p]import cpw.mods.fml.common.IWorldGenerator;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenerator;[/p]
[p]public class Hive extends WorldGenerator implements IWorldGenerator
{
protected Block[] getValidSpawnBlocks() {
return new Block[] {
Blocks.grass
};
}[/p]
[p]public boolean locationIsValidSpawn(World world, int i, int j, int k){
int distanceToAir = 0;
Block check = world.getBlock(i, j, k);[/p]
[p]while (check != Blocks.air){
if (distanceToAir > 3){
return false;
}[/p]
[p]distanceToAir++;
check = world.getBlock(i, j + distanceToAir, k);
}[/p]
[p]j += distanceToAir - 1;[/p]
[p]Block block = world.getBlock(i, j, k);
Block blockAbove = world.getBlock(i, j+1, k);
Block blockBelow = world.getBlock(i, j-1, k);
for (Block x : getValidSpawnBlocks()){
if (blockAbove != Blocks.air){
return false;
}
if (block == x){
return true;
}else if (block == Blocks.snow && blockBelow == x){
return true;
}
}
return false;
}[/p]
[p]public Hive() { }[/p]
[p]@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { }[/p]
[p]public void setBlock(World world, int x, int y, int z, Block block, int metadata)
{
Block b1 = world.getBlock(x, y, z);[/p]
[p]if(b1.isAir(world, x, y, z) || b1.isLeaves(world, x, y, z))
{
world.setBlock(x, y, z, block, metadata, 2);
}
}[/p]
[p]public boolean generate(World world, Random rand, int i, int j, int k) {
//check that each corner is one of the valid spawn blocks
if(!locationIsValidSpawn(world, i, j, k) || !locationIsValidSpawn(world, i + 2, j, k) || !locationIsValidSpawn(world, i + 2, j, k + 2) || !locationIsValidSpawn(world, i, j, k + 2))
{
return false;
}[/p]
[p]k = k - 10;
i = i - 10;[/p]
[p]this.setBlock(world, i + 0, j + 0, k + 0, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 0, j + 0, k + 1, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 0, j + 0, k + 2, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 0, j + 1, k + 0, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 0, j + 1, k + 1, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 0, j + 1, k + 2, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 0, j + 2, k + 0, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 0, j + 2, k + 1, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 0, j + 2, k + 2, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 1, j + 0, k + 0, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 1, j + 0, k + 1, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 1, j + 0, k + 2, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 1, j + 1, k + 0, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 1, j + 1, k + 1, Blocks.mob_spawner, 182);
this.setBlock(world, i + 1, j + 1, k + 2, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 1, j + 2, k + 0, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 1, j + 2, k + 1, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 1, j + 2, k + 2, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 2, j + 0, k + 0, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 2, j + 0, k + 1, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 2, j + 0, k + 2, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 2, j + 1, k + 0, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 2, j + 1, k + 1, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 2, j + 1, k + 2, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 2, j + 2, k + 0, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 2, j + 2, k + 1, MBlocks.HiveBlock, 0);
this.setBlock(world, i + 2, j + 2, k + 2, MBlocks.HiveBlock, 0);[/p]
[p]return true;
}
}[/p]
[p]
The Entity spawned by a spawner is controlled by the TileEntity, not the metadata of the Block (which can only go up to 15 anyway).
To properly generate a mob spawner, you need to do the following:
Set the Block at the specified coordinates to Blocks.mob_spawner
Get the TileEntityMobSpawner at those coordinates
Call TileEntityMobSpawner#func_145881_a to get its MobSpawnerBaseLogic instance
Call MobSpawnerBaseLogic#setEntityName to set the name of the Entity to spawn (this is the same name you used to register the Entity with EntityRegistry)
To create a one-use mob spawner, you can probably copy TileEntityMobSpawner and override MobSpawnerBaseLogic#func_98265_a (which spawns the Entity) to set the Block at the spawner's coordinates to Air.
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.
How would I get the TileEntityMobSpawner at those coordinates?
Call World#getTileEntity and cast the result to TileEntityMobSpawner.
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.
Ah, just tried this, but It seems to still not work, despite being exactly on the Spawner's Coordinates.
That's odd. Which part isn't working?
Is the spawner being placed correctly? Is the TileEntity being created? Is it spawning anything?
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.
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.
Using "Wasp" should work, since that's the name you registered it with. If you use "Wasp", does it still spawn pigs?
I just tested this with my own custom entity here (registration) and it worked without issue.
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 even tried using the Unlocalized name "Wasp", but it still doesn't work.
That is not the recommended way to register your own entities. You now register them by name, not Id. IDs are only for Minecraft to use, not mods. Something like this is preferred:
Hmm, odd. I had an Error on "modEntityID" in the first line, and "Core.instance" also showed up as an Error, so I replaced it with "Refstrings.MODID".
Ya, I copied that code from my mod, so of course you need to make some changes to use it
So the Core.instance is simply a class variable in the main mode file (I called my main class Core), that I declared like this:
@Instance(REFERENCE.MODID)
public static Core instance;
So it isn't the MODID, it is a reference to the main class of the mod, the one with the @Mod at the top.
And looking at your latest code, you added this:
int entityID = EntityRegistry.findGlobalUniqueEntityId();
So you are essentially going back to trying to get the id the old way, but you don't need that. Simply add the variable as a class variable (if you Google that, you will see that that is not a local variable, but one that is global to the class). Most people put this up at the top of the Java file, just under where you declare the class.
Hmm, I wish I could point you to a "good" tutorial on this, but everyone I look at is either full of "errors" or just too complicated for what you are trying to do.
There are so many ways to do your own entities, and there is probably at least one tutorial out there that contains mistakes for each thing you can do "wrong".
Another common mistake when registering an entity is to set the update value to 1, like you do here:
In most cases, 3 or more is fine. Setting this to 1 causes 3 times as many "updates" to the entity as 3 does. The problem is that if you have a lot of entities, then this can begin to lag Minecraft with to many "updates". I put that in quotes, because I'm not exactly sure what it does
Mind if you show me your Entity Registry Class for Reference? I understand the Velocity Updates that you mentioned in your second post, but am still clueless on where to initialize "entityID".
I have a Question. I have a few generated Structures that I have created. However, since Entities don't spawn in them, I thought of resorting to One-use Spawners. The problem is, how would this be resolved? I want the Spawners to load in the Mobs when approached at a certain distance, but, again, not sure how to do it. Here is the Basic Code I came up with for the Block:
If your entity is set to never despawn, you can just spawn it when you generate the structure.
Something else that I've done is spawn the entity when a chest is opened. For that, you can use an event and then you would need to make sure it is the right chest that was opened. Another way to do it is have a custom chest.
I've never tried to make a mob spawner just spawn one entity though.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Actually, I just now found out that I could actually use Spawners from NEI to generate in my Structures. The Problem is, that they turn into a Pig Spawner whenever the Structure Generates. Here is the Code I used for the Structure, notice the Metadata I used for the Spawner is akin to my Entity's Mob ID.
The Entity spawned by a spawner is controlled by the TileEntity, not the metadata of the Block (which can only go up to 15 anyway).
To properly generate a mob spawner, you need to do the following:
To create a one-use mob spawner, you can probably copy TileEntityMobSpawner and override MobSpawnerBaseLogic#func_98265_a (which spawns the Entity) to set the Block at the spawner's coordinates to Air.
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.
How would I get the TileEntityMobSpawner at those coordinates? I tried:
Call World#getTileEntity and cast the result to TileEntityMobSpawner.
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.
Ah, just tried this, but It seems to still not work, despite being exactly on the Spawner's Coordinates.
I don't think you need that last setBlockMetadataWithNotify.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
That's odd. Which part isn't working?
Is the spawner being placed correctly? Is the TileEntity being created? Is it spawning anything?
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.
All it's Spawning is Pigs. But the Game is Registering it, because my "Printin" works.
Does the ".setEntityName("EntityMutatedWasp");" need to have the Targeted Entity in Quotations?
Is "EntityMutatedWisp" the name you used when registering the Entity with EntityRegistry.registerModEntity?
I just wrote this basic example of a sheep spawner world generator and it works without issue (with the caveat that sheep require grass to spawn on).
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.
Here is the Registration Line for my Entity:
I even tried using the Unlocalized name "Wasp", but it still doesn't work.
Using "Wasp" should work, since that's the name you registered it with. If you use "Wasp", does it still spawn pigs?
I just tested this with my own custom entity here (registration) and it worked without issue.
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.
That is not the recommended way to register your own entities. You now register them by name, not Id. IDs are only for Minecraft to use, not mods. Something like this is preferred:
private static int modEntityID = 0;
EntityRegistry.registerModEntity(EntityMutatedWasp.class, "Wasp", ++modEntityID, Core.instance, 80, 3, true);
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Hmm, odd. I had an Error on "modEntityID" in the first line, and "Core.instance" also showed up as an Error, so I replaced it with "Refstrings.MODID".
Here is what my EntityRegistry Class looks like now. But in-game I get no Spawn eggs:
Ya, I copied that code from my mod, so of course you need to make some changes to use it
So the Core.instance is simply a class variable in the main mode file (I called my main class Core), that I declared like this:
@Instance(REFERENCE.MODID)
public static Core instance;
So it isn't the MODID, it is a reference to the main class of the mod, the one with the @Mod at the top.
And looking at your latest code, you added this:
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Hmm, I wish I could point you to a "good" tutorial on this, but everyone I look at is either full of "errors" or just too complicated for what you are trying to do.
There are so many ways to do your own entities, and there is probably at least one tutorial out there that contains mistakes for each thing you can do "wrong".
Another common mistake when registering an entity is to set the update value to 1, like you do here:
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Mind if you show me your Entity Registry Class for Reference? I understand the Velocity Updates that you mentioned in your second post, but am still clueless on where to initialize "entityID".