Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Ok I have a block with a gui and I was wondering how to make it save the data heres the code

 

package com.mcpixelplex.Gui;

import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.geom.AffineTransform;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.lwjgl.opengl.GL11;

import com.mcpixelplex.items.bStick;
import com.mcpixelplex.lib.RefStrings;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ResourceLocation;

public class InfoGui extends GuiScreen {

Minecraft mc = Minecraft.getMinecraft();

GuiButton testButton;

EntityPlayer player = mc.thePlayer;


String title = "Info Block";
AffineTransform affinetransform = new AffineTransform();     
FontRenderContext frc = new FontRenderContext(affinetransform,true,true); 
Font font = new Font("Tahoma", Font.PLAIN, 12);
int titleWidth = (int)(font.getStringBounds(title, frc).getWidth());
int titleheight = (int)(font.getStringBounds(title, frc).getHeight());

int tabWidth = 61 + 10;

int titleXPos = (tabWidth - titleWidth) / 2;


SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
String time = sdf.format(new Date());

String format = "24 Hour Period";
boolean timeFormat;

public final int xSizeOfTexture = 256;
public final int ySizeOfTexture = 156;


public final int xSizeOfInterier = 226;
public final int ySizeOfInterier = 113;

public final int xSizeOfSideGap = 11;
public final int ySizeOfSideGap = 115;

public final int xSizeOfTopGap = 228;
public final int ySizeOfTopGap = 11;
public final int xSizeOfBottomGap = xSizeOfTopGap;
public final int ySizeOfBottomGap = ySizeOfTopGap;


@Override
public void drawScreen(int x, int y, float f){

	int xPos = (this.width - xSizeOfTexture) / 2;
	int yPos = (this.height - ySizeOfTexture) / 2;

	int levelPosX = (xSizeOfTexture) / 2;
	int levelPosY = (ySizeOfTexture) / 2;

	int bottom = (ySizeOfTexture - 20 - 2);

	GL11.glColor4f(1F, 1F, 1F, 1F);
	mc.renderEngine.bindTexture(new ResourceLocation(RefStrings.MODID, "/textures/gui/background2.png"));

	drawDefaultBackground();

	drawTexturedModalRect(xPos, yPos, 0, 0, xSizeOfTexture, ySizeOfTexture);
	//drawRect(xPos + 5, bottom + 40, 30, 100, 0x000000);
	//drawRect(xPos + 5, bottom + 40, 30, currentPower, 0xd01414);

	fontRendererObj.drawString("Info Block", xPos + 10 + titleXPos, yPos + 4, 0x000000);

	fontRendererObj.drawString("Name: " + player.getDisplayName(), xPos + xSizeOfSideGap + 5 , yPos + ySizeOfBottomGap + 120, 0x000000);
	fontRendererObj.drawString("Time: " + time, xPos + xSizeOfSideGap + 5 , yPos + ySizeOfBottomGap + 100, 0x000000);	
	fontRendererObj.drawString("Location " + "X: " + bStick.xm + " Y: " + bStick.ym + " Z: " + bStick.zm, xPos + xSizeOfSideGap + 5, yPos + ySizeOfBottomGap + 80, 0x000000);

	super.drawScreen(x, y, f);

}

public void initGui(){

	int xSize = 100;
	int ySize = 20;

	int xPos = (xSizeOfTexture) / 2;
	int yPos = (ySizeOfTexture) / 2;

	int bottom = (ySizeOfTexture - ySize - 2);

	buttonList.clear();
	buttonList.add(new GuiButton(0, xPos + xSizeOfSideGap + 100, bottom + ySizeOfBottomGap + 40, 100, 20, format));

	super.initGui();
}


public void actionPerformed(GuiButton button){
	switch(button.id){
	case 0:
		if(timeFormat == true){
			timeFormat = false;
			format = "12 Hour Period";
			sdf = new SimpleDateFormat("h:mm a");
			time = sdf.format(new Date());
		}else{
			timeFormat = true;
			format = "24 Hour Period";
			sdf = new SimpleDateFormat("HH:mm");
			time = sdf.format(new Date());
		}
		break;
	}
	player.addChatComponentMessage(new ChatComponentText("TimeFormat: " + timeFormat));
}

@Override
public boolean doesGuiPauseGame(){
	return false;
}

}

thats the gui code, what about the blocks code

your block should extend BlockContainer or implement ITileEntityProvider

then store the information in the attached tile entity

 

  • Author

Im sorry Im pretty new, do you have a link somewhere of where I can go to get a better understanding

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.