13
0
geforkt von Mirrors/Paper

Merge remote branch 'upstream/master'

Dieser Commit ist enthalten in:
durron597 2011-01-05 04:54:39 -05:00
Commit 0aa7b970ad
8 geänderte Dateien mit 519 neuen und 19 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,155 @@
package net.minecraft.server;
import java.util.Random;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.LeavesDecayEvent;
public class BlockLeaves extends BlockLeavesBase {
private int c;
int b[];
protected BlockLeaves(int i, int j) {
super(i, j, Material.h, false);
c = j;
a(true);
}
public void b(World world, int i, int j, int k) {
int l = 1;
int i1 = l + 1;
if (world.a(i - i1, j - i1, k - i1, i + i1, j + i1, k + i1)) {
for (int j1 = -l; j1 <= l; j1++) {
for (int k1 = -l; k1 <= l; k1++) {
for (int l1 = -l; l1 <= l; l1++) {
int i2 = world.a(i + j1, j + k1, k + l1);
if (i2 == Block.K.bh) {
world.c(i + j1, j + k1, k + l1, 7);
}
}
}
}
}
}
public void a(World world, int i, int j, int k, Random random) {
if (world.z) {
return;
}
if (world.b(i, j, k) == 7) {
byte byte0 = 4;
int l = byte0 + 1;
byte byte1 = 32;
int i1 = byte1 * byte1;
int j1 = byte1 / 2;
if (b == null) {
b = new int[byte1 * byte1 * byte1];
}
if (world.a(i - l, j - l, k - l, i + l, j + l, k + l)) {
for (int k1 = -byte0; k1 <= byte0; k1++) {
for (int j2 = -byte0; j2 <= byte0; j2++) {
for (int l2 = -byte0; l2 <= byte0; l2++) {
int j3 = world.a(i + k1, j + j2, k + l2);
if (j3 == Block.J.bh) {
b[(k1 + j1) * i1 + (j2 + j1) * byte1 + (l2 + j1)] = 0;
continue;
}
if (j3 == Block.K.bh) {
b[(k1 + j1) * i1 + (j2 + j1) * byte1 + (l2 + j1)] = -2;
} else {
b[(k1 + j1) * i1 + (j2 + j1) * byte1 + (l2 + j1)] = -1;
}
}
}
}
for (int l1 = 1; l1 <= 4; l1++) {
for (int k2 = -byte0; k2 <= byte0; k2++) {
for (int i3 = -byte0; i3 <= byte0; i3++) {
for (int k3 = -byte0; k3 <= byte0; k3++) {
if (b[(k2 + j1) * i1 + (i3 + j1) * byte1 + (k3 + j1)] != l1 - 1) {
continue;
}
if (b[((k2 + j1) - 1) * i1 + (i3 + j1) * byte1 + (k3 + j1)] == -2) {
b[((k2 + j1) - 1) * i1 + (i3 + j1) * byte1 + (k3 + j1)] = l1;
}
if (b[(k2 + j1 + 1) * i1 + (i3 + j1) * byte1 + (k3 + j1)] == -2) {
b[(k2 + j1 + 1) * i1 + (i3 + j1) * byte1 + (k3 + j1)] = l1;
}
if (b[(k2 + j1) * i1 + ((i3 + j1) - 1) * byte1 + (k3 + j1)] == -2) {
b[(k2 + j1) * i1 + ((i3 + j1) - 1) * byte1 + (k3 + j1)] = l1;
}
if (b[(k2 + j1) * i1 + (i3 + j1 + 1) * byte1 + (k3 + j1)] == -2) {
b[(k2 + j1) * i1 + (i3 + j1 + 1) * byte1 + (k3 + j1)] = l1;
}
if (b[(k2 + j1) * i1 + (i3 + j1) * byte1 + ((k3 + j1) - 1)] == -2) {
b[(k2 + j1) * i1 + (i3 + j1) * byte1 + ((k3 + j1) - 1)] = l1;
}
if (b[(k2 + j1) * i1 + (i3 + j1) * byte1 + (k3 + j1 + 1)] == -2) {
b[(k2 + j1) * i1 + (i3 + j1) * byte1 + (k3 + j1 + 1)] = l1;
}
}
}
}
}
}
int i2 = b[j1 * i1 + j1 * byte1 + j1];
if (i2 >= 0) {
world.b(i, j, k, 0);
} else {
g(world, i, j, k);
}
}
}
private void g(World world, int i, int j, int k) {
// Craftbukkit start
CraftServer server = ((WorldServer)world).getServer();
CraftWorld cworld = ((WorldServer)world).getWorld();
LeavesDecayEvent event = new LeavesDecayEvent(Type.LEAVES_DECAY, cworld.getBlockAt(i, j, k));
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
// Craftbukkit end
a_(world, i, j, k, world.b(i, j, k));
world.d(i, j, k, 0);
}
public int a(Random random) {
return random.nextInt(16) != 0 ? 0 : 1;
}
public int a(int i, Random random) {
return Block.y.bh;
}
public boolean a() {
return !a;
}
public void b(World world, int i, int j, int k, Entity entity) {
super.b(world, i, j, k, entity);
}
}

Datei anzeigen

@ -0,0 +1,226 @@
package net.minecraft.server;
import java.io.IOException;
import java.util.*;
import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.Event.Type;
import org.bukkit.event.world.ChunkLoadedEvent;
public class ChunkProviderServer
implements IChunkProvider {
private Set a;
private Chunk b;
private IChunkProvider c;
private IChunkLoader d;
private Map e;
private List f;
private WorldServer g;
public ChunkProviderServer(WorldServer worldserver, IChunkLoader ichunkloader, IChunkProvider ichunkprovider) {
a = new HashSet();
e = new HashMap();
f = new ArrayList();
b = new Chunk(worldserver, new byte[32768], 0, 0);
b.q = true;
b.p = true;
g = worldserver;
d = ichunkloader;
c = ichunkprovider;
}
public boolean a(int i, int j) {
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(i, j);
return e.containsKey(chunkcoordinates);
}
public void c(int i, int j) {
int k = (i * 16 + 8) - g.m;
int l = (j * 16 + 8) - g.o;
char c1 = '\200';
if (k < -c1 || k > c1 || l < -c1 || l > c1) {
a.add(new ChunkCoordinates(i, j));
}
}
public Chunk d(int i, int j) {
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(i, j);
a.remove(new ChunkCoordinates(i, j));
Chunk chunk = (Chunk) e.get(chunkcoordinates);
if (chunk == null) {
chunk = e(i, j);
if (chunk == null) {
if (c == null) {
chunk = b;
} else {
chunk = c.b(i, j);
}
}
e.put(chunkcoordinates, chunk);
f.add(chunk);
chunk.c();
if (chunk != null) {
chunk.d();
}
// Craftbukkit start
CraftServer server = g.getServer();
if (server != null) {
/*
* If it's a new world, the first few chunks are generated inside
* the World constructor. We can't reliably alter that, so we have
* no way of creating a CraftWorld/CraftServer at that point.
*/
CraftWorld world = g.getWorld();
CraftChunk cchunk = world.updateChunk(i, j);
server.getPluginManager().callEvent(new ChunkLoadedEvent(Type.CHUNK_LOADED, cchunk));
}
// Craftbukkit end
if (!chunk.n && a(i + 1, j + 1) && a(i, j + 1) && a(i + 1, j)) {
a(this, i, j);
}
if (a(i - 1, j) && !b(i - 1, j).n && a(i - 1, j + 1) && a(i, j + 1) && a(i - 1, j)) {
a(this, i - 1, j);
}
if (a(i, j - 1) && !b(i, j - 1).n && a(i + 1, j - 1) && a(i, j - 1) && a(i + 1, j)) {
a(this, i, j - 1);
}
if (a(i - 1, j - 1) && !b(i - 1, j - 1).n && a(i - 1, j - 1) && a(i, j - 1) && a(i - 1, j)) {
a(this, i - 1, j - 1);
}
}
return chunk;
}
public Chunk b(int i, int j) {
ChunkCoordinates chunkcoordinates = new ChunkCoordinates(i, j);
Chunk chunk = (Chunk) e.get(chunkcoordinates);
if (chunk == null) {
if (g.x) {
return d(i, j);
} else {
return b;
}
} else {
return chunk;
}
}
private Chunk e(int i, int j) {
if (d == null) {
return null;
}
try {
Chunk chunk = d.a(g, i, j);
if (chunk != null) {
chunk.s = g.e;
}
return chunk;
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
private void a(Chunk chunk) {
if (d == null) {
return;
}
try {
d.b(g, chunk);
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void b(Chunk chunk) {
if (d == null) {
return;
}
try {
chunk.s = g.e;
d.a(g, chunk);
} catch (Throwable ioexception) { // Craftbukkit: Cast down to compile
ioexception.printStackTrace();
}
}
public void a(IChunkProvider ichunkprovider, int i, int j) {
Chunk chunk = b(i, j);
if (!chunk.n) {
chunk.n = true;
if (c != null) {
c.a(ichunkprovider, i, j);
chunk.f();
}
}
}
public boolean a(boolean flag, IProgressUpdate iprogressupdate) {
int i = 0;
for (int j = 0; j < f.size(); j++) {
Chunk chunk = (Chunk) f.get(j);
if (flag && !chunk.p) {
a(chunk);
}
if (!chunk.a(flag)) {
continue;
}
b(chunk);
chunk.o = false;
if (++i == 24 && !flag) {
return false;
}
}
if (flag) {
if (d == null) {
return true;
}
d.b();
}
return true;
}
public boolean a() {
if (!g.C) {
for (int i = 0; i < 100; i++) {
if (!a.isEmpty()) {
ChunkCoordinates chunkcoordinates = (ChunkCoordinates) a.iterator().next();
Chunk chunk = b(chunkcoordinates.a, chunkcoordinates.b);
chunk.e();
b(chunk);
a(chunk);
a.remove(chunkcoordinates);
e.remove(chunkcoordinates);
f.remove(chunk);
}
}
if (d != null) {
d.a();
}
}
return c.a();
}
public boolean b() {
return !g.C;
}
}

Datei anzeigen

@ -113,6 +113,12 @@ public class EntityMinecart extends Entity
// CraftBukkit end
}
// CraftBukkit start
public ItemStack[] getContents() {
return this.ak;
}
// CraftBukkit end
public AxisAlignedBB d(Entity entity) {
return entity.z;
}

Datei anzeigen

@ -36,14 +36,14 @@ public class WorldServer extends World {
@Override
public boolean c(int i1, int j1, int k1, int l1) {
boolean result = super.c(i1, j1, k1, l1);
world.updateBlock(i1, j1, k1);
if (world != null) world.updateBlock(i1, j1, k1);
return result;
}
@Override
public boolean d(int i1, int j1, int k1, int l1) {
boolean result = super.d(i1, j1, k1, l1);
world.updateBlock(i1, j1, k1);
if (world != null) world.updateBlock(i1, j1, k1);
return result;
}
@ -75,10 +75,12 @@ public class WorldServer extends World {
if (block != null) {
// CraftBukkit start
BlockPhysicsEvent event = new BlockPhysicsEvent(Event.Type.BLOCK_PHYSICS, world.getBlockAt(i1, j1, k1), l1);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
if (world != null) {
BlockPhysicsEvent event = new BlockPhysicsEvent(Event.Type.BLOCK_PHYSICS, world.getBlockAt(i1, j1, k1), l1);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
}
// CraftBukkit stop
@ -102,16 +104,12 @@ public class WorldServer extends World {
return false;
}
// Craftbukkit - check this first as we dont want to allow the user to override this either
// Notch checks it after the check to see if block is water, lava, fire, portal
if (!(i1 > 0 && block == null)) return false;
boolean defaultReturn;
if (block == Block.A || block == Block.B || block == Block.C || block == Block.D || block == Block.ar || block == Block.aS) {
defaultReturn = true;
} else {
defaultReturn = block1.a(this, j1, k1, l1);
defaultReturn = (i1 > 0) && (block == null) && (block1.a(this, j1, k1, l1));
}
// Craftbukkit - If flag is true, it's natural, not user placement. Don't hook.

Datei anzeigen

@ -2,16 +2,28 @@
package org.bukkit.craftbukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
public class CraftChunk implements Chunk {
private final CraftWorld world;
private final int x;
private final int z;
protected CraftChunk(final int x, final int z) {
protected CraftChunk(final CraftWorld world, final int x, final int z) {
this.world = world;
this.x = x;
this.z = z;
}
/**
* Gets the world containing this chunk
*
* @return World
*/
public World getWorld() {
return world;
}
/**
* Gets the X-coordinate of this chunk
*

Datei anzeigen

@ -0,0 +1,61 @@
package org.bukkit.craftbukkit;
import org.bukkit.ItemStack;
import org.bukkit.Material;
public class CraftItemStack extends ItemStack {
protected net.minecraft.server.ItemStack item;
public CraftItemStack(net.minecraft.server.ItemStack item) {
super(item.c, item.a);
this.item = item;
}
/*
* Unsure if we have to syn before each of these calls the values in 'item'
* are all public.
*/
@Override
public Material getType() {
super.setTypeID(item.c); // sync, needed?
return super.getType();
}
@Override
public int getTypeID() {
super.setTypeID(item.c); // sync, needed?
return item.c;
}
@Override
public void setTypeID(int type) {
super.setTypeID(item.c);
item.c = type;
}
@Override
public int getAmount() {
super.setAmount(item.a); // sync, needed?
return item.a;
}
@Override
public void setAmount(int amount) {
super.setAmount(amount);
item.a = amount;
}
@Override
public void setDamage(final byte damage) {
super.setDamage(damage);
item.d = damage;
}
@Override
public byte getDamage() {
super.setDamage((byte) item.d); // sync, needed?
return (byte) item.d;
}
}

Datei anzeigen

@ -1,6 +1,11 @@
package org.bukkit.craftbukkit;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.EntityMinecart;
import org.bukkit.ItemStack;
import org.bukkit.StorageMinecart;
/**
@ -8,10 +13,33 @@ import org.bukkit.StorageMinecart;
*
* @author sk89q
*/
public class CraftStorageMinecart extends CraftMinecart
implements StorageMinecart {
public class CraftStorageMinecart extends CraftMinecart implements StorageMinecart {
public CraftStorageMinecart(CraftServer server, EntityMinecart entity) {
super(server, entity);
}
public int getSize() {
return minecart.c();
}
public String getName() {
return minecart.b();
}
public ItemStack getItem(int index) {
return new CraftItemStack(minecart.a(index));
}
public List<ItemStack> getContents() {
ArrayList<ItemStack> items = new ArrayList<ItemStack>();
for (net.minecraft.server.ItemStack item: minecart.getContents()) {
ItemStack i = null;
if (item != null) {
i = new CraftItemStack( item );
}
items.add(i);
}
return items;
}
}

Datei anzeigen

@ -21,8 +21,8 @@ import org.bukkit.Vector;
import org.bukkit.World;
public class CraftWorld implements World {
private final Map<ChunkCoordinate, Chunk> chunkCache = new HashMap<ChunkCoordinate, Chunk>();
private final Map<BlockCoordinate, Block> blockCache = new HashMap<BlockCoordinate, Block>();
private final Map<ChunkCoordinate, CraftChunk> chunkCache = new HashMap<ChunkCoordinate, CraftChunk>();
private final Map<BlockCoordinate, CraftBlock> blockCache = new HashMap<BlockCoordinate, CraftBlock>();
private final WorldServer world;
private static final Random rand = new Random();
@ -33,7 +33,7 @@ public class CraftWorld implements World {
public Block getBlockAt(int x, int y, int z) {
BlockCoordinate loc = new BlockCoordinate(x, y, z);
Block block = blockCache.get(loc);
CraftBlock block = blockCache.get(loc);
if (block == null) {
block = new CraftBlock(this, x, y, z, world.a(x, y, z), (byte)world.b(x, y, z));
@ -49,10 +49,10 @@ public class CraftWorld implements World {
public Chunk getChunkAt(int x, int z) {
ChunkCoordinate loc = new ChunkCoordinate(x, z);
Chunk chunk = chunkCache.get(loc);
CraftChunk chunk = chunkCache.get(loc);
if (chunk == null) {
chunk = new CraftChunk(x, z);
chunk = new CraftChunk(this, x, z);
chunkCache.put(loc, chunk);
}
@ -84,6 +84,20 @@ public class CraftWorld implements World {
return block;
}
public CraftChunk updateChunk(int x, int z) {
ChunkCoordinate loc = new ChunkCoordinate(x, z);
CraftChunk chunk = chunkCache.get(loc);
if (chunk == null) {
chunk = new CraftChunk(this, x, z);
chunkCache.put(loc, chunk);
} else {
// TODO: Chunk stuff
}
return chunk;
}
public WorldServer getHandle() {
return world;
}