Portals fixes and optimization
This commit is contained in:
parent
886be5bbc6
commit
b18c9ed96c
3 changed files with 45 additions and 66 deletions
|
@ -32,7 +32,7 @@ import ru.betterend.util.PortalFrameHelper;
|
||||||
|
|
||||||
public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable {
|
public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable {
|
||||||
public EndPortalBlock() {
|
public EndPortalBlock() {
|
||||||
super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL).luminance(state -> {
|
super(FabricBlockSettings.copyOf(Blocks.NETHER_PORTAL).resistance(Blocks.BEDROCK.getBlastResistance()).luminance(state -> {
|
||||||
return 12;
|
return 12;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
package ru.betterend.blocks;
|
package ru.betterend.blocks;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.state.property.BooleanProperty;
|
import net.minecraft.state.property.BooleanProperty;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import ru.betterend.blocks.basis.BlockBase;
|
import ru.betterend.blocks.basis.BlockBase;
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
import ru.betterend.util.BlocksHelper;
|
import ru.betterend.util.BlocksHelper;
|
||||||
|
import ru.betterend.util.PortalFrameHelper;
|
||||||
|
|
||||||
public class RunedFlavolite extends BlockBase {
|
public class RunedFlavolite extends BlockBase {
|
||||||
public static final BooleanProperty ACTIVATED = BooleanProperty.of("active");
|
public static final BooleanProperty ACTIVATED = BooleanProperty.of("active");
|
||||||
|
|
||||||
public RunedFlavolite() {
|
public RunedFlavolite() {
|
||||||
super(FabricBlockSettings.copyOf(BlockRegistry.FLAVOLITE.polished).luminance(state -> {
|
super(FabricBlockSettings.copyOf(BlockRegistry.FLAVOLITE.polished).resistance(Blocks.OBSIDIAN.getBlastResistance()).luminance(state -> {
|
||||||
return state.get(ACTIVATED) ? 8 : 0;
|
return state.get(ACTIVATED) ? 8 : 0;
|
||||||
}));
|
}));
|
||||||
this.setDefaultState(stateManager.getDefaultState().with(ACTIVATED, false));
|
this.setDefaultState(stateManager.getDefaultState().with(ACTIVATED, false));
|
||||||
|
@ -29,17 +33,18 @@ public class RunedFlavolite extends BlockBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||||
super.onBreak(world, pos, state, player);
|
BlockPos bottom = PortalFrameHelper.findBottomCorner((World) world, pos, this);
|
||||||
if(state.get(ACTIVATED)) {
|
BlockPos top = PortalFrameHelper.findTopCorner((World) world, pos, this);
|
||||||
for (BlockPos position : BlockPos.iterate(pos.add(-3, -4, -3), pos.add(3, 4, 3))) {
|
if (bottom == null || top == null) return;
|
||||||
if (position.equals(pos)) continue;
|
for (BlockPos position : BlockPos.iterate(bottom, top)) {
|
||||||
BlockState posState = world.getBlockState(position);
|
if (position.equals(pos)) continue;
|
||||||
if (posState.getBlock() instanceof RunedFlavolite) {
|
BlockState posState = world.getBlockState(position);
|
||||||
BlocksHelper.setWithoutUpdate(world, position, posState.with(ACTIVATED, false));
|
if (posState.getBlock() instanceof RunedFlavolite && posState.get(ACTIVATED)) {
|
||||||
} else if (posState.isOf(BlockRegistry.END_PORTAL_BLOCK)) {
|
BlocksHelper.setWithoutUpdate(world, position, posState.with(ACTIVATED, false));
|
||||||
world.removeBlock(position, false);
|
} else if (posState.isOf(BlockRegistry.END_PORTAL_BLOCK)) {
|
||||||
}
|
world.removeBlock(position, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
super.onBreak(world, pos, state, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
import ru.betterend.registry.FeatureRegistry;
|
import ru.betterend.registry.FeatureRegistry;
|
||||||
|
|
||||||
|
@ -22,34 +23,29 @@ public class PortalFrameHelper {
|
||||||
boolean valid = true;
|
boolean valid = true;
|
||||||
int width = 1, height = 1;
|
int width = 1, height = 1;
|
||||||
Direction.Axis axis = Direction.Axis.X;
|
Direction.Axis axis = Direction.Axis.X;
|
||||||
BlockPos checkPos = bottomCorner.up();
|
BlockPos.Mutable checkPos = bottomCorner.up().mutableCopy();
|
||||||
Direction moveDir = Direction.UP;
|
Direction moveDir = Direction.UP;
|
||||||
while(valid && !checkPos.equals(bottomCorner)) {
|
while(valid && !checkPos.equals(bottomCorner)) {
|
||||||
valid = world.getBlockState(checkPos).isOf(frameBlock);
|
valid = world.getBlockState(checkPos).isOf(frameBlock);
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
|
checkPos = checkPos.move(moveDir.getOpposite());
|
||||||
switch(moveDir) {
|
switch(moveDir) {
|
||||||
case UP: {
|
case UP: {
|
||||||
checkPos = checkPos.down();
|
|
||||||
if (world.getBlockState(checkPos.east()).isOf(frameBlock)) {
|
if (world.getBlockState(checkPos.east()).isOf(frameBlock)) {
|
||||||
checkPos = checkPos.east();
|
|
||||||
moveDir = Direction.EAST;
|
moveDir = Direction.EAST;
|
||||||
valid = true;
|
valid = true;
|
||||||
} else if (world.getBlockState(checkPos.south()).isOf(frameBlock)) {
|
} else if (world.getBlockState(checkPos.south()).isOf(frameBlock)) {
|
||||||
axis = Direction.Axis.Z;
|
axis = Direction.Axis.Z;
|
||||||
checkPos = checkPos.south();
|
|
||||||
moveDir = Direction.SOUTH;
|
moveDir = Direction.SOUTH;
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DOWN: {
|
case DOWN: {
|
||||||
checkPos = checkPos.up();
|
|
||||||
if (world.getBlockState(checkPos.west()).isOf(frameBlock)) {
|
if (world.getBlockState(checkPos.west()).isOf(frameBlock)) {
|
||||||
checkPos = checkPos.west();
|
|
||||||
moveDir = Direction.WEST;
|
moveDir = Direction.WEST;
|
||||||
valid = true;
|
valid = true;
|
||||||
} else if (world.getBlockState(checkPos.north()).isOf(frameBlock)) {
|
} else if (world.getBlockState(checkPos.north()).isOf(frameBlock)) {
|
||||||
checkPos = checkPos.north();
|
|
||||||
moveDir = Direction.NORTH;
|
moveDir = Direction.NORTH;
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
|
@ -57,9 +53,7 @@ public class PortalFrameHelper {
|
||||||
}
|
}
|
||||||
case SOUTH:
|
case SOUTH:
|
||||||
case EAST: {
|
case EAST: {
|
||||||
checkPos = moveDir.equals(Direction.SOUTH) ? checkPos.north() : checkPos.west();
|
|
||||||
if (world.getBlockState(checkPos.down()).isOf(frameBlock)) {
|
if (world.getBlockState(checkPos.down()).isOf(frameBlock)) {
|
||||||
checkPos = checkPos.down();
|
|
||||||
moveDir = Direction.DOWN;
|
moveDir = Direction.DOWN;
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
|
@ -69,39 +63,17 @@ public class PortalFrameHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!valid) return false;
|
if (!valid) return false;
|
||||||
|
checkPos = checkPos.move(moveDir);
|
||||||
} else {
|
} else {
|
||||||
switch(moveDir) {
|
if (moveDir.equals(Direction.EAST) || moveDir.equals(Direction.SOUTH)) {
|
||||||
case UP: {
|
width++;
|
||||||
height++;
|
} else if (moveDir.equals(Direction.UP)) {
|
||||||
checkPos = checkPos.up();
|
height++;
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DOWN: {
|
|
||||||
checkPos = checkPos.down();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NORTH: {
|
|
||||||
checkPos = checkPos.north();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SOUTH: {
|
|
||||||
width++;
|
|
||||||
checkPos = checkPos.south();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case EAST: {
|
|
||||||
width++;
|
|
||||||
checkPos = checkPos.east();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case WEST: {
|
|
||||||
checkPos = checkPos.west();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
checkPos = checkPos.move(moveDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (width < 4 || height < 5 || width > 40 || height > 40) return false;
|
if (width < 4 || height < 5 || width > 20 || height > 25) return false;
|
||||||
if (axis.equals(Direction.Axis.X)) {
|
if (axis.equals(Direction.Axis.X)) {
|
||||||
if(!checkIsAreaEmpty(world, bottomCorner.add(1, 1, 0), topCorner.add(-1, -1, 0))) return false;
|
if(!checkIsAreaEmpty(world, bottomCorner.add(1, 1, 0), topCorner.add(-1, -1, 0))) return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -124,27 +96,28 @@ public class PortalFrameHelper {
|
||||||
BlockState south = world.getBlockState(pos.south());
|
BlockState south = world.getBlockState(pos.south());
|
||||||
BlockState west = world.getBlockState(pos.west());
|
BlockState west = world.getBlockState(pos.west());
|
||||||
BlockState east = world.getBlockState(pos.east());
|
BlockState east = world.getBlockState(pos.east());
|
||||||
|
BlockPos.Mutable mutable = pos instanceof BlockPos.Mutable ? (BlockPos.Mutable) pos : pos.mutableCopy();
|
||||||
if (up.isOf(frameBlock) && !down.isOf(frameBlock)) {
|
if (up.isOf(frameBlock) && !down.isOf(frameBlock)) {
|
||||||
if (south.isOf(frameBlock) || east.isOf(frameBlock)) {
|
if (south.isOf(frameBlock) || east.isOf(frameBlock)) {
|
||||||
return pos;
|
return pos.toImmutable();
|
||||||
} else if (west.isOf(frameBlock)) {
|
} else if (west.isOf(frameBlock)) {
|
||||||
return findBottomCorner(world, pos.west(), frameBlock);
|
return findBottomCorner(world, mutable.move(Direction.WEST), frameBlock);
|
||||||
} else if (north.isOf(frameBlock)){
|
} else if (north.isOf(frameBlock)){
|
||||||
return findBottomCorner(world, pos.north(), frameBlock);
|
return findBottomCorner(world, mutable.move(Direction.NORTH), frameBlock);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (down.isOf(frameBlock)) {
|
} else if (down.isOf(frameBlock)) {
|
||||||
if (west.isOf(frameBlock)) {
|
if (west.isOf(frameBlock)) {
|
||||||
return findBottomCorner(world, pos.west(), frameBlock);
|
return findBottomCorner(world, mutable.move(Direction.WEST), frameBlock);
|
||||||
} else if (north.isOf(frameBlock)) {
|
} else if (north.isOf(frameBlock)) {
|
||||||
return findBottomCorner(world, pos.north(), frameBlock);
|
return findBottomCorner(world, mutable.move(Direction.NORTH), frameBlock);
|
||||||
} else {
|
} else {
|
||||||
return findBottomCorner(world, pos.down(), frameBlock);
|
return findBottomCorner(world, mutable.move(Direction.DOWN), frameBlock);
|
||||||
}
|
}
|
||||||
} else if (west.isOf(frameBlock)) {
|
} else if (west.isOf(frameBlock)) {
|
||||||
return findBottomCorner(world, pos.west(), frameBlock);
|
return findBottomCorner(world, mutable.move(Direction.WEST), frameBlock);
|
||||||
} else if (north.isOf(frameBlock)) {
|
} else if (north.isOf(frameBlock)) {
|
||||||
return findBottomCorner(world, pos.north(), frameBlock);
|
return findBottomCorner(world, mutable.move(Direction.NORTH), frameBlock);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -156,27 +129,28 @@ public class PortalFrameHelper {
|
||||||
BlockState south = world.getBlockState(pos.south());
|
BlockState south = world.getBlockState(pos.south());
|
||||||
BlockState west = world.getBlockState(pos.west());
|
BlockState west = world.getBlockState(pos.west());
|
||||||
BlockState east = world.getBlockState(pos.east());
|
BlockState east = world.getBlockState(pos.east());
|
||||||
|
BlockPos.Mutable mutable = pos instanceof BlockPos.Mutable ? (BlockPos.Mutable) pos : pos.mutableCopy();
|
||||||
if (!up.isOf(frameBlock) && down.isOf(frameBlock)) {
|
if (!up.isOf(frameBlock) && down.isOf(frameBlock)) {
|
||||||
if (north.isOf(frameBlock) || west.isOf(frameBlock)) {
|
if (north.isOf(frameBlock) || west.isOf(frameBlock)) {
|
||||||
return pos;
|
return pos.toImmutable();
|
||||||
} else if (east.isOf(frameBlock)) {
|
} else if (east.isOf(frameBlock)) {
|
||||||
return findTopCorner(world, pos.east(), frameBlock);
|
return findTopCorner(world, mutable.move(Direction.EAST), frameBlock);
|
||||||
} else if (south.isOf(frameBlock)){
|
} else if (south.isOf(frameBlock)){
|
||||||
return findTopCorner(world, pos.south(), frameBlock);
|
return findTopCorner(world, mutable.move(Direction.SOUTH), frameBlock);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} else if (up.isOf(frameBlock)) {
|
} else if (up.isOf(frameBlock)) {
|
||||||
if (east.isOf(frameBlock)) {
|
if (east.isOf(frameBlock)) {
|
||||||
return findTopCorner(world, pos.east(), frameBlock);
|
return findTopCorner(world, mutable.move(Direction.EAST), frameBlock);
|
||||||
} else if (south.isOf(frameBlock)){
|
} else if (south.isOf(frameBlock)){
|
||||||
return findTopCorner(world, pos.south(), frameBlock);
|
return findTopCorner(world, mutable.move(Direction.SOUTH), frameBlock);
|
||||||
} else {
|
} else {
|
||||||
return findTopCorner(world, pos.up(), frameBlock);
|
return findTopCorner(world, mutable.move(Direction.UP), frameBlock);
|
||||||
}
|
}
|
||||||
} else if (east.isOf(frameBlock)) {
|
} else if (east.isOf(frameBlock)) {
|
||||||
return findTopCorner(world, pos.east(), frameBlock);
|
return findTopCorner(world, mutable.move(Direction.EAST), frameBlock);
|
||||||
} else if (south.isOf(frameBlock)){
|
} else if (south.isOf(frameBlock)){
|
||||||
return findTopCorner(world, pos.south(), frameBlock);
|
return findTopCorner(world, mutable.move(Direction.SOUTH), frameBlock);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue