BlockPortal .java

net.minecraft.block.BlockPortal (class, 485 lines): members: getMetaForAxis, func_176548_d, func_181089_f, Size, AXIS, onEntityCollidedWithBlock, getItem.

net.minecraft.blockclass485 linescommonextends BlockBreakable17.9 KB

API Surface (24)

void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
int getMetaForAxis(EnumFacing.Axis axis)
boolean isFullCube()
boolean func_176548_d(World worldIn, BlockPos p_176548_2_)
void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
int quantityDropped(Random random)
EnumWorldBlockLayer getBlockLayer()
void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
Item getItem(World worldIn, BlockPos pos)
IBlockState getStateFromMeta(int meta)
int getMetaFromState(IBlockState state)
BlockState createBlockState()
BlockPattern.PatternHelper func_181089_f(World p_181089_1_, BlockPos p_181089_2_)
int func_180120_a(BlockPos p_180120_1_, EnumFacing p_180120_2_)
int func_181100_a()
int func_181101_b()
int func_150858_a()
boolean func_150857_a(Block p_150857_1_)
boolean func_150860_b()
void func_150859_c()

Fields & Constants (1)

AXIS

String literals (3)

"axis"
"doMobSpawning"
"portal.portal"

Full Source

BlockPortal.java485 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block;
2
3
import com.google.common.cache.LoadingCache;
4
import java.util.Random;
5
import net.minecraft.block.material.Material;
6
import net.minecraft.block.properties.IProperty;
7
import net.minecraft.block.properties.PropertyEnum;
8
import net.minecraft.block.state.BlockState;
9
import net.minecraft.block.state.BlockWorldState;
10
import net.minecraft.block.state.IBlockState;
11
import net.minecraft.block.state.pattern.BlockPattern;
12
import net.minecraft.entity.Entity;
13
import net.minecraft.init.Blocks;
14
import net.minecraft.item.Item;
15
import net.minecraft.item.ItemMonsterPlacer;
16
import net.minecraft.util.AxisAlignedBB;
17
import net.minecraft.util.BlockPos;
18
import net.minecraft.util.EnumFacing;
19
import net.minecraft.util.EnumParticleTypes;
20
import net.minecraft.util.EnumWorldBlockLayer;
21
import net.minecraft.world.IBlockAccess;
22
import net.minecraft.world.World;
23
24
public class BlockPortal extends BlockBreakable
25
{
26
    public static final PropertyEnum<EnumFacing.Axis> AXIS = PropertyEnum.<EnumFacing.Axis>create("axis", EnumFacing.Axis.class, new EnumFacing.Axis[] {EnumFacing.Axis.X, EnumFacing.Axis.Z});
27
28
    public BlockPortal()
29
    {
30
        super(Material.portal, false);
31
        this.setDefaultState(this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.X));
32
        this.setTickRandomly(true);
33
    }
34
35
    public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
36
    {
37
        super.updateTick(worldIn, pos, state, rand);
38
39
        if (worldIn.provider.isSurfaceWorld() && worldIn.getGameRules().getBoolean("doMobSpawning") && rand.nextInt(2000) < worldIn.getDifficulty().getDifficultyId())
40
        {
41
            int i = pos.getY();
42
            BlockPos blockpos;
43
44
            for (blockpos = pos; !World.doesBlockHaveSolidTopSurface(worldIn, blockpos) && blockpos.getY() > 0; blockpos = blockpos.down())
45
            {
46
                ;
47
            }
48
49
            if (i > 0 && !worldIn.getBlockState(blockpos.up()).getBlock().isNormalCube())
50
            {
51
                Entity entity = ItemMonsterPlacer.spawnCreature(worldIn, 57, (double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 1.1D, (double)blockpos.getZ() + 0.5D);
52
53
                if (entity != null)
54
                {
55
                    entity.timeUntilPortal = entity.getPortalCooldown();
56
                }
57
            }
58
        }
59
    }
60
61
    public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
62
    {
63
        return null;
64
    }
65
66
    public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos)
67
    {
68
        EnumFacing.Axis enumfacing$axis = (EnumFacing.Axis)worldIn.getBlockState(pos).getValue(AXIS);
69
        float f = 0.125F;
70
        float f1 = 0.125F;
71
72
        if (enumfacing$axis == EnumFacing.Axis.X)
73
        {
74
            f = 0.5F;
75
        }
76
77
        if (enumfacing$axis == EnumFacing.Axis.Z)
78
        {
79
            f1 = 0.5F;
80
        }
81
82
        this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f1, 0.5F + f, 1.0F, 0.5F + f1);
83
    }
84
85
    public static int getMetaForAxis(EnumFacing.Axis axis)
86
    {
87
        return axis == EnumFacing.Axis.X ? 1 : (axis == EnumFacing.Axis.Z ? 2 : 0);
88
    }
89
90
    public boolean isFullCube()
91
    {
92
        return false;
93
    }
94
95
    public boolean func_176548_d(World worldIn, BlockPos p_176548_2_)
96
    {
97
        BlockPortal.Size blockportal$size = new BlockPortal.Size(worldIn, p_176548_2_, EnumFacing.Axis.X);
98
99
        if (blockportal$size.func_150860_b() && blockportal$size.field_150864_e == 0)
100
        {
101
            blockportal$size.func_150859_c();
102
            return true;
103
        }
104
        else
105
        {
106
            BlockPortal.Size blockportal$size1 = new BlockPortal.Size(worldIn, p_176548_2_, EnumFacing.Axis.Z);
107
108
            if (blockportal$size1.func_150860_b() && blockportal$size1.field_150864_e == 0)
109
            {
110
                blockportal$size1.func_150859_c();
111
                return true;
112
            }
113
            else
114
            {
115
                return false;
116
            }
117
        }
118
    }
119
120
    /**
121
     * Called when a neighboring block changes.
122
     */
123
    public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
124
    {
125
        EnumFacing.Axis enumfacing$axis = (EnumFacing.Axis)state.getValue(AXIS);
126
127
        if (enumfacing$axis == EnumFacing.Axis.X)
128
        {
129
            BlockPortal.Size blockportal$size = new BlockPortal.Size(worldIn, pos, EnumFacing.Axis.X);
130
131
            if (!blockportal$size.func_150860_b() || blockportal$size.field_150864_e < blockportal$size.field_150868_h * blockportal$size.field_150862_g)
132
            {
133
                worldIn.setBlockState(pos, Blocks.air.getDefaultState());
134
            }
135
        }
136
        else if (enumfacing$axis == EnumFacing.Axis.Z)
137
        {
138
            BlockPortal.Size blockportal$size1 = new BlockPortal.Size(worldIn, pos, EnumFacing.Axis.Z);
139
140
            if (!blockportal$size1.func_150860_b() || blockportal$size1.field_150864_e < blockportal$size1.field_150868_h * blockportal$size1.field_150862_g)
141
            {
142
                worldIn.setBlockState(pos, Blocks.air.getDefaultState());
143
            }
144
        }
145
    }
146
147
    public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side)
148
    {
149
        EnumFacing.Axis enumfacing$axis = null;
150
        IBlockState iblockstate = worldIn.getBlockState(pos);
151
152
        if (worldIn.getBlockState(pos).getBlock() == this)
153
        {
154
            enumfacing$axis = (EnumFacing.Axis)iblockstate.getValue(AXIS);
155
156
            if (enumfacing$axis == null)
157
            {
158
                return false;
159
            }
160
161
            if (enumfacing$axis == EnumFacing.Axis.Z && side != EnumFacing.EAST && side != EnumFacing.WEST)
162
            {
163
                return false;
164
            }
165
166
            if (enumfacing$axis == EnumFacing.Axis.X && side != EnumFacing.SOUTH && side != EnumFacing.NORTH)
167
            {
168
                return false;
169
            }
170
        }
171
172
        boolean flag = worldIn.getBlockState(pos.west()).getBlock() == this && worldIn.getBlockState(pos.west(2)).getBlock() != this;
173
        boolean flag1 = worldIn.getBlockState(pos.east()).getBlock() == this && worldIn.getBlockState(pos.east(2)).getBlock() != this;
174
        boolean flag2 = worldIn.getBlockState(pos.north()).getBlock() == this && worldIn.getBlockState(pos.north(2)).getBlock() != this;
175
        boolean flag3 = worldIn.getBlockState(pos.south()).getBlock() == this && worldIn.getBlockState(pos.south(2)).getBlock() != this;
176
        boolean flag4 = flag || flag1 || enumfacing$axis == EnumFacing.Axis.X;
177
        boolean flag5 = flag2 || flag3 || enumfacing$axis == EnumFacing.Axis.Z;
178
        return flag4 && side == EnumFacing.WEST ? true : (flag4 && side == EnumFacing.EAST ? true : (flag5 && side == EnumFacing.NORTH ? true : flag5 && side == EnumFacing.SOUTH));
179
    }
180
181
    /**
182
     * Returns the quantity of items to drop on block destruction.
183
     */
184
    public int quantityDropped(Random random)
185
    {
186
        return 0;
187
    }
188
189
    public EnumWorldBlockLayer getBlockLayer()
190
    {
191
        return EnumWorldBlockLayer.TRANSLUCENT;
192
    }
193
194
    /**
195
     * Called When an Entity Collided with the Block
196
     */
197
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
198
    {
199
        if (entityIn.ridingEntity == null && entityIn.riddenByEntity == null)
200
        {
201
            entityIn.setPortal(pos);
202
        }
203
    }
204
205
    public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
206
    {
207
        if (rand.nextInt(100) == 0)
208
        {
209
            worldIn.playSound((double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, "portal.portal", 0.5F, rand.nextFloat() * 0.4F + 0.8F, false);
210
        }
211
212
        for (int i = 0; i < 4; ++i)
213
        {
214
            double d0 = (double)((float)pos.getX() + rand.nextFloat());
215
            double d1 = (double)((float)pos.getY() + rand.nextFloat());
216
            double d2 = (double)((float)pos.getZ() + rand.nextFloat());
217
            double d3 = ((double)rand.nextFloat() - 0.5D) * 0.5D;
218
            double d4 = ((double)rand.nextFloat() - 0.5D) * 0.5D;
219
            double d5 = ((double)rand.nextFloat() - 0.5D) * 0.5D;
220
            int j = rand.nextInt(2) * 2 - 1;
221
222
            if (worldIn.getBlockState(pos.west()).getBlock() != this && worldIn.getBlockState(pos.east()).getBlock() != this)
223
            {
224
                d0 = (double)pos.getX() + 0.5D + 0.25D * (double)j;
225
                d3 = (double)(rand.nextFloat() * 2.0F * (float)j);
226
            }
227
            else
228
            {
229
                d2 = (double)pos.getZ() + 0.5D + 0.25D * (double)j;
230
                d5 = (double)(rand.nextFloat() * 2.0F * (float)j);
231
            }
232
233
            worldIn.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5, new int[0]);
234
        }
235
    }
236
237
    public Item getItem(World worldIn, BlockPos pos)
238
    {
239
        return null;
240
    }
241
242
    /**
243
     * Convert the given metadata into a BlockState for this Block
244
     */
245
    public IBlockState getStateFromMeta(int meta)
246
    {
247
        return this.getDefaultState().withProperty(AXIS, (meta & 3) == 2 ? EnumFacing.Axis.Z : EnumFacing.Axis.X);
248
    }
249
250
    /**
251
     * Convert the BlockState into the correct metadata value
252
     */
253
    public int getMetaFromState(IBlockState state)
254
    {
255
        return getMetaForAxis((EnumFacing.Axis)state.getValue(AXIS));
256
    }
257
258
    protected BlockState createBlockState()
259
    {
260
        return new BlockState(this, new IProperty[] {AXIS});
261
    }
262
263
    public BlockPattern.PatternHelper func_181089_f(World p_181089_1_, BlockPos p_181089_2_)
264
    {
265
        EnumFacing.Axis enumfacing$axis = EnumFacing.Axis.Z;
266
        BlockPortal.Size blockportal$size = new BlockPortal.Size(p_181089_1_, p_181089_2_, EnumFacing.Axis.X);
267
        LoadingCache<BlockPos, BlockWorldState> loadingcache = BlockPattern.func_181627_a(p_181089_1_, true);
268
269
        if (!blockportal$size.func_150860_b())
270
        {
271
            enumfacing$axis = EnumFacing.Axis.X;
272
            blockportal$size = new BlockPortal.Size(p_181089_1_, p_181089_2_, EnumFacing.Axis.Z);
273
        }
274
275
        if (!blockportal$size.func_150860_b())
276
        {
277
            return new BlockPattern.PatternHelper(p_181089_2_, EnumFacing.NORTH, EnumFacing.UP, loadingcache, 1, 1, 1);
278
        }
279
        else
280
        {
281
            int[] aint = new int[EnumFacing.AxisDirection.values().length];
282
            EnumFacing enumfacing = blockportal$size.field_150866_c.rotateYCCW();
283
            BlockPos blockpos = blockportal$size.field_150861_f.up(blockportal$size.func_181100_a() - 1);
284
285
            for (EnumFacing.AxisDirection enumfacing$axisdirection : EnumFacing.AxisDirection.values())
286
            {
287
                BlockPattern.PatternHelper blockpattern$patternhelper = new BlockPattern.PatternHelper(enumfacing.getAxisDirection() == enumfacing$axisdirection ? blockpos : blockpos.offset(blockportal$size.field_150866_c, blockportal$size.func_181101_b() - 1), EnumFacing.getFacingFromAxis(enumfacing$axisdirection, enumfacing$axis), EnumFacing.UP, loadingcache, blockportal$size.func_181101_b(), blockportal$size.func_181100_a(), 1);
288
289
                for (int i = 0; i < blockportal$size.func_181101_b(); ++i)
290
                {
291
                    for (int j = 0; j < blockportal$size.func_181100_a(); ++j)
292
                    {
293
                        BlockWorldState blockworldstate = blockpattern$patternhelper.translateOffset(i, j, 1);
294
295
                        if (blockworldstate.getBlockState() != null && blockworldstate.getBlockState().getBlock().getMaterial() != Material.air)
296
                        {
297
                            ++aint[enumfacing$axisdirection.ordinal()];
298
                        }
299
                    }
300
                }
301
            }
302
303
            EnumFacing.AxisDirection enumfacing$axisdirection1 = EnumFacing.AxisDirection.POSITIVE;
304
305
            for (EnumFacing.AxisDirection enumfacing$axisdirection2 : EnumFacing.AxisDirection.values())
306
            {
307
                if (aint[enumfacing$axisdirection2.ordinal()] < aint[enumfacing$axisdirection1.ordinal()])
308
                {
309
                    enumfacing$axisdirection1 = enumfacing$axisdirection2;
310
                }
311
            }
312
313
            return new BlockPattern.PatternHelper(enumfacing.getAxisDirection() == enumfacing$axisdirection1 ? blockpos : blockpos.offset(blockportal$size.field_150866_c, blockportal$size.func_181101_b() - 1), EnumFacing.getFacingFromAxis(enumfacing$axisdirection1, enumfacing$axis), EnumFacing.UP, loadingcache, blockportal$size.func_181101_b(), blockportal$size.func_181100_a(), 1);
314
        }
315
    }
316
317
    public static class Size
318
    {
319
        private final World world;
320
        private final EnumFacing.Axis axis;
321
        private final EnumFacing field_150866_c;
322
        private final EnumFacing field_150863_d;
323
        private int field_150864_e = 0;
324
        private BlockPos field_150861_f;
325
        private int field_150862_g;
326
        private int field_150868_h;
327
328
        public Size(World worldIn, BlockPos p_i45694_2_, EnumFacing.Axis p_i45694_3_)
329
        {
330
            this.world = worldIn;
331
            this.axis = p_i45694_3_;
332
333
            if (p_i45694_3_ == EnumFacing.Axis.X)
334
            {
335
                this.field_150863_d = EnumFacing.EAST;
336
                this.field_150866_c = EnumFacing.WEST;
337
            }
338
            else
339
            {
340
                this.field_150863_d = EnumFacing.NORTH;
341
                this.field_150866_c = EnumFacing.SOUTH;
342
            }
343
344
            for (BlockPos blockpos = p_i45694_2_; p_i45694_2_.getY() > blockpos.getY() - 21 && p_i45694_2_.getY() > 0 && this.func_150857_a(worldIn.getBlockState(p_i45694_2_.down()).getBlock()); p_i45694_2_ = p_i45694_2_.down())
345
            {
346
                ;
347
            }
348
349
            int i = this.func_180120_a(p_i45694_2_, this.field_150863_d) - 1;
350
351
            if (i >= 0)
352
            {
353
                this.field_150861_f = p_i45694_2_.offset(this.field_150863_d, i);
354
                this.field_150868_h = this.func_180120_a(this.field_150861_f, this.field_150866_c);
355
356
                if (this.field_150868_h < 2 || this.field_150868_h > 21)
357
                {
358
                    this.field_150861_f = null;
359
                    this.field_150868_h = 0;
360
                }
361
            }
362
363
            if (this.field_150861_f != null)
364
            {
365
                this.field_150862_g = this.func_150858_a();
366
            }
367
        }
368
369
        protected int func_180120_a(BlockPos p_180120_1_, EnumFacing p_180120_2_)
370
        {
371
            int i;
372
373
            for (i = 0; i < 22; ++i)
374
            {
375
                BlockPos blockpos = p_180120_1_.offset(p_180120_2_, i);
376
377
                if (!this.func_150857_a(this.world.getBlockState(blockpos).getBlock()) || this.world.getBlockState(blockpos.down()).getBlock() != Blocks.obsidian)
378
                {
379
                    break;
380
                }
381
            }
382
383
            Block block = this.world.getBlockState(p_180120_1_.offset(p_180120_2_, i)).getBlock();
384
            return block == Blocks.obsidian ? i : 0;
385
        }
386
387
        public int func_181100_a()
388
        {
389
            return this.field_150862_g;
390
        }
391
392
        public int func_181101_b()
393
        {
394
            return this.field_150868_h;
395
        }
396
397
        protected int func_150858_a()
398
        {
399
            label24:
400
401
            for (this.field_150862_g = 0; this.field_150862_g < 21; ++this.field_150862_g)
402
            {
403
                for (int i = 0; i < this.field_150868_h; ++i)
404
                {
405
                    BlockPos blockpos = this.field_150861_f.offset(this.field_150866_c, i).up(this.field_150862_g);
406
                    Block block = this.world.getBlockState(blockpos).getBlock();
407
408
                    if (!this.func_150857_a(block))
409
                    {
410
                        break label24;
411
                    }
412
413
                    if (block == Blocks.portal)
414
                    {
415
                        ++this.field_150864_e;
416
                    }
417
418
                    if (i == 0)
419
                    {
420
                        block = this.world.getBlockState(blockpos.offset(this.field_150863_d)).getBlock();
421
422
                        if (block != Blocks.obsidian)
423
                        {
424
                            break label24;
425
                        }
426
                    }
427
                    else if (i == this.field_150868_h - 1)
428
                    {
429
                        block = this.world.getBlockState(blockpos.offset(this.field_150866_c)).getBlock();
430
431
                        if (block != Blocks.obsidian)
432
                        {
433
                            break label24;
434
                        }
435
                    }
436
                }
437
            }
438
439
            for (int j = 0; j < this.field_150868_h; ++j)
440
            {
441
                if (this.world.getBlockState(this.field_150861_f.offset(this.field_150866_c, j).up(this.field_150862_g)).getBlock() != Blocks.obsidian)
442
                {
443
                    this.field_150862_g = 0;
444
                    break;
445
                }
446
            }
447
448
            if (this.field_150862_g <= 21 && this.field_150862_g >= 3)
449
            {
450
                return this.field_150862_g;
451
            }
452
            else
453
            {
454
                this.field_150861_f = null;
455
                this.field_150868_h = 0;
456
                this.field_150862_g = 0;
457
                return 0;
458
            }
459
        }
460
461
        protected boolean func_150857_a(Block p_150857_1_)
462
        {
463
            return p_150857_1_.blockMaterial == Material.air || p_150857_1_ == Blocks.fire || p_150857_1_ == Blocks.portal;
464
        }
465
466
        public boolean func_150860_b()
467
        {
468
            return this.field_150861_f != null && this.field_150868_h >= 2 && this.field_150868_h <= 21 && this.field_150862_g >= 3 && this.field_150862_g <= 21;
469
        }
470
471
        public void func_150859_c()
472
        {
473
            for (int i = 0; i < this.field_150868_h; ++i)
474
            {
475
                BlockPos blockpos = this.field_150861_f.offset(this.field_150866_c, i);
476
477
                for (int j = 0; j < this.field_150862_g; ++j)
478
                {
479
                    this.world.setBlockState(blockpos.up(j), Blocks.portal.getDefaultState().withProperty(BlockPortal.AXIS, this.axis), 2);
480
                }
481
            }
482
        }
483
    }
484
}
485

Deobfuscated MCP 1.8.9 source of BlockPortal from Marcelektro/MavenMCP-1.8.9 (net/minecraft/block/BlockPortal.java), stored verbatim.