Jump to content

[1.6.4] - .setBlock problem


Felixkeeg

Recommended Posts

Hi again!

 

I'm working on a mod letting spawn an asteroid (Darkmatter_Block) with a chance of one tenth every time a new Chunk is generated.

It should be spawned inside a 200 block radius from the player (for now I only included the positive values)

 

The problem is:

I get an error at the

World.setBlock(plX, plY, plZ, 500);

line at the very end.

Eclipse tells me that I should "change the modifier of '.setBlock()' to 'static' " in the world.class but that would cause the world.class not to work

 

I begin to doubt that .setBlock() is even the right method but tbh I don't find anything coming close to making more sense.

 

If anyone sees my fault I would really appreciate some help with this. Probably it's just me being a little retarded^^

Thank you in advance =)

 

 

 

package darkmatter;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = darkmatter.modid, name = "Darkmatter", version = "1.0")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class darkmatter 
{
public static final String modid = "Felixkeeg_Darkmatter";

public static Block Darkmatter_Block;

public static Item Concentratedredstone_Item;
public static Item Darkmatter_Item;

@EventHandler
public void load(FMLInitializationEvent event)
{

//Block
	Darkmatter_Block = new BlockDarkmatter_Block (500, Material.rock).setUnlocalizedName("Darkmatter_Block");

	GameRegistry.registerBlock(Darkmatter_Block, modid + Darkmatter_Block.getUnlocalizedName().substring(5));

	LanguageRegistry.addName(Darkmatter_Block, "Darkmatter Block");


//Item
	Darkmatter_Item = new Darkmatter_Item(5000).setUnlocalizedName("Darkmatter");

	LanguageRegistry.addName(Darkmatter_Item, "Darkmatter");


	Concentratedredstone_Item = new Concentratedredstone_Item(5001).setUnlocalizedName("Concentratedredstone");

	LanguageRegistry.addName(Concentratedredstone_Item, "Concentrated Redstone");

//Crafting
	DarkmatterCrafting.loadRecipes();

}

//Asteroid 





	public void onChunkGenerate()
	{
		int varrand = (int) ((Math.random()*10)+1);
		if(10 <= varrand)
		{
			int extX = (int) ((Math.random()*200)+1);
			int extZ = (int) ((Math.random()*200)+1);

			int plX = (int)Minecraft.getMinecraft().thePlayer.posX + extX;
			int plY = 250;
		    int plZ = (int)Minecraft.getMinecraft().thePlayer.posZ + extZ;

		    World.setBlock(plX, plY, plZ, 500);
		}
	};


}

 

 

Link to comment
Share on other sites

World != world

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

@GotoLink

 

I know that I am not able to reference a non-static method in a static context normally but I do know there's a way to manage this, as I think this is the method they used for the setBlock Command of CommandBlocks in 1.7.2.

 

If I am wrong and am using the wrong method I just want to know which method I gotta use in order to place a block at a position.

 

@Draco18s

I know it's not the same.

world.setBlock() cannot be resolved, therefore World.setBlock() is the right option.

I was just a little careless with the problem-description, sorry for that.

Link to comment
Share on other sites

world.setBlock() cannot be resolved, therefore World.setBlock() is the right option.

 

*Groan*

No it's not.

 

You need a f*ing reference to an instance of the World class to be able to setBlock.  You can't do that with the World class itself.

 

You're basically trying to do this:

 

Integer integer = 10;
Integer += 1; //this makes no f*ing sense

 

Except that the first line is missing entirely.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

In other words, what you need is this

World world = Minecraft.getMinecraft().theWorld;
world.setBlock(plX, plY, plZ, 500); //Or whatever

 

Except that this is bad practice.  IIRC, this will fail on the dedicated server side.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1) get passed a reference to it

2) DimensionManager.getWorld(id)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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