use of net.minecraft.util.text.StringTextComponent in project BluePower by Qmunity.
the class BlockBPMicroblock method getCloneItemStack.
@Override
public ItemStack getCloneItemStack(IBlockReader world, BlockPos pos, BlockState state) {
TileEntity tileentity = world.getBlockEntity(pos);
ItemStack stack = ItemStack.EMPTY;
if (tileentity instanceof TileBPMultipart) {
tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
}
if (tileentity instanceof TileBPMicroblock) {
CompoundNBT nbt = new CompoundNBT();
nbt.putString("block", ((TileBPMicroblock) tileentity).getBlock().getRegistryName().toString());
stack = new ItemStack(this);
stack.setTag(nbt);
stack.setHoverName(new TranslationTextComponent(((TileBPMicroblock) tileentity).getBlock().getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(this.getDescriptionId())));
}
return stack;
}
use of net.minecraft.util.text.StringTextComponent in project Bookshelf by Darkhax-Minecraft.
the class CommandHand method hand.
private int hand(CommandContext<CommandSource> context) throws CommandSyntaxException {
final OutputType type = context.getArgument("type", OutputType.class);
final ServerPlayerEntity player = context.getSource().getPlayerOrException();
final String outputText = type.converter.apply(player.getMainHandItem());
final ITextComponent component = TextComponentUtils.wrapInSquareBrackets(new StringTextComponent(outputText).withStyle((style) -> {
return style.withColor(TextFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, outputText)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent("chat.copy.click"))).withInsertion(outputText);
}));
context.getSource().sendSuccess(component, false);
return 0;
}
use of net.minecraft.util.text.StringTextComponent in project BluePower by Qmunity.
the class JEIPlugin method getMicroblockRecipes.
private static List<IRecipe<?>> getMicroblockRecipes() {
List<IRecipe<?>> recipes = new ArrayList<>();
for (Block block : ForgeRegistries.BLOCKS.getValues().stream().filter(b -> !b.hasTileEntity(b.defaultBlockState())).collect(Collectors.toList())) {
VoxelShape shape = null;
try {
shape = block.defaultBlockState().getShape(null, null);
} catch (NullPointerException ignored) {
// Shulker Boxes try to query the Tile Entity
}
if (block.getRegistryName() != null && shape == VoxelShapes.block()) {
ItemStack output = ItemStack.EMPTY;
for (Block mb : BPBlocks.microblocks) {
NonNullList<Ingredient> input = NonNullList.create();
input.add(Ingredient.of(ItemTags.createOptional(new ResourceLocation("bluepower:saw"))));
if (mb == BPBlocks.half_block) {
input.add(Ingredient.of(new ItemStack(block)));
} else {
input.add(Ingredient.of(output));
}
CompoundNBT nbt = new CompoundNBT();
nbt.putString("block", block.getRegistryName().toString());
ItemStack stack = new ItemStack(mb);
stack.setTag(nbt);
stack.setHoverName(new TranslationTextComponent(block.getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(mb.getDescriptionId())));
output = stack;
recipes.add(new ShapelessRecipe(new ResourceLocation("bluepower:" + mb.getDescriptionId() + block.getDescriptionId()), "", output, input));
}
}
}
return recipes;
}
use of net.minecraft.util.text.StringTextComponent in project BluePower by Qmunity.
the class BlockBPMicroblock method getDrops.
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
TileEntity tileentity = builder.getParameter(LootParameters.BLOCK_ENTITY);
List<ItemStack> itemStacks = new ArrayList<>();
if (tileentity instanceof TileBPMultipart) {
tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
}
if (tileentity instanceof TileBPMicroblock) {
CompoundNBT nbt = new CompoundNBT();
nbt.putString("block", ((TileBPMicroblock) tileentity).getBlock().getRegistryName().toString());
ItemStack stack = new ItemStack(this);
stack.setTag(nbt);
stack.setHoverName(new TranslationTextComponent(((TileBPMicroblock) tileentity).getBlock().getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(this.getDescriptionId())));
itemStacks.add(stack);
}
return itemStacks;
}
use of net.minecraft.util.text.StringTextComponent in project BluePower by Qmunity.
the class ItemMultimeter method useOn.
@Override
public ActionResultType useOn(ItemUseContext context) {
TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity != null && tileEntity.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY).isPresent()) {
if (!context.getLevel().isClientSide) {
double volts = tileEntity.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY).orElse(null).getVoltage();
double amps = tileEntity.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY).orElse(null).getCurrent();
String voltage = String.format("%.2f", volts);
String ampere = String.format("%.2f", amps);
String watts = String.format("%.2f", volts * amps);
if (context.getPlayer() != null)
context.getPlayer().sendMessage(new StringTextComponent("Reading " + voltage + "V " + ampere + "A (" + watts + "W)"), Util.NIL_UUID);
}
return ActionResultType.SUCCESS;
}
return super.useOn(context);
}
Aggregations