Jump to content

How to override base minecraft code


tminor1

Recommended Posts

Hi so before I started using forge to make my mod pack I used MCP Which allowed me to make mods by base editing. However my mods would only work for the sever and I could not do all the things I wanted to do. So I started using forge so I could do more and make my mods work on both server and client. The thing is now I need to know how I can override base minecraft code with forge so I can include my old mods in to my new mod pack. Some of my mods include making glass drop its self when destroyed with out a silktouch pickaxe, making a boat drop 5 planks if it smashes in to something that causes it to break so you can re-make i with ease, making some of the mobs drop more Xp when killed, making some of the command names shorter for faster typing them, and allowing people in survival mode to fly. How can I override base minecraft code so I can bring my old mods to work with forge?

Link to comment
Share on other sites

In my experiences I've seen other mods that create their own versions of those things. For example "MyBoat" which extends the vanilla class and/or whatnot except that it drops as you desire. There are implications about how it gets crafted and so forth, I guess.

 

Alternatively, I just started playing with it, you can investigate "MinecraftForge.EVENT_BUS" and perhaps there's an event you can listen for and, to it, respond as you desire when the situation merits.

 

Were I you I would steer clear of overriding the base Minecraft code since who knows when/if/what will change from release to release. IMO, that's not the way to go and is, in fact, what Forge helps establish (that is, a means to make mods work release to release as much as possible with less impact).

 

I am not sure if that helps except to provide some avenues to explore, and maybe others have better ideas, too :)

Link to comment
Share on other sites

All the mods you had are possible to easily recreate in forge without base edits.

 

Ok then but how would I go about doing that? So lets start with the glass drop mod how can I tell minecraft to make glass drop itself when mined with out silk touch? Also, how would I make obsidian quicker to mine?

Link to comment
Share on other sites

For glass you'd look at BlockEvent.BreakEvent. Just do your logic there.

 

For obsidian there's PlayedEvent.BreakSpeed or something like that.

 

I suggest you read on forge events.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Link to comment
Share on other sites

Ok. So to do that would I go in my main mod class and do this?

 

@EventHandler

public void (BlockEvent.BreakEvent event)

 

If so then what would I do? And where is it that I can read about forge events?

 

No, the @EventHandler is for certain types of events, but not the BreakEvent.  You can read more to understand better my tutorial here: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

If you're searching for copy->paste code, you won't find it here

 

If there's been a plethora of links posted so far, if you can't figure it out from them, you need to learn java some more before you attempt making mods.

 

Use an IDE (like Eclipse), and try some code out for yourself.

 

No-one here will give you code to paste, as we aren't making the mods for you.

 

Link to comment
Share on other sites

If you're searching for copy->paste code, you won't find it here

 

If there's been a plethora of links posted so far, if you can't figure it out from them, you need to learn java some more before you attempt making mods.

 

Use an IDE (like Eclipse), and try some code out for yourself.

 

No-one here will give you code to paste, as we aren't making the mods for you.

It's pretty obvious he knows how to mod since he used MCP to make base edits before forge was the standard... He wants to know how to use the event... telling someone to go find it on their own isn't helpful at all... it would be more productive if you would just take the few minutes to explain it to him since I assume you know how to do it...

Link to comment
Share on other sites

If you're searching for copy->paste code, you won't find it here

 

If there's been a plethora of links posted so far, if you can't figure it out from them, you need to learn java some more before you attempt making mods.

 

Use an IDE (like Eclipse), and try some code out for yourself.

 

No-one here will give you code to paste, as we aren't making the mods for you.

It's pretty obvious he knows how to mod since he used MCP to make base edits before forge was the standard... He wants to know how to use the event... telling someone to go find it on their own isn't helpful at all... it would be more productive if you would just take the few minutes to explain it to him since I assume you know how to do it...

 

But we literally gave him 5 links on how to use events, all of which have plenty of examples!  I already took the time to write several pages of explanation in my tutorial linked above so I don't have to write it over and over again each time someone asks the same questions.

 

Basically we're saying "we've already written you pages and pages of explanation".  Go read it and try something.  Then we'll be willing to help.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Ok well I tried to make something work but can't figure it out.

 

package net.Cristalore.mod;

import net.minecraftforge.event.world.BlockEvent;

public class glassDrop {

@ForgeSubscribe
public void blockBreak(BlockEvent.BreakEvent event)
{

}

 

It says that @ForgeSubscribe cannot be resolved to a type. I am trying to make the glassDrop mod.

Link to comment
Share on other sites

Would something like this work? I tried to do this and minecraft crashed. Am I on the right track or have I just completely messed up?

 

package net.Cristalore.mod;

 

import java.util.Random;

 

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

import net.minecraft.block.BlockGlass;

import net.minecraft.block.material.Material;

import net.minecraft.init.Blocks;

import net.minecraft.item.Item;

import net.minecraftforge.event.world.BlockEvent;

 

public class glassDrop extends BlockGlass {

 

public glassDrop(Material p_i45408_1_, boolean p_i45408_2_) {

super(p_i45408_1_, p_i45408_2_);

// TODO Auto-generated constructor stub

}

 

@SubscribeEvent

public void blockBreak(BlockEvent.BreakEvent event)

{

 

}

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)

    {

        return Item.getItemFromBlock(Blocks.glass);

    }

 

}

 

 

Link to comment
Share on other sites

Well the break block event handler method shouldn't be in your actual block, but instead probably best to make an event handler class and put it in there.  Because the break block event will be fired for EVERY block that breaks.  So what you need to do in that method is check which block got broken and then proceed from there.

 

The event handling code there shouldn't crash things (it doesn't even do anything).  So it must be something else. What is the crash log say?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Well as for making a class file for the event that is what I was trying to do and the reason I have the part of the code for the glass in there is because I didn't know what I needed to do to make it check to see if you destroyed a glass block and there for drop a glass block. as for the crash report here it is.

 

---- Minecraft Crash Report ----

// Don't be sad, have a hug! <3

 

Time: 8/25/14 3:49 PM

Description: Initializing game

 

java.lang.NullPointerException: Initializing game

at net.minecraft.block.Block.<init>(Block.java:462)

at net.minecraft.block.BlockBreakable.<init>(BlockBreakable.java:19)

at net.minecraft.block.BlockGlass.<init>(BlockGlass.java:15)

at net.Cristalore.mod.glassDrop.<init>(glassDrop.java:15)

at net.Cristalore.mod.cristalore.<init>(cristalore.java:34)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at java.lang.Class.newInstance(Unknown Source)

at cpw.mods.fml.common.ILanguageAdapter$JavaAdapter.getNewInstance(ILanguageAdapter.java:173)

at cpw.mods.fml.common.FMLModContainer.constructMod(FMLModContainer.java:486)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

at com.google.common.eventbus.EventBus.post(EventBus.java:267)

at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208)

at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

at com.google.common.eventbus.EventBus.post(EventBus.java:267)

at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118)

at cpw.mods.fml.common.Loader.loadMods(Loader.java:491)

at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:204)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:522)

at net.minecraft.client.Minecraft.run(Minecraft.java:892)

at net.minecraft.client.main.Main.main(Main.java:112)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at net.minecraft.block.Block.<init>(Block.java:462)

at net.minecraft.block.BlockBreakable.<init>(BlockBreakable.java:19)

at net.minecraft.block.BlockGlass.<init>(BlockGlass.java:15)

at net.Cristalore.mod.glassDrop.<init>(glassDrop.java:15)

at net.Cristalore.mod.cristalore.<init>(cristalore.java:34)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at java.lang.Class.newInstance(Unknown Source)

at cpw.mods.fml.common.ILanguageAdapter$JavaAdapter.getNewInstance(ILanguageAdapter.java:173)

at cpw.mods.fml.common.FMLModContainer.constructMod(FMLModContainer.java:486)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

at com.google.common.eventbus.EventBus.post(EventBus.java:267)

at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:208)

at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:187)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:47)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

at com.google.common.eventbus.EventBus.post(EventBus.java:267)

at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:118)

at cpw.mods.fml.common.Loader.loadMods(Loader.java:491)

at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:204)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:522)

 

-- Initialization --

Details:

Stacktrace:

at net.minecraft.client.Minecraft.run(Minecraft.java:892)

at net.minecraft.client.main.Main.main(Main.java:112)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

 

-- System Details --

Details:

Minecraft Version: 1.7.2

Operating System: Windows 7 (amd64) version 6.1

Java Version: 1.7.0_65, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 866426944 bytes (826 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 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: 0, tallocated: 0

FML: MCP v9.03 FML v7.2.217.1147 Minecraft Forge 10.12.2.1147 6 mods loaded, 6 mods active

mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed

FML{7.2.217.1147} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.2.1147.jar) Unloaded->Constructed

Forge{10.12.2.1147} [Minecraft Forge] (forgeSrc-1.7.2-10.12.2.1147.jar) Unloaded->Constructed

classicBlocks{v1.0} [ClassicBlocks] (bin) Unloaded->Constructed

cristalore{beta v1.0} [Cristalores] (bin) Unloaded->Errored

sandItems{v1.0} [sandStoneItems] (bin) Unloaded->Constructed

Launched Version: 1.6

LWJGL: 2.9.0

OpenGL: Intel® HD Graphics GL version 3.1.0 - Build 8.15.10.2752, Intel

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs: []

Current Language: ~~ERROR~~ NullPointerException: null

Profiler Position: N/A (disabled)

Vec3 Pool Size: ~~ERROR~~ NullPointerException: null

Anisotropic Filtering: Off (1)

 

Link to comment
Share on other sites

Hey by any chance is this doing anything?

package net.Cristalore.mod;

import java.util.Random;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.BlockGlass;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraftforge.event.world.BlockEvent;

public class glassDrop  {

@SubscribeEvent
public void blockBreak(BlockEvent.BreakEvent event)
{
	if (Blocks.glass != null);
}
	public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
    {
        return Item.getItemFromBlock(Blocks.glass);
    }


}

Link to comment
Share on other sites

That won't work. Try this:

 

@SubscribeEvent
public void glassDrop(BreakEvent evt){

	if (evt.block == Blocks.glass){
		EntityItem item = new EntityItem(evt.world, evt.x, evt.y, evt.z, new ItemStack(Item.getItemFromBlock(Blocks.glass)));
		EntityPlayer player = evt.getPlayer();

		if(!player.capabilities.isCreativeMode) evt.world.spawnEntityInWorld(item);
	}

}

 

That just spawns a glass item entity when a glass block is broken. Unfortunately, it would drop 2 items when broken with Silk Touch. There is probably a way to fix that with player.getHeldItem().

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Link to comment
Share on other sites

That won't work. Try this:

 

@SubscribeEvent
public void glassDrop(BreakEvent evt){

	if (evt.block == Blocks.glass){
		EntityItem item = new EntityItem(evt.world, evt.x, evt.y, evt.z, new ItemStack(Item.getItemFromBlock(Blocks.glass)));
		EntityPlayer player = evt.getPlayer();

		if(!player.capabilities.isCreativeMode) evt.world.spawnEntityInWorld(item);
	}

}

 

That just spawns a glass item entity when a glass block is broken. Unfortunately, it would drop 2 items when broken with Silk Touch. There is probably a way to fix that with player.getHeldItem().

 

Thanks. But is there a way to not make the glass item go straight for the player causing the player to instantly pick it up and not have it fall to the ground like normal. Because that is what is happening I mine the glass block and the glass item spawns and goes to the player. If I had to I would just go with that, but I would like it to fall to the ground like normal and the player has to walk over to pick it up not it come to the player. Also, how would I make this work for if a boat crashes and breaks so I can make it drop 5 planks?

Link to comment
Share on other sites

Hey now that I have my glassDrops working I was working on more of my mods and one of things I want to do is every time a cow dies it will spawn 1 leather. I got a start on it but I am having some trouble. Can some one help me with this?

package net.glassDrops.mod;

import java.util.Random;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.BlockGlass;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;


public class leatherDrop  {

@SubscribeEvent
public void giveLeather(LivingDropsEvent evt){

	if (evt.entity == Entity.Cow){
		EntityItem item = new EntityItem(evt.world, evt.x, evt.y, evt.z, new ItemStack(Items.leather));
		EntityPlayer player = evt.getPlayer();

		if(!player.capabilities.isCreativeMode) evt.world.spawnEntityInWorld(item);
	}

}}

Link to comment
Share on other sites

Hey now that I have my glassDrops working I was working on more of my mods and one of things I want to do is every time a cow dies it will spawn 1 leather. I got a start on it but I am having some trouble. Can some one help me with this?

package net.glassDrops.mod;

import java.util.Random;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.block.BlockGlass;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;


public class leatherDrop  {

@SubscribeEvent
public void giveLeather(LivingDropsEvent evt){

	if (evt.entity == Entity.Cow){
		EntityItem item = new EntityItem(evt.world, evt.x, evt.y, evt.z, new ItemStack(Items.leather));
		EntityPlayer player = evt.getPlayer();

		if(!player.capabilities.isCreativeMode) evt.world.spawnEntityInWorld(item);
	}

}}

 

You have to check with instanceof, since the entity is an instance of the EntityCow

something like that if (evt.entity instanceof EntityCow){

evt.drops is a list of all the drops, so if u want the cow to ONLY spawn 1 leather, u can say evt.drops.clear();

and then add the leather it back in

evt.drops.add(new EntityItem(evt.entity.worldObj, evt.entity.posX, evt.entity.posY, evt.entity.posZ, new ItemStack(Items.leather)));

Link to comment
Share on other sites

That won't work. Try this:

 

@SubscribeEvent
public void glassDrop(BreakEvent evt){

	if (evt.block == Blocks.glass){
		EntityItem item = new EntityItem(evt.world, evt.x, evt.y, evt.z, new ItemStack(Item.getItemFromBlock(Blocks.glass)));
		EntityPlayer player = evt.getPlayer();

		if(!player.capabilities.isCreativeMode) evt.world.spawnEntityInWorld(item);
	}

}

 

That just spawns a glass item entity when a glass block is broken. Unfortunately, it would drop 2 items when broken with Silk Touch. There is probably a way to fix that with player.getHeldItem().

 

Thanks. But is there a way to not make the glass item go straight for the player causing the player to instantly pick it up and not have it fall to the ground like normal. Because that is what is happening I mine the glass block and the glass item spawns and goes to the player. If I had to I would just go with that, but I would like it to fall to the ground like normal and the player has to walk over to pick it up not it come to the player. Also, how would I make this work for if a boat crashes and breaks so I can make it drop 5 planks?

To the instant pick up, I think u just have to set item.delayBeforeCanPickup to any value u wish ^^

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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