MobSpawner.java:19: error: incompatible types: Entity cannot be converted to Optional<Entity>
.createEntity(EntityTypes.CREEPER, spawnLocation.getPosition());
So my question…how would one go about fixing this?
If you’re curious I’m going to be tryinag this without EntitySpawnEvent, so that way i can spawn Mobs in the overworld without a EntitySpawn event…so any help would be nice.
…well here’s the thing lol here’s the older code i use to use
public void onEntitySpawn(SpawnEntityEvent event){
//this logs the Spawn event to show that this is working.
//Sponge.getGame().getServer().getBroadcastChannel().send(Text.of("Don't be an Idiot"));
for (EntitySnapshot entitySnapshot : event.getEntitySnapshots()) {
if (entitySnapshot.getType().equals(EntityTypes.BLAZE)) {
java.util.Optional<Location<World>> location = entitySnapshot.getLocation();
if (location.isPresent()) {
World world = location.get().getExtent();
for (int i = 0; i < (ConfigurationManager.getInstance().getConfig().getNode("Spawning!", "Blaze", "Blaze#").getInt()); i++) { // Do this 5 times
Random roll = new Random();
int answer = roll.nextInt(100)+1;
if (answer <= (ConfigurationManager.getInstance().getConfig().getNode("Spawning!", "Blaze", "Blaze%").getInt())){
Optional<Entity> newCreeper = (Optional<Entity>) world.createEntity(EntityTypes.BLAZE, location.get().getPosition());
if (newCreeper.isPresent()) {
event.getEntities().add(newCreeper.get());
}
}
}
}
}
and when i do this here’s the error log that happens…
I’m trying to grab the entity in this case as it spawns so that i can spawn more based upon a random figure that’s configurable with a percentile chance.
C:\Users\chris\Desktop\Mod Workstation\workshop\eclipse\HellOnSpongee\src\main\java\me\Cleardragonf\HOS\MobSpawning.java:31: error: no suitable method found for add(Location<World>)
event.getEntities().add(newCreeper.get());
^
method Collection.add(Entity) is not applicable
It’s telling you that you’re trying to add a Location to the entity list, but the collection is of type Entity. Once you have an Entity, you don’t need to call .get() on it anymore.
Ok…i see that now. however when i change that and use the SpawnEntity() I’m now getting one error on the if(entity.isPresent())
here’s the compilation
C:\Users\chris\Desktop\Mod Workstation\workshop\eclipse\HellOnSpongee\src\main\java\me\Cleardragonf\HOS\HOS.java:114: error: cannot find symbol
if (entity.isPresent()) {
^
symbol: method isPresent()
location: variable entity of type Entity
1 error
Alright so I played around with it for a bit…and this seems to be getting the correct specifications…however the adding of another creeper doesn’t seem to be working…can someone point out the obvious for me?
You need to call createEntity() and then pass that to spawnEntity().
You’re trying to spawn the entity from the event. Don’t do that; if it appears in the event, it will be spawned automatically after the listeners finish running.
A Vector3d is not an EntityUniverse. A Vector3d is just an X/Y/Z position (although it’s used for rotation in some cases). The World is available from Location.getExtent(); it implements EntityUniverse.
You mean its erroring at
if (optional.isPresent())
since you don’t have an optional variable-object in scope, because When you made this plugin before, the createEntity() method returned an optional vairable, and as everyone has been saying repeatedly, the newer API versions have changed that to NOT be an Optional return, but rather a straight-up Entity.
your Entity entity = The Creeper Object returned
and the Entity creeper = optional.get() is acting on nothing at all, again, because you dont’ have an “optional” variable object. And the creeper is already the entity, not Optional to need to .get()