use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class BlockContainerFacingBase method setState.
public static void setState(Direction facing, World worldIn, BlockPos pos) {
BlockState iblockstate = worldIn.getBlockState(pos);
TileEntity tileentity = worldIn.getBlockEntity(pos);
worldIn.setBlock(pos, iblockstate.setValue(FACING, facing), 3);
if (tileentity != null) {
tileentity.clearRemoved();
worldIn.setBlockEntity(pos, tileentity);
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class BlockContainerHorizontalFacingBase method setState.
public static void setState(boolean active, World worldIn, BlockPos pos) {
BlockState iblockstate = worldIn.getBlockState(pos);
TileEntity tileentity = worldIn.getBlockEntity(pos);
worldIn.setBlock(pos, iblockstate.setValue(ACTIVE, active), 3);
if (tileentity != null) {
tileentity.clearRemoved();
worldIn.setBlockEntity(pos, tileentity);
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class BlockContainerHorizontalFacingBase method setState.
public static void setState(Direction facing, World worldIn, BlockPos pos) {
BlockState iblockstate = worldIn.getBlockState(pos);
TileEntity tileentity = worldIn.getBlockEntity(pos);
worldIn.setBlock(pos, iblockstate.setValue(FACING, facing), 3);
if (tileentity != null) {
tileentity.clearRemoved();
worldIn.setBlockEntity(pos, tileentity);
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class BluePowerAPI method loadSilkySettings.
@Override
public void loadSilkySettings(World world, BlockPos pos, ItemStack stack) {
TileEntity te = world.getBlockEntity(pos);
BlockState blockState = world.getBlockState(pos);
if (te == null)
throw new IllegalStateException("This block doesn't have a tile entity?!");
if (stack.isEmpty())
throw new IllegalArgumentException("ItemStack is empty!");
if (stack.hasTag()) {
CompoundNBT tag = stack.getTag();
if (tag.contains("tileData")) {
if (te instanceof IAdvancedSilkyRemovable) {
((IAdvancedSilkyRemovable) te).readSilkyData(world, pos, tag.getCompound("tileData"));
} else if (blockState.getBlock() instanceof IAdvancedSilkyRemovable) {
((IAdvancedSilkyRemovable) blockState.getBlock()).readSilkyData(world, pos, tag.getCompound("tileData"));
} else {
CompoundNBT tileTag = tag.getCompound("tileData");
tileTag.putInt("x", pos.getX());
tileTag.putInt("y", pos.getY());
tileTag.putInt("z", pos.getZ());
te.load(blockState, tileTag);
}
}
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class BPEventHandler method blockHighlightEvent.
@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public void blockHighlightEvent(DrawHighlightEvent event) {
PlayerEntity player = Minecraft.getInstance().player;
if (player == null) {
return;
}
World world = player.level;
if (world == null) {
return;
}
RayTraceResult mop = event.getTarget();
if (mop instanceof BlockRayTraceResult) {
BlockPos pos = ((BlockRayTraceResult) mop).getBlockPos();
BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockBPMultipart) {
BlockState partstate = MultipartUtils.getClosestState(player, pos);
IVertexBuilder builder = event.getBuffers().getBuffer(RenderType.lines());
if (partstate != null) {
VoxelShape shape = partstate.getShape(world, pos, ISelectionContext.of(player));
Vector3d projectedView = event.getInfo().getPosition();
double d0 = pos.getX() - projectedView.x();
double d1 = pos.getY() - projectedView.y();
double d2 = pos.getZ() - projectedView.z();
Matrix4f matrix4f = event.getMatrix().last().pose();
shape.forAllEdges((startX, startY, startZ, endX, endY, endZ) -> {
builder.vertex(matrix4f, (float) (startX + d0), (float) (startY + d1), (float) (startZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
builder.vertex(matrix4f, (float) (endX + d0), (float) (endY + d1), (float) (endZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
});
event.setCanceled(true);
}
}
}
}
Aggregations