use of com.bluepowermod.block.BlockBPMultipart 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);
}
}
}
}
use of com.bluepowermod.block.BlockBPMultipart in project BluePower by Qmunity.
the class ItemBPPart method place.
@Override
public ActionResultType place(BlockItemUseContext context) {
BlockState state = context.getLevel().getBlockState(context.getClickedPos());
BlockState thisState = getBlock().getStateForPlacement(context);
if (state.getBlock() instanceof IBPPartBlock && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
// Save the Tile Entity Data
CompoundNBT nbt = new CompoundNBT();
TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity != null) {
nbt = tileEntity.save(nbt);
}
// Replace with Multipart
context.getLevel().setBlockAndUpdate(context.getClickedPos(), BPBlocks.multipart.defaultBlockState());
tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity instanceof TileBPMultipart) {
// Add the original State to the Multipart
((TileBPMultipart) tileEntity).addState(state);
// Restore the Tile Entity Data
TileEntity tile = ((TileBPMultipart) tileEntity).getTileForState(state);
if (tile != null)
tile.load(state, nbt);
// Add the new State
((TileBPMultipart) tileEntity).addState(thisState);
thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
}
// Update Self
state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
context.getItemInHand().shrink(1);
// Place Sound
context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
return ActionResultType.SUCCESS;
} else if (state.getBlock() instanceof BlockBPMultipart && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
// Add to the Existing Multipart
TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity instanceof TileBPMultipart) {
((TileBPMultipart) tileEntity).addState(thisState);
thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
// Update Neighbors
for (Direction dir : Direction.values()) {
context.getLevel().getBlockState(context.getClickedPos().relative(dir)).neighborChanged(context.getLevel(), context.getClickedPos().relative(dir), state.getBlock(), context.getClickedPos(), false);
}
// Update Self
state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
context.getItemInHand().shrink(1);
// Place Sound
context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
return ActionResultType.SUCCESS;
}
}
return super.place(context);
}
use of com.bluepowermod.block.BlockBPMultipart in project BluePower by Qmunity.
the class Renderers method init.
public static void init() {
ClientRegistry.bindTileEntityRenderer(BPTileEntityType.LAMP, RenderLamp::new);
ClientRegistry.bindTileEntityRenderer(BPTileEntityType.ENGINE, RenderEngine::new);
for (Item item : BPItems.itemList) {
if (item instanceof IBPColoredItem) {
Minecraft.getInstance().getItemColors().register(new BPItemColor(), item);
}
}
for (Block block : BPBlocks.blockList) {
if (block instanceof IBPColoredBlock) {
Minecraft.getInstance().getBlockColors().register(new BPBlockColor(), block);
Minecraft.getInstance().getItemColors().register(new BPBlockColor(), Item.byBlock(block));
}
if (block instanceof BlockLampSurface || block instanceof BlockGateBase || block instanceof BlockBattery)
RenderTypeLookup.setRenderLayer(block, RenderType.cutout());
if (block instanceof BlockBPGlass || block instanceof BlockBPMicroblock || block instanceof BlockBPMultipart)
RenderTypeLookup.setRenderLayer(block, RenderType.translucent());
}
RenderTypeLookup.setRenderLayer(BPBlocks.indigo_flower, RenderType.cutout());
RenderTypeLookup.setRenderLayer(BPBlocks.flax_crop, RenderType.cutout());
RenderTypeLookup.setRenderLayer(BPBlocks.cracked_basalt_lava, RenderType.cutout());
RenderTypeLookup.setRenderLayer(BPBlocks.cracked_basalt_decorative, RenderType.cutout());
RenderTypeLookup.setRenderLayer(BPBlocks.rubber_leaves, RenderType.cutout());
RenderTypeLookup.setRenderLayer(BPBlocks.rubber_sapling, RenderType.cutout());
RenderTypeLookup.setRenderLayer(BPBlocks.tube, RenderType.cutout());
}
Aggregations