#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);
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;
@ -68,11 +68,10 @@ public class ItemUpgrade extends Item implements IUpgrade {
@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;
}
}

View file

@ -605,6 +605,76 @@
"techreborn.message.nightgen": "Panel in reduced sunlight",
"techreborn.message.zerogen": "Panel obstructed from sky",
"techreborn.message.info.item.techreborn.overclocker_upgrade": "Increases speed at the cost of more energy",
"techreborn.message.info.item.techreborn.transformer_upgrade": "Increase energy tier",
"techreborn.message.info.item.techreborn.energy_storage_upgrade": "Increase energy store",
"techreborn.message.info.item.techreborn.superconductor_upgrade": "Increases energy flow rate",
"techreborn.message.info.block.techreborn.basic_solar_panel": "Produce energy from sunlight",
"techreborn.message.info.block.techreborn.advanced_solar_panel": "Produce energy from sunlight",
"techreborn.message.info.block.techreborn.industrial_solar_panel": "Produce energy from sunlight",
"techreborn.message.info.block.techreborn.ultimate_solar_panel": "Produce energy from sunlight",
"techreborn.message.info.block.techreborn.quantum_solar_panel": "Produce energy from sunlight",
"techreborn.message.info.block.techreborn.creative_solar_panel": "Infinite energy source, creative",
"techreborn.message.info.block.techreborn.fusion_control_computer": "The core of the fusion reactor",
"techreborn.message.info.block.techreborn.creative_quantum_chest": "Stores near-infinite of a single item",
"techreborn.message.info.block.techreborn.adjustable_su": "Adjustable energy storage\nConfigurable",
"techreborn.message.info.block.techreborn.interdimensional_su": "High tier energy storage\nSynchronised wireless energy transfer",
"techreborn.message.info.block.techreborn.low_voltage_su": "Basic tier energy storage",
"techreborn.message.info.block.techreborn.medium_voltage_su": "Intermediate tier energy storage",
"techreborn.message.info.block.techreborn.high_voltage_su": "High tier energy storage",
"techreborn.message.info.block.techreborn.lv_transformer": "Medium to Low energy tier",
"techreborn.message.info.block.techreborn.mv_transformer": "High to Medium energy tier",
"techreborn.message.info.block.techreborn.hv_transformer": "Extreme to High energy tier",
"techreborn.message.info.block.techreborn.ev_transformer": "Insane to Extreme energy tier",
"techreborn.message.info.block.techreborn.alarm": "Produces sound when given redstone signal\nConfigurable",
"techreborn.message.info.block.techreborn.lamp_incandescent": "Provides luminance, when given power",
"techreborn.message.info.block.techreborn.lamp_led": "Provides luminance, when given power",
"techreborn.message.info.block.techreborn.player_detector": "Redstone emitting block used to detect players, configurable",
"techreborn.message.info.block.techreborn.alloy_smelter": "Make alloys from ingots or dusts",
"techreborn.message.info.block.techreborn.assembly_machine": "Assemble components more efficiently",
"techreborn.message.info.block.techreborn.auto_crafting_table": "Automatically craft recipes given power and resources",
"techreborn.message.info.block.techreborn.chemical_reactor": "Reacts two chemicals together to form a product",
"techreborn.message.info.block.techreborn.compressor": "Compresses blocks and ingots",
"techreborn.message.info.block.techreborn.distillation_tower": "Crack oil into its various components",
"techreborn.message.info.block.techreborn.extractor": "Process natural resources into another useful product\nOften more efficient than other means",
"techreborn.message.info.block.techreborn.fluid_replicator": "Replicates fluid placed inside middle of it\nMulti-block structure\nRequires energy and UU Matter",
"techreborn.message.info.block.techreborn.grinder": "Grind ores and other materials into dusts",
"techreborn.message.info.block.techreborn.electric_furnace": "A furnace but electric and upgradeable",
"techreborn.message.info.block.techreborn.implosion_compressor": "Uses the immense power of TNT to make items under pressure",
"techreborn.message.info.block.techreborn.industrial_blast_furnace": "Smelts tough metals under extreme temperature",
"techreborn.message.info.block.techreborn.industrial_centrifuge": "Glorified blender\nMixes fluids and dusts together",
"techreborn.message.info.block.techreborn.industrial_electrolyzer": "Splits products into their byproducts through electrolysis",
"techreborn.message.info.block.techreborn.industrial_grinder": "Better grinding of items than conventional means",
"techreborn.message.info.block.techreborn.industrial_sawmill": "Multi-block wood processing machine",
"techreborn.message.info.block.techreborn.iron_alloy_furnace": "Primitive machine to make alloys from ingots or dusts",
"techreborn.message.info.block.techreborn.iron_furnace": "Fancier furnace",
"techreborn.message.info.block.techreborn.matter_fabricator": "Uses scrap and energy to churn out UU matter",
"techreborn.message.info.block.techreborn.recycler": "Takes your unwanted materials and recycles it into scrap",
"techreborn.message.info.block.techreborn.rolling_machine": "Flattens stuff, especially useful for coils",
"techreborn.message.info.block.techreborn.scrapboxinator": "Open scrap boxes automatically",
"techreborn.message.info.block.techreborn.vacuum_freezer": "Multi-block structure for crafting at extreme frigid temperatures",
"techreborn.message.info.block.techreborn.solid_canning_machine": "Turn blocks and items into their cell counterpart",
"techreborn.message.info.block.techreborn.wire_mill": "Efficiently produce wire from ingots",
"techreborn.message.info.block.techreborn.diesel_generator": "Uses diesel to produce energy\nThe traditional pollinating method",
"techreborn.message.info.block.techreborn.dragon_egg_syphon": "Place a dragon egg on top of it to harvest its energy",
"techreborn.message.info.block.techreborn.gas_turbine": "Burns hydrogen, methane or other gases to generate energy",
"techreborn.message.info.block.techreborn.lightning_rod": "Harvest the power of the mother nature to power your machines",
"techreborn.message.info.block.techreborn.plasma_generator": "Produces energy by using Heliumplasma as a fuel source",
"techreborn.message.info.block.techreborn.semi_fluid_generator": "Produces energy from various basic fluids, like Oil and others",
"techreborn.message.info.block.techreborn.solid_fuel_generator": "Produces energy from the burnables\nWorks with what you would normally use to fuel a furnace",
"techreborn.message.info.block.techreborn.thermal_generator": "Converts lava and other heat sources into energy",
"techreborn.message.info.block.techreborn.water_mill": "Uses the power of any water source adjacent to it to generate energy",
"techreborn.message.info.block.techreborn.wind_mill": "Produces energy when placed above the height of 64 blocks from air\n25% more efficient in thunderstorms",
"techreborn.message.info.block.techreborn.creative_quantum_tank": "Infinite liquid, creative-only",
"techreborn.message.info.block.techreborn.digital_chest": "Stores 32,640 of a single item",
"techreborn.message.info.block.techreborn.quantum_chest": "Stores near-infinite of a single item",
"techreborn.message.info.block.techreborn.quantum_tank": "Stores near-infinite of a single liquid",
"techreborn.message.info.block.techreborn.charge_o_mat": "Charges up to 6 items simultaneously",
"techreborn.message.info.block.techreborn.chunk_loader": "Keeps chunks loaded, allows machines to run when you're not nearby",
"keys.techreborn.category": "TechReborn Category",
"keys.techreborn.config": "Config",