Jump to content

Recommended Posts

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;
}

}

Posted

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

 

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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