mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-26 06:43:05 +00:00
Add multiblock tooltips and error game overlay renderer
This commit is contained in:
1 parent
7ff4944281
commit
931e518ca2
10 files changed
+148
-71
No files matched your search
@@ -90,6 +90,7 @@ public class Forestry {
|
||||
MinecraftForge.EVENT_BUS.register(eventHandlerCore);
|
||||
MinecraftForge.EVENT_BUS.register(new MultiblockEventHandler());
|
||||
MinecraftForge.EVENT_BUS.register(new ClimateEventHandler());
|
||||
Proxies.common.registerEventHandlers();
|
||||
|
||||
configFolder = new File(event.getModConfigurationDirectory(), Constants.MOD_ID);
|
||||
Config.load();
|
||||
|
||||
@@ -35,6 +35,7 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.tiles.IActivatable;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
@@ -42,7 +43,9 @@ import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
@@ -255,4 +258,10 @@ public abstract class BlockAlveary extends BlockStructure implements IStateMappe
|
||||
Proxies.net.sendNetworkPacket(new PacketAlvearyChange(referenceCoord), referenceCoord, worldIn);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
tooltip.add(Translator.translateToLocal("tile.for.alveary.tooltip"));
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,9 @@
|
||||
package forestry.core.multiblock;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.utils.Log;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
/**
|
||||
@@ -26,7 +13,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
* process any blocks that are in chunks which are still loading.
|
||||
*/
|
||||
public class MultiblockEventHandler {
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
@SubscribeEvent
|
||||
public void onChunkLoad(ChunkEvent.Load loadEvent) {
|
||||
Chunk chunk = loadEvent.getChunk();
|
||||
World world = loadEvent.getWorld();
|
||||
@@ -34,49 +21,8 @@ public class MultiblockEventHandler {
|
||||
}
|
||||
|
||||
// Cleanup, for nice memory usageness
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
@SubscribeEvent
|
||||
public void onWorldUnload(WorldEvent.Unload unloadWorldEvent) {
|
||||
MultiblockRegistry.onWorldUnloaded(unloadWorldEvent.getWorld());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldRenderLast(RenderWorldLastEvent event){
|
||||
try{
|
||||
World world = Minecraft.getMinecraft().world;
|
||||
Set<IMultiblockControllerInternal> controllers = MultiblockRegistry.getControllersFromWorld(world);
|
||||
if(!controllers.isEmpty()){
|
||||
float partialTicks = event.getPartialTicks();
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
|
||||
double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
|
||||
double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.glLineWidth(2.0F);
|
||||
GlStateManager.depthMask(false);
|
||||
for(IMultiblockController controller : controllers){
|
||||
if(controller != null){
|
||||
BlockPos lastErrorPosition = controller.getLastValidationErrorPosition();
|
||||
if(lastErrorPosition != null){
|
||||
if(world.isBlockLoaded(lastErrorPosition) && player.getDistanceSq(lastErrorPosition) < 64F){
|
||||
AxisAlignedBB box = Block.FULL_BLOCK_AABB.offset(lastErrorPosition.getX() - playerX, lastErrorPosition.getY() - playerY, lastErrorPosition.getZ() - playerZ);
|
||||
RenderGlobal.drawSelectionBoundingBox(box, 1.0F, 0.0F, 0.0F, 0.25F);
|
||||
RenderGlobal.renderFilledBox(box, 1.0F, 0.0F, 0.0F, 0.125F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager.depthMask(true);
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}catch(Exception e){
|
||||
Log.error("Failed to render the position of a multiblock exeption.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package forestry.core.multiblock;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.api.multiblock.IMultiblockController;
|
||||
import forestry.core.utils.Log;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class MultiblockEventHandlerClient {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGameOverlay(RenderGameOverlayEvent.Post event){
|
||||
if(event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null){
|
||||
Minecraft minecraft = Minecraft.getMinecraft();
|
||||
RayTraceResult posHit = minecraft.objectMouseOver;
|
||||
FontRenderer font = minecraft.fontRendererObj;
|
||||
ScaledResolution resolution = event.getResolution();
|
||||
|
||||
if(posHit != null && posHit.getBlockPos() != null){
|
||||
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
|
||||
if(tile instanceof IMultiblockComponent){
|
||||
IMultiblockComponent component = (IMultiblockComponent) tile;
|
||||
IMultiblockController controller = component.getMultiblockLogic().getController();
|
||||
String lastValidationError = controller.getLastValidationError();
|
||||
if(lastValidationError != null){
|
||||
lastValidationError = TextFormatting.DARK_RED.toString() + TextFormatting.ITALIC.toString() + lastValidationError;
|
||||
minecraft.fontRendererObj.drawSplitString(lastValidationError, resolution.getScaledWidth() / 2 + 35, resolution.getScaledHeight() / 2 - 25, 128, 16777215);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldRenderLast(RenderWorldLastEvent event){
|
||||
try{
|
||||
World world = Minecraft.getMinecraft().world;
|
||||
Set<IMultiblockControllerInternal> controllers = MultiblockRegistry.getControllersFromWorld(world);
|
||||
if(!controllers.isEmpty()){
|
||||
float partialTicks = event.getPartialTicks();
|
||||
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
|
||||
double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
|
||||
double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.glLineWidth(2.0F);
|
||||
GlStateManager.depthMask(false);
|
||||
for(IMultiblockController controller : controllers){
|
||||
if(controller != null){
|
||||
BlockPos lastErrorPosition = controller.getLastValidationErrorPosition();
|
||||
if(lastErrorPosition != null){
|
||||
if(world.isBlockLoaded(lastErrorPosition) && player.getDistanceSq(lastErrorPosition) < 64F){
|
||||
AxisAlignedBB box = Block.FULL_BLOCK_AABB.offset(lastErrorPosition.getX() - playerX, lastErrorPosition.getY() - playerY, lastErrorPosition.getZ() - playerZ);
|
||||
RenderGlobal.drawSelectionBoundingBox(box, 1.0F, 0.0F, 0.0F, 0.25F);
|
||||
RenderGlobal.renderFilledBox(box, 1.0F, 0.0F, 0.0F, 0.125F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager.depthMask(true);
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}catch(Exception e){
|
||||
Log.error("Failed to render the position of a multiblock exeption.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import java.io.File;
|
||||
import forestry.core.TickHandlerCoreClient;
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.core.multiblock.MultiblockClientTickHandler;
|
||||
import forestry.core.multiblock.MultiblockEventHandlerClient;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.worldgen.WorldGenerator;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -43,6 +44,11 @@ public class ProxyClient extends ProxyCommon {
|
||||
MinecraftForge.EVENT_BUS.register(new MultiblockClientTickHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEventHandlers() {
|
||||
MinecraftForge.EVENT_BUS.register(new MultiblockEventHandlerClient());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBlock(Block block) {
|
||||
ModelManager.getInstance().registerBlockClient(block);
|
||||
|
||||
@@ -48,6 +48,10 @@ public class ProxyCommon {
|
||||
MultiblockServerTickHandler multiblockServerTickHandler = new MultiblockServerTickHandler();
|
||||
MinecraftForge.EVENT_BUS.register(multiblockServerTickHandler);
|
||||
}
|
||||
|
||||
public void registerEventHandlers(){
|
||||
|
||||
}
|
||||
|
||||
public String getDisplayName(ItemStack itemstack) {
|
||||
return null;
|
||||
|
||||
@@ -38,8 +38,9 @@ public class ItemBlockFarm extends ItemBlock {
|
||||
if (itemstack.getTagCompound() == null) {
|
||||
return;
|
||||
}
|
||||
EnumFarmBlockTexture texture = EnumFarmBlockTexture.getFromCompound(itemstack.getTagCompound());
|
||||
|
||||
info.add(TextFormatting.ITALIC + EnumFarmBlockTexture.getFromCompound(itemstack.getTagCompound()).getName());
|
||||
info.add(Translator.translateToLocal("tile.for.ffarm.material.tooltip") + texture.getFormatting() + TextFormatting.ITALIC + " "+ texture.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,28 +18,35 @@ import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public enum EnumFarmBlockTexture {
|
||||
BRICK_STONE(new ItemStack(Blocks.STONEBRICK, 1, 0)),
|
||||
BRICK_MOSSY(new ItemStack(Blocks.STONEBRICK, 1, 1)),
|
||||
BRICK_CRACKED(new ItemStack(Blocks.STONEBRICK, 1, 2)),
|
||||
BRICK(new ItemStack(Blocks.BRICK_BLOCK)),
|
||||
SANDSTONE_SMOOTH(new ItemStack(Blocks.SANDSTONE, 1, 2)),
|
||||
SANDSTONE_CHISELED(new ItemStack(Blocks.SANDSTONE, 1, 1)),
|
||||
BRICK_NETHER(new ItemStack(Blocks.NETHER_BRICK)),
|
||||
BRICK_CHISELED(new ItemStack(Blocks.STONEBRICK, 1, 3)),
|
||||
QUARTZ(new ItemStack(Blocks.QUARTZ_BLOCK, 1, 0)),
|
||||
QUARTZ_CHISELED(new ItemStack(Blocks.QUARTZ_BLOCK, 1, 1)),
|
||||
QUARTZ_LINES(new ItemStack(Blocks.QUARTZ_BLOCK, 1, 2));
|
||||
BRICK_STONE(new ItemStack(Blocks.STONEBRICK, 1, 0), TextFormatting.DARK_GRAY),
|
||||
BRICK_MOSSY(new ItemStack(Blocks.STONEBRICK, 1, 1), TextFormatting.DARK_GRAY),
|
||||
BRICK_CRACKED(new ItemStack(Blocks.STONEBRICK, 1, 2), TextFormatting.DARK_GRAY),
|
||||
BRICK(new ItemStack(Blocks.BRICK_BLOCK), TextFormatting.GOLD),
|
||||
SANDSTONE_SMOOTH(new ItemStack(Blocks.SANDSTONE, 1, 2), TextFormatting.YELLOW),
|
||||
SANDSTONE_CHISELED(new ItemStack(Blocks.SANDSTONE, 1, 1), TextFormatting.YELLOW),
|
||||
BRICK_NETHER(new ItemStack(Blocks.NETHER_BRICK), TextFormatting.DARK_RED),
|
||||
BRICK_CHISELED(new ItemStack(Blocks.STONEBRICK, 1, 3), TextFormatting.GOLD),
|
||||
QUARTZ(new ItemStack(Blocks.QUARTZ_BLOCK, 1, 0), TextFormatting.WHITE),
|
||||
QUARTZ_CHISELED(new ItemStack(Blocks.QUARTZ_BLOCK, 1, 1), TextFormatting.WHITE),
|
||||
QUARTZ_LINES(new ItemStack(Blocks.QUARTZ_BLOCK, 1, 2), TextFormatting.WHITE);
|
||||
|
||||
private final ItemStack base;
|
||||
private final TextFormatting formatting;
|
||||
|
||||
EnumFarmBlockTexture(ItemStack base) {
|
||||
EnumFarmBlockTexture(ItemStack base, TextFormatting formatting) {
|
||||
this.base = base;
|
||||
this.formatting = formatting;
|
||||
}
|
||||
|
||||
|
||||
public TextFormatting getFormatting() {
|
||||
return formatting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The texture sprite from the material of the farm block
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.greenhouse.blocks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -33,6 +34,7 @@ import forestry.core.tiles.IActivatable;
|
||||
import forestry.core.utils.CamouflageUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseButterflyHatch;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseClimateControl;
|
||||
import forestry.greenhouse.tiles.TileGreenhouseControl;
|
||||
@@ -74,6 +76,7 @@ import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
@@ -447,4 +450,11 @@ public abstract class BlockGreenhouse extends BlockStructure implements ISpriteR
|
||||
|
||||
|
||||
public abstract BlockGreenhouseType getGreenhouseType();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
tooltip.add(Translator.translateToLocal("tile.for.greenhouse.tooltip"));
|
||||
tooltip.add(TextFormatting.GREEN.toString() + TextFormatting.ITALIC.toString() + Translator.translateToLocal("tile.for.greenhouse.camouflage.tooltip"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user