Jump to content

Recommended Posts

Posted

Hey there everyone. I'm fairly new to modding and I'm trying to figure out why my class isn't overriding the existing block, in this case the farmland.

 

 

 

package chaosmod.coinmods;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockFarmland;
import net.minecraft.block.material.Material;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.IPlantable;

public class ChaosFarm2 extends BlockFarmland {

public ChaosFarm2(int par1) {
	super(par1);
	// TODO Auto-generated constructor stub
}

@Override
public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        //NEW UPDATED TICK FOR FARMLAND

        if (!this.isWaterNearby(par1World, par2, par3, par4))
        {
            int l = par1World.getBlockMetadata(par2, par3, par4);

            if (l > 0)
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, l - 1, 2);
            }
            else if (!this.isCropsNearby(par1World, par2, par3, par4))
            {
                par1World.setBlock(par2, par3, par4, Block.dirt.blockID);
            }
        }
        else
        {
            //Getting metadata and increasing to max 7 if already watered (>0)
            int l = par1World.getBlockMetadata(par2, par3, par4);

            if (l > 0 && l < 7)
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, l + 1, 2);
            }
            else
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 1, 2);
                nukewater(par1World, par2, par3, par4);
            }

            //Original update method - replaced with above to increase rather than set to 7
            //par1World.setBlockMetadataWithNotify(par2, par3, par4, 7, 2);
        }
    }

private boolean isWaterNearby(World par1World, int par2, int par3, int par4)
    {
        //NEW IS WATER METHOD
        for (int l = par2 - 4; l <= par2 + 4; ++l)
        {
            for (int i1 = par3; i1 <= par3 + 1; ++i1)
            {
                for (int j1 = par4 - 4; j1 <= par4 + 4; ++j1)
                {
                    //Now only looks for water source blocks
                    if (par1World.getBlockId(l, i1, j1) == 9 && (par1World.getBlockMetadata(l,  i1,  j1)) == 0)
                    {
                        return true;
                    }
                }
            }
        }

        return false;
    }


    /* Nuke Command for changing water source blocks when farm absorbs water */
    private void nukewater(World par1World, int par2, int par3, int par4)
    {
        for (int l = par2 - 4; l <= par2 + 4; ++l)
        {
            for (int i1 = par3; i1 <= par3 + 1; ++i1)
            {
                for (int j1 = par4 - 4; j1 <= par4 + 4; ++j1)
                {
                    if (par1World.getBlockId(l, i1, j1) == 9 && (par1World.getBlockMetadata(l,  i1,  j1)) == 0)
                    {
                        par1World.setBlock(l, i1, j1, 0);
                        return;
                    }
                }
            }
        }
    }

private boolean isCropsNearby(World par1World, int par2, int par3, int par4)
    {
        byte b0 = 0;

        for (int l = par2 - b0; l <= par2 + b0; ++l)
        {
            for (int i1 = par4 - b0; i1 <= par4 + b0; ++i1)
            {
                int j1 = par1World.getBlockId(l, par3 + 1, i1);
                Block plant = blocksList[j1];

                if (plant instanceof IPlantable && canSustainPlant(par1World, par2, par3, par4, ForgeDirection.UP, (IPlantable)plant))
                {
                    return true;
                }
            }
        }

        return false;
    }

}

 

 

 

That's the existing code I'm using and when I run it, the farmland acts the same instead of "absorbing" water blocks nearby. I thought if you copied the exact code from the super that you can override it with additional or even completely different code to change the code so that it's mod friendly. I can make the changes to the base but I really want to avoid that.

 

Thanks!

Posted

You can't change the behaviour of a vanilla block without changing it's class file. The only relatively safe way to do that is using ASM APIs for transforming java bytecode, so you register for a certain event and your callback receives the bytecode (as a byte[]) and the name for every class minecraft launcher loads. So you decide which ones you need to transform.

 

That's kinda advanced stuff, and since you're new to modding I'd suggest you don't try that right now. Register that block you made and use it instead of the normal farmland. Maybe there's a world event you can subscribe to prevent vanilla farmland blocks from being placed (everytime one is placed you set it to dirt, or something). But I don't know if there's such a thing. edit: only mentioned that as a possible inspiration for more experienced modders to try and answer your question.

Posted

So for now then, I should modify the base class - assuming I did that and I run the recompile and reobfuscate_srg bats, I end up with a file I can zip up as my mod, but I know that the base class file would need to be put into the minecraft jar and I the file names don't look like the ones inside the minecraft jar so I'm pretty sure just dropping them in won't work.

 

How would I go about recompiling the new base class files so that I can drop them into the jar (or have others do the same - shouldn't be conflicts with other mods as the behavior of the block is pretty much the same except when dealing with water source blocks)

 

Oh and also I could simply add a new block, but when a hoe is used to till the land, I'd have to change -that- class as well to produce the right block, or make custom tools for custom farmlands but that seems a bit excessive for what I'm trying to accomplish here.

Posted

I never tried that... And you shouldn't. But if you don't mind risking conflict with other mods and random crashes... I think that if you don't change the NAME of the vanilla class and run recompile.bat and then reobfuscate.bat (not reobfuscate_srg.bat) you should output your class with the correctly obfuscated name, the same obfuscated name as the untampered vanilla class I'd guess. I don't know where to put it though. I don't really know where minecraft class files are located in this 1.6.2 version.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • on my last computer, i had a similar problem with forge/ neoforge mods but instead them launcher screen was black
    • I am trying to make a mod, all it is, a config folder that tells another mod to not require a dependency, pretty simple right.. well, I dont want whoever downloads my mod to have to download 4 other mods and then decide if they want 2 more that they kinda really need.. i want to make my mod basically implement all of these mods, i really dont care how it does it, ive tried putting them in every file location you can think of, ive downloaded intellij, mcreator, and tried vmware but thats eh (had it from school). I downloaded them in hopes theyd create the correct file i needed but honestly im only more lost now. I have gotten my config file to work, if i put all these mods into my own mods folder and the config file into the config and it works (unvbelievably) but i want to share this to everyone else, lets just say this mod will legitimately get 7M downloads.  I tried putting them in a run folder then having it create all the contents in that for a game (mods,config..etc) then i drop the mods in and all the sudden i cant even open the game, like it literally works with my own world i play on, but i cant get it to work on any coding platform, they all have like built in java versions you cant switch, its a nightmare. I am on 1.20.1 I need Java 17 (i dont think the specific versions of 17 matter) I have even tried recreating the mods i want to implement and deleting import things like net.adamsandler.themodsname and replacing it with what mine is. that only creates other problems, where im at right now is i got the thing to start opening then it crashes, closest ive gotten it, then it just says this  exception in thread "main" cpw.mods.niofs.union.unionfilesystem$uncheckedioexception: java.util.zip.zipexception: zip end header not found caused by: java.util.zip.zipexception: zip end header not found basically saying theres something wrong with my java.exe file, so i tried downloading so many different versions of java and putting them all in so many different spots, nothing, someone online says its just a mod that isnt built right so i put the mod into an editor and bunch of errors came up, id post it but i deleted it on accident, i just need help integrating mods
    • Vanilla 1.16.5 Crash Report [#L2KYKaK] - mclo.gs  
    • Hello, probably the last update, if anyone has the same problem or this can be of any help, the answer was pretty simple, textures started rendering just using a Tesselator instead of a VertexConsumer given by a MultibufferSource and a RenderType, pretty simple
    • Finally circling back to this, and I think all of us were half right.  getChunk() does appear to immediately load the chunk, but what changed between 1.16 and 1.18 is that the list of entities is now stored in the server, not per chunk.  So while it was possible to load a chunk in 1.16 and immediately grab an entity out of it, 1.18 loads the chunk and submits a request to load its entities on the next tick (if I understand correctly).  All this to say, you can immediately access the chunk itself, however you have to wait an additional tick for its entities to load in. In my case what this means is that I do have to set up an interface to wait an additional tick before submitting the request to retrieve the entity.  However, other functions do appear to be available immediately.  Just depends on what you're trying to do. Thank you all for the help! 
  • Topics

×
×
  • Create New...

Important Information

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