Refactor display tooltip

This commit is contained in:
khj xiaogu 2021-10-27 02:46:16 +08:00
parent ef419cc574
commit 976697e77c
No known key found for this signature in database
GPG key ID: DEA172814EAFF426
11 changed files with 147 additions and 16 deletions

View file

@ -18,7 +18,11 @@
package com.teammoeg.steampowered.client;
import com.simibubi.create.AllItems;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@ -32,4 +36,7 @@ public class ClientUtils {
public static World getClientWorld() {
return mc().level;
}
public static boolean hasGoggles() {
return AllItems.GOGGLES.isIn(mc().player.getItemBySlot(EquipmentSlotType.HEAD));
}
}

View file

@ -21,12 +21,15 @@ package com.teammoeg.steampowered.content.alternator;
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.item.TooltipHelper;
import com.simibubi.create.foundation.item.ItemDescription.Palette;
import com.simibubi.create.foundation.utility.VoxelShaper;
import com.teammoeg.steampowered.SPConfig;
import com.teammoeg.steampowered.block.SPShapes;
import com.teammoeg.steampowered.registrate.SPTiles;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemGroup;
@ -129,6 +132,11 @@ public class DynamoBlock extends DirectionalKineticBlock implements ITE<DynamoTi
@Override
public void appendHoverText(ItemStack i, IBlockReader w, List<ITextComponent> t, ITooltipFlag f) {
t.add(new TranslationTextComponent("tooltip.steampowered.alternator").withStyle(TextFormatting.GRAY));
if(Screen.hasShiftDown()) {
t.add(new TranslationTextComponent("tooltip.steampowered.alternator.thanks").withStyle(TextFormatting.GOLD));
}else {
t.add(TooltipHelper.holdShift(Palette.Gray,false));
}
/*if (ModList.get().isLoaded("createaddition")) {
if (SPConfig.SERVER.disableDynamo.get()) {
t.add(new StringTextComponent("Dynamo is disabled in [save]/serverconfig/steampowered-server.toml").withStyle(TextFormatting.RED));

View file

@ -20,9 +20,14 @@ package com.teammoeg.steampowered.content.boiler;
import java.util.List;
import com.simibubi.create.foundation.item.ItemDescription.Palette;
import com.simibubi.create.foundation.item.TooltipHelper;
import com.teammoeg.steampowered.client.ClientUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ILiquidContainer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
@ -79,10 +84,17 @@ public abstract class BoilerBlock extends Block implements ILiquidContainer{
@Override
public void appendHoverText(ItemStack i, IBlockReader w, List<ITextComponent> t,
ITooltipFlag f) {
t.add(new TranslationTextComponent("tooltip.steampowered.boiler.danger").withStyle(TextFormatting.RED));
t.add(new TranslationTextComponent("tooltip.steampowered.boiler.huconsume",this.getHuConsume()).withStyle(TextFormatting.GOLD));
t.add(new TranslationTextComponent("tooltip.steampowered.boiler.waterconsume",this.getHuConsume()/120).withStyle(TextFormatting.AQUA));
t.add(new TranslationTextComponent("tooltip.steampowered.boiler.steamproduce",this.getHuConsume()/10).withStyle(TextFormatting.GOLD));
if(Screen.hasShiftDown()) {
t.add(new TranslationTextComponent("tooltip.steampowered.boiler.brief").withStyle(TextFormatting.GOLD));
if(ClientUtils.hasGoggles()) {
t.add(new TranslationTextComponent("tooltip.steampowered.boiler.danger").withStyle(TextFormatting.RED));
t.add(new TranslationTextComponent("tooltip.steampowered.boiler.huconsume",this.getHuConsume()).withStyle(TextFormatting.GOLD));
t.add(new TranslationTextComponent("tooltip.steampowered.boiler.waterconsume",((int)Math.ceil(this.getHuConsume()/120.0))).withStyle(TextFormatting.AQUA));
t.add(new TranslationTextComponent("tooltip.steampowered.boiler.steamproduce",this.getHuConsume()/10).withStyle(TextFormatting.GOLD));
}
}else {
t.add(TooltipHelper.holdShift(Palette.Gray,false));
}
super.appendHoverText(i,w,t,f);
}

View file

@ -43,14 +43,18 @@ import net.minecraftforge.fluids.capability.templates.FluidTank;
import java.util.List;
public abstract class BoilerTileEntity extends TileEntity implements IHeatReceiver, ITickableTileEntity, IHaveGoggleInformation {
FluidTank input = new FluidTank(10000) {
@Override
public boolean isFluidValid(FluidStack stack) {
return stack.getFluid() == Fluids.WATER;
}
FluidTank input = new FluidTank(10000,s->s.getFluid() == Fluids.WATER) {
@Override
public FluidStack getFluid() {
return new FluidStack(Fluids.WATER,this.getFluidAmount());
}
};
FluidTank output = new FluidTank(10000) {
@Override
public FluidStack getFluid() {
return new FluidStack(FluidRegistry.steam.get().getFluid(),this.getFluidAmount());
}
};
private IFluidHandler ft = new IFluidHandler() {
@Override
@ -158,8 +162,8 @@ public abstract class BoilerTileEntity extends TileEntity implements IHeatReceiv
if (this.level != null && !this.level.isClientSide) {
int consume = Math.min(getHUPerTick(), heatreceived);
heatreceived = 0;
int waterconsume=(int) (SPConfig.COMMON.steamPerWater.get()*10);
consume = Math.min(this.input.drain((int) Math.ceil(consume / waterconsume), FluidAction.EXECUTE).getAmount() * waterconsume, consume);
double waterconsume=(SPConfig.COMMON.steamPerWater.get()*10);
consume = Math.min((int)(this.input.drain((int) Math.ceil(consume / waterconsume), FluidAction.EXECUTE).getAmount() * waterconsume), consume);
this.output.fill(new FluidStack(FluidRegistry.steam.get().getFluid(), consume / 10), FluidAction.EXECUTE);
this.level.sendBlockUpdated(this.getBlockPos(),this.getBlockState(),this.getBlockState(), 3);

View file

@ -20,8 +20,13 @@ package com.teammoeg.steampowered.content.burner;
import java.util.List;
import com.simibubi.create.foundation.item.TooltipHelper;
import com.simibubi.create.foundation.item.ItemDescription.Palette;
import com.teammoeg.steampowered.client.ClientUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
@ -80,9 +85,16 @@ public abstract class BurnerBlock extends Block {
@Override
public void appendHoverText(ItemStack i, IBlockReader w, List<ITextComponent> t,
ITooltipFlag f) {
t.add(new TranslationTextComponent("tooltip.steampowered.burner.danger").withStyle(TextFormatting.RED));
t.add(new TranslationTextComponent("tooltip.steampowered.burner.huproduce",this.getHuProduce()).withStyle(TextFormatting.GOLD));
if(Screen.hasShiftDown()) {
t.add(new TranslationTextComponent("tooltip.steampowered.burner.brief").withStyle(TextFormatting.GOLD));
if(ClientUtils.hasGoggles()) {
t.add(new TranslationTextComponent("tooltip.steampowered.burner.danger").withStyle(TextFormatting.RED));
t.add(new TranslationTextComponent("tooltip.steampowered.burner.huproduce",this.getHuProduce()).withStyle(TextFormatting.GOLD));
}
}else {
t.add(TooltipHelper.holdShift(Palette.Gray,false));
}
super.appendHoverText(i,w,t,f);
}

View file

@ -18,10 +18,22 @@
package com.teammoeg.steampowered.content.engine;
import java.util.List;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.item.TooltipHelper;
import com.simibubi.create.foundation.item.ItemDescription.Palette;
import com.teammoeg.steampowered.SPConfig;
import com.teammoeg.steampowered.client.ClientUtils;
import com.teammoeg.steampowered.registrate.SPTiles;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IBlockReader;
public class BronzeSteamEngineBlock extends SteamEngineBlock implements ITE<BronzeSteamEngineTileEntity> {
@ -38,4 +50,16 @@ public class BronzeSteamEngineBlock extends SteamEngineBlock implements ITE<Bron
public Class<BronzeSteamEngineTileEntity> getTileEntityClass() {
return BronzeSteamEngineTileEntity.class;
}
@Override
public void appendHoverText(ItemStack i, IBlockReader w, List<ITextComponent> t,
ITooltipFlag f) {
if(Screen.hasShiftDown()) {
t.add(new TranslationTextComponent("tooltip.steampowered.engine.brief").withStyle(TextFormatting.GOLD));
if(ClientUtils.hasGoggles())
t.add(new TranslationTextComponent("tooltip.steampowered.engine.steamconsume",SPConfig.COMMON.bronzeFlywheelSteamConsumptionPerTick.get()).withStyle(TextFormatting.GOLD));
}else {
t.add(TooltipHelper.holdShift(Palette.Gray,false));
}
super.appendHoverText(i,w,t,f);
}
}

View file

@ -18,10 +18,22 @@
package com.teammoeg.steampowered.content.engine;
import java.util.List;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.item.TooltipHelper;
import com.simibubi.create.foundation.item.ItemDescription.Palette;
import com.teammoeg.steampowered.SPConfig;
import com.teammoeg.steampowered.client.ClientUtils;
import com.teammoeg.steampowered.registrate.SPTiles;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IBlockReader;
public class CastIronSteamEngineBlock extends SteamEngineBlock implements ITE<CastIronSteamEngineTileEntity> {
@ -33,7 +45,18 @@ public class CastIronSteamEngineBlock extends SteamEngineBlock implements ITE<Ca
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return SPTiles.CAST_IRON_STEAM_ENGINE.create();
}
@Override
public void appendHoverText(ItemStack i, IBlockReader w, List<ITextComponent> t,
ITooltipFlag f) {
if(Screen.hasShiftDown()) {
t.add(new TranslationTextComponent("tooltip.steampowered.engine.brief").withStyle(TextFormatting.GOLD));
if(ClientUtils.hasGoggles())
t.add(new TranslationTextComponent("tooltip.steampowered.engine.steamconsume",SPConfig.COMMON.castIronFlywheelSteamConsumptionPerTick.get()).withStyle(TextFormatting.GOLD));
}else {
t.add(TooltipHelper.holdShift(Palette.Gray,false));
}
super.appendHoverText(i,w,t,f);
}
@Override
public Class<CastIronSteamEngineTileEntity> getTileEntityClass() {
return CastIronSteamEngineTileEntity.class;

View file

@ -18,10 +18,22 @@
package com.teammoeg.steampowered.content.engine;
import java.util.List;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.item.TooltipHelper;
import com.simibubi.create.foundation.item.ItemDescription.Palette;
import com.teammoeg.steampowered.SPConfig;
import com.teammoeg.steampowered.client.ClientUtils;
import com.teammoeg.steampowered.registrate.SPTiles;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.IBlockReader;
public class SteelSteamEngineBlock extends SteamEngineBlock implements ITE<SteelSteamEngineTileEntity> {
@ -33,7 +45,18 @@ public class SteelSteamEngineBlock extends SteamEngineBlock implements ITE<Steel
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return SPTiles.STEEL_STEAM_ENGINE.create();
}
@Override
public void appendHoverText(ItemStack i, IBlockReader w, List<ITextComponent> t,
ITooltipFlag f) {
if(Screen.hasShiftDown()) {
t.add(new TranslationTextComponent("tooltip.steampowered.engine.brief").withStyle(TextFormatting.GOLD));
if(ClientUtils.hasGoggles())
t.add(new TranslationTextComponent("tooltip.steampowered.engine.steamconsume",SPConfig.COMMON.steelFlywheelSteamConsumptionPerTick.get()).withStyle(TextFormatting.GOLD));
}else {
t.add(TooltipHelper.holdShift(Palette.Gray,false));
}
super.appendHoverText(i,w,t,f);
}
@Override
public Class<SteelSteamEngineTileEntity> getTileEntityClass() {
return SteelSteamEngineTileEntity.class;

View file

@ -43,6 +43,7 @@
"block.steampowered.alternator": "Alternating Dynamo",
"tooltip.steampowered.alternator": "Not same as CC&A!",
"tooltip.steampowered.alternator.thanks": "Thanks to MRH0 For his wonderful works!",
"steampowered.ponder.dynamo.header": "Generating Electric energy using a Dynamo",
"steampowered.ponder.dynamo.text_1": "The Dynamo generates electric energy (FE) from rotational force",
@ -58,11 +59,16 @@
"tooltip.steampowered.burner.item" : "Fuel Remaining: %s x %s",
"tooltip.steampowered.burner.huproduce" : "Generates %s HU/t",
"tooltip.steampowered.burner.danger": "Caution! Standing on when burning causes damage!",
"tooltip.steampowered.burner.brief": "Generate heat by burning fuel.",
"tooltip.steampowered.boiler.huconsume" : "Maximum Heat Intake %s HU/t",
"tooltip.steampowered.boiler.waterconsume" : "Requires Water %s mb/t",
"tooltip.steampowered.boiler.steamproduce" : "Maximum Steam Output %s mb/t",
"tooltip.steampowered.boiler.danger": "Caution! Standing on when working causes damage!",
"tooltip.steampowered.boiler.brief": "Generate steam by heating water.",
"tooltip.steampowered.engine.steamconsume": "Requires %s mb/t of Steam",
"tooltip.steampowered.engine.brief": "Generate kinetic force with steam.",
"steampowered.ponder.boiler.header": "Generating Steam through Boilers and Burning Chambers",
"steampowered.ponder.boiler.text_1": "The Boiler needs water to produce Steam",

View file

@ -43,6 +43,7 @@
"block.steampowered.alternator": "オルタネーター Dynamo",
"tooltip.steampowered.alternator":"Not same as CC&A!",
"tooltip.steampowered.alternator.thanks": "Thanks to MRH0 For his wonderful works!",
"steampowered.ponder.dynamo.header": "オルタネーターによる発電",
"steampowered.ponder.dynamo.text_1": "回転力で電気(FE)を発電します",
@ -58,11 +59,16 @@
"tooltip.steampowered.burner.item": "Fuel Remaining: %s x %s",
"tooltip.steampowered.burner.huproduce": "Generates %s HU/t",
"tooltip.steampowered.burner.danger": "Caution! Standing on when burning causes damage!",
"tooltip.steampowered.burner.brief": "Generate heat by burning fuel.",
"tooltip.steampowered.boiler.huconsume": "Maximum Heat Intake %s HU/t",
"tooltip.steampowered.boiler.waterconsume": "Requires Water %s mb/t",
"tooltip.steampowered.boiler.steamproduce": "Maximum Steam Output %s mb/t",
"tooltip.steampowered.boiler.danger": "Caution! Standing on when working causes damage!",
"tooltip.steampowered.boiler.brief": "Generate steam by heating water.",
"tooltip.steampowered.engine.steamconsume": "Requires %s mb/t of Steam",
"tooltip.steampowered.engine.brief": "Generate kinetic force with steam.",
"steampowered.ponder.boiler.header": "Generating Steam through Boilers and Burning Chambers",
"steampowered.ponder.boiler.text_1": "The Boiler needs water to produce Steam",

View file

@ -43,6 +43,7 @@
"block.steampowered.alternator": "交流式发电机",
"tooltip.steampowered.alternator": "另一个旋转动力发电机",
"tooltip.steampowered.alternator.thanks": "感谢MRH0的启发性工作",
"steampowered.ponder.dynamo.header": "使用发电机发电",
"steampowered.ponder.dynamo.text_1": "发电机从旋转动力中产生电能FE",
@ -58,11 +59,16 @@
"tooltip.steampowered.burner.item" : "燃料: %s x %s",
"tooltip.steampowered.burner.huproduce" : "产生%s HU/t",
"tooltip.steampowered.burner.danger": "工作时站在上面会受伤!",
"tooltip.steampowered.burner.brief": "燃烧燃料发热",
"tooltip.steampowered.boiler.huconsume" : "最大消耗 %s HU/t",
"tooltip.steampowered.boiler.waterconsume" : "使用水 %s mb/t",
"tooltip.steampowered.boiler.steamproduce" : "最大蒸汽产出 %s mb/t",
"tooltip.steampowered.boiler.danger": "工作时站在上面会受伤!",
"tooltip.steampowered.boiler.brief": "加热水以获得蒸汽",
"tooltip.steampowered.engine.steamconsume": "需要蒸汽%s mb/t",
"tooltip.steampowered.engine.brief": "消耗蒸汽产生动力",
"steampowered.ponder.boiler.header": "通过锅炉和燃烧室产生蒸汽",
"steampowered.ponder.boiler.text_1": "锅炉需要水以产生蒸汽",