Fixes
This commit is contained in:
parent
a968b9bb23
commit
8beabd0f96
18 changed files with 176 additions and 63 deletions
|
@ -6,14 +6,18 @@ import java.util.Random;
|
|||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.util.BlockMirror;
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockPos.Mutable;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import ru.betterend.blocks.BlockBlueVine;
|
||||
import ru.betterend.blocks.basis.BlockDoublePlant;
|
||||
import ru.betterend.blocks.basis.BlockGlowingFur;
|
||||
|
||||
public class BlocksHelper {
|
||||
public static final int FLAG_UPDATE_BLOCK = 1;
|
||||
|
@ -24,6 +28,9 @@ public class BlocksHelper {
|
|||
|
||||
public static final int SET_SILENT = FLAG_UPDATE_BLOCK | FLAG_IGNORE_OBSERVERS | FLAG_SEND_CLIENT_CHANGES;
|
||||
public static final Direction[] HORIZONTAL = new Direction[] { Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST };
|
||||
|
||||
private static final Mutable POS = new Mutable();
|
||||
protected static final BlockState AIR = Blocks.AIR.getDefaultState();
|
||||
|
||||
private static final Vec3i[] OFFSETS = new Vec3i[] {
|
||||
new Vec3i(-1, -1, -1), new Vec3i(-1, -1, 0), new Vec3i(-1, -1, 1),
|
||||
|
@ -69,7 +76,7 @@ public class BlocksHelper {
|
|||
return state.rotate(mirror.getRotation((Direction) state.get(facing)));
|
||||
}
|
||||
|
||||
public static int getLengthDown(ServerWorld world, BlockPos pos, Block block) {
|
||||
public static int getLengthDown(WorldAccess world, BlockPos pos, Block block) {
|
||||
int count = 1;
|
||||
while (world.getBlockState(pos.down(count)).getBlock() == block)
|
||||
count++;
|
||||
|
@ -105,4 +112,47 @@ public class BlocksHelper {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void fixBlocks(WorldAccess world, BlockPos start, BlockPos end) {
|
||||
synchronized (world) {
|
||||
BlockState state;
|
||||
for (int x = start.getX(); x <= end.getX(); x++) {
|
||||
POS.setX(x);
|
||||
for (int z = start.getZ(); z <= end.getZ(); z++) {
|
||||
POS.setZ(z);
|
||||
for (int y = start.getY(); y <= end.getY(); y++) {
|
||||
POS.setY(y);
|
||||
state = world.getBlockState(POS);
|
||||
if (!state.canPlaceAt(world, POS)) {
|
||||
// Is blue Vine
|
||||
if (state.getBlock() instanceof BlockBlueVine) {
|
||||
while (!state.canPlaceAt(world, POS)) {
|
||||
BlocksHelper.setWithoutUpdate(world, POS, AIR);
|
||||
for (Direction dir : HORIZONTAL) {
|
||||
BlockPos p = POS.offset(dir).up();
|
||||
state = world.getBlockState(p);
|
||||
if (state.getBlock() instanceof BlockGlowingFur) {
|
||||
BlocksHelper.setWithoutUpdate(world, p, AIR);
|
||||
}
|
||||
}
|
||||
POS.setY(POS.getY() + 1);
|
||||
state = world.getBlockState(POS);
|
||||
}
|
||||
}
|
||||
// Double plants
|
||||
if (state.getBlock() instanceof BlockDoublePlant) {
|
||||
BlocksHelper.setWithoutUpdate(world, POS, AIR);
|
||||
POS.setY(POS.getY() + 1);
|
||||
BlocksHelper.setWithoutUpdate(world, POS, AIR);
|
||||
}
|
||||
// Common plants & blocks
|
||||
else {
|
||||
BlocksHelper.setWithoutUpdate(world, POS, AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue