use of mekanism.common.item.ItemConfigurator in project Mekanism by mekanism.
the class GuiGauge method renderToolTip.
@Override
public void renderToolTip(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
super.renderToolTip(matrix, mouseX, mouseY);
ItemStack stack = minecraft.player.inventory.getCarried();
EnumColor color = getGaugeColor().getColor();
if (!stack.isEmpty() && stack.getItem() instanceof ItemConfigurator && color != null) {
if (gui() instanceof GuiMekanismTile) {
TileEntityMekanism tile = ((GuiMekanismTile<?, ?>) gui()).getTileEntity();
if (tile instanceof ISideConfiguration && getTransmission() != null) {
DataType dataType = null;
ConfigInfo config = ((ISideConfiguration) tile).getConfig().getConfig(getTransmission());
if (config != null) {
Set<DataType> supportedDataTypes = config.getSupportedDataTypes();
for (DataType type : supportedDataTypes) {
if (type.getColor() == color) {
dataType = type;
break;
}
}
}
if (dataType == null) {
displayTooltip(matrix, MekanismLang.GENERIC_PARENTHESIS.translateColored(color, color.getName()), mouseX, mouseY);
} else {
displayTooltip(matrix, MekanismLang.GENERIC_WITH_PARENTHESIS.translateColored(color, dataType, color.getName()), mouseX, mouseY);
}
}
}
} else {
List<ITextComponent> list = new ArrayList<>();
if (getLabel() != null) {
list.add(getLabel());
}
list.addAll(getTooltipText());
displayTooltips(matrix, list, mouseX, mouseY);
}
}
use of mekanism.common.item.ItemConfigurator in project Mekanism by mekanism.
the class RenderLogisticalTransporter method render.
@Override
protected void render(TileEntityLogisticalTransporterBase tile, float partialTick, MatrixStack matrix, IRenderTypeBuffer renderer, int light, int overlayLight, IProfiler profiler) {
LogisticalTransporterBase transporter = tile.getTransmitter();
Collection<TransporterStack> inTransit = transporter.getTransit();
BlockPos pos = tile.getBlockPos();
if (!inTransit.isEmpty()) {
matrix.pushPose();
itemRenderer.init(tile.getLevel(), pos);
float partial = partialTick * transporter.tier.getSpeed();
Collection<TransporterStack> reducedTransit = getReducedTransit(inTransit);
for (TransporterStack stack : reducedTransit) {
float[] stackPos = TransporterUtils.getStackPosition(transporter, stack, partial);
matrix.pushPose();
matrix.translate(stackPos[0], stackPos[1], stackPos[2]);
matrix.scale(0.75F, 0.75F, 0.75F);
itemRenderer.renderAsStack(matrix, renderer, stack.itemStack);
matrix.popPose();
if (stack.color != null) {
modelBox.render(matrix, renderer, MekanismRenderer.FULL_LIGHT, overlayLight, stackPos[0], stackPos[1], stackPos[2], stack.color);
}
}
matrix.popPose();
}
if (transporter instanceof DiversionTransporter) {
PlayerEntity player = Minecraft.getInstance().player;
ItemStack itemStack = player.inventory.getSelected();
if (!itemStack.isEmpty() && itemStack.getItem() instanceof ItemConfigurator) {
BlockRayTraceResult rayTraceResult = MekanismUtils.rayTrace(player);
if (!rayTraceResult.getType().equals(Type.MISS) && rayTraceResult.getBlockPos().equals(pos)) {
Direction side = tile.getSideLookingAt(player, rayTraceResult.getDirection());
matrix.pushPose();
matrix.scale(0.5F, 0.5F, 0.5F);
matrix.translate(0.5, 0.5, 0.5);
MekanismRenderer.renderObject(getOverlayModel((DiversionTransporter) transporter, side), matrix, renderer.getBuffer(Atlases.translucentCullBlockSheet()), MekanismRenderer.getColorARGB(255, 255, 255, 0.8F), MekanismRenderer.FULL_LIGHT, overlayLight, FaceDisplay.FRONT);
matrix.popPose();
}
}
}
}
use of mekanism.common.item.ItemConfigurator 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.item.ItemConfigurator in project Mekanism by mekanism.
the class GuiMekanismTile method drawForegroundText.
@Override
protected void drawForegroundText(@Nonnull MatrixStack matrix, int mouseX, int mouseY) {
super.drawForegroundText(matrix, mouseX, mouseY);
if (tile instanceof ISideConfiguration) {
ItemStack stack = getMinecraft().player.inventory.getCarried();
if (!stack.isEmpty() && stack.getItem() instanceof ItemConfigurator) {
for (int i = 0; i < menu.slots.size(); i++) {
Slot slot = menu.slots.get(i);
if (isMouseOverSlot(slot, mouseX, mouseY)) {
DataType data = getFromSlot(slot);
if (data != null) {
EnumColor color = data.getColor();
displayTooltip(matrix, MekanismLang.GENERIC_WITH_PARENTHESIS.translateColored(color, data, color.getName()), mouseX - leftPos, mouseY - topPos);
}
break;
}
}
}
}
}
use of mekanism.common.item.ItemConfigurator in project Mekanism by mekanism.
the class EntityRobit method interactAt.
@Nonnull
@Override
public ActionResultType interactAt(PlayerEntity player, @Nonnull Vector3d vec, @Nonnull Hand hand) {
ItemStack stack = player.getItemInHand(hand);
if (player.isShiftKeyDown()) {
if (!stack.isEmpty() && stack.getItem() instanceof ItemConfigurator) {
if (!level.isClientSide) {
drop();
}
remove();
player.swing(hand);
return ActionResultType.SUCCESS;
}
} else {
if (!SecurityUtils.canAccess(player, this)) {
if (!level.isClientSide) {
SecurityUtils.displayNoAccess(player);
}
return ActionResultType.FAIL;
}
if (!level.isClientSide) {
INamedContainerProvider provider = MekanismContainerTypes.MAIN_ROBIT.getProvider(MekanismLang.ROBIT, this);
if (provider != null) {
// Validate the provider isn't null, it shouldn't be but just in case
NetworkHooks.openGui((ServerPlayerEntity) player, provider, buf -> buf.writeVarInt(getId()));
}
}
return ActionResultType.SUCCESS;
}
return ActionResultType.PASS;
}
Aggregations