
hkiller1
Members-
Posts
52 -
Joined
-
Last visited
Everything posted by hkiller1
-
your code from pastebin is not correct try reading some tutorials.
-
Not by itself, you need to import library's to do that. Try looking at Apache derby. http://db.apache.org/derby/
-
It works fine. Make sure you read it correctly. Look at the completed file on the tutorial page.
-
http://www.minecraftforge.net/wiki/How_to_make_an_advanced_configuration_file
-
If you didn't want to help then please don't post
-
that not what I was looking for I need to save the player names and how much money they have into the file and I need to load the file then change the amount of money and save it again.
-
How do you make a block face toward the player when it is placed down?
hkiller1 replied to hkiller1's topic in Modder Support
I think I need to use the getBlockTextureFromSideAndMetadata class. The code I have now makes the block always face one direction but I want it to face towards the player when placed down, like how pumpkins and logs changes which direction their facing. -
Could you give me the link to a tutorial because I can't find any.
-
I think im going to try java db, im trying to use http://docs.oracle.com/javadb/10.8.2.2/getstart/index.html , so far I have package economy.common; import java.sql.*; public class Data { public static void init() throws SQLException{ String sqlCreate = "CREATE TABLE IF NOT EXISTS Economy" + " (player VARCHAR(20)," + " amount INTEGER)"; try { Connection db = DriverManager.getConnection("jdbc:derby:Economy;create=true"); db.createStatement().execute(sqlCreate); System.out.println("Economy successfully connected to the database"); } catch (Throwable e) { System.out.println("Economy failed to connected to the database"); } } public void load() throws SQLException { Connection db = DriverManager.getConnection("jdbc:derby:economy;create=true"); db.close(); } public void save(String player, String amount) throws SQLException { Connection db = DriverManager.getConnection("jdbc:derby:economy;create=true"); db.close(); } } but it wont start and connect to the database. Why is it not starting it?
-
I'm trying to make a money mod and I need to be able to store the variable in a file. Whats the best / easiest thing to use to do this, java db, yaml, or xml? Also I cant figure out how to use any of them to save and load data so any tutorials will be very helpful.
-
Ok I found that forge already includes a Json parser called argo. I got the load method to work but I cant figure out how to do the save method. How would I add a new node into the Json data thats already their?
-
I cant real figure out how to use Json for saving and loading data from a file. Also is it included with forge or does it need to be imported?
-
First of all your not using any of the forge api. You set it up like a modloader mod. Second you didn't import forge. Also you are making it in the wrong package, you should make it in YourMod.common. You should read the tutorials for how to make a forge mod http://www.minecraftforge.net/wiki/Category:Generic_Mod http://www.minecraftforge.net/wiki/How_to_use_infinite_terrain_and_sprite_indexes http://wuppy29.blogspot.nl/ also Youtube can be very helpful.
-
Put this in your block.java file public String getTextureFile() { return "/YourMod/SpriteSheet.png"; } Also you need to set up a proxy first.
-
I got the save function to work but im having some trouble with the load function, curently I have package economy.common; import java.io.*; import java.util.*; import org.yaml.snakeyaml.Yaml; public class Data { public static String LoadData(String player) throws IOException { File file = new File("config/EconomyAcounts.yml"); if(!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } //TODO: Load file Yaml yaml = new Yaml(); List<String> list = (List<String>) yaml.load(document); //TODO: find the amount of money the player has //return amount } public static void SaveData(String player, String amount) throws FileNotFoundException { File file = new File("config/EconomyAcounts.yml"); if(!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } Map<String, Object> data = new HashMap<String, Object>(); data.put(player, amount); Yaml yaml = new Yaml(); String output = yaml.dump(data); PrintWriter out = new PrintWriter(file); out.println(output); out.close(); } }
-
Im just going to use yaml.
-
Do I import the src or the jar into the project for yaml?
-
Whats better xml or yaml?
-
Never mind lol. I must of accidentally deleted public String getTextureFile() { return "/economy/SpriteSheet.png"; }
-
I am trying to add a custom Gui, i followed the tutorial but now when I start minecraft the block has a stone texture insted of the one I added and the gui wont open. Here is the code I have currently. Economy.java package economy.common; import java.io.File; import java.util.List; import net.minecraft.src.*; import net.minecraft.server.MinecraftServer; import net.minecraftforge.common.Configuration; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.PreInit; import cpw.mods.fml.common.Mod.ServerStarting; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = "Hunter_Economy", name = "Economy", version = "1.0") @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class Economy { @Instance("Hunter_Economy") public static Economy instance; public static Block AtmBlock; public static Boolean test; public static int AtmBlockID; public static String blockname; public static MinecraftServer server; @PreInit public void preInit(FMLPreInitializationEvent event) { //minecraft config Configuration config = new Configuration(event.getSuggestedConfigurationFile()); config.load(); AtmBlockID = config.getBlock("AtmBlock", 201).getInt(); test = config.get(Configuration.CATEGORY_GENERAL, "test", false).getBoolean(false); config.save(); } @SidedProxy(clientSide = "economy.client.ClientProxyEconomy", serverSide = "economy.common.CommonProxyEconomy") public static CommonProxyEconomy proxy; @Init public void load(FMLInitializationEvent event) { proxy.registerRenderThings(); NetworkRegistry.instance().registerGuiHandler(instance, proxy); proxy.initTileEntities(); AtmBlock = new AtmBlock(AtmBlockID, 0, Material.iron); GameRegistry.registerBlock(AtmBlock); LanguageRegistry.addName(AtmBlock, "Atm"); GameRegistry.addRecipe(new ItemStack(this.AtmBlock), new Object[]{ "III", "IIG", "III", 'I', Item.ingotIron, 'G', Block.glass}); } @ServerStarting public void serverStarting(FMLServerStartingEvent event) { //minecraft config File file = new File("config/Economy_Acounts.cfg"); Configuration config = new Configuration(file); config.load(); config.save(); server = ModLoader.getMinecraftServerInstance(); ICommandManager commandManager = server.getCommandManager(); ServerCommandManager manager = ((ServerCommandManager) commandManager); manager.registerCommand(new economy.common.command.Money()); manager.registerCommand(new economy.common.command.SetMoney()); } } AtmBlock.java package economy.common; import java.util.Random; import net.minecraft.src.*; public class AtmBlock extends BlockContainer { public AtmBlock(int i, int j, Material m) { super(i, j, m); this.setCreativeTab(CreativeTabs.tabBlock); this.setHardness(10.0F); this.setResistance(10.0F); this.setStepSound(Block.soundMetalFootstep); this.setBlockName("Atm"); } public int getBlockTextureFromSideAndMetadata(int i, int j) { switch(i) { case 0: return 1; case 1: return 1; case 2: return 1; case 3: return 0; case 4: return 1; case 5: return 1; default: return 1; } } @Override public TileEntity createNewTileEntity(World var1) { return new TileAtm(); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int idk, float what, float these, float are) { TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if (tileEntity == null || player.isSneaking()) { return false; } player.openGui(Economy.instance, 0, world, x, y, z); return true; } } TileAtm.java package economy.common; import economy.common.AtmBlock; import net.minecraft.src.*; public class TileAtm extends TileEntity implements IInventory { private ItemStack[] atmItemStacks = new ItemStack[3]; public void readFromNBT(NBTTagCompound nbtTagCompound) { super.readFromNBT(nbtTagCompound); // Read in the ItemStacks in the inventory from NBT NBTTagList tagList = nbtTagCompound.getTagList("Items"); this.atmItemStacks = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < tagList.tagCount(); ++i) { NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(i); byte slot = tagCompound.getByte("Slot"); if (slot >= 0 && slot < this.atmItemStacks.length) { this.atmItemStacks[slot] = ItemStack.loadItemStackFromNBT(tagCompound); } } } public void writeToNBT(NBTTagCompound nbtTagCompound) { super.writeToNBT(nbtTagCompound); // Write the ItemStacks in the inventory to NBT NBTTagList tagList = new NBTTagList(); for (int currentIndex = 0; currentIndex < this.atmItemStacks.length; ++currentIndex) { if (this.atmItemStacks[currentIndex] != null) { NBTTagCompound tagCompound = new NBTTagCompound(); tagCompound.setByte("Slot", (byte)currentIndex); this.atmItemStacks[currentIndex].writeToNBT(tagCompound); tagList.appendTag(tagCompound); } } nbtTagCompound.setTag("Items", tagList); } /** * Returns the number of slots in the inventory. */ public int getSizeInventory() { return this.atmItemStacks.length; } /** * Returns the stack in slot i */ public ItemStack getStackInSlot(int i) { return this.atmItemStacks[i]; } public ItemStack decrStackSize(int i, int j) { // TODO Auto-generated method stub return null; } public ItemStack getStackInSlotOnClosing(int i) { return null; } @Override public void setInventorySlotContents(int var1, ItemStack var2) { // TODO Auto-generated method stub } public String getInvName() { return "container.atm"; } public int getInventoryStackLimit() { return 64; } public void openChest() { } public void closeChest() { } @Override public boolean isUseableByPlayer(EntityPlayer var1) { // TODO Auto-generated method stub return true; } } ContainerAtm.java package economy.common; import net.minecraft.src.*; import economy.common.TileAtm; public class ContainerAtm extends Container { private TileAtm atm; public ContainerAtm(InventoryPlayer inventoryPlayer, TileAtm atm) { this.atm = atm; this.addSlotToContainer(new Slot(atm, 0, 56, 17)); this.addSlotToContainer(new Slot(atm, 1, 56, 62)); for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) { for (int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex) { this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 94 + inventoryRowIndex * 18)); } } // Add the player's action bar slots to the container for (int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex) { this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 152)); } } public boolean canInteractWith(EntityPlayer player) { //return atm.isUseableByPlayer(player); return true; } } CommonProxyEconomy.java package economy.common; import net.minecraft.src.*; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.registry.GameRegistry; import economy.client.GuiAtm; import economy.common.ContainerAtm; import economy.common.TileAtm; public class CommonProxyEconomy implements IGuiHandler { public void initTileEntities() { GameRegistry.registerTileEntity(TileAtm.class, "tileAtm"); } @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if (ID == 201) { TileAtm atm = (TileAtm)world.getBlockTileEntity(x, y, z); return new ContainerAtm(player.inventory, atm); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if (ID == 201) { TileAtm atm = (TileAtm)world.getBlockTileEntity(x, y, z); return new GuiAtm(player.inventory, atm); } return null; } public void registerRenderThings() { } } ClientProxyEconomy.java package economy.client; import net.minecraftforge.client.MinecraftForgeClient; import economy.common.CommonProxyEconomy; public class ClientProxyEconomy extends CommonProxyEconomy { @Override public void registerRenderThings() { MinecraftForgeClient.preloadTexture("economy/SpriteSheet.png"); } } GuiAtm.java package economy.client; import org.lwjgl.opengl.GL11; import cpw.mods.fml.common.Side; import cpw.mods.fml.common.asm.SideOnly; import cpw.mods.fml.common.registry.LanguageRegistry; import economy.common.ContainerAtm; import economy.common.TileAtm; import net.minecraft.src.*; public class GuiAtm extends GuiContainer { public GuiAtm (InventoryPlayer inventoryPlayer, TileAtm tileAtm) { super(new ContainerAtm(inventoryPlayer, tileAtm)); } protected void drawGuiContainerForegroundLayer() { fontRenderer.drawString("Atm", 8, 6, 4210752); fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) { int texture = mc.renderEngine.getTexture("economy/AtmGui.png"); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(texture); int x = (width - xSize) / 2; int y = (height - ySize) / 2; this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize); } }
-
I made a block with 2 textures and only the front side is different, how do I make the front side face towards the player when it is placed down.
-
I am trying to make a money mod, but I need a way to store and change the variables like the player name and money amount in a external file. What would I use to do this?