Jump to content

HeXHaX

Members
  • Posts

    22
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    Creating amazing things very, very, very slowly.

HeXHaX's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. It's beyond me. Initially, there is only one thank you, but after I reload the page, another one appears out of the blue. It's almost like it's adding a dummy account before mine with a blank username because there is a comma preceding my username in the thank you.
  2. Could you please explain why not to use the Minecraft class in the WorldTickEvent? I only started modding two weeks ago, so even though I am capable of understanding this stuff, I have no clue where to find it out because of poor documentation/community organization. So even though I know you mean well, your comment doesn't really help me understand what I am doing; it just gives me an example of code from vanilla that I can adapt to my application.
  3. How do I get the biome the player is currently in? Here is what I am using right now: BlockPos blockPos = new BlockPos(Minecraft.getMinecraft().thePlayer.posX, Minecraft.getMinecraft().thePlayer.posY, Minecraft.getMinecraft().thePlayer.posZ); String currentBiome = event.world.getBiomeGenForCoords(blockPos).biomeName; This bit of code is inside a tick event function which uses the WorldTickEvent. As of now, currentBiome is being set to "Hell" no matter where I am: Jungle, Desert, Forest, Ocean, Nether, End, it doesn't matter. What am I doing wrong?
  4. I am trying to use several different types of events (world tick, world load, and world save) to all work on the same data. All my functions are in the same class, but for some reason, the variable dayCount seems to be a different instance for each function. Here is my code. public class TimeHandler { private boolean flag; public int dayCount; public TimeHandler() { this.flag = false; } @SubscribeEvent public void incrementDayCount(WorldTickEvent event) { if(flag == true && getTimeFromWorldTime(event.world.getWorldInfo().getWorldTime()) > 0) { flag = false; } else if(getTimeFromWorldTime(event.world.getWorldInfo().getWorldTime()) == 0 && flag == false) { flag = true; ++this.dayCount; ChatComponentText message = new ChatComponentText("Days elapsed since spawn: " + this.dayCount); Minecraft.getMinecraft().thePlayer.addChatMessage(message); } //System.out.println(getTimeFromWorldTime(event.world.getWorldInfo().getWorldTime())); } @SubscribeEvent public void createTimeSaves(WorldEvent.Load event) throws IOException { String pathToDir = FileIO.getMcDir().toString() + "/xpansion_data"; System.out.println(pathToDir); byte[] dayCountBinary = {0}; File testDir = new File(pathToDir); if(testDir.exists() && testDir.isDirectory()) { String pathToDat = FileIO.getMcDir().toString() + "/xpansion_data/day_count.dat"; File testFile = new File(pathToDat); if(testFile.exists() && !testFile.isDirectory()) { dayCountBinary = FileIO.readBinary(pathToDat); CharBuffer cb = ByteBuffer.wrap(dayCountBinary).asCharBuffer(); if(!StringUtils.isEmpty(cb.toString())) { System.out.println(cb.toString()); this.dayCount = Integer.parseInt(cb.toString(), 2); } else { this.dayCount = 0; } } else { this.dayCount = 0; FileIO.writeBinary(pathToDat, dayCountBinary); } } else { testDir.mkdir(); String pathToDat = FileIO.getMcDir().toString() + "/xpansion_data/day_count.dat"; File testFile = new File(pathToDat); this.dayCount = 0; FileIO.writeBinary(pathToDat, dayCountBinary); } } @SubscribeEvent public void saveDayCount(WorldEvent.Save event) throws IOException { System.out.println(this.dayCount); byte[] dayCountBinary = toBinary(this.dayCount); String path = FileIO.getMcDir().toString() + "/xpansion_data/day_count.dat"; FileIO.writeBinary(path, dayCountBinary); } private static long getTimeFromWorldTime(long time) { return (time%24000); } public byte[] toBinary(int n) { byte[] binary = {}; if (n == 0) { System.out.println("n is zero"); return binary; }; while (n > 0) { int rem = n % 2; System.out.println(rem); binary[binary.length] = (byte) rem; n = n / 2; } return binary; } } public class FileIO { public static byte[] readBinary(String filePath) throws IOException { Path path = Paths.get(filePath); return Files.readAllBytes(path); } public static void writeBinary(String fileName, byte[] contents) throws IOException { Path path = Paths.get(fileName); Files.write(path, contents); } public static File getMcDir() { if (MinecraftServer.getServer() != null && MinecraftServer.getServer().isDedicatedServer()) { return new File("."); } return Minecraft.getMinecraft().mcDataDir; } } When I run this, I do get a chat message that tells me the correct number of elapsed days, but when I hit the escape key and the save event is fired (this triggers the saveDayCount function) the dayCount variable is now 0 again. I don't know what I am doing wrong.
  5. Honestly, I have no idea why it does that because I only have one account. It has done that since I started on this forum. Oh well, I guess that's just a little extra incentive for people to help me out!
  6. So I would like to be able to save some custom binary files in the Minecraft folder and I was wondering if there is a function I can call to get the game folder regardless of operating system.
  7. Never mind, it's working. I made a noobie mistake with my function scope.
  8. I am having issues registering my WorldTickEvent. Is it different from 1.7.10? I have @SubscribeEvent in front of my event function and have tried to register it with the line: FMLCommonHandler.instance().bus().register(new TimeHandler()); but that does nothing.
  9. Is there an event I can use to call a function when the day changes over?
  10. I need help again! Maybe I am just an idiot, but I can not seem to find out how to hook into Minecraft's tick update function! I need to be able to check time on tick update (I am adding a day counter to Minecraft as a part of my mod) so that when a new day rolls around, I can increment my day counter.
  11. Where can I find the class that handles time in Minecraft 1.8?
  12. https://www.dropbox.com/s/x71ap4lxff6u4ke/2015-05-04_21.14.48.png?dl=0 I guess that would be important, wouldn't it?
  13. I am making a basic mod that adds a few new crops. I know this is overdone; I'm just getting my feet wet. Anyways, the issue I'm having is abnormal spawning of village crops. Basic overview of my code: For each x, z coordinate in each chunk, get the height of the terrain. If the block at that position is wheat, potatoes, or carrots, then call the spawnCrops function (I am using a 100 percent chance of spawning for testing here.) Inside this spawnCrops function, if the crop's random spawn number is withing the spawn range, then use two while loops to iterate through all the crops in the row in both directions, replacing them with the mod crop chosen for that row. My issue: The crops do not fill up the entire row. Village Crop Generation class: package com.hexhax.xpansion.worldGen; import java.util.ArrayList; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import com.hexhax.xpansion.common.EnumCrops; import com.hexhax.xpansion.init.XpansionBlocks; public class GenerateVillageCrops { public static boolean spawnCrops(World world, BlockPos pos, Random rand, int spawnChance, Block cropAtPos) { int direction = getRowDirection(world, pos); /* * cropChoice can have values between 1 and 2. */ int cropChoice = rand.nextInt(3) + 1; if( rand.nextInt(100) < spawnChance ) { boolean flag = false; if( direction == 1 ) { BlockPos newPos = new BlockPos( pos ); while( !flag ) { if( world.getBlockState(newPos.east()).getBlock() == cropAtPos ) { spawnOneCrop(world, newPos, cropChoice, rand); newPos = newPos.east(); } else { flag = true; } } flag = false; newPos = new BlockPos( pos ); while( !flag ) { if( world.getBlockState(newPos.west()).getBlock() == cropAtPos ) { spawnOneCrop(world, newPos, cropChoice, rand); newPos = newPos.west(); } else { flag = true; } } } else if( direction == 2 ) { BlockPos newPos = new BlockPos( pos ); while( !flag ) { if( world.getBlockState(newPos.north()).getBlock() == cropAtPos ) { spawnOneCrop(world, newPos, cropChoice, rand); newPos = newPos.north(); } else { flag = true; } } flag = false; newPos = new BlockPos( pos ); while( !flag ) { if( world.getBlockState(newPos.south()).getBlock() == cropAtPos ) { spawnOneCrop(world, newPos, cropChoice, rand); newPos = newPos.south(); } else { flag = true; } } } return true; } return false; } /* * Returns an integer telling the direction of the crop row. */ private static int getRowDirection(World world, BlockPos pos) { boolean north = false; boolean south = false; boolean east = false; boolean west = false; if( isBlockReplacablePlant(world, pos) ) { if( isBlockReplacablePlant(world, pos.north(1)) && isBlockReplacablePlant(world, pos.north(2)) ) { north = true; } if( isBlockReplacablePlant(world, pos.south(1)) && isBlockReplacablePlant(world, pos.south(2)) ) { south = true; } if( isBlockReplacablePlant(world, pos.east(1)) && isBlockReplacablePlant(world, pos.east(2)) ) { east = true; } if( isBlockReplacablePlant(world, pos.west(1)) && isBlockReplacablePlant(world, pos.west(2)) ) { west = true; } if( north || south ) { return 1; } else if( east || west ) { return 2; } } return 0; } private static boolean isBlockReplacablePlant(World world, BlockPos pos) { Block block = world.getBlockState(pos).getBlock(); if( block == Blocks.wheat || block == Blocks.potatoes || block == Blocks.carrots ) { return true; } return false; } private static void spawnOneCrop(World world, BlockPos pos, int cropChoice, Random rand) { switch( cropChoice ) { case 1: world.setBlockState(pos, XpansionBlocks.tomato_crop.getDefaultState().withProperty(PropertyInteger.create("age", 0, 7), rand.nextInt()); break; case 2: world.setBlockState(pos, XpansionBlocks.tomato_crop.getDefaultState()); break; } } } Overworld World Generation Function: private void GenerateOverworld(World world, int i, int j, Random random) { addOre(XpansionBlocks.copper_ore, Blocks.stone, random, world, i, j, 15, 60, 4, 10, 20); for( int l=i; l<i+16; l++) { for( int m=j; m<j+16; m++) { int k = 128; boolean isAir = true; BlockPos iterBlockPos = new BlockPos(l, k, m); while( isAir ) { iterBlockPos = iterBlockPos.down(); isAir = world.getBlockState(iterBlockPos).getBlock() == Blocks.air; k--; } BlockPos currentPosition = new BlockPos(l, k, m); if( world.getBlockState(currentPosition).getBlock() == Blocks.wheat || world.getBlockState(currentPosition).getBlock() == Blocks.carrots || world.getBlockState(currentPosition).getBlock() == Blocks.potatoes ) { GenerateVillageCrops.spawnCrops(world, new BlockPos( l, k, m ), random, 100, world.getBlockState(currentPosition).getBlock() ); } } } }
×
×
  • Create New...

Important Information

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