Commits

md_5 authored e3df3d5cda4
Add Override annotations where appropriate
No tags

src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java

Modified
66 66 }
67 67
68 68 public net.minecraft.server.IBlockData getNMS() {
69 69 return world.getType(position);
70 70 }
71 71
72 72 public BlockPosition getPosition() {
73 73 return position;
74 74 }
75 75
76 + @Override
76 77 public World getWorld() {
77 78 return world.getMinecraftWorld().getWorld();
78 79 }
79 80
80 81 public CraftWorld getCraftWorld() {
81 82 return (CraftWorld) getWorld();
82 83 }
83 84
85 + @Override
84 86 public Location getLocation() {
85 87 return new Location(getWorld(), position.getX(), position.getY(), position.getZ());
86 88 }
87 89
90 + @Override
88 91 public Location getLocation(Location loc) {
89 92 if (loc != null) {
90 93 loc.setWorld(getWorld());
91 94 loc.setX(position.getX());
92 95 loc.setY(position.getY());
93 96 loc.setZ(position.getZ());
94 97 loc.setYaw(0);
95 98 loc.setPitch(0);
96 99 }
97 100
98 101 return loc;
99 102 }
100 103
101 104 public BlockVector getVector() {
102 105 return new BlockVector(getX(), getY(), getZ());
103 106 }
104 107
108 + @Override
105 109 public int getX() {
106 110 return position.getX();
107 111 }
108 112
113 + @Override
109 114 public int getY() {
110 115 return position.getY();
111 116 }
112 117
118 + @Override
113 119 public int getZ() {
114 120 return position.getZ();
115 121 }
116 122
123 + @Override
117 124 public Chunk getChunk() {
118 125 return getWorld().getChunkAt(this);
119 126 }
120 127
121 128 public void setData(final byte data) {
122 129 setData(data, 3);
123 130 }
124 131
125 132 public void setData(final byte data, boolean applyPhysics) {
126 133 if (applyPhysics) {
131 138 }
132 139
133 140 private void setData(final byte data, int flag) {
134 141 world.setTypeAndData(position, CraftMagicNumbers.getBlock(getType(), data), flag);
135 142 }
136 143
137 144 private IBlockData getData0() {
138 145 return world.getType(position);
139 146 }
140 147
148 + @Override
141 149 public byte getData() {
142 150 IBlockData blockData = world.getType(position);
143 151 return CraftMagicNumbers.toLegacyData(blockData);
144 152 }
145 153
146 154 @Override
147 155 public BlockData getBlockData() {
148 156 return CraftBlockData.fromData(getData0());
149 157 }
150 158
159 + @Override
151 160 public void setType(final Material type) {
152 161 setType(type, true);
153 162 }
154 163
155 164 @Override
156 165 public void setType(Material type, boolean applyPhysics) {
157 166 Preconditions.checkArgument(type != null, "Material cannot be null");
158 167 setBlockData(type.createBlockData(), applyPhysics);
159 168 }
160 169
190 199 position,
191 200 old,
192 201 blockData,
193 202 3
194 203 );
195 204 }
196 205 return success;
197 206 }
198 207 }
199 208
209 + @Override
200 210 public Material getType() {
201 211 return CraftMagicNumbers.getMaterial(world.getType(position).getBlock());
202 212 }
203 213
214 + @Override
204 215 public byte getLightLevel() {
205 216 return (byte) world.getMinecraftWorld().getLightLevel(position);
206 217 }
207 218
219 + @Override
208 220 public byte getLightFromSky() {
209 221 return (byte) world.getBrightness(EnumSkyBlock.SKY, position);
210 222 }
211 223
224 + @Override
212 225 public byte getLightFromBlocks() {
213 226 return (byte) world.getBrightness(EnumSkyBlock.BLOCK, position);
214 227 }
215 228
216 229
217 230 public Block getFace(final BlockFace face) {
218 231 return getRelative(face, 1);
219 232 }
220 233
221 234 public Block getFace(final BlockFace face, final int distance) {
222 235 return getRelative(face, distance);
223 236 }
224 237
238 + @Override
225 239 public Block getRelative(final int modX, final int modY, final int modZ) {
226 240 return getWorld().getBlockAt(getX() + modX, getY() + modY, getZ() + modZ);
227 241 }
228 242
243 + @Override
229 244 public Block getRelative(BlockFace face) {
230 245 return getRelative(face, 1);
231 246 }
232 247
248 + @Override
233 249 public Block getRelative(BlockFace face, int distance) {
234 250 return getRelative(face.getModX() * distance, face.getModY() * distance, face.getModZ() * distance);
235 251 }
236 252
253 + @Override
237 254 public BlockFace getFace(final Block block) {
238 255 BlockFace[] values = BlockFace.values();
239 256
240 257 for (BlockFace face : values) {
241 258 if ((this.getX() + face.getModX() == block.getX()) &&
242 259 (this.getY() + face.getModY() == block.getY()) &&
243 260 (this.getZ() + face.getModZ() == block.getZ())
244 261 ) {
245 262 return face;
246 263 }
286 303 return EnumDirection.SOUTH;
287 304 case WEST:
288 305 return EnumDirection.WEST;
289 306 case EAST:
290 307 return EnumDirection.EAST;
291 308 default:
292 309 return null;
293 310 }
294 311 }
295 312
313 + @Override
296 314 public BlockState getState() {
297 315 Material material = getType();
298 316
299 317 switch (material) {
300 318 case ACACIA_SIGN:
301 319 case ACACIA_WALL_SIGN:
302 320 case BIRCH_SIGN:
303 321 case BIRCH_WALL_SIGN:
304 322 case DARK_OAK_SIGN:
305 323 case DARK_OAK_WALL_SIGN:
449 467 if (tileEntity != null) {
450 468 // block with unhandled TileEntity:
451 469 return new CraftBlockEntityState<TileEntity>(this, (Class<TileEntity>) tileEntity.getClass());
452 470 } else {
453 471 // Block without TileEntity:
454 472 return new CraftBlockState(this);
455 473 }
456 474 }
457 475 }
458 476
477 + @Override
459 478 public Biome getBiome() {
460 479 return getWorld().getBiome(getX(), getZ());
461 480 }
462 481
482 + @Override
463 483 public void setBiome(Biome bio) {
464 484 getWorld().setBiome(getX(), getZ(), bio);
465 485 }
466 486
467 487 public static Biome biomeBaseToBiome(BiomeBase base) {
468 488 if (base == null) {
469 489 return null;
470 490 }
471 491
472 492 return Biome.valueOf(IRegistry.BIOME.getKey(base).getKey().toUpperCase(java.util.Locale.ENGLISH));
473 493 }
474 494
475 495 public static BiomeBase biomeToBiomeBase(Biome bio) {
476 496 if (bio == null) {
477 497 return null;
478 498 }
479 499
480 500 return IRegistry.BIOME.get(new MinecraftKey(bio.name().toLowerCase(java.util.Locale.ENGLISH)));
481 501 }
482 502
503 + @Override
483 504 public double getTemperature() {
484 505 return world.getBiome(position).getAdjustedTemperature(position);
485 506 }
486 507
508 + @Override
487 509 public double getHumidity() {
488 510 return getWorld().getHumidity(getX(), getZ());
489 511 }
490 512
513 + @Override
491 514 public boolean isBlockPowered() {
492 515 return world.getMinecraftWorld().getBlockPower(position) > 0;
493 516 }
494 517
518 + @Override
495 519 public boolean isBlockIndirectlyPowered() {
496 520 return world.getMinecraftWorld().isBlockIndirectlyPowered(position);
497 521 }
498 522
499 523 @Override
500 524 public boolean equals(Object o) {
501 525 if (o == this) return true;
502 526 if (!(o instanceof CraftBlock)) return false;
503 527 CraftBlock other = (CraftBlock) o;
504 528
505 529 return this.position.equals(other.position) && this.getWorld().equals(other.getWorld());
506 530 }
507 531
508 532 @Override
509 533 public int hashCode() {
510 534 return this.position.hashCode() ^ this.getWorld().hashCode();
511 535 }
512 536
537 + @Override
513 538 public boolean isBlockFacePowered(BlockFace face) {
514 539 return world.getMinecraftWorld().isBlockFacePowered(position, blockFaceToNotch(face));
515 540 }
516 541
542 + @Override
517 543 public boolean isBlockFaceIndirectlyPowered(BlockFace face) {
518 544 int power = world.getMinecraftWorld().getBlockFacePower(position, blockFaceToNotch(face));
519 545
520 546 Block relative = getRelative(face);
521 547 if (relative.getType() == Material.REDSTONE_WIRE) {
522 548 return Math.max(power, relative.getData()) > 0;
523 549 }
524 550
525 551 return power > 0;
526 552 }
527 553
554 + @Override
528 555 public int getBlockPower(BlockFace face) {
529 556 int power = 0;
530 557 BlockRedstoneWire wire = (BlockRedstoneWire) Blocks.REDSTONE_WIRE;
531 558 net.minecraft.server.World world = this.world.getMinecraftWorld();
532 559 int x = getX();
533 560 int y = getY();
534 561 int z = getZ();
535 562 if ((face == BlockFace.DOWN || face == BlockFace.SELF) && world.isBlockFacePowered(new BlockPosition(x, y - 1, z), EnumDirection.DOWN)) power = wire.getPower(power, world.getType(new BlockPosition(x, y - 1, z)));
536 563 if ((face == BlockFace.UP || face == BlockFace.SELF) && world.isBlockFacePowered(new BlockPosition(x, y + 1, z), EnumDirection.UP)) power = wire.getPower(power, world.getType(new BlockPosition(x, y + 1, z)));
537 564 if ((face == BlockFace.EAST || face == BlockFace.SELF) && world.isBlockFacePowered(new BlockPosition(x + 1, y, z), EnumDirection.EAST)) power = wire.getPower(power, world.getType(new BlockPosition(x + 1, y, z)));
538 565 if ((face == BlockFace.WEST || face == BlockFace.SELF) && world.isBlockFacePowered(new BlockPosition(x - 1, y, z), EnumDirection.WEST)) power = wire.getPower(power, world.getType(new BlockPosition(x - 1, y, z)));
539 566 if ((face == BlockFace.NORTH || face == BlockFace.SELF) && world.isBlockFacePowered(new BlockPosition(x, y, z - 1), EnumDirection.NORTH)) power = wire.getPower(power, world.getType(new BlockPosition(x, y, z - 1)));
540 567 if ((face == BlockFace.SOUTH || face == BlockFace.SELF) && world.isBlockFacePowered(new BlockPosition(x, y, z + 1), EnumDirection.SOUTH)) power = wire.getPower(power, world.getType(new BlockPosition(x, y, z + 1)));
541 568 return power > 0 ? power : (face == BlockFace.SELF ? isBlockIndirectlyPowered() : isBlockFaceIndirectlyPowered(face)) ? 15 : 0;
542 569 }
543 570
571 + @Override
544 572 public int getBlockPower() {
545 573 return getBlockPower(BlockFace.SELF);
546 574 }
547 575
576 + @Override
548 577 public boolean isEmpty() {
549 578 return getNMS().isAir();
550 579 }
551 580
581 + @Override
552 582 public boolean isLiquid() {
553 583 return (getType() == Material.WATER) || (getType() == Material.LAVA);
554 584 }
555 585
586 + @Override
556 587 public PistonMoveReaction getPistonMoveReaction() {
557 588 return PistonMoveReaction.getById(getNMS().getPushReaction().ordinal());
558 589 }
559 590
591 + @Override
560 592 public boolean breakNaturally() {
561 593 return breakNaturally(new ItemStack(Material.AIR));
562 594 }
563 595
596 + @Override
564 597 public boolean breakNaturally(ItemStack item) {
565 598 // Order matters here, need to drop before setting to air so skulls can get their data
566 599 net.minecraft.server.Block block = this.getNMSBlock();
567 600 boolean result = false;
568 601
569 602 if (block != null && block != Blocks.AIR) {
570 603 net.minecraft.server.Block.dropItems(getNMS(), world.getMinecraftWorld(), position, world.getTileEntity(position), null, CraftItemStack.asNMSCopy(item));
571 604 result = true;
572 605 }
573 606
574 607 return setTypeAndData(Blocks.AIR.getBlockData(), true) && result;
575 608 }
576 609
610 + @Override
577 611 public Collection<ItemStack> getDrops() {
578 612 return getDrops(new ItemStack(Material.AIR));
579 613 }
580 614
615 + @Override
581 616 public Collection<ItemStack> getDrops(ItemStack item) {
582 617 return net.minecraft.server.Block.getDrops(getNMS(), (WorldServer) world.getMinecraftWorld(), position, world.getTileEntity(position), null, CraftItemStack.asNMSCopy(item))
583 618 .stream().map(CraftItemStack::asBukkitCopy).collect(Collectors.toList());
584 619 }
585 620
621 + @Override
586 622 public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
587 623 getCraftWorld().getBlockMetadata().setMetadata(this, metadataKey, newMetadataValue);
588 624 }
589 625
626 + @Override
590 627 public List<MetadataValue> getMetadata(String metadataKey) {
591 628 return getCraftWorld().getBlockMetadata().getMetadata(this, metadataKey);
592 629 }
593 630
631 + @Override
594 632 public boolean hasMetadata(String metadataKey) {
595 633 return getCraftWorld().getBlockMetadata().hasMetadata(this, metadataKey);
596 634 }
597 635
636 + @Override
598 637 public void removeMetadata(String metadataKey, Plugin owningPlugin) {
599 638 getCraftWorld().getBlockMetadata().removeMetadata(this, metadataKey, owningPlugin);
600 639 }
601 640
602 641 @Override
603 642 public boolean isPassable() {
604 643 return this.getData0().getCollisionShape(world, position).isEmpty();
605 644 }
606 645
607 646 @Override

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut