Jump to content

[1.8] Any way to make vanilla dirt a falling block?


Anon10W1z

Recommended Posts

Sadly, I believe this will require ASM, but I was wondering if I could use at worst reflection, which I am comfortable with, or some other method to replace the vanilla dirt block with my own? There is no way I could use events, right?

 

You could just get the block list and remove the vanilla dirt block and then substitute it with your own. Just make sure to re-set the dirt variable (dirt = new Dirt()) so that other mods don't run into an error.

Link to comment
Share on other sites

Hi

 

I've noticed something in Forge that might help

 

GameRegistry.addSubstitutionAlias().

 

I've never used it and it may be useless... but it does look promising.

 

-TGG

I would use it, however, they must be type compatible. I cannot extend both BlockDirt and BlockFalling ;(

Maker of the Craft++ mod.

Link to comment
Share on other sites

I would use it, however, they must be type compatible. I cannot extend both BlockDirt and BlockFalling ;(

 

No, but you can extend one and insert the duplicated necessary methods of the other.

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

I would use it, however, they must be type compatible. I cannot extend both BlockDirt and BlockFalling ;(

 

No, but you can extend one and insert the duplicated necessary methods of the other.

True, true...I guess I can.

EDIT: Nope, I still get the error:

[18:47:56] [Client thread/ERROR] [FML]: The substitute net.minecraft.block.BlockDirt for craft++:dirt (type com.anon10w1z.craftPP.blocks.BlockNewDirt) is type incompatible. This won't work
[18:47:56] [Client thread/INFO] [FML]: Applying holder lookups
[18:47:56] [Client thread/INFO] [FML]: Holder lookups applied
[18:47:56] [Client thread/ERROR] [FML]: Fatal errors were detected during the transition from PREINITIALIZATION to INITIALIZATION. Loading cannot continue
[18:47:56] [Client thread/ERROR] [FML]: 
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized
FML{8.0.20.1290} [Forge Mod Loader] (forgeSrc-1.8-11.14.0.1290-1.8.jar) Unloaded->Constructed->Pre-initialized
Forge{11.14.0.1290} [Minecraft Forge] (forgeSrc-1.8-11.14.0.1290-1.8.jar) Unloaded->Constructed->Pre-initialized
craft++{2.1} [Craft++] (main) Unloaded->Constructed->Errored
[18:47:56] [Client thread/ERROR] [FML]: The following problems were captured during this phase
[18:47:56] [Client thread/ERROR] [FML]: Caught exception from craft++
net.minecraftforge.fml.common.registry.IncompatibleSubstitutionException
at net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry.addSubstitutionAlias(FMLControlledNamespacedRegistry.java:497) ~[forgeSrc-1.8-11.14.0.1290-1.8.jar:?]
at net.minecraftforge.fml.common.registry.GameData.registerSubstitutionAlias(GameData.java:920) ~[forgeSrc-1.8-11.14.0.1290-1.8.jar:?]
at net.minecraftforge.fml.common.registry.GameRegistry.addSubstitutionAlias(GameRegistry.java:161) ~[forgeSrc-1.8-11.14.0.1290-1.8.jar:?]
at com.anon10w1z.craftPP.blocks.CppBlocks.registerBlocks(CppBlocks.java:34) ~[main/:?]
at com.anon10w1z.craftPP.main.CraftPlusPlus.onPreInit(CraftPlusPlus.java:87) ~[main/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_55]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_55]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_55]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_55]

Maker of the Craft++ mod.

Link to comment
Share on other sites

Question:

Which class did you subclass?  You should be subclassing BlockDirt for this to work and must not have registered the new block with the registry already.

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

Question:

...and must not have registered the new block with the registry already.

I removed the GameRegistry.registerBlock call but now it crashes with:


java.lang.NullPointerException: The replacement target is not present. This won't work
at net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry.addSubstitutionAlias(FMLControlledNamespacedRegistry.java:492)
at net.minecraftforge.fml.common.registry.GameData.registerSubstitutionAlias(GameData.java:920)
at net.minecraftforge.fml.common.registry.GameRegistry.addSubstitutionAlias(GameRegistry.java:161)
at com.anon10w1z.craftPP.blocks.CppBlocks.registerBlocks(CppBlocks.java:38)
at com.anon10w1z.craftPP.main.CraftPlusPlus.onPreInit(CraftPlusPlus.java:87)
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)

Maker of the Craft++ mod.

Link to comment
Share on other sites

Hmm.  Apologies.  I was trying to trace the code path and couldn't locate the line the last crash happened at (the line number pointed at a line that didn't make any sense) and then was trying to read the function to determine what it was doing.  And it looked like it threw a crash if the replacement block had an ID that was not -1, e.g. it would crash if you had registered the block.

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

Hmm.  Apologies.  I was trying to trace the code path and couldn't locate the line the last crash happened at (the line number pointed at a line that didn't make any sense) and then was trying to read the function to determine what it was doing.  And it looked like it threw a crash if the replacement block had an ID that was not -1, e.g. it would crash if you had registered the block.

It's OK.

Maker of the Craft++ mod.

Link to comment
Share on other sites

OK, I tried a reflection-hack method:

System.out.println(replaceBlock(Blocks.dirt, falling_dirt));

public static boolean replaceBlock(Block toReplace, Block newBlock) {
	Field modifiersField;
	try {
		modifiersField = Field.class.getDeclaredField("modifiers");
		modifiersField.setAccessible(true);

		for (Field field : Blocks.class.getDeclaredFields()) {
			if (Block.class.isAssignableFrom(field.getType())) {
				Block block = (Block) field.get(null);
				if (block == toReplace) {
					String registryName = Block.blockRegistry.getNameForObject(block).toString();
					int id = Block.getIdFromBlock(block);
					ItemBlock item = (ItemBlock) Item.getItemFromBlock(block);
					System.out.println("Replacing block - " + id + "/" + registryName);

					FMLControlledNamespacedRegistry<Block> registry = GameData.getBlockRegistry();
					registry.putObject(registryName, newBlock);

					Field map = RegistryNamespaced.class.getDeclaredFields()[0];
					map.setAccessible(true);
					((ObjectIntIdentityMap) map.get(registry)).put(newBlock, id);

					map = FMLControlledNamespacedRegistry.class.getDeclaredField("persistentSubstitutions");
					map.setAccessible(true);
					((BiMap) map.get(registry)).put(registryName, id);

					field.setAccessible(true);
					int modifiers = modifiersField.getInt(field);
					modifiers &= ~Modifier.FINAL;
					modifiersField.setInt(field, modifiers);
					field.set(null, newBlock);

					Field itemblock = ItemBlock.class.getDeclaredFields()[0];
					itemblock.setAccessible(true);
					modifiers = modifiersField.getInt(itemblock);
					modifiers &= ~Modifier.FINAL;
					modifiersField.setInt(itemblock, modifiers);
					itemblock.set(item, newBlock);

					System.out.println("Check field: " + field.get(null).getClass());
					System.out.println("Check registry: " + Block.blockRegistry.getObjectById(id).getClass());
					System.out.println("Check item: " + ((ItemBlock) Item.getItemFromBlock(block)).block.getClass());
				}
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
	return true;
}

This gives the output:

[11:17:56] [Client thread/INFO] [sTDOUT]: [com.anon10w1z.craftPP.blocks.CppBlocks:replaceBlock:62]: Replacing block - 3/minecraft:dirt
[11:17:56] [Client thread/WARN] [FML]: ****************************************
[11:17:56] [Client thread/WARN] [FML]: * Ignoring putObject(minecraft:dirt, com.anon10w1z.craftPP.blocks.BlockFallingDirt@3efcf4dd), adding alias to craft++:falling_dirt instead
[11:17:56] [Client thread/WARN] [FML]: *  at net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry.putObject(FMLControlledNamespacedRegistry.java:158)
[11:17:56] [Client thread/WARN] [FML]: *  at com.anon10w1z.craftPP.blocks.CppBlocks.replaceBlock(CppBlocks.java:65)
[11:17:56] [Client thread/WARN] [FML]: *  at com.anon10w1z.craftPP.blocks.CppBlocks.registerBlocks(CppBlocks.java:45)
[11:17:56] [Client thread/WARN] [FML]: *  at com.anon10w1z.craftPP.main.CraftPlusPlus.onPreInit(CraftPlusPlus.java:87)
[11:17:56] [Client thread/WARN] [FML]: *  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[11:17:56] [Client thread/WARN] [FML]: *  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)...
[11:17:56] [Client thread/WARN] [FML]: ****************************************
[11:17:56] [Client thread/INFO] [sTDOUT]: [com.anon10w1z.craftPP.blocks.CppBlocks:replaceBlock:88]: Check field: class com.anon10w1z.craftPP.blocks.BlockFallingDirt
[11:17:56] [Client thread/INFO] [sTDOUT]: [com.anon10w1z.craftPP.blocks.CppBlocks:replaceBlock:89]: Check registry: class com.anon10w1z.craftPP.blocks.BlockFallingDirt
[11:17:56] [Client thread/INFO] [sTDOUT]: [com.anon10w1z.craftPP.blocks.CppBlocks:replaceBlock:90]: Check item: class com.anon10w1z.craftPP.blocks.BlockFallingDirt
true
[11:17:56] [Client thread/INFO] [craft++]: Pre-initialization completed successfully
[11:17:56] [Client thread/INFO] [FML]: Applying holder lookups
[11:17:56] [Client thread/INFO] [FML]: Holder lookups applied
[11:17:57] [sound Library Loader/INFO]: Starting up SoundSystem...
[11:17:57] [Thread-7/INFO]: Initializing LWJGL OpenAL
[11:17:57] [Thread-7/INFO]: (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)
[11:17:57] [Thread-7/INFO]: OpenAL initialized.
[11:17:57] [sound Library Loader/INFO]: Sound engine started
[11:17:58] [Client thread/WARN]: Unable to load definition craft++:falling_dirt#snowy=false,variant=dirt
java.lang.RuntimeException: Encountered an exception when loading model definition of model craft++:blockstates/falling_dirt.json
//no model exists currently
[11:17:59] [Client thread/INFO]: Created: 512x512 textures-atlas
[11:18:00] [Client thread/WARN]: Missing model for: craft++:item/falling_dirt
[11:18:00] [Client thread/INFO] [craft++]: Registering the block inventory renderers
[11:18:00] [Client thread/INFO] [craft++]: Registering the event handler
[11:18:00] [Client thread/INFO] [craft++]: Registering the fuel handler
[11:18:00] [Client thread/INFO] [craft++]: Registering the crafting/furnace recipes
[11:18:00] [Client thread/INFO] [craft++]: Registering the dispenser behaviors
[11:18:00] [Client thread/INFO] [craft++]: Registering dispenser behavior for Sand/Red Sand
[11:18:00] [Client thread/INFO] [craft++]: Registering dispenser behavior for Gravel
[11:18:00] [Client thread/INFO] [craft++]: Registering dispenser behavior for Block of Sugar
[11:18:00] [Client thread/INFO] [craft++]: Registering default dispenser behavior for Flint and Steel
[11:18:00] [Client thread/INFO] [craft++]: Initializing the vanilla properties changer
[11:18:00] [Client thread/INFO] [craft++]: Initializing the crafting recipe remover
[11:18:00] [Client thread/INFO] [craft++]: Replacing stone tool recipes
[11:18:00] [Client thread/INFO] [craft++]: Replacing stairs recipes
[11:18:00] [Client thread/INFO] [craft++]: Replacing vanilla button recipes
[11:18:00] [Client thread/INFO] [craft++]: Removing tool repair recipes
[11:18:00] [Client thread/INFO] [craft++]: Initialization completed successfully
[11:18:00] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:568]: ---- Minecraft Crash Report ----
// You're mean.

Time: 2/16/15 11:18 AM
Description: Initializing game

java.lang.IllegalStateException: Registry entry for ItemBlock net.minecraft.item.ItemBlock@6e88c81e, id 201, is missing or uses the non-matching id 3.
at net.minecraftforge.fml.common.registry.FMLControlledNamespacedRegistry.validateContent(FMLControlledNamespacedRegistry.java:88)

Maker of the Craft++ mod.

Link to comment
Share on other sites

> [18:47:56] [Client thread/ERROR] [FML]: The substitute net.minecraft.block.BlockDirt for craft++:dirt (type com.anon10w1z.craftPP.blocks.BlockNewDirt) is type incompatible. This won't work

 

Looks to me like you did the substitution the wrong way.  i.e. you tried to replace BlockNewDirt with BlockDirt instead of the other way around.

 

-TGG

Link to comment
Share on other sites

> [18:47:56] [Client thread/ERROR] [FML]: The substitute net.minecraft.block.BlockDirt for craft++:dirt (type com.anon10w1z.craftPP.blocks.BlockNewDirt) is type incompatible. This won't work

 

Looks to me like you did the substitution the wrong way.  i.e. you tried to replace BlockNewDirt with BlockDirt instead of the other way around.

 

-TGG

Nope, I put the name of the new block and the object of the old block, just like it said in the Javadoc. BlockNewDirt extends BlockDirt.

Maker of the Craft++ mod.

Link to comment
Share on other sites

Did you try it the other way?  It will take you 30 seconds.

 

The JavaDoc is (as usual) ambiguous, but the error message is very clear that you are trying to substitute BlockDirt for BlockNewDirt, which is back to front.

    /**
     * Add a forced persistent substitution alias for the block or item to another block or item. This will have
     * the effect of using the substituted block or item instead of the original, where ever it is
     * referenced.
     *
     * @param nameToSubstitute The name to link to (this is the NEW block or item)
     * @param type The type (Block or Item)
     * @param object a NEW instance that is type compatible with the existing instance
     * @throws ExistingSubstitutionException if someone else has already registered an alias either from or to one of the names
     * @throws IncompatibleSubstitutionException if the substitution is incompatible
     */
    public static void addSubstitutionAlias(String nameToSubstitute, GameRegistry.Type type, Object object) throws ExistingSubstitutionException

 

-TGG

 

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.

Announcements



×
×
  • Create New...

Important Information

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