Portals fixes and optimization

This commit is contained in:
Aleksey 2020-10-25 18:27:01 +03:00
parent 886be5bbc6
commit b18c9ed96c
3 changed files with 45 additions and 66 deletions

View file

@ -1,22 +1,26 @@
package ru.betterend.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ru.betterend.blocks.basis.BlockBase;
import ru.betterend.registry.BlockRegistry;
import ru.betterend.util.BlocksHelper;
import ru.betterend.util.PortalFrameHelper;
public class RunedFlavolite extends BlockBase {
public static final BooleanProperty ACTIVATED = BooleanProperty.of("active");
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;
}));
this.setDefaultState(stateManager.getDefaultState().with(ACTIVATED, false));
@ -29,17 +33,18 @@ public class RunedFlavolite extends BlockBase {
@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
super.onBreak(world, pos, state, player);
if(state.get(ACTIVATED)) {
for (BlockPos position : BlockPos.iterate(pos.add(-3, -4, -3), pos.add(3, 4, 3))) {
if (position.equals(pos)) continue;
BlockState posState = world.getBlockState(position);
if (posState.getBlock() instanceof RunedFlavolite) {
BlocksHelper.setWithoutUpdate(world, position, posState.with(ACTIVATED, false));
} else if (posState.isOf(BlockRegistry.END_PORTAL_BLOCK)) {
world.removeBlock(position, false);
}
BlockPos bottom = PortalFrameHelper.findBottomCorner((World) world, pos, this);
BlockPos top = PortalFrameHelper.findTopCorner((World) world, pos, this);
if (bottom == null || top == null) return;
for (BlockPos position : BlockPos.iterate(bottom, top)) {
if (position.equals(pos)) continue;
BlockState posState = world.getBlockState(position);
if (posState.getBlock() instanceof RunedFlavolite && posState.get(ACTIVATED)) {
BlocksHelper.setWithoutUpdate(world, position, posState.with(ACTIVATED, false));
} else if (posState.isOf(BlockRegistry.END_PORTAL_BLOCK)) {
world.removeBlock(position, false);
}
}
super.onBreak(world, pos, state, player);
}
}