summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/BlockPortal.java
blob: 1356f132cf9bc3f565624b03ece2f70781099cd3 (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
package net.minecraft.server;

import java.util.Random;

import org.bukkit.event.entity.EntityPortalEnterEvent; // CraftBukkit

public class BlockPortal extends BlockHalfTransparent {

    public static final int[][] a = new int[][] { new int[0], { 3, 1}, { 2, 0}};

    public BlockPortal() {
        super("portal", Material.PORTAL, false);
        this.a(true);
    }

    public void a(World world, int i, int j, int k, Random random) {
        super.a(world, i, j, k, random);
        if (world.worldProvider.d() && world.getGameRules().getBoolean("doMobSpawning") && random.nextInt(2000) < world.difficulty.a()) {
            int l;

            for (l = j; !World.a((IBlockAccess) world, i, l, k) && l > 0; --l) {
                ;
            }

            if (l > 0 && !world.getType(i, l + 1, k).r()) {
                // CraftBukkit - set spawn reason to NETHER_PORTAL
                Entity entity = ItemMonsterEgg.spawnCreature(world, 57, (double) i + 0.5D, (double) l + 1.1D, (double) k + 0.5D, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NETHER_PORTAL);

                if (entity != null) {
                    entity.portalCooldown = entity.ah();
                }
            }
        }
    }

    public AxisAlignedBB a(World world, int i, int j, int k) {
        return null;
    }

    public void updateShape(IBlockAccess iblockaccess, int i, int j, int k) {
        int l = b(iblockaccess.getData(i, j, k));

        if (l == 0) {
            if (iblockaccess.getType(i - 1, j, k) != this && iblockaccess.getType(i + 1, j, k) != this) {
                l = 2;
            } else {
                l = 1;
            }

            if (iblockaccess instanceof World && !((World) iblockaccess).isStatic) {
                ((World) iblockaccess).setData(i, j, k, l, 2);
            }
        }

        float f = 0.125F;
        float f1 = 0.125F;

        if (l == 1) {
            f = 0.5F;
        }

        if (l == 2) {
            f1 = 0.5F;
        }

        this.a(0.5F - f, 0.0F, 0.5F - f1, 0.5F + f, 1.0F, 0.5F + f1);
    }

    public boolean d() {
        return false;
    }

    public boolean e(World world, int i, int j, int k) {
        PortalCreator portalcreator = new PortalCreator(world, i, j, k, 1);
        PortalCreator portalcreator1 = new PortalCreator(world, i, j, k, 2);

        if (portalcreator.b() && PortalCreator.a(portalcreator) == 0) {
            // CraftBukkit start - return portalcreator
            return portalcreator.c();
            // return true;
        } else if (portalcreator1.b() && PortalCreator.a(portalcreator1) == 0) {
            return portalcreator1.c();
            // return true;
            // CraftBukkit end
        } else {
            return false;
        }
    }

    public void doPhysics(World world, int i, int j, int k, Block block) {
        int l = b(world.getData(i, j, k));
        PortalCreator portalcreator = new PortalCreator(world, i, j, k, 1);
        PortalCreator portalcreator1 = new PortalCreator(world, i, j, k, 2);

        if (l == 1 && (!portalcreator.b() || PortalCreator.a(portalcreator) < PortalCreator.b(portalcreator) * PortalCreator.c(portalcreator))) {
            world.setTypeUpdate(i, j, k, Blocks.AIR);
        } else if (l == 2 && (!portalcreator1.b() || PortalCreator.a(portalcreator1) < PortalCreator.b(portalcreator1) * PortalCreator.c(portalcreator1))) {
            world.setTypeUpdate(i, j, k, Blocks.AIR);
        } else if (l == 0 && !portalcreator.b() && !portalcreator1.b()) {
            world.setTypeUpdate(i, j, k, Blocks.AIR);
        }
    }

    public int a(Random random) {
        return 0;
    }

    public void a(World world, int i, int j, int k, Entity entity) {
        if (entity.vehicle == null && entity.passenger == null) {
            // CraftBukkit start - Entity in portal
            EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), i, j, k));
            world.getServer().getPluginManager().callEvent(event);
            // CraftBukkit end

            entity.ag();
        }
    }

    public static int b(int i) {
        return i & 3;
    }
}