#1913 Improved in-game documentation via tooltips for both machines & upgrades and solar panel exception fix (#1917)

* Overclocker and energy storage tooltip added

* Add default constructor to fix NoSuchMethodException

java.lang.NoSuchMethodException when loading world with existing solar panels

* Base Upgrade tooltips (Might move to reborn core)

* Migrated to tooltip callback and added most machine infos

* Optimize imports of stuff previously touched

* Added more informationtips and cleanup

* Revert itemUpgrade formatting

* Final touches

* Readd easter eggs, multi-line tips and translation updates

Easter egg tooltips are now restricted to only ctrl-hover
This commit is contained in:
Justin Vitale 2019-12-23 09:53:01 +11:00 committed by modmuss50
parent 34074d7a8a
commit 3dbc7feb62
11 changed files with 229 additions and 28 deletions

View file

@ -24,21 +24,21 @@
package techreborn.blockentity;
import net.minecraft.util.Formatting;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.LiteralText;
import net.minecraft.sound.SoundCategory;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Formatting;
import net.minecraft.util.Tickable;
import reborncore.api.IToolDrop;
import reborncore.common.util.ChatUtils;
import reborncore.common.util.StringUtils;
import techreborn.blocks.BlockAlarm;
import techreborn.init.ModSounds;
import techreborn.init.TRContent;
import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent;
import techreborn.utils.MessageIDs;
public class AlarmBlockEntity extends BlockEntity

View file

@ -24,6 +24,7 @@
package techreborn.blockentity;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
@ -68,6 +69,8 @@ public class IndustrialCentrifugeBlockEntity extends GenericMachineBlockEntity i
@Override
public void addInfo(final List<Text> info, final boolean isReal, boolean hasData) {
super.addInfo(info, isReal, hasData);
info.add(new LiteralText("Round and round it goes"));
if(Screen.hasControlDown()) {
info.add(new LiteralText("Round and round it goes"));
}
}
}

View file

@ -63,6 +63,10 @@ public class SolarPanelBlockEntity extends PowerAcceptorBlockEntity implements I
private SolarPanels panel;
public SolarPanelBlockEntity() {
super(TRBlockEntities.SOLAR_PANEL);
}
public SolarPanelBlockEntity(SolarPanels panel) {
super(TRBlockEntities.SOLAR_PANEL);
this.panel = panel;

View file

@ -24,14 +24,13 @@
package techreborn.blocks;
import net.minecraft.block.*;
import net.minecraft.entity.EntityContext;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.EntityContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
@ -39,6 +38,10 @@ import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;

View file

@ -32,12 +32,9 @@ import net.minecraft.world.World;
import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity;
import techreborn.blocks.GenericMachineBlock;
import techreborn.client.EGui;
import techreborn.client.gui.GuiSolar;
import techreborn.init.TRContent.SolarPanels;
import techreborn.blockentity.generator.SolarPanelBlockEntity;
import techreborn.client.EGui;
import techreborn.init.TRContent.SolarPanels;
/**
* Created by modmuss50 on 25/02/2016.

View file

@ -229,6 +229,9 @@ public class TechRebornConfig {
@Config(config = "items", category = "upgrades", key = "energy_storage", comment = "Energy storage behavior extra power")
public static double energyStoragePower = 40_000;
@Config(config = "items", category = "upgrades", key = "super_conductor", comment = "Energy flow power increase")
public static double superConductorCount = 1;
// Machines
@Config(config = "machines", category = "grinder", key = "GrinderInput", comment = "Grinder Max Input (Value in EU)")
public static int grinderMaxInput = 32;

View file

@ -40,12 +40,17 @@ import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.registry.Registry;
import reborncore.api.IListInfoProvider;
import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.util.StringUtils;
import team.reborn.energy.Energy;
import team.reborn.energy.EnergyHolder;
import team.reborn.energy.EnergySide;
import techreborn.TechReborn;
import techreborn.init.TRContent;
import techreborn.items.ItemUpgrade;
import techreborn.utils.DocumentAssistUtils;
import java.util.List;
@ -58,6 +63,24 @@ public class StackToolTipHandler implements ItemTooltipCallback {
@Override
public void getTooltip(ItemStack stack, TooltipContext tooltipContext, List<Text> components) {
Item item = stack.getItem();
// Machine info and upgrades helper section
Block block = Block.getBlockFromItem(item);
if(block instanceof BaseBlockEntityProvider){
DocumentAssistUtils.addInfo(item.getTranslationKey(), components);
}
if(item instanceof ItemUpgrade){
ItemUpgrade upgrade = (ItemUpgrade)item;
DocumentAssistUtils.addInfo(item.getTranslationKey(), components, false);
components.addAll(DocumentAssistUtils.getUpgradeStats(TRContent.Upgrades.valueOf(upgrade.name.toUpperCase()), stack.getCount(), Screen.hasShiftDown()));
}
// Other section
if (item instanceof IListInfoProvider) {
((IListInfoProvider) item).addInfo(components, false, false);
} else if (stack.getItem() instanceof EnergyHolder) {
@ -79,8 +102,7 @@ public class StackToolTipHandler implements ItemTooltipCallback {
}
} else {
try {
Block block = Block.getBlockFromItem(item);
if (block != null && (block instanceof BlockWithEntity || block instanceof BlockEntityProvider) && Registry.BLOCK.getId(block).getNamespace().contains("techreborn")) {
if ((block instanceof BlockEntityProvider) && Registry.BLOCK.getId(block).getNamespace().contains("techreborn")) {
BlockEntity blockEntity = ((BlockEntityProvider) block).createBlockEntity(MinecraftClient.getInstance().world);
boolean hasData = false;
if (stack.hasTag() && stack.getTag().contains("blockEntity_data")) {

View file

@ -755,7 +755,7 @@ public class TRContent {
aesu = (AdjustableSUBlockEntity) blockEntity;
}
if (aesu != null) {
aesu.superconductors++;
aesu.superconductors += TechRebornConfig.superConductorCount;
}
});

View file

@ -35,8 +35,8 @@ import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.world.World;
import reborncore.api.blockentity.IUpgrade;
import reborncore.common.recipes.IUpgradeHandler;
import reborncore.common.blockentity.MachineBaseBlockEntity;
import reborncore.common.recipes.IUpgradeHandler;
import techreborn.TechReborn;
import techreborn.init.TRContent;
@ -57,22 +57,21 @@ public class ItemUpgrade extends Item implements IUpgrade {
@Override
public void process(
@Nonnull MachineBaseBlockEntity blockEntity,
@Nullable
IUpgradeHandler handler,
@Nonnull
ItemStack stack) {
@Nonnull MachineBaseBlockEntity blockEntity,
@Nullable
IUpgradeHandler handler,
@Nonnull
ItemStack stack) {
behavior.process(blockEntity, handler, stack);
}
@Environment(EnvType.CLIENT)
@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
if(stack.getItem() == TRContent.Upgrades.SUPERCONDUCTOR.item){
if(Screen.hasShiftDown()){
if (stack.getItem() == TRContent.Upgrades.SUPERCONDUCTOR.item) {
if (Screen.hasControlDown()) {
tooltip.add(new LiteralText(Formatting.GOLD + "Blame obstinate_3 for this"));
}
}
super.appendTooltip(stack, world, tooltip, context);
}
}
}

View file

@ -0,0 +1,100 @@
package techreborn.utils;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.resource.language.I18n;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
import java.util.ArrayList;
import java.util.List;
public class DocumentAssistUtils {
// Colour constants
private static final Formatting instructColour = Formatting.BLUE;
private static final Formatting infoColour = Formatting.GOLD;
private static final Formatting statColour = Formatting.GOLD;
private static final Formatting posColour = Formatting.GREEN;
private static final Formatting negColour = Formatting.RED;
public static List<Text> getUpgradeStats(TRContent.Upgrades upgradeType, int count, boolean shiftHeld) {
List<Text> tips = new ArrayList<>();
boolean shouldStackCalculate = true;
switch (upgradeType) {
case OVERCLOCKER:
tips.add(getPositive("Speed increase", calculateValue(TechRebornConfig.overclockerSpeed * 100, count, shiftHeld), "%"));
tips.add(getNegative("Energy increase", calculateValue(TechRebornConfig.overclockerPower * 100, count, shiftHeld), "%"));
break;
case TRANSFORMER:
shouldStackCalculate = false;
break;
case ENERGY_STORAGE:
tips.add(getPositive("Storage increase", calculateValue(TechRebornConfig.energyStoragePower, count, shiftHeld), " E"));
break;
case SUPERCONDUCTOR:
tips.add(getPositive("Increased flow by: ", calculateValue(Math.pow(2, (TechRebornConfig.superConductorCount + 2)) * 100, count, shiftHeld), "%"));
break;
}
// Add reminder that they can use shift to calculate the entire stack
if(shouldStackCalculate && !shiftHeld){
tips.add(new LiteralText(instructColour + "Hold shift for stack calculation"));
}
return tips;
}
public static void addInfo(String inKey, List<Text> list){
addInfo(inKey, list, true);
}
public static void addInfo(String inKey, List<Text> list, boolean hidden){
String key = ("techreborn.message.info." + inKey);
if(I18n.hasTranslation(key)){
if(!hidden || Screen.hasShiftDown()){
String info = new TranslatableText(key).asString();
String infoLines[] = info.split("\\r?\\n");
for (String infoLine: infoLines) {
list.add(new LiteralText(infoColour + infoLine));
}
}else{
list.add(new LiteralText(instructColour + "Hold shift for info"));
}
}
}
private static int calculateValue(double value, int count, boolean shiftHeld) {
int calculatedVal;
if (shiftHeld) {
calculatedVal = (int) value * count;
} else {
calculatedVal = (int) value;
}
return calculatedVal;
}
private static Text getPositive(String text, int value, String unit) {
return new LiteralText(posColour + getStatStringUnit(text, value, unit));
}
private static Text getNegative(String text, int value, String unit) {
return new LiteralText(negColour + getStatStringUnit(text, value, unit));
}
private static String getStatStringUnit(String text, int value, String unit) {
return text + ": " + statColour + value + unit;
}
}