Skip to content

Commit

Permalink
Remove unnecessary use of Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Oct 23, 2017
1 parent 33d01ed commit d5b2d15
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) {
this.mcBlock = block;
components.add(new BWBlockTransform(this, world, pos));
components.add(new BlockProperty.Opacity()).setOpacity(() -> mcBlock.getMaterial().isOpaque() ? 1 : 0);
Optional.of(components.add(new BlockProperty.Replaceable()))
.filter(r -> block != Blocks.air)
.ifPresent(r -> r.setReplaceable(() -> mcBlock.isReplaceable(blockAccess(), xi(), yi(), zi())));
BlockProperty.Replaceable replaceable = components.add(new BlockProperty.Replaceable());
if (block != Blocks.air) {
replaceable.setReplaceable(() -> mcBlock.canPlaceBlockAt((net.minecraft.world.World) blockAccess(), xi(), yi(), zi()));
}

BlockProperty.BlockSound blockSound = components.add(new BlockProperty.BlockSound());
blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", mcBlock.stepSound.func_150496_b()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,21 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
@Override
public float getExplosionResistance(Entity expEntity, World world, int x, int y, int z, double explosionX, double p_explosionresistance, double explosionY) {
// TODO: Maybe do something withPriority these parameters.

// This number was calculated from the blast resistance of Stone,
// which requires exactly one cubic meter of TNT to get blown up.
//
// 1. During construction, the setResistance method is called
// on minecraft:stone with a value of 10.
//
// 2. The setResistance method multiplies that by 3 and assigns
// the result to the blockResistance instance variable.
//
// 3. Finally, the getExplosionResistance method divides the
// blockResistance instance variable by 5 and returns the result.
//
// From this we see that minecraft:stone’s final blast resistance is 6.

return (float) getBlockInstance(world, new Vector3D(x, y, z)).getResistance() * 6;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) {
this.mcBlock = block;
components.add(new BWBlockTransform(this, world, pos));
components.add(new BlockProperty.Opacity()).setOpacity(() -> mcBlock.getMaterial().isOpaque() ? 1 : 0);
Optional.of(components.add(new BlockProperty.Replaceable()))
.filter(r -> block != Blocks.air)
.ifPresent(r -> r.setReplaceable(() -> mcBlock.isReplaceable((net.minecraft.world.World) blockAccess(), blockPos())));
BlockProperty.Replaceable replaceable = components.add(new BlockProperty.Replaceable());
if (block != Blocks.air) {
replaceable.setReplaceable(() -> mcBlock.canPlaceBlockAt((net.minecraft.world.World) blockAccess(), blockPos()));
}

BlockProperty.BlockSound blockSound = components.add(new BlockProperty.BlockSound());
blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", mcBlock.stepSound.getPlaceSound()));
Expand Down Expand Up @@ -171,7 +172,7 @@ public boolean shouldDisplacePlacement() {
return false;
}

if (mcBlock == Blocks.vine || mcBlock == Blocks.tallgrass || mcBlock == Blocks.deadbush || mcBlock.isReplaceable((net.minecraft.world.World) WorldConverter.instance().toNative(world()), new BlockPos(x(), y(), z()))) {
if (mcBlock == Blocks.vine || mcBlock == Blocks.tallgrass || mcBlock == Blocks.deadbush || mcBlock.isReplaceable((net.minecraft.world.World) blockAccess(), blockPos())) {
return false;
}
return super.shouldDisplacePlacement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,21 @@ public String getLocalizedName() {
@Override
public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) {
// TODO: Maybe do something withPriority these parameters.

// This number was calculated from the blast resistance of Stone,
// which requires exactly one cubic meter of TNT to get blown up.
//
// 1. During construction, the setResistance method is called
// on minecraft:stone with a value of 10.
//
// 2. The setResistance method multiplies that by 3 and assigns
// the result to the blockResistance instance variable.
//
// 3. Finally, the getExplosionResistance method divides the
// blockResistance instance variable by 5 and returns the result.
//
// From this we see that minecraft:stone’s final blast resistance is 6.

return (float) getBlockInstance(world, VectorConverter.instance().toNova(pos)).getResistance() * 6;
}

Expand Down

0 comments on commit d5b2d15

Please sign in to comment.