3
0

Initial commit (Forge 1291).

This commit is contained in:
gamerforEA
2015-03-22 20:38:04 +03:00
commit 16773ead6a
611 changed files with 64826 additions and 0 deletions

View File

@ -0,0 +1,228 @@
--- ../src-base/minecraft/net/minecraft/world/chunk/storage/AnvilChunkLoader.java
+++ ../src-work/minecraft/net/minecraft/world/chunk/storage/AnvilChunkLoader.java
@@ -33,6 +33,13 @@
import org.apache.logging.log4j.Logger;
import cpw.mods.fml.common.FMLLog;
+// Cauldron start
+import java.util.Map;
+import net.minecraft.server.MinecraftServer;
+import net.minecraftforge.cauldron.CauldronUtils;
+import net.minecraftforge.common.util.EnumHelper;
+import cpw.mods.fml.common.asm.transformers.SideTransformer;
+// Cauldron end
public class AnvilChunkLoader implements IChunkLoader, IThreadedFileIO
{
@@ -41,6 +48,7 @@
private Set pendingAnvilChunksCoordinates = new HashSet();
private Object syncLockObject = new Object();
public final File chunkSaveLocation;
+ private List checkedTileEntities = new ArrayList(); // Cauldron
private static final String __OBFID = "CL_00000384";
public AnvilChunkLoader(File p_i2003_1_)
@@ -73,13 +81,16 @@
public Chunk loadChunk(World p_75815_1_, int p_75815_2_, int p_75815_3_) throws IOException
{
+ p_75815_1_.timings.syncChunkLoadDataTimer.startTiming(); // Spigot
Object[] data = this.loadChunk__Async(p_75815_1_, p_75815_2_, p_75815_3_);
+ p_75815_1_.timings.syncChunkLoadDataTimer.stopTiming(); // Spigot
if (data != null)
{
Chunk chunk = (Chunk) data[0];
NBTTagCompound nbttagcompound = (NBTTagCompound) data[1];
this.loadEntities(p_75815_1_, nbttagcompound.getCompoundTag("Level"), chunk);
+ MinecraftForge.EVENT_BUS.post(new ChunkDataEvent.Load(chunk, nbttagcompound)); // Cauldron - Don't call ChunkDataEvent.Load async
return chunk;
}
@@ -156,8 +167,8 @@
if (!chunk.isAtLocation(p_75822_2_, p_75822_3_))
{
logger.error("Chunk file at " + p_75822_2_ + "," + p_75822_3_ + " is in the wrong location; relocating. (Expected " + p_75822_2_ + ", " + p_75822_3_ + ", got " + chunk.xPosition + ", " + chunk.zPosition + ")");
- p_75822_4_.setInteger("xPos", p_75822_2_);
- p_75822_4_.setInteger("zPos", p_75822_3_);
+ p_75822_4_.getCompoundTag("Level").setInteger("xPos", p_75822_2_); // CraftBukkit - .getCompound("Level")
+ p_75822_4_.getCompoundTag("Level").setInteger("zPos", p_75822_3_); // CraftBukkit - .getCompound("Level")
// Have to move tile entities since we don't load them at this stage
NBTTagList tileEntities = p_75822_4_.getCompoundTag("Level").getTagList("TileEntities", 10);
@@ -187,8 +198,18 @@
public void saveChunk(World p_75816_1_, Chunk p_75816_2_) throws MinecraftException, IOException
{
- p_75816_1_.checkSessionLock();
+ // CraftBukkit start - "handle" exception
+ try
+ {
+ p_75816_1_.checkSessionLock();
+ }
+ catch (MinecraftException ex)
+ {
+ ex.printStackTrace();
+ }
+ // CraftBukkit end
+
try
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
@@ -230,7 +251,7 @@
public boolean writeNextIO()
{
- AnvilChunkLoader.PendingChunk pendingchunk = null;
+ PendingChunk pendingchunktosave = null;
Object object = this.syncLockObject;
synchronized (this.syncLockObject)
@@ -240,15 +261,15 @@
return false;
}
- pendingchunk = (AnvilChunkLoader.PendingChunk)this.chunksToRemove.remove(0);
- this.pendingAnvilChunksCoordinates.remove(pendingchunk.chunkCoordinate);
+ pendingchunktosave = (PendingChunk) this.chunksToRemove.remove(0);
+ this.pendingAnvilChunksCoordinates.remove(pendingchunktosave.chunkCoordinate);
}
- if (pendingchunk != null)
+ if (pendingchunktosave != null)
{
try
{
- this.writeChunkNBTTags(pendingchunk);
+ this.writeChunkNBTTags(pendingchunktosave);
}
catch (Exception exception)
{
@@ -259,7 +280,7 @@
return true;
}
- private void writeChunkNBTTags(AnvilChunkLoader.PendingChunk p_75821_1_) throws IOException
+ public void writeChunkNBTTags(AnvilChunkLoader.PendingChunk p_75821_1_) throws java.io.IOException // CraftBukkit - public -> private, added throws
{
DataOutputStream dataoutputstream = RegionFileCache.getChunkOutputStream(this.chunkSaveLocation, p_75821_1_.chunkCoordinate.chunkXPos, p_75821_1_.chunkCoordinate.chunkZPos);
CompressedStreamTools.write(p_75821_1_.nbtTags, dataoutputstream);
@@ -307,19 +328,19 @@
if (extendedblockstorage.getBlockMSBArray() != null)
{
- nbttagcompound1.setByteArray("Add", extendedblockstorage.getBlockMSBArray().data);
+ nbttagcompound1.setByteArray("Add", extendedblockstorage.getBlockMSBArray().getValueArray()); // Spigot
}
- nbttagcompound1.setByteArray("Data", extendedblockstorage.getMetadataArray().data);
- nbttagcompound1.setByteArray("BlockLight", extendedblockstorage.getBlocklightArray().data);
+ nbttagcompound1.setByteArray("Data", extendedblockstorage.getMetadataArray().getValueArray()); // Spigot
+ nbttagcompound1.setByteArray("BlockLight", extendedblockstorage.getBlocklightArray().getValueArray()); // Spigot
if (flag)
{
- nbttagcompound1.setByteArray("SkyLight", extendedblockstorage.getSkylightArray().data);
+ nbttagcompound1.setByteArray("SkyLight", extendedblockstorage.getSkylightArray().getValueArray()); // Spigot
}
else
{
- nbttagcompound1.setByteArray("SkyLight", new byte[extendedblockstorage.getBlocklightArray().data.length]);
+ nbttagcompound1.setByteArray("SkyLight", new byte[extendedblockstorage.getBlocklightArray().getValueArray().length]); // Spigot
}
nbttaglist.appendTag(nbttagcompound1);
@@ -455,6 +476,7 @@
public void loadEntities(World p_75823_1_, NBTTagCompound p_75823_2_, Chunk chunk)
{
+ p_75823_1_.timings.syncChunkLoadEntitiesTimer.startTiming(); // Spigot
NBTTagList nbttaglist1 = p_75823_2_.getTagList("Entities", 10);
if (nbttaglist1 != null)
@@ -468,24 +490,31 @@
if (entity2 != null)
{
chunk.addEntity(entity2);
- Entity entity = entity2;
-
- for (NBTTagCompound nbttagcompound2 = nbttagcompound3; nbttagcompound2.hasKey("Riding", 10); nbttagcompound2 = nbttagcompound2.getCompoundTag("Riding"))
+ // Cauldron start - check to see if we killed entity due to invalid location
+ if (!entity2.isDead)
{
- Entity entity1 = EntityList.createEntityFromNBT(nbttagcompound2.getCompoundTag("Riding"), p_75823_1_);
+ Entity entity = entity2;
- if (entity1 != null)
+ for (NBTTagCompound nbttagcompound2 = nbttagcompound3; nbttagcompound2.hasKey("Riding", 10); nbttagcompound2 = nbttagcompound2.getCompoundTag("Riding"))
{
- chunk.addEntity(entity1);
- entity.mountEntity(entity1);
- }
+ Entity entity1 = EntityList.createEntityFromNBT(nbttagcompound2.getCompoundTag("Riding"), p_75823_1_);
- entity = entity1;
+ if (entity1 != null)
+ {
+ chunk.addEntity(entity1);
+ entity.mountEntity(entity1);
+ }
+
+ entity = entity1;
+ }
}
+ // Cauldron end
}
}
}
+ p_75823_1_.timings.syncChunkLoadEntitiesTimer.stopTiming(); // Spigot
+ p_75823_1_.timings.syncChunkLoadTileEntitiesTimer.startTiming(); // Spigot
NBTTagList nbttaglist2 = p_75823_2_.getTagList("TileEntities", 10);
if (nbttaglist2 != null)
@@ -497,11 +526,35 @@
if (tileentity != null)
{
+ // Cauldron start - check if TE should tick and inject into Bukkit's InventoryType
+ if (!this.checkedTileEntities.contains(tileentity.getClass()))
+ {
+ // verify if TE should tick
+ if (MinecraftServer.getServer().tileEntityConfig.preventInvalidTileEntityUpdates.getValue())
+ {
+ SideTransformer.allowInvalidSide = true;
+ if (!CauldronUtils.isOverridingUpdateEntity(tileentity.getClass()) && CauldronUtils.canTileEntityUpdate(tileentity.getClass()))
+ {
+ if (MinecraftServer.getServer().tileEntityConfig.enableTECanUpdateWarning.getValue())
+ {
+ MinecraftServer.getServer().logInfo("Detected TE " + tileentity.getClass().getName() + " with canUpdate set to true and no updateEntity override!. Please report to mod author as this can hurt performance.");
+ }
+ MinecraftServer.getServer().bannedTileEntityUpdates.add(tileentity.getClass());
+ }
+ SideTransformer.allowInvalidSide = false;
+ }
+ // inject TE into InventoryType to support inventory events
+ EnumHelper.addInventoryType(tileentity);
+ this.checkedTileEntities.add(tileentity.getClass());
+ }
+ // Cauldron end
chunk.addTileEntity(tileentity);
}
}
}
+ p_75823_1_.timings.syncChunkLoadTileEntitiesTimer.stopTiming(); // Spigot
+ p_75823_1_.timings.syncChunkLoadTileTicksTimer.startTiming(); // Spigot
if (p_75823_2_.hasKey("TileTicks", 9))
{
NBTTagList nbttaglist3 = p_75823_2_.getTagList("TileTicks", 10);
@@ -515,6 +568,7 @@
}
}
}
+ p_75823_1_.timings.syncChunkLoadTileTicksTimer.stopTiming(); // Spigot
// return chunk;
}

View File

@ -0,0 +1,25 @@
--- ../src-base/minecraft/net/minecraft/world/chunk/storage/AnvilSaveHandler.java
+++ ../src-work/minecraft/net/minecraft/world/chunk/storage/AnvilSaveHandler.java
@@ -21,6 +21,11 @@
public IChunkLoader getChunkLoader(WorldProvider p_75763_1_)
{
File file1 = this.getWorldDirectory();
+ // Cauldron start
+ // To workaround the issue of Bukkit relying on every world having a seperate container
+ // we won't be generating a DIMXX folder for chunk loaders since this name is already generated
+ // for the world container with provider.getSaveFolder().
+ /*
File file2;
if (p_75763_1_.getSaveFolder() != null)
@@ -32,7 +37,9 @@
else
{
return new AnvilChunkLoader(file1);
- }
+ } */
+ return new AnvilChunkLoader(file1);
+ // Cauldron end
}
public void saveWorldInfoWithPlayer(WorldInfo p_75755_1_, NBTTagCompound p_75755_2_)

View File

@ -0,0 +1,17 @@
--- ../src-base/minecraft/net/minecraft/world/chunk/storage/ChunkLoader.java
+++ ../src-work/minecraft/net/minecraft/world/chunk/storage/ChunkLoader.java
@@ -113,9 +113,11 @@
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Y", (byte)(j & 255));
nbttagcompound1.setByteArray("Blocks", abyte1);
- nbttagcompound1.setByteArray("Data", nibblearray.data);
- nbttagcompound1.setByteArray("SkyLight", nibblearray1.data);
- nbttagcompound1.setByteArray("BlockLight", nibblearray2.data);
+ // Spigot start - data -> getValueArray() accessor
+ nbttagcompound1.setByteArray("Data", nibblearray.getValueArray());
+ nbttagcompound1.setByteArray("SkyLight", nibblearray1.getValueArray());
+ nbttagcompound1.setByteArray("BlockLight", nibblearray2.getValueArray());
+ // Spigot end
nbttaglist.appendTag(nbttagcompound1);
}
}

View File

@ -0,0 +1,217 @@
--- ../src-base/minecraft/net/minecraft/world/chunk/storage/ExtendedBlockStorage.java
+++ ../src-work/minecraft/net/minecraft/world/chunk/storage/ExtendedBlockStorage.java
@@ -31,6 +31,29 @@
}
}
+ // CraftBukkit start
+ public ExtendedBlockStorage(int y, boolean flag, byte[] blkIds, byte[] extBlkIds)
+ {
+ this.yBase = y;
+ this.blockLSBArray = blkIds;
+
+ if (extBlkIds != null)
+ {
+ this.blockMSBArray = new NibbleArray(extBlkIds, 4);
+ }
+
+ this.blockMetadataArray = new NibbleArray(this.blockLSBArray.length, 4);
+ this.blocklightArray = new NibbleArray(this.blockLSBArray.length, 4);
+
+ if (flag)
+ {
+ this.skylightArray = new NibbleArray(this.blockLSBArray.length, 4);
+ }
+
+ this.removeInvalidBlocks();
+ }
+ // CraftBukkit end
+
public Block getBlockByExtId(int p_150819_1_, int p_150819_2_, int p_150819_3_)
{
int l = this.blockLSBArray[p_150819_2_ << 8 | p_150819_3_ << 4 | p_150819_1_] & 255;
@@ -139,6 +162,106 @@
public void removeInvalidBlocks()
{
+ // CraftBukkit start - Optimize for speed
+ byte[] blkIds = this.blockLSBArray;
+ int cntNonEmpty = 0;
+ int cntTicking = 0;
+
+ if (this.blockMSBArray == null) // No extended block IDs? Don't waste time messing with them
+ {
+ for (int off = 0; off < blkIds.length; off++)
+ {
+ int l = blkIds[off] & 0xFF;
+
+ if (l > 0)
+ {
+ if (Block.getBlockById(l) == null)
+ {
+ blkIds[off] = 0;
+ }
+ else
+ {
+ ++cntNonEmpty;
+
+ if (Block.getBlockById(l).getTickRandomly())
+ {
+ ++cntTicking;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ this.blockMSBArray.forceToNonTrivialArray(); // Spigot
+ byte[] ext = this.blockMSBArray.getValueArray();
+
+ for (int off = 0, off2 = 0; off < blkIds.length;)
+ {
+ byte extid = ext[off2];
+ int l = (blkIds[off] & 0xFF) | ((extid & 0xF) << 8); // Even data
+
+ if (l > 0)
+ {
+ if (Block.getBlockById(l) == null)
+ {
+ blkIds[off] = 0;
+ ext[off2] &= 0xF0;
+ }
+ else
+ {
+ ++cntNonEmpty;
+
+ if (Block.getBlockById(l).getTickRandomly())
+ {
+ ++cntTicking;
+ }
+ }
+ }
+
+ off++;
+ l = (blkIds[off] & 0xFF) | ((extid & 0xF0) << 4); // Odd data
+
+ if (l > 0)
+ {
+ if (Block.getBlockById(l) == null)
+ {
+ blkIds[off] = 0;
+ ext[off2] &= 0x0F;
+ }
+ else
+ {
+ ++cntNonEmpty;
+
+ if (Block.getBlockById(l).getTickRandomly())
+ {
+ ++cntTicking;
+ }
+ }
+ }
+
+ off++;
+ off2++;
+ }
+
+ // Spigot start
+ this.blockMSBArray.detectAndProcessTrivialArray();
+
+ if (this.blockMSBArray.isTrivialArray() && (this.blockMSBArray.getTrivialArrayValue() == 0))
+ {
+ this.blockMSBArray = null;
+ }
+
+ // Spigot end
+ }
+
+ this.blockRefCount = cntNonEmpty;
+ this.tickRefCount = cntTicking;
+ }
+
+ public void old_recalcBlockCounts()
+ {
+ // CraftBukkit end
this.blockRefCount = 0;
this.tickRefCount = 0;
@@ -197,29 +320,72 @@
public void setBlockLSBArray(byte[] p_76664_1_)
{
- this.blockLSBArray = p_76664_1_;
+ this.blockLSBArray = this.validateByteArray(p_76664_1_); // CraftBukkit - Validate data
}
public void setBlockMSBArray(NibbleArray p_76673_1_)
{
- this.blockMSBArray = p_76673_1_;
+ // CraftBukkit start - Don't hang on to an empty nibble array
+ boolean empty = true;
+
+ // Spigot start
+ if ((!p_76673_1_.isTrivialArray()) || (p_76673_1_.getTrivialArrayValue() != 0))
+ {
+ empty = false;
+ }
+
+ // Spigot end
+
+ if (empty)
+ {
+ return;
+ }
+
+ // CraftBukkit end
+ this.blockMSBArray = this.validateNibbleArray(p_76673_1_); // CraftBukkit - Validate data
}
public void setBlockMetadataArray(NibbleArray p_76668_1_)
{
- this.blockMetadataArray = p_76668_1_;
+ this.blockMetadataArray = this.validateNibbleArray(p_76668_1_); // CraftBukkit - Validate data
}
public void setBlocklightArray(NibbleArray p_76659_1_)
{
- this.blocklightArray = p_76659_1_;
+ this.blocklightArray = this.validateNibbleArray(p_76659_1_); // CraftBukkit - Validate data
}
public void setSkylightArray(NibbleArray p_76666_1_)
{
- this.skylightArray = p_76666_1_;
+ this.skylightArray = this.validateNibbleArray(p_76666_1_); // CraftBukkit - Validate data
}
+ // CraftBukkit start - Validate array lengths
+ private NibbleArray validateNibbleArray(NibbleArray nibbleArray)
+ {
+ // Spigot start - fix for more awesome nibble arrays
+ if (nibbleArray != null && nibbleArray.getByteLength() < 2048)
+ {
+ nibbleArray.resizeArray(2048);
+ }
+
+ // Spigot end
+ return nibbleArray;
+ }
+
+ private byte[] validateByteArray(byte[] byteArray)
+ {
+ if (byteArray != null && byteArray.length < 4096)
+ {
+ byte[] newArray = new byte[4096];
+ System.arraycopy(byteArray, 0, newArray, 0, byteArray.length);
+ byteArray = newArray;
+ }
+
+ return byteArray;
+ }
+ // CraftBukkit end
+
@SideOnly(Side.CLIENT)
public NibbleArray createBlockMSBArray()
{

View File

@ -0,0 +1,11 @@
--- ../src-base/minecraft/net/minecraft/world/chunk/storage/RegionFileCache.java
+++ ../src-work/minecraft/net/minecraft/world/chunk/storage/RegionFileCache.java
@@ -10,7 +10,7 @@
public class RegionFileCache
{
- private static final Map regionsByFilename = new HashMap();
+ public static final Map regionsByFilename = new HashMap(); // CraftBukkit - private -> public
private static final String __OBFID = "CL_00000383";
public static synchronized RegionFile createOrLoadRegionFile(File p_76550_0_, int p_76550_1_, int p_76550_2_)