This commit is contained in:
modmuss50 2019-10-28 21:10:12 +00:00
parent 44b9c2ef05
commit 9314899b08
2 changed files with 45 additions and 17 deletions

View file

@ -38,10 +38,12 @@ import net.minecraft.state.StateFactory;
import net.minecraft.state.property.AbstractProperty; import net.minecraft.state.property.AbstractProperty;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.SystemUtil;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
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.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -56,6 +58,10 @@ import techreborn.init.TRContent;
import techreborn.utils.damageSources.ElectrialShockSource; import techreborn.utils.damageSources.ElectrialShockSource;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* Created by modmuss50 on 19/05/2017. * Created by modmuss50 on 19/05/2017.
@ -69,6 +75,15 @@ public class CableBlock extends BlockWithEntity {
public static final BooleanProperty UP = BooleanProperty.of("up"); public static final BooleanProperty UP = BooleanProperty.of("up");
public static final BooleanProperty DOWN = BooleanProperty.of("down"); public static final BooleanProperty DOWN = BooleanProperty.of("down");
public static final Map<Direction, BooleanProperty> PROPERTY_MAP = SystemUtil.consume(new HashMap<>(), map -> {
map.put(Direction.EAST, EAST);
map.put(Direction.WEST, WEST);
map.put(Direction.NORTH, NORTH);
map.put(Direction.SOUTH, SOUTH);
map.put(Direction.UP, UP);
map.put(Direction.DOWN, DOWN);
});
public final TRContent.Cables type; public final TRContent.Cables type;
public CableBlock(TRContent.Cables type) { public CableBlock(TRContent.Cables type) {
@ -173,13 +188,21 @@ public class CableBlock extends BlockWithEntity {
@Override @Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, EntityContext entityContext) { public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, EntityContext entityContext) {
if (type != null) { double size = type != null ? type.cableThickness : 6;
// outline is 1px bigger then model to ease selection VoxelShape baseShape = Block.createCuboidShape(size, size, size, 16.0D - size, 16.0D - size, 16.0D - size);
double culling = type.cableThickness - 1;
return Block.createCuboidShape(culling, culling, culling, 16.0D - culling, 16.0D - culling, List<VoxelShape> connections = new ArrayList<>();
16.0D - culling); for(Direction dir : Direction.values()){
if(state.get(PROPERTY_MAP.get(dir))) {
double x = dir == Direction.WEST ? 0 : dir == Direction.EAST ? 16D : size;
double z = dir == Direction.NORTH ? 0 : dir == Direction.SOUTH ? 16D : size;
double y = dir == Direction.DOWN ? 0 : dir == Direction.UP ? 16D : size;
VoxelShape shape = Block.createCuboidShape(x, y, z, 16.0D - size, 16.0D - size, 16.0D - size);
connections.add(shape);
}
} }
return Block.createCuboidShape(4, 4, 4, 12, 12, 12); return VoxelShapes.union(baseShape, connections.toArray(new VoxelShape[]{}));
} }
@Override @Override

View file

@ -27,6 +27,7 @@ package techreborn.blocks.lighting;
import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.EntityContext;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -60,25 +61,29 @@ public class BlockLamp extends BaseBlockEntityProvider {
public BlockLamp(int cost, double depth, double width) { public BlockLamp(int cost, double depth, double width) {
super(FabricBlockSettings.of(Material.REDSTONE_LAMP).strength(2f, 2f).lightLevel(brightness).build()); super(FabricBlockSettings.of(Material.REDSTONE_LAMP).strength(2f, 2f).lightLevel(brightness).build());
this.shape = GenCuboidShapes(depth, width); this.shape = genCuboidShapes(depth, width);
this.cost = cost; this.cost = cost;
this.setDefaultState(this.stateFactory.getDefaultState().with(FACING, Direction.NORTH).with(ACTIVE, false)); this.setDefaultState(this.stateFactory.getDefaultState().with(FACING, Direction.NORTH).with(ACTIVE, false));
BlockWrenchEventHandler.wrenableBlocks.add(this); BlockWrenchEventHandler.wrenableBlocks.add(this);
} }
private VoxelShape[] GenCuboidShapes(double depth, double width) { private VoxelShape[] genCuboidShapes(double depth, double width) {
double culling = (16.0D - width) / 2 ; double culling = (16.0D - width) / 2 ;
VoxelShape[] shapes = { return new VoxelShape[]{
Block.createCuboidShape(culling, 16.0 - depth, culling, 16.0 - culling, 16.0D, 16.0 - culling), createCuboidShape(culling, 16.0 - depth, culling, 16.0 - culling, 16.0D, 16.0 - culling),
Block.createCuboidShape(culling, 0.0D, culling, 16.0D - culling, depth, 16.0 - culling), createCuboidShape(culling, 0.0D, culling, 16.0D - culling, depth, 16.0 - culling),
Block.createCuboidShape(culling, culling, 16.0 - depth, 16.0 - culling, 16.0 - culling, 16.0D), createCuboidShape(culling, culling, 16.0 - depth, 16.0 - culling, 16.0 - culling, 16.0D),
Block.createCuboidShape(culling, culling, 0.0D, 16.0 - culling, 16.0 - culling, depth), createCuboidShape(culling, culling, 0.0D, 16.0 - culling, 16.0 - culling, depth),
Block.createCuboidShape(16.0 - depth, culling, culling, 16.0D, 16.0 - culling, 16.0 - culling), createCuboidShape(16.0 - depth, culling, culling, 16.0D, 16.0 - culling, 16.0 - culling),
Block.createCuboidShape(0.0D, culling, culling, depth, 16.0 - culling, 16.0 - culling) createCuboidShape(0.0D, culling, culling, depth, 16.0 - culling, 16.0 - culling)
}; };
return shapes;
} }
@Override
public VoxelShape getOutlineShape(BlockState blockState, BlockView blockView, BlockPos blockPos, EntityContext entityContext) {
return shape[blockState.get(FACING).ordinal()];
}
public static boolean isActive(BlockState state) { public static boolean isActive(BlockState state) {
return state.get(ACTIVE); return state.get(ACTIVE);
} }