Jump to content

TLHPoE

Members
  • Posts

    638
  • Joined

  • Last visited

Everything posted by TLHPoE

  1. Characters weren't a problem I disabled all other mobs and loaded a world with my attributes. For some reason, whenever the break point hit at the snapshot class at world load, it was either maxHealth or speed. None of my attributes showed up. When I stepped up a block, the snapshot fired up and it was my step height attribute. I'm not sure what to make of this.
  2. Ok, I'm looking through it right now. It seems that the server goes through all of the entity's attributes, saves them to a snap shot, sends the snapshot to the client, and the client syncs up with the server via the data from the snapshot. Not sure if I'm able to tell what the client is trying to sync there.
  3. Here's my code: ModAttributes (I call the loadAttribute method in the pre initialization stage): package terrarium.entity.attribute; import net.minecraft.entity.ai.attributes.IAttribute; public class ModAttributes { public static IAttribute jumpHeight; public static IAttribute maxJumps; public static IAttribute stepHeight; public static IAttribute maxMana; public static IAttribute healthRegen; public static IAttribute manaRegen; public static IAttribute maxHurtResistantTime; public static void loadAttributes() { jumpHeight = (new ModAttribute("generic.jumpHeight", 0.41999998688697815D, true)).setShouldWatch(true); maxJumps = (new ModAttribute("generic.maxJumps", 1, true)).setShouldWatch(true); stepHeight = (new ModAttribute("generic.stepHeight", 1, false)).setShouldWatch(true); maxMana = (new ModAttribute("generic.maxMana", 20, true)).setShouldWatch(true); healthRegen = new ModAttribute("generic.healthRegen", 1, false); manaRegen = new ModAttribute("generic.manaRegen", 1.5, true); maxHurtResistantTime = new ModAttribute("generic.maxHurtResistantTime", 20, false); } } ModAttribute: package terrarium.entity.attribute; import net.minecraft.entity.ai.attributes.BaseAttribute; import terrarium.Reference; public class ModAttribute extends BaseAttribute { public boolean isPlayerOnly = false; public ModAttribute(String name, double defaultValue, boolean isPlayerOnly) { super(name, defaultValue); this.isPlayerOnly = isPlayerOnly; Reference.modAttributes.add(this); } @Override public double clampValue(double value) { return value; } } ForgeServerEventHandler: @SubscribeEvent public void entityConstruct(EntityConstructing event) { if(!event.entity.worldObj.isRemote) { if(event.entity instanceof EntityLivingBase) { EntityLivingBase entity = (EntityLivingBase) event.entity; boolean isPlayer = entity instanceof EntityPlayer; if(isPlayer) { ExtendedPlayerProperties.handlePropertiesFor((EntityPlayer) entity); } for(ModAttribute attribute : Reference.modAttributes) { if(attribute.isPlayerOnly && isPlayer) { entity.getAttributeMap().registerAttribute(attribute); } else if(!attribute.isPlayerOnly) { entity.getAttributeMap().registerAttribute(attribute); } } } } } Forgot the crash, sorry: ---- Minecraft Crash Report ---- // Ooh. Shiny. Time: 7/26/14 7:21 PM Description: Unexpected error java.lang.IllegalArgumentException: Default value cannot be lower than minimum value! at net.minecraft.entity.ai.attributes.RangedAttribute.<init>(RangedAttribute.java:22) at net.minecraft.client.network.NetHandlerPlayClient.handleEntityProperties(NetHandlerPlayClient.java:1849) at net.minecraft.network.play.server.S20PacketEntityProperties.processPacket(S20PacketEntityProperties.java:96) at net.minecraft.network.play.server.S20PacketEntityProperties.processPacket(S20PacketEntityProperties.java:104) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247) at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:321) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1693) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) at net.minecraft.client.Minecraft.run(Minecraft.java:961) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at GradleStart.bounce(GradleStart.java:108) at GradleStart.startClient(GradleStart.java:101) at GradleStart.main(GradleStart.java:56) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.entity.ai.attributes.RangedAttribute.<init>(RangedAttribute.java:22) at net.minecraft.client.network.NetHandlerPlayClient.handleEntityProperties(NetHandlerPlayClient.java:1849) at net.minecraft.network.play.server.S20PacketEntityProperties.processPacket(S20PacketEntityProperties.java:96) at net.minecraft.network.play.server.S20PacketEntityProperties.processPacket(S20PacketEntityProperties.java:104) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247) at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:321) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['ForgeDevName'/275, l='MpServer', x=4.40, y=147.58, z=0.55]] Chunk stats: MultiplayerChunkCache: 5, 5 Level seed: 0 Level generator: ID 00 - SIZE2, ver 0. Features enabled: false Level generator options: Level spawn location: World: (-29,64,-19), Chunk: (at 3,4,13 in -2,-2; contains blocks -32,0,-32 to -17,255,-17), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1) Level time: 76 game time, 76 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 2 total; [EntityClientPlayerMP['ForgeDevName'/275, l='MpServer', x=4.40, y=147.58, z=0.55], EntitySheep['Sheep'/179, l='MpServer', x=17.22, y=147.00, z=29.78]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:417) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2568) at net.minecraft.client.Minecraft.run(Minecraft.java:990) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at GradleStart.bounce(GradleStart.java:108) at GradleStart.startClient(GradleStart.java:101) at GradleStart.main(GradleStart.java:56) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 7 (amd64) version 6.1 Java Version: 1.7.0_51, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 664297352 bytes (633 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 1, tcache: 1, allocated: 8, tallocated: 71 FML: MCP v9.05 FML v7.10.25.1188 Minecraft Forge 10.13.0.1188 4 mods loaded, 4 mods active mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{7.10.25.1188} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1188.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{10.13.0.1188} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1188.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available terrarium{Indev} [Terrarium] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Launched Version: 1.7.10 LWJGL: 2.9.1 OpenGL: GeForce GT 520/PCIe/SSE2 GL version 4.3.0, NVIDIA Corporation GL Caps: Using GL 1.3 multitexturing. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Anisotropic filtering is supported and maximum anisotropy is 16. Shaders are available because OpenGL 2.1 is supported. Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: English (US) Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Anisotropic Filtering: Off (1)
  4. Ok, that didn't work either... I did some more debugging and I tried not loading my attributes. It didn't crash. All of my attributes' base values are not below their minimum value. Is their a maximum amount of attributes that I can have?
  5. Hi, I get a crash about an attribute having a base value that's lower than the minimum value. It's in the NetHandlerPlayClient: iattributeinstance = baseattributemap.registerAttribute(new RangedAttribute(snapshot.func_151409_a(), 0.0D, 2.2250738585072014E-308D, Double.MAX_VALUE));
  6. Ok, I traced it back to this line in NetHandlerPlayClient: iattributeinstance = baseattributemap.registerAttribute(new RangedAttribute(snapshot.func_151409_a(), 0.0D, 2.2250738585072014E-308D, Double.MAX_VALUE)); It's setting the base value to 0.0D and setting the minimum value to 2.2250738585072014E-308D; Is this just a forge problem? Or is it caused by me somehow?
  7. Hi, I'm getting this crash: ---- Minecraft Crash Report ---- // There are four lights! Time: 7/25/14 2:23 AM Description: Unexpected error java.lang.IllegalArgumentException: Default value cannot be lower than minimum value! at net.minecraft.entity.ai.attributes.RangedAttribute.<init>(RangedAttribute.java:22) at net.minecraft.client.network.NetHandlerPlayClient.handleEntityProperties(NetHandlerPlayClient.java:1848) at net.minecraft.network.play.server.S20PacketEntityProperties.processPacket(S20PacketEntityProperties.java:96) at net.minecraft.network.play.server.S20PacketEntityProperties.processPacket(S20PacketEntityProperties.java:104) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247) at net.minecraft.client.Minecraft.runTick(Minecraft.java:2151) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1038) at net.minecraft.client.Minecraft.run(Minecraft.java:961) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at GradleStart.bounce(GradleStart.java:95) at GradleStart.startClient(GradleStart.java:88) at GradleStart.main(GradleStart.java:56) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.entity.ai.attributes.RangedAttribute.<init>(RangedAttribute.java:22) at net.minecraft.client.network.NetHandlerPlayClient.handleEntityProperties(NetHandlerPlayClient.java:1848) at net.minecraft.network.play.server.S20PacketEntityProperties.processPacket(S20PacketEntityProperties.java:96) at net.minecraft.network.play.server.S20PacketEntityProperties.processPacket(S20PacketEntityProperties.java:104) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['ForgeDevName'/321, l='MpServer', x=0.00, y=156.62, z=0.00]] Chunk stats: MultiplayerChunkCache: 5, 5 Level seed: 0 Level generator: ID 00 - SIZE2, ver 0. Features enabled: false Level generator options: Level spawn location: World: (0,64,0), Chunk: (at 0,4,0 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 6 game time, 6 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 2 total; [EntityClientPlayerMP['ForgeDevName'/321, l='MpServer', x=0.00, y=156.62, z=0.00], EntityPig['Pig'/75, l='MpServer', x=-61.50, y=157.00, z=-0.50]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:417) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2567) at net.minecraft.client.Minecraft.run(Minecraft.java:990) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at GradleStart.bounce(GradleStart.java:95) at GradleStart.startClient(GradleStart.java:88) at GradleStart.main(GradleStart.java:56) -- System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 7 (amd64) version 6.1 Java Version: 1.7.0_51, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 882953976 bytes (842 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 9, tallocated: 72 FML: MCP v9.05 FML v7.10.18.1180 Minecraft Forge 10.13.0.1180 4 mods loaded, 4 mods active mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{7.10.18.1180} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{10.13.0.1180} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available terrarium{Indev} [Terrarium] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Launched Version: 1.7.10 LWJGL: 2.9.1 OpenGL: GeForce GT 520/PCIe/SSE2 GL version 4.3.0, NVIDIA Corporation GL Caps: Using GL 1.3 multitexturing. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Anisotropic filtering is supported and maximum anisotropy is 16. Shaders are available because OpenGL 2.1 is supported. Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [] Current Language: English (US) Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Anisotropic Filtering: Off (1) I'm not sure what's causing the crash since it's traced back to a packet. There were calls to set the base value of the player's maxhealth, but I commented them out. Also I have attributes, but they're not ranged attributes either. So any idea what's causing the problem?
  8. Configuration config = new Configuration(event.getSuggestedConfigurationFile(), true); config.load(); config.get("Booleans", "Boolean1", false).set(true); config.save();
  9. Oh, didn't see that part. You could give invisibility to the player and then spawn the entity/set the block at the player's location.
  10. That's a bit too extreme for what you're trying to accomplish. Just cancel the RenderPlayerEvent and then do your own rendering.
  11. You're telling WorldGenMinable to replace stone. new WorldGenMinable(block, (minVainSize + random.nextInt(maxVainSize - minVainSize)), Blocks.stone).generate(world, random, posX, posY, posZ);
  12. Hi, I'm using this code to draw a filled circle at the given coordinates with the block that's given: public static void fillCircle(World world, int x, int y, int z, int radius, Block block) { while(radius != 0) { for(int i = 0; i < 360; i++){ world.setBlock((int) (x + radius * Math.cos(i)), y, (int) (z + radius * Math.sin(i)), block); } radius--; } } The above code isn't the most efficient (I think) and sometimes produces this: at some radius sizes. Is there any other efficient way of doing this?
  13. Well, the print is firing. I've also tried registering it on the server side and checking if the world is remote, but the world is never remote. Nothing more. Ok, after some debugging I've discovered some things. 1. The world on both sides aren't remote 2. The server side event is only called from the server (I was expecting it to call on the client and server thread)
  14. What I'm trying to achieve is the "reddust" particle being spawned 4 times each time a living entity is hurt. For some reason, nothing happens. package terrarium.handler.event; import net.minecraft.entity.EntityLivingBase; import net.minecraftforge.event.entity.living.LivingHurtEvent; import terrarium.util.LogUtil; import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class ForgeClientEventHandler { @SubscribeEvent public void entityHurt(LivingHurtEvent event) { EntityLivingBase entity = event.entityLiving; LogUtil.info("HI"); for(int i = 0; i < 4; i++) { entity.worldObj.spawnParticle("reddust", entity.posX, entity.posY, entity.posZ, 0, 0, 0); } } } The class is registered on the client side in MinecraftForge.EVENT_BUS, and it's printing "HI" in the console whenever I hit an entity. Am I missing something obvious?
  15. I'm replacing the computeLightValue method in the World class. What I'm trying to accomplish is adding a new check for how many solid blocks and air blocks stand inbetween the the block it's computing the light value for and the block at the top that can see the sky. Then I'll use that information to somehow alter the light value so that something floating high above the air won't cast the largest shadow on earth.
  16. Thanks, both links are very helpful.
  17. Oh, I didn't know that the inventory was synced with the client.
  18. Hi, I'm using the ItemTooltipEvent to add some more information to itemstacks in my gui. The problem is, I need to get either the slot or the inventory in which the itemstack is inside of. I have my own crafting system that collects information on how much of what itemstack is in the player's inventory and displays what the player can craft. The reason I need the slot/inventory, is because I want to add the ingredients of the recipe to the itemstack tooltip. If there's any other way of doing this, I'm all ears.
  19. Are there any tutorials that cover creating a coremod and writing in ASM?
  20. What version of Minecraft are you using? That method doesn't seem to exist in 1.7.10...
  21. I think this is what you're looking for: this.setTickRandomly(true);
  22. Hi, I'm pretty sure I need to replace a method in the World class, seeing as I don't know how else to do it. I know ASM is used to make methods public, but it can also modify/replace the method itself? I've looked here for an idea on how to do it, but EventTransformer does not exist in 1.7.10. So do any of you know of a tutorial that can still be used in 1.7.10?
  23. After reading all of the replies, I'll try spawning blocks bellow my island that give off sunlight, since I use vanilla blocks to generate my island. If I can't do that, creating the new sky ceiling will be my next option.
  24. Hi, in my mod I generate floating islands: Is there anyway to allow sky light to go through the island and stop the large shadow?
  25. Ok, I attempted an interpolation method, and this what I got: package terrarium.util; import java.awt.Color; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Random; import javax.imageio.ImageIO; import net.minecraft.world.gen.NoiseGeneratorPerlin; public class NoiseTesting { public static void init() { Random random = new Random(1L); double[][] noise1 = generateNoise(random, 1, 0, 0, 25, 25); double[][] noise2 = generateNoise(random, 1, 0, 0, 50, 50); double[][] noise3 = generateNoise(random, 1, 0, 0, 100, 100); double[][] noise4 = generateNoise(random, 1, 0, 0, 200, 200); double[][] noise5 = generateNoise(random, 1, 0, 0, 400, 400); noise4 = interpolateBilinear(noise4, 200, 200); noise3 = interpolateBilinear(noise3, 100, 100); noise3 = interpolateBilinear(noise3, 200, 200); noise2 = interpolateBilinear(noise2, 50, 50); noise2 = interpolateBilinear(noise2, 100, 100); noise2 = interpolateBilinear(noise2, 200, 200); noise1 = interpolateBilinear(noise1, 25, 25); noise1 = interpolateBilinear(noise1, 50, 50); noise1 = interpolateBilinear(noise1, 100, 100); noise1 = interpolateBilinear(noise1, 200, 200); try { saveImage(noiseToImage(noise5, 400, 400), "./", "noise5"); } catch(IOException e) { e.printStackTrace(); } noise5 = combineArrays(noise5, noise4, 400, 400); try { saveImage(noiseToImage(noise5, 400, 400), "./", "noise5+4"); } catch(IOException e) { e.printStackTrace(); } noise5 = combineArrays(noise5, noise3, 400, 400); try { saveImage(noiseToImage(noise5, 400, 400), "./", "noise5+4+3"); } catch(IOException e) { e.printStackTrace(); } noise5 = combineArrays(noise5, noise2, 400, 400); try { saveImage(noiseToImage(noise5, 400, 400), "./", "noise5+4+3+2"); } catch(IOException e) { e.printStackTrace(); } noise5 = combineArrays(noise5, noise1, 400, 400); try { saveImage(noiseToImage(noise5, 400, 400), "./", "noise5+4+3+2+1"); } catch(IOException e) { e.printStackTrace(); } } public static double[][] generateNoise(Random random, int octaves, int x, int y, int width, int height) { NoiseGeneratorPerlin noiseGenerator = new NoiseGeneratorPerlin(random, octaves); double[][] noiseArray = new double[width][height]; for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { noiseArray[i][j] = noiseGenerator.func_151601_a(x + i, y + j); } } return noiseArray; } public static BufferedImage noiseToImage(double[][] noise, int width, int height) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { int hue = (int) (255 * ((1D + noise[i][j]) / 2)); img.setRGB(i, j, new Color(hue, hue, hue).getRGB()); } } return img; } public static void saveImage(BufferedImage img, String directory, String name) throws IOException { ImageIO.write(img, "png", new File(directory + name + ".png")); } public static void setAlpha(BufferedImage img, int alpha) { for(int i = 0; i < img.getWidth(); i++) { for(int j = 0; j < img.getHeight(); j++) { Color currentColor = new Color(img.getRGB(i, j)); Color newColor = new Color(currentColor.getRed(), currentColor.getGreen(), currentColor.getBlue(), alpha); img.setRGB(i, j, newColor.getRGB()); } } } public static double[][] interpolateBilinear(double[][] array, int width, int height) { double[][] res = new double[width * 2][height * 2]; for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { res[i * 2][j * 2] = array[i][j]; } } for(int i = 0; i < width * 2; i++) { for(int j = 0; j < height * 2; j++) { if(i == 0 || i % 2 == 0) { if((j + 1) % 2 == 0) { if(j != (width * 2) - 1) { res[i][j] = bilinearInterpolatePoints(res[i][j - 1], res[i][j + 1]); } else { res[i][j] = res[i][j - 2]; } } } else { if(i != (height * 2) - 1) { res[i][j] = bilinearInterpolatePoints(res[i - 1][j], res[i + 1][j]); } else { res[i][j] = res[i - 2][j]; } } } } return res; } public static double[][] combineArrays(double[][] array1, double[][] array2, int width, int height) { double[][] res = new double[width][height]; for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { res[i][j] = bilinearInterpolatePoints(array1[i][j], array2[i][j]); } } return res; } public static double cosineInterpolatePoints(double p1, double p2) { double mu2; mu2 = (1 - Math.cos(0.5 * Math.PI)) / 2; //0.5 is mu return(p1 * (1 - mu2) + p2 * mu2); } public static double bilinearInterpolatePoints(double p1, double p2) { return (p1 + p2) / 2; } } As you can see in the code, I generate the file every time I'm about to stack another layer of noise on top. I guess my attempt was semi-fruitful, as you can see in the pictures:
×
×
  • Create New...

Important Information

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