use of mekanism.common.tile.TileEntityBoundingBlock in project Mekanism by mekanism.
the class RenderTickHandler method onBlockHover.
@SubscribeEvent
public void onBlockHover(DrawHighlightEvent.HighlightBlock event) {
PlayerEntity player = minecraft.player;
if (player == null) {
return;
}
BlockRayTraceResult rayTraceResult = event.getTarget();
if (!rayTraceResult.getType().equals(Type.MISS)) {
World world = player.getCommandSenderWorld();
BlockPos pos = rayTraceResult.getBlockPos();
IRenderTypeBuffer renderer = event.getBuffers();
ActiveRenderInfo info = event.getInfo();
MatrixStack matrix = event.getMatrix();
IProfiler profiler = world.getProfiler();
BlockState blockState = world.getBlockState(pos);
boolean shouldCancel = false;
profiler.push(ProfilerConstants.MEKANISM_OUTLINE);
if (!blockState.isAir(world, pos) && world.getWorldBorder().isWithinBounds(pos)) {
BlockPos actualPos = pos;
BlockState actualState = blockState;
if (blockState.getBlock() instanceof BlockBounding) {
TileEntityBoundingBlock tile = WorldUtils.getTileEntity(TileEntityBoundingBlock.class, world, pos);
if (tile != null) {
actualPos = tile.getMainPos();
actualState = world.getBlockState(actualPos);
}
}
AttributeCustomSelectionBox customSelectionBox = Attribute.get(actualState, AttributeCustomSelectionBox.class);
if (customSelectionBox != null) {
WireFrameRenderer renderWireFrame = null;
if (customSelectionBox.isJavaModel()) {
// If we use a TER to render the wire frame, grab the tile
TileEntity tile = WorldUtils.getTileEntity(world, actualPos);
if (tile != null) {
TileEntityRenderer<TileEntity> tileRenderer = TileEntityRendererDispatcher.instance.getRenderer(tile);
if (tileRenderer instanceof IWireFrameRenderer) {
IWireFrameRenderer wireFrameRenderer = (IWireFrameRenderer) tileRenderer;
if (wireFrameRenderer.hasSelectionBox(actualState)) {
renderWireFrame = (buffer, matrixStack, state, red, green, blue, alpha) -> {
if (wireFrameRenderer.isCombined()) {
renderQuadsWireFrame(state, buffer, matrixStack.last().pose(), world.random, red, green, blue, alpha);
}
wireFrameRenderer.renderWireFrame(tile, event.getPartialTicks(), matrixStack, buffer, red, green, blue, alpha);
};
}
}
}
} else {
// Otherwise, skip getting the tile and just grab the model
renderWireFrame = (buffer, matrixStack, state, red, green, blue, alpha) -> renderQuadsWireFrame(state, buffer, matrixStack.last().pose(), world.random, red, green, blue, alpha);
}
if (renderWireFrame != null) {
matrix.pushPose();
Vector3d viewPosition = info.getPosition();
matrix.translate(actualPos.getX() - viewPosition.x, actualPos.getY() - viewPosition.y, actualPos.getZ() - viewPosition.z);
renderWireFrame.render(renderer.getBuffer(RenderType.lines()), matrix, actualState, 0, 0, 0, 0.4F);
matrix.popPose();
shouldCancel = true;
}
}
}
profiler.pop();
ItemStack stack = player.getMainHandItem();
if (stack.isEmpty() || !(stack.getItem() instanceof ItemConfigurator)) {
// If we are not holding a configurator, look if we are in the offhand
stack = player.getOffhandItem();
if (stack.isEmpty() || !(stack.getItem() instanceof ItemConfigurator)) {
if (shouldCancel) {
event.setCanceled(true);
}
return;
}
}
profiler.push(ProfilerConstants.CONFIGURABLE_MACHINE);
ConfiguratorMode state = ((ItemConfigurator) stack.getItem()).getMode(stack);
if (state.isConfigurating()) {
TransmissionType type = Objects.requireNonNull(state.getTransmission(), "Configurating state requires transmission type");
TileEntity tile = WorldUtils.getTileEntity(world, pos);
if (tile instanceof ISideConfiguration) {
ISideConfiguration configurable = (ISideConfiguration) tile;
TileComponentConfig config = configurable.getConfig();
if (config.supports(type)) {
Direction face = rayTraceResult.getDirection();
DataType dataType = config.getDataType(type, RelativeSide.fromDirections(configurable.getDirection(), face));
if (dataType != null) {
Vector3d viewPosition = info.getPosition();
matrix.pushPose();
matrix.translate(pos.getX() - viewPosition.x, pos.getY() - viewPosition.y, pos.getZ() - viewPosition.z);
MekanismRenderer.renderObject(getOverlayModel(face, type), matrix, renderer.getBuffer(Atlases.translucentCullBlockSheet()), MekanismRenderer.getColorARGB(dataType.getColor(), 0.6F), MekanismRenderer.FULL_LIGHT, OverlayTexture.NO_OVERLAY, FaceDisplay.FRONT);
matrix.popPose();
}
}
}
}
profiler.pop();
if (shouldCancel) {
event.setCanceled(true);
}
}
}
use of mekanism.common.tile.TileEntityBoundingBlock in project Mekanism by mekanism.
the class HwylaDataProvider method appendServerData.
@Override
public void appendServerData(CompoundNBT data, ServerPlayerEntity player, World world, TileEntity tile) {
if (tile instanceof TileEntityBoundingBlock) {
// If we are a bounding block that has a position set, redirect the check to the main location
TileEntityBoundingBlock boundingBlock = (TileEntityBoundingBlock) tile;
if (!boundingBlock.receivedCoords || tile.getBlockPos().equals(boundingBlock.getMainPos())) {
// If the coords haven't been received, exit
return;
}
tile = WorldUtils.getTileEntity(world, boundingBlock.getMainPos());
if (tile == null) {
// If there is no tile where the bounding block thinks the main tile is, exit
return;
}
}
HwylaLookingAtHelper helper = new HwylaLookingAtHelper();
LookingAtUtils.addInfo(helper, tile, true, true);
// Add our data if we have any
helper.finalizeData(data);
}
use of mekanism.common.tile.TileEntityBoundingBlock in project Mekanism by mekanism.
the class WorldUtils method makeBoundingBlock.
/**
* Places a fake bounding block at the defined location.
*
* @param world world to place block in
* @param boundingLocation coordinates of bounding block
* @param orig original block position
*/
public static void makeBoundingBlock(@Nullable IWorld world, BlockPos boundingLocation, BlockPos orig) {
if (world == null) {
return;
}
BlockBounding boundingBlock = MekanismBlocks.BOUNDING_BLOCK.getBlock();
BlockState newState = BlockStateHelper.getStateForPlacement(boundingBlock, boundingBlock.defaultBlockState(), world, boundingLocation, null, Direction.NORTH);
world.setBlock(boundingLocation, newState, BlockFlags.DEFAULT);
if (!world.isClientSide()) {
TileEntityBoundingBlock tile = getTileEntity(TileEntityBoundingBlock.class, world, boundingLocation);
if (tile != null) {
tile.setMainLocation(orig);
} else {
Mekanism.logger.warn("Unable to find Bounding Block Tile at: {}", boundingLocation);
}
}
}
Aggregations