New world event for controlling potential entity spawnlists. For #430
This commit is contained in:
parent
ebdc10eb1d
commit
20db933cee
4 changed files with 80 additions and 50 deletions
|
@ -1,16 +1,23 @@
|
||||||
package net.minecraftforge.event;
|
package net.minecraftforge.event;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.EntityLiving;
|
import net.minecraft.entity.EntityLiving;
|
||||||
|
import net.minecraft.entity.EnumCreatureType;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.Event.Result;
|
import net.minecraftforge.event.Event.Result;
|
||||||
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
|
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingSpecialSpawnEvent;
|
import net.minecraftforge.event.entity.living.LivingSpecialSpawnEvent;
|
||||||
import net.minecraftforge.event.entity.player.*;
|
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||||
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class ForgeEventFactory
|
public class ForgeEventFactory
|
||||||
|
@ -49,14 +56,16 @@ public class ForgeEventFactory
|
||||||
|
|
||||||
public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
|
public static boolean doSpecialSpawn(EntityLiving entity, World world, float x, float y, float z)
|
||||||
{
|
{
|
||||||
boolean result = MinecraftForge.EVENT_BUS.post(new LivingSpecialSpawnEvent(entity, world, x, y, z));
|
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z));
|
||||||
LivingSpawnEvent.SpecialSpawn nEvent = new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z);
|
}
|
||||||
|
|
||||||
if (result) //For the time being, copy the canceled state from the old legacy event
|
public static List getPotentialSpawns(WorldServer world, EnumCreatureType type, int x, int y, int z, List oldList)
|
||||||
{ // Remove when we remove LivingSpecialSpawnEvent.
|
{
|
||||||
nEvent.setCanceled(true);
|
WorldEvent.PotentialSpawns event = new WorldEvent.PotentialSpawns(world, type, x, y, z, oldList);
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(event))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
return event.list;
|
||||||
return MinecraftForge.EVENT_BUS.post(nEvent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package net.minecraftforge.event.entity.living;
|
|
||||||
|
|
||||||
import net.minecraft.entity.EntityLiving;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.event.Cancelable;
|
|
||||||
|
|
||||||
@Deprecated //Remove next MC Version
|
|
||||||
@Cancelable
|
|
||||||
public class LivingSpecialSpawnEvent extends LivingEvent
|
|
||||||
{
|
|
||||||
public final World world;
|
|
||||||
public final float x;
|
|
||||||
public final float y;
|
|
||||||
public final float z;
|
|
||||||
private boolean handeled = false;
|
|
||||||
|
|
||||||
public LivingSpecialSpawnEvent(EntityLiving entity, World world, float x, float y, float z)
|
|
||||||
{
|
|
||||||
super(entity);
|
|
||||||
this.world = world;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,12 @@
|
||||||
package net.minecraftforge.event.world;
|
package net.minecraftforge.event.world;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.entity.EnumCreatureType;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.biome.SpawnListEntry;
|
||||||
|
import net.minecraftforge.event.Cancelable;
|
||||||
import net.minecraftforge.event.Event;
|
import net.minecraftforge.event.Event;
|
||||||
|
|
||||||
public class WorldEvent extends Event
|
public class WorldEvent extends Event
|
||||||
|
@ -26,4 +32,35 @@ public class WorldEvent extends Event
|
||||||
{
|
{
|
||||||
public Save(World world) { super(world); }
|
public Save(World world) { super(world); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by WorldServer to gather a list of all possible entities that can spawn at the specified location.
|
||||||
|
* Canceling the event will result in a empty list, meaning no entity will be spawned.
|
||||||
|
*/
|
||||||
|
@Cancelable
|
||||||
|
public static class PotentialSpawns extends WorldEvent
|
||||||
|
{
|
||||||
|
public final EnumCreatureType type;
|
||||||
|
public final int x;
|
||||||
|
public final int y;
|
||||||
|
public final int z;
|
||||||
|
public final List<SpawnListEntry> list;
|
||||||
|
|
||||||
|
public PotentialSpawns(World world, EnumCreatureType type, int x, int y, int z, List oldList)
|
||||||
|
{
|
||||||
|
super(world);
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.type = type;
|
||||||
|
if (oldList != null)
|
||||||
|
{
|
||||||
|
this.list = (List<SpawnListEntry>)oldList;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.list = new ArrayList<SpawnListEntry>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -47,11 +49,18 @@
|
@@ -47,11 +49,19 @@
|
||||||
import net.minecraft.world.biome.WorldChunkManager;
|
import net.minecraft.world.biome.WorldChunkManager;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.chunk.IChunkProvider;
|
import net.minecraft.world.chunk.IChunkProvider;
|
||||||
|
@ -24,11 +24,12 @@
|
||||||
+import static net.minecraftforge.common.ChestGenHooks.*;
|
+import static net.minecraftforge.common.ChestGenHooks.*;
|
||||||
+import net.minecraftforge.common.DimensionManager;
|
+import net.minecraftforge.common.DimensionManager;
|
||||||
+import net.minecraftforge.common.MinecraftForge;
|
+import net.minecraftforge.common.MinecraftForge;
|
||||||
|
+import net.minecraftforge.event.ForgeEventFactory;
|
||||||
+import net.minecraftforge.event.world.WorldEvent;
|
+import net.minecraftforge.event.world.WorldEvent;
|
||||||
|
|
||||||
public class WorldServer extends World
|
public class WorldServer extends World
|
||||||
{
|
{
|
||||||
@@ -88,6 +97,10 @@
|
@@ -88,6 +98,10 @@
|
||||||
/** An IntHashMap of entity IDs (integers) to their Entity objects. */
|
/** An IntHashMap of entity IDs (integers) to their Entity objects. */
|
||||||
private IntHashMap entityIdMap;
|
private IntHashMap entityIdMap;
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@
|
||||||
public WorldServer(MinecraftServer par1MinecraftServer, ISaveHandler par2ISaveHandler, String par3Str, int par4, WorldSettings par5WorldSettings, Profiler par6Profiler, ILogAgent par7ILogAgent)
|
public WorldServer(MinecraftServer par1MinecraftServer, ISaveHandler par2ISaveHandler, String par3Str, int par4, WorldSettings par5WorldSettings, Profiler par6Profiler, ILogAgent par7ILogAgent)
|
||||||
{
|
{
|
||||||
super(par2ISaveHandler, par3Str, par5WorldSettings, WorldProvider.getProviderForDimension(par4), par6Profiler, par7ILogAgent);
|
super(par2ISaveHandler, par3Str, par5WorldSettings, WorldProvider.getProviderForDimension(par4), par6Profiler, par7ILogAgent);
|
||||||
@@ -122,6 +135,7 @@
|
@@ -122,6 +136,7 @@
|
||||||
|
|
||||||
scoreboardsavedata.func_96499_a(this.field_96442_D);
|
scoreboardsavedata.func_96499_a(this.field_96442_D);
|
||||||
((ServerScoreboard)this.field_96442_D).func_96547_a(scoreboardsavedata);
|
((ServerScoreboard)this.field_96442_D).func_96547_a(scoreboardsavedata);
|
||||||
|
@ -47,7 +48,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,6 +198,10 @@
|
@@ -184,6 +199,10 @@
|
||||||
this.villageSiegeObj.tick();
|
this.villageSiegeObj.tick();
|
||||||
this.theProfiler.endStartSection("portalForcer");
|
this.theProfiler.endStartSection("portalForcer");
|
||||||
this.field_85177_Q.func_85189_a(this.getTotalWorldTime());
|
this.field_85177_Q.func_85189_a(this.getTotalWorldTime());
|
||||||
|
@ -58,7 +59,15 @@
|
||||||
this.theProfiler.endSection();
|
this.theProfiler.endSection();
|
||||||
this.sendAndApplyBlockEvents();
|
this.sendAndApplyBlockEvents();
|
||||||
}
|
}
|
||||||
@@ -237,10 +255,7 @@
|
@@ -194,6 +213,7 @@
|
||||||
|
public SpawnListEntry spawnRandomCreature(EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4)
|
||||||
|
{
|
||||||
|
List list = this.getChunkProvider().getPossibleCreatures(par1EnumCreatureType, par2, par3, par4);
|
||||||
|
+ list = ForgeEventFactory.getPotentialSpawns(this, par1EnumCreatureType, par2, par3, par4, list);
|
||||||
|
return list != null && !list.isEmpty() ? (SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -237,10 +257,7 @@
|
||||||
|
|
||||||
private void resetRainAndThunder()
|
private void resetRainAndThunder()
|
||||||
{
|
{
|
||||||
|
@ -70,7 +79,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean areAllPlayersAsleep()
|
public boolean areAllPlayersAsleep()
|
||||||
@@ -311,6 +326,14 @@
|
@@ -311,6 +328,14 @@
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
Iterator iterator = this.activeChunkSet.iterator();
|
Iterator iterator = this.activeChunkSet.iterator();
|
||||||
|
@ -85,7 +94,7 @@
|
||||||
|
|
||||||
while (iterator.hasNext())
|
while (iterator.hasNext())
|
||||||
{
|
{
|
||||||
@@ -321,14 +344,18 @@
|
@@ -321,14 +346,18 @@
|
||||||
Chunk chunk = this.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos);
|
Chunk chunk = this.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos);
|
||||||
this.moodSoundAndLightCheck(k, l, chunk);
|
this.moodSoundAndLightCheck(k, l, chunk);
|
||||||
this.theProfiler.endStartSection("tickChunk");
|
this.theProfiler.endStartSection("tickChunk");
|
||||||
|
@ -106,7 +115,7 @@
|
||||||
{
|
{
|
||||||
this.updateLCG = this.updateLCG * 3 + 1013904223;
|
this.updateLCG = this.updateLCG * 3 + 1013904223;
|
||||||
i1 = this.updateLCG >> 2;
|
i1 = this.updateLCG >> 2;
|
||||||
@@ -345,7 +372,7 @@
|
@@ -345,7 +374,7 @@
|
||||||
this.theProfiler.endStartSection("iceandsnow");
|
this.theProfiler.endStartSection("iceandsnow");
|
||||||
int i2;
|
int i2;
|
||||||
|
|
||||||
|
@ -115,7 +124,7 @@
|
||||||
{
|
{
|
||||||
this.updateLCG = this.updateLCG * 3 + 1013904223;
|
this.updateLCG = this.updateLCG * 3 + 1013904223;
|
||||||
i1 = this.updateLCG >> 2;
|
i1 = this.updateLCG >> 2;
|
||||||
@@ -430,7 +457,8 @@
|
@@ -430,7 +459,8 @@
|
||||||
public void func_82740_a(int par1, int par2, int par3, int par4, int par5, int par6)
|
public void func_82740_a(int par1, int par2, int par3, int par4, int par5, int par6)
|
||||||
{
|
{
|
||||||
NextTickListEntry nextticklistentry = new NextTickListEntry(par1, par2, par3, par4);
|
NextTickListEntry nextticklistentry = new NextTickListEntry(par1, par2, par3, par4);
|
||||||
|
@ -125,7 +134,7 @@
|
||||||
|
|
||||||
if (this.scheduledUpdatesAreImmediate && par4 > 0)
|
if (this.scheduledUpdatesAreImmediate && par4 > 0)
|
||||||
{
|
{
|
||||||
@@ -493,7 +521,7 @@
|
@@ -493,7 +523,7 @@
|
||||||
*/
|
*/
|
||||||
public void updateEntities()
|
public void updateEntities()
|
||||||
{
|
{
|
||||||
|
@ -134,7 +143,7 @@
|
||||||
{
|
{
|
||||||
if (this.updateEntityTick++ >= 1200)
|
if (this.updateEntityTick++ >= 1200)
|
||||||
{
|
{
|
||||||
@@ -559,7 +587,8 @@
|
@@ -559,7 +589,8 @@
|
||||||
{
|
{
|
||||||
nextticklistentry = (NextTickListEntry)iterator.next();
|
nextticklistentry = (NextTickListEntry)iterator.next();
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
|
@ -144,7 +153,7 @@
|
||||||
|
|
||||||
if (this.checkChunksExist(nextticklistentry.xCoord - b0, nextticklistentry.yCoord - b0, nextticklistentry.zCoord - b0, nextticklistentry.xCoord + b0, nextticklistentry.yCoord + b0, nextticklistentry.zCoord + b0))
|
if (this.checkChunksExist(nextticklistentry.xCoord - b0, nextticklistentry.yCoord - b0, nextticklistentry.zCoord - b0, nextticklistentry.xCoord + b0, nextticklistentry.yCoord + b0, nextticklistentry.zCoord + b0))
|
||||||
{
|
{
|
||||||
@@ -698,16 +727,28 @@
|
@@ -698,16 +729,28 @@
|
||||||
{
|
{
|
||||||
ArrayList arraylist = new ArrayList();
|
ArrayList arraylist = new ArrayList();
|
||||||
|
|
||||||
|
@ -183,7 +192,7 @@
|
||||||
return arraylist;
|
return arraylist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,6 +756,11 @@
|
@@ -715,6 +758,11 @@
|
||||||
* Called when checking if a certain block can be mined or not. The 'spawn safe zone' check is located here.
|
* Called when checking if a certain block can be mined or not. The 'spawn safe zone' check is located here.
|
||||||
*/
|
*/
|
||||||
public boolean canMineBlock(EntityPlayer par1EntityPlayer, int par2, int par3, int par4)
|
public boolean canMineBlock(EntityPlayer par1EntityPlayer, int par2, int par3, int par4)
|
||||||
|
@ -195,7 +204,7 @@
|
||||||
{
|
{
|
||||||
return !this.mcServer.func_96290_a(this, par2, par3, par4, par1EntityPlayer);
|
return !this.mcServer.func_96290_a(this, par2, par3, par4, par1EntityPlayer);
|
||||||
}
|
}
|
||||||
@@ -799,7 +845,7 @@
|
@@ -799,7 +847,7 @@
|
||||||
*/
|
*/
|
||||||
protected void createBonusChest()
|
protected void createBonusChest()
|
||||||
{
|
{
|
||||||
|
@ -204,7 +213,7 @@
|
||||||
|
|
||||||
for (int i = 0; i < 10; ++i)
|
for (int i = 0; i < 10; ++i)
|
||||||
{
|
{
|
||||||
@@ -842,6 +888,7 @@
|
@@ -842,6 +890,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.chunkProvider.saveChunks(par1, par2IProgressUpdate);
|
this.chunkProvider.saveChunks(par1, par2IProgressUpdate);
|
||||||
|
@ -212,7 +221,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -853,6 +900,7 @@
|
@@ -853,6 +902,7 @@
|
||||||
this.checkSessionLock();
|
this.checkSessionLock();
|
||||||
this.saveHandler.saveWorldInfoWithPlayer(this.worldInfo, this.mcServer.getConfigurationManager().getHostPlayerData());
|
this.saveHandler.saveWorldInfoWithPlayer(this.worldInfo, this.mcServer.getConfigurationManager().getHostPlayerData());
|
||||||
this.mapStorage.saveAllData();
|
this.mapStorage.saveAllData();
|
||||||
|
@ -220,7 +229,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1066,4 +1114,9 @@
|
@@ -1066,4 +1116,9 @@
|
||||||
{
|
{
|
||||||
return this.field_85177_Q;
|
return this.field_85177_Q;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue