summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/WorldServer.java
blob: 9731634609a19e29a01c30eb171558e5b892308b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package net.minecraft.server;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

// CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
// CraftBukkit end

public class WorldServer extends World {

    public ChunkProviderServer A;
    public boolean B = false;
    public boolean C;
    private MinecraftServer D;
    private EntityList E = new EntityList();

    public WorldServer(MinecraftServer minecraftserver, File file1, String s, int i) {
        super(file1, s, (new Random()).nextLong(), WorldProvider.a(i));
        this.D = minecraftserver;

        // CraftBukkit start
        world = new CraftWorld(this);
        server = minecraftserver.server;
    }

    private final CraftWorld world;
    private final CraftServer server;

    @Override
    public boolean d(int i1, int j1, int k1, int l1) {
        boolean result = super.d(i1, j1, k1, l1);
        if ((result) && (world != null)) world.updateBlock(i1, j1, k1);
        return result;
    }

    @Override
    public boolean setTypeId(int i, int j, int k, int l) {
        boolean result = super.setTypeId(i, j, k, l);
        if ((result) && (world != null)) world.updateBlock(i, j, k);
        return result;
    }

    @Override
    public boolean setTypeIdAndData(int i, int j, int k, int l, int i1) {
        boolean result = super.setTypeIdAndData(i, j, k, l, i1);
        if ((result) && (world != null)) world.updateBlock(i, j, k);
        return result;
    }

    @Override
    public void setTileEntity(int i, int j, int k, TileEntity tileentity) {
        super.setTileEntity(i, j, k, tileentity);
        if (world != null) world.updateBlock(i, j, k);
    }

    public CraftWorld getWorld() {
        return world;
    }

    public CraftServer getServer() {
        return server;
    }
    // CraftBukkit end

    public void f() {
        super.f();
    }

    public void a(Entity entity, boolean flag) {
        if (!this.D.m && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
            entity.q();
        }

        if (entity.passenger == null || !(entity.passenger instanceof EntityHuman)) {
            super.a(entity, flag);
        }
    }

    public void b(Entity entity, boolean flag) {
        super.a(entity, flag);
    }

    protected IChunkProvider a(File file1) {
        this.A = new ChunkProviderServer(this, this.q.a(file1), this.q.c());
        return this.A;
    }

    public List d(int i, int j, int k, int l, int i1, int j1) {
        ArrayList arraylist = new ArrayList();

        for (int k1 = 0; k1 < this.c.size(); ++k1) {
            TileEntity tileentity = (TileEntity) this.c.get(k1);

            if (tileentity.b >= i && tileentity.c >= j && tileentity.d >= k && tileentity.b < l && tileentity.c < i1 && tileentity.d < j1) {
                arraylist.add(tileentity);
            }
        }

        return arraylist;
    }

    public boolean a(EntityHuman entityhuman, int i, int j, int k) {
        int l = (int) MathHelper.e((float) (i - this.spawnX));
        int i1 = (int) MathHelper.e((float) (k - this.spawnZ));

        if (l > i1) {
            i1 = l;
        }

        return i1 > 16 || this.D.f.g(entityhuman.name);
    }

    protected void b(Entity entity) {
        super.b(entity);
        this.E.a(entity.id, entity);
    }

    protected void c(Entity entity) {
        super.c(entity);
        this.E.d(entity.id);
    }

    public Entity a(int i) {
        return (Entity) this.E.a(i);
    }

    public void a(Entity entity, byte b0) {
        Packet38EntityStatus packet38entitystatus = new Packet38EntityStatus(entity.id, b0);

        this.D.k.b(entity, packet38entitystatus);
    }

    public Explosion a(Entity entity, double d0, double d1, double d2, float f, boolean flag) {
        Explosion explosion = super.a(entity, d0, d1, d2, f, flag);

        this.D.f.a(d0, d1, d2, 64.0D, new Packet60Explosion(d0, d1, d2, f, explosion.g));
        return explosion;
    }

    public void c(int i, int j, int k, int l, int i1) {
        super.c(i, j, k, l, i1);
        this.D.f.a((double) i, (double) j, (double) k, 64.0D, new Packet54PlayNoteBlock(i, j, k, l, i1));
    }

    // XXX: the following method is straight from the World.java with tweaks as noted. KEEP THEM UPDATED!
    // XXX: done because it calls private k()
    @Override
    public void h(int i, int j, int k, int l) {
        this.l(i - 1, j, k, l);
        this.l(i + 1, j, k, l);
        this.l(i, j - 1, k, l);
        this.l(i, j + 1, k, l);
        this.l(i, j, k - 1, l);
        this.l(i, j, k + 1, l);
    }

    // XXX: the following method is straight from the World.java with tweaks as noted. KEEP THEM UPDATED!
    private void l(int i, int j, int k, int l) {
        if (!this.i && !this.isStatic) {
            Block block = Block.byId[this.getTypeId(i, j, k)];

            if (block != null) {
                // CraftBukkit start
                if (world != null) {
                    BlockPhysicsEvent event = new BlockPhysicsEvent(Event.Type.BLOCK_PHYSICS, world.getBlockAt(i, j, k), l);
                    server.getPluginManager().callEvent(event);
                    if (event.isCancelled()) {
                        return;
                    }
                }
                // CraftBukkit stop

                block.b(this, i, j, k, l);
            }
        }
    }

    // XXX: the following method is straight from the World.java with tweaks as noted. KEEP THEM UPDATED!
    @Override
    public boolean a(int i, int j, int k, int l, boolean flag) {
        int i1 = this.getTypeId(j, k, l);
        Block block = Block.byId[i1];
        Block block1 = Block.byId[i];
        AxisAlignedBB axisalignedbb = block1.d(this, j, k, l);

        if (flag) {
            axisalignedbb = null;
        }

        // Craftbukkit start - We dont want to allow the user to override the bounding box check
        boolean defaultReturn = axisalignedbb != null && !this.a(axisalignedbb) ? false : (block != Block.WATER && block != Block.STATIONARY_WATER && block != Block.LAVA && block != Block.STATIONARY_LAVA && block != Block.FIRE && block != Block.SNOW ? i > 0 && block == null && block1.a(this, j, k, l) : true);

        if (!defaultReturn) {
            return false;
        }

        BlockCanBuildEvent event = new BlockCanBuildEvent(Type.BLOCK_CANBUILD, getWorld().getBlockAt(j, k, l), i1, defaultReturn);
        server.getPluginManager().callEvent(event);

        return event.isBuildable();
        // CraftBukkit end
    }
}