Implemented ChickenBone's Chunk handler
This commit is contained in:
parent
c3d7bb6b7d
commit
5946d70ebf
8 changed files with 194 additions and 32 deletions
|
@ -7,6 +7,8 @@ package net.minecraft.src.forge;
|
|||
|
||||
import net.minecraft.src.BaseMod;
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.Chunk;
|
||||
import net.minecraft.src.ChunkCoordIntPair;
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.EntityMinecart;
|
||||
|
@ -160,6 +162,27 @@ public class ForgeHooks
|
|||
return cont;
|
||||
}
|
||||
static LinkedList<IPickupHandler> pickupHandlers = new LinkedList<IPickupHandler>();
|
||||
|
||||
public static void addActiveChunks(World world, Set<ChunkCoordIntPair> chunkList)
|
||||
{
|
||||
for(IChunkLoadHandler loader : chunkLoadHandlers)
|
||||
{
|
||||
loader.addActiveChunks(world, chunkList);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canUnloadChunk(Chunk chunk)
|
||||
{
|
||||
for(IChunkLoadHandler loader : chunkLoadHandlers)
|
||||
{
|
||||
if(!loader.canUnloadChunk(chunk))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static LinkedList<IChunkLoadHandler> chunkLoadHandlers = new LinkedList<IChunkLoadHandler>();
|
||||
|
||||
// Plant Management
|
||||
// ------------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package net.minecraft.src.forge;
|
||||
|
||||
import java.util.Set;
|
||||
import net.minecraft.src.Chunk;
|
||||
import net.minecraft.src.ChunkCoordIntPair;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
/**
|
||||
* Register an implementation of this interface to be used for chunk load handling.
|
||||
*/
|
||||
public interface IChunkLoadHandler
|
||||
{
|
||||
/**
|
||||
* Called from World.tickBlocksAndAmbiance
|
||||
* Add loaded chunks to this set for them to receive block tick updates
|
||||
* @param world The world containing the chunks
|
||||
* @param chunkList The set of active chunks
|
||||
*/
|
||||
public void addActiveChunks(World world, Set<ChunkCoordIntPair> chunkList);
|
||||
|
||||
/**
|
||||
* Called from ChunkProvider.dropChunk
|
||||
* Return false to prevent the unloading of this chunk
|
||||
* @param chunk The chunk to be unloaded
|
||||
*/
|
||||
public boolean canUnloadChunk(Chunk chunk);
|
||||
}
|
|
@ -92,6 +92,15 @@ public class MinecraftForge
|
|||
{
|
||||
ForgeHooks.connectionHandlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new Chunk Load event handler
|
||||
* @param handler The Handler to be registered
|
||||
*/
|
||||
public static void registerChunkLoadHandler(IChunkLoadHandler handler)
|
||||
{
|
||||
ForgeHooks.chunkLoadHandlers.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new Item Pickup event handler
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
--- ../src_base/minecraft/net/minecraft/src/ChunkProvider.java 0000-00-00 00:00:00.000000000 -0000
|
||||
+++ ../src_work/minecraft/net/minecraft/src/ChunkProvider.java 0000-00-00 00:00:00.000000000 -0000
|
||||
@@ -6,6 +6,8 @@
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
+import net.minecraft.src.forge.ForgeHooks;
|
||||
+
|
||||
public class ChunkProvider implements IChunkProvider
|
||||
{
|
||||
/** A set of dropped chunks. Currently not used in single player. */
|
||||
@@ -48,6 +50,11 @@
|
||||
|
||||
public void dropChunk(int par1, int par2)
|
||||
{
|
||||
+ if(!ForgeHooks.canUnloadChunk(worldObj.getChunkFromChunkCoords(par1, par2)))
|
||||
+ {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
ChunkCoordinates var3 = this.worldObj.getSpawnPoint();
|
||||
int var4 = par1 * 16 + 8 - var3.posX;
|
||||
int var5 = par2 * 16 + 8 - var3.posZ;
|
|
@ -1,6 +1,15 @@
|
|||
--- ../src_base/minecraft/net/minecraft/src/World.java 0000-00-00 00:00:00.000000000 -0000
|
||||
+++ ../src_work/minecraft/net/minecraft/src/World.java 0000-00-00 00:00:00.000000000 -0000
|
||||
@@ -67,7 +67,7 @@
|
||||
@@ -9,6 +9,8 @@
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
+import net.minecraft.src.forge.ForgeHooks;
|
||||
+
|
||||
public class World implements IBlockAccess
|
||||
{
|
||||
/**
|
||||
@@ -67,7 +69,7 @@
|
||||
* Contains a timestamp from when the World object was created. Is used in the session.lock file
|
||||
*/
|
||||
private long lockTimestamp;
|
||||
|
@ -9,7 +18,7 @@
|
|||
|
||||
/** Option > Difficulty setting (0 - 3) */
|
||||
public int difficultySetting;
|
||||
@@ -539,7 +539,8 @@
|
||||
@@ -539,7 +541,8 @@
|
||||
*/
|
||||
public boolean isAirBlock(int par1, int par2, int par3)
|
||||
{
|
||||
|
@ -19,7 +28,7 @@
|
|||
}
|
||||
|
||||
/**
|
||||
@@ -2037,7 +2038,7 @@
|
||||
@@ -2037,7 +2040,7 @@
|
||||
|
||||
if (var7 != null)
|
||||
{
|
||||
|
@ -28,7 +37,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
@@ -2067,18 +2068,18 @@
|
||||
@@ -2067,18 +2070,18 @@
|
||||
{
|
||||
this.loadedTileEntityList.add(var8);
|
||||
}
|
||||
|
@ -51,18 +60,18 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -2091,13 +2092,13 @@
|
||||
@@ -2091,13 +2094,13 @@
|
||||
|
||||
public void addTileEntity(Collection par1Collection)
|
||||
{
|
||||
- if (this.scanningTileEntities)
|
||||
+ List dest = scanningTileEntities ? addedTileEntityList : loadedTileEntityList;
|
||||
+ for(Object entity : par1Collection)
|
||||
{
|
||||
- {
|
||||
- this.addedTileEntityList.addAll(par1Collection);
|
||||
- }
|
||||
- else
|
||||
- {
|
||||
+ List dest = scanningTileEntities ? addedTileEntityList : loadedTileEntityList;
|
||||
+ for(Object entity : par1Collection)
|
||||
{
|
||||
- this.loadedTileEntityList.addAll(par1Collection);
|
||||
+ if(((TileEntity)entity).canUpdate())
|
||||
+ {
|
||||
|
@ -71,7 +80,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -2296,7 +2297,14 @@
|
||||
@@ -2296,7 +2299,14 @@
|
||||
if (var11 == Block.fire.blockID || var11 == Block.lavaMoving.blockID || var11 == Block.lavaStill.blockID)
|
||||
{
|
||||
return true;
|
||||
|
@ -87,7 +96,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
@@ -2597,25 +2605,19 @@
|
||||
@@ -2597,25 +2607,19 @@
|
||||
*/
|
||||
public void setBlockTileEntity(int par1, int par2, int par3, TileEntity par4TileEntity)
|
||||
{
|
||||
|
@ -125,7 +134,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -2624,27 +2626,10 @@
|
||||
@@ -2624,27 +2628,10 @@
|
||||
*/
|
||||
public void removeBlockTileEntity(int par1, int par2, int par3)
|
||||
{
|
||||
|
@ -156,7 +165,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -2670,7 +2655,8 @@
|
||||
@@ -2670,7 +2657,8 @@
|
||||
*/
|
||||
public boolean isBlockNormalCube(int par1, int par2, int par3)
|
||||
{
|
||||
|
@ -166,7 +175,15 @@
|
|||
}
|
||||
|
||||
/**
|
||||
@@ -3263,7 +3249,7 @@
|
||||
@@ -2948,6 +2936,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
+ ForgeHooks.addActiveChunks(this, activeChunkSet);
|
||||
|
||||
Profiler.endSection();
|
||||
|
||||
@@ -3263,7 +3252,7 @@
|
||||
|
||||
private int computeBlockLightValue(int par1, int par2, int par3, int par4, int par5, int par6)
|
||||
{
|
||||
|
@ -175,7 +192,7 @@
|
|||
int var8 = this.getSavedLightValue(EnumSkyBlock.Block, par2 - 1, par3, par4) - par6;
|
||||
int var9 = this.getSavedLightValue(EnumSkyBlock.Block, par2 + 1, par3, par4) - par6;
|
||||
int var10 = this.getSavedLightValue(EnumSkyBlock.Block, par2, par3 - 1, par4) - par6;
|
||||
@@ -3789,7 +3775,10 @@
|
||||
@@ -3789,7 +3778,10 @@
|
||||
{
|
||||
var8 = null;
|
||||
}
|
||||
|
@ -187,7 +204,7 @@
|
|||
return par1 > 0 && var8 == null && var9.canPlaceBlockOnSide(this, par2, par3, par4, par6);
|
||||
}
|
||||
}
|
||||
@@ -4381,4 +4370,39 @@
|
||||
@@ -4381,4 +4373,39 @@
|
||||
{
|
||||
return this.worldInfo.getTerrainType() == WorldType.field_48636_c ? 0.0D : 63.0D;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
--- ../src_base/minecraft_server/net/minecraft/src/ChunkProvider.java 0000-00-00 00:00:00.000000000 -0000
|
||||
+++ ../src_work/minecraft_server/net/minecraft/src/ChunkProvider.java 0000-00-00 00:00:00.000000000 -0000
|
||||
@@ -6,6 +6,8 @@
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
+import net.minecraft.src.forge.ForgeHooks;
|
||||
+
|
||||
public class ChunkProvider implements IChunkProvider
|
||||
{
|
||||
private Set droppedChunksSet = new HashSet();
|
||||
@@ -42,6 +44,11 @@
|
||||
*/
|
||||
public void dropChunk(int par1, int par2)
|
||||
{
|
||||
+ if(!ForgeHooks.canUnloadChunk(worldObj.getChunkFromChunkCoords(par1, par2)))
|
||||
+ {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
ChunkCoordinates var3 = this.worldObj.getSpawnPoint();
|
||||
int var4 = par1 * 16 + 8 - var3.posX;
|
||||
int var5 = par2 * 16 + 8 - var3.posZ;
|
|
@ -0,0 +1,23 @@
|
|||
--- ../src_base/minecraft_server/net/minecraft/src/ChunkProviderServer.java 0000-00-00 00:00:00.000000000 -0000
|
||||
+++ ../src_work/minecraft_server/net/minecraft/src/ChunkProviderServer.java 0000-00-00 00:00:00.000000000 -0000
|
||||
@@ -7,6 +7,8 @@
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
+import net.minecraft.src.forge.ForgeHooks;
|
||||
+
|
||||
public class ChunkProviderServer implements IChunkProvider
|
||||
{
|
||||
private Set droppedChunksSet = new HashSet();
|
||||
@@ -49,6 +51,11 @@
|
||||
|
||||
public void dropChunk(int par1, int par2)
|
||||
{
|
||||
+ if(!ForgeHooks.canUnloadChunk(world.getChunkFromChunkCoords(par1, par2)))
|
||||
+ {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
if (this.world.worldProvider.canRespawnHere())
|
||||
{
|
||||
ChunkCoordinates var3 = this.world.getSpawnPoint();
|
|
@ -1,6 +1,15 @@
|
|||
--- ../src_base/minecraft_server/net/minecraft/src/World.java 0000-00-00 00:00:00.000000000 -0000
|
||||
+++ ../src_work/minecraft_server/net/minecraft/src/World.java 0000-00-00 00:00:00.000000000 -0000
|
||||
@@ -66,7 +66,7 @@
|
||||
@@ -9,6 +9,8 @@
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
+import net.minecraft.src.forge.ForgeHooks;
|
||||
+
|
||||
public class World implements IBlockAccess
|
||||
{
|
||||
/**
|
||||
@@ -66,7 +68,7 @@
|
||||
* Contains a timestamp from when the World object was created. Is used in the session.lock file
|
||||
*/
|
||||
private long lockTimestamp = System.currentTimeMillis();
|
||||
|
@ -9,7 +18,7 @@
|
|||
|
||||
/** Whether monsters are enabled or not. (1 = on, 0 = off) */
|
||||
public int difficultySetting;
|
||||
@@ -324,7 +324,8 @@
|
||||
@@ -324,7 +326,8 @@
|
||||
*/
|
||||
public boolean isAirBlock(int par1, int par2, int par3)
|
||||
{
|
||||
|
@ -19,7 +28,7 @@
|
|||
}
|
||||
|
||||
public boolean func_48084_h(int par1, int par2, int par3)
|
||||
@@ -1549,7 +1550,7 @@
|
||||
@@ -1549,7 +1552,7 @@
|
||||
|
||||
if (var7 != null)
|
||||
{
|
||||
|
@ -28,7 +37,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
@@ -1579,14 +1580,16 @@
|
||||
@@ -1579,14 +1582,16 @@
|
||||
{
|
||||
this.loadedTileEntityList.add(var8);
|
||||
}
|
||||
|
@ -47,7 +56,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -1603,13 +1606,13 @@
|
||||
@@ -1603,13 +1608,13 @@
|
||||
|
||||
public void addTileEntity(Collection par1Collection)
|
||||
{
|
||||
|
@ -67,7 +76,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -1841,6 +1844,13 @@
|
||||
@@ -1841,6 +1846,13 @@
|
||||
if (var11 == Block.fire.blockID || var11 == Block.lavaMoving.blockID || var11 == Block.lavaStill.blockID)
|
||||
{
|
||||
return true;
|
||||
|
@ -81,7 +90,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
@@ -2121,25 +2131,21 @@
|
||||
@@ -2121,25 +2133,21 @@
|
||||
*/
|
||||
public void setBlockTileEntity(int par1, int par2, int par3, TileEntity par4TileEntity)
|
||||
{
|
||||
|
@ -120,21 +129,21 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -2148,27 +2154,10 @@
|
||||
@@ -2148,27 +2156,10 @@
|
||||
*/
|
||||
public void removeBlockTileEntity(int par1, int par2, int par3)
|
||||
{
|
||||
- TileEntity var4 = this.getBlockTileEntity(par1, par2, par3);
|
||||
-
|
||||
- if (var4 != null && this.scanningTileEntities)
|
||||
+ Chunk var5 = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4);
|
||||
+ if (var5 != null)
|
||||
{
|
||||
- {
|
||||
- var4.invalidate();
|
||||
- this.addedTileEntityList.remove(var4);
|
||||
- }
|
||||
- else
|
||||
- {
|
||||
+ Chunk var5 = this.getChunkFromChunkCoords(par1 >> 4, par3 >> 4);
|
||||
+ if (var5 != null)
|
||||
{
|
||||
- if (var4 != null)
|
||||
- {
|
||||
- this.addedTileEntityList.remove(var4);
|
||||
|
@ -151,7 +160,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
@@ -2191,7 +2180,8 @@
|
||||
@@ -2191,7 +2182,8 @@
|
||||
*/
|
||||
public boolean isBlockNormalCube(int par1, int par2, int par3)
|
||||
{
|
||||
|
@ -161,7 +170,15 @@
|
|||
}
|
||||
|
||||
/**
|
||||
@@ -2785,7 +2775,7 @@
|
||||
@@ -2463,6 +2455,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
+ ForgeHooks.addActiveChunks(this, activeChunkSet);
|
||||
|
||||
Profiler.endSection();
|
||||
|
||||
@@ -2785,7 +2778,7 @@
|
||||
|
||||
private int computeBlockLightValue(int par1, int par2, int par3, int par4, int par5, int par6)
|
||||
{
|
||||
|
@ -170,7 +187,7 @@
|
|||
int var8 = this.getSavedLightValue(EnumSkyBlock.Block, par2 - 1, par3, par4) - par6;
|
||||
int var9 = this.getSavedLightValue(EnumSkyBlock.Block, par2 + 1, par3, par4) - par6;
|
||||
int var10 = this.getSavedLightValue(EnumSkyBlock.Block, par2, par3 - 1, par4) - par6;
|
||||
@@ -3267,6 +3257,11 @@
|
||||
@@ -3267,6 +3260,11 @@
|
||||
{
|
||||
var8 = null;
|
||||
}
|
||||
|
@ -182,7 +199,7 @@
|
|||
|
||||
return par1 > 0 && var8 == null && var9.canPlaceBlockOnSide(this, par2, par3, par4, par6);
|
||||
}
|
||||
@@ -3735,4 +3730,38 @@
|
||||
@@ -3735,4 +3733,38 @@
|
||||
{
|
||||
return this.getChunkProvider().findClosestStructure(this, par1Str, par2, par3, par4);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue