Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8] My First Modding Experience


Recommended Posts

Now, my mistake - show where you make the spawnEntityInWorld for the item

 

@SubscribeEvent
public void onPlayerClickEvent(PlayerInteractEvent event) {
	if (event.action == Action.LEFT_CLICK_BLOCK) {

		Block block = event.world.getBlockState(event.pos).getBlock();

		if (event.entityPlayer.getCurrentEquippedItem() == null) {

			if (block == Blocks.grass && event.face == event.face.UP) {

				if (!event.world.isRemote) {

					if (checkIfUnderLeaves(event)) {

						float chance = Level.rnumber.nextFloat();

						if (chance < 0.10f) {
							event.world.setBlockState(event.pos, Blocks.dirt.getDefaultState());
						}

						if (chance < 0.15f) {
							event.world.spawnEntityInWorld(new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), new ItemStack(Items.stick)));
						} else if (chance > 0.985) {
							event.world.spawnEntityInWorld(new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), new ItemStack(Level.sharpstick)));

						}
					}
				}
			}

 

I think its due to im spawning the item at the block location when the block is not destroyed, but unsure what to do about it since i do the same thing about logs where you can be any side so spawning on top wont work

Link to post
Share on other sites
  • Replies 71
  • Created
  • Last Reply

Top Posters In This Topic

I have my rake working, however since it doesn't destroy any blocks it never calls item use when using it as a rake, I can manually damage the item stack easily using helditem.attemptDamageItem(1, Level.rnumber); but I cant find out how to manually destroy the item when this method breaks the item. Anyone help?

 

Thanks :)

Link to post
Share on other sites

Sorry had no progress yesterday, I have had some stuff happening so didn't have the time. But back to business! I still am having trouble manually doing a check to destroy my item as I damage it from an event handler as there is no onItemUse call but I can't figure out how to manually destroy the item, it just degrades to 0 then the bar starts to fade red once it gets into negative numbers.

 

Also how do I create and store player unique values? I am wanting to create a few 'skills' and 'levels' etc for things like mining, strength, agility etc.

 

Thanks for all your guys support, this forum has been an amazing help for me.

Link to post
Share on other sites
Also how do I create and store player unique values? I am wanting to create a few 'skills' and 'levels' etc for things like mining, strength, agility etc.

 

You'll want to use

[url=http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-forge-1-6-4-1-8-eventhandler-and]IExtendedEntityProperties[/url]

for that.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to post
Share on other sites

player.inventory.mainInventory[player.inventory.currentItem] = null;

Note: This should be done on server side, so you wll have to update client by settin update boolean to true.

 

player.addChatComponentMessage(new ChatComponentText("Message"));

1.7.10 is no longer supported by forge, you are on your own.

Link to post
Share on other sites

player.inventory.mainInventory[player.inventory.currentItem] = null;

Note: This should be done on server side, so you wll have to update client by settin update boolean to true.

 

player.addChatComponentMessage(new ChatComponentText("Message"));

 

thanks! if I create a new function but call that function through a isRemote check is that function only run on server side then?

 

Link to post
Share on other sites

player.inventory.mainInventory[player.inventory.currentItem] = null;

Note: This should be done on server side, so you wll have to update client by settin update boolean to true.

 

player.addChatComponentMessage(new ChatComponentText("Message"));

 

thanks! if I create a new function but call that function through a isRemote check is that function only run on server side then?

 

No. In a way, this is what makes @SideOnly different from isRemote(). You can use isRemote() to run a part of the method on a specified side, or choose to only run it on one side (yet the method exists on both sides, unlike @SideOnly).

 

This code has a block that is only called on the server. The method is called on both sides, but the block checks with side to execute on.

public void example(World world)
{

    System.out.println("This code is ran on both the client and the server (if the method is called that way I.E called on common)");

    if(!world.isRemote)
    {
        System.out.println("This code is ran only on the server.");
    }
}

 

You shouldn't really need to do this - it will make your method fully server side but the method will exist on both sides

public void example(World world)
{
    if(world.isRemote)
    {
        return;
    }
    System.out.println("You will only see this code displayed through the server in the console, yet the method exists on both sides."
}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to post
Share on other sites

player.inventory.mainInventory[player.inventory.currentItem] = null;

Note: This should be done on server side, so you wll have to update client by settin update boolean to true.

 

player.addChatComponentMessage(new ChatComponentText("Message"));

 

thanks! if I create a new function but call that function through a isRemote check is that function only run on server side then?

 

No. In a way, this is what makes @SideOnly different from isRemote(). You can use isRemote() to run a part of the method on a specified side, or choose to only run it on one side (yet the method exists on both sides, unlike @SideOnly).

 

This code has a block that is only called on the server. The method is called on both sides, but the block checks with side to execute on.

public void example(World world)
{

    System.out.println("This code is ran on both the client and the server (if the method is called that way I.E called on common)");

    if(!world.isRemote)
    {
        System.out.println("This code is ran only on the server.");
    }
}

 

You shouldn't really need to do this - it will make your method fully server side but the method will exist on both sides

public void example(World world)
{
    if(world.isRemote)
    {
        return;
    }
    System.out.println("You will only see this code displayed through the server in the console, yet the method exists on both sides."
}

 

Yes I know it will also be compiled on client side but will it only RUN on server side if I do this?

 

public void example(World world)
{
    if(world.isRemote)
    {
        example2();
    }
    System.out.println("You will only see this code displayed through the server in the console, yet the method exists on both sides."
}

public void example2() {
    System.out.println("This will only run on server?");
}

Link to post
Share on other sites

Really happy today, I decided to try and add a custom sound of my tools breaking, since again I have to set damage, set to null etc manually I also need to manually play a sound, so I downloaded one from a royalty free website and very first try, WORKED PERFECTLY. Really rare when that happens but when it does god its a wave of ecstasy (I really need a life).

 

PS: should damaging tools be done server side only?

Link to post
Share on other sites

Hey all, I am looking for a partner developer to help develop this mod :) obviously I can't pay as it is a home project / non-profit mod etc, however I will DEFINITELY give you all the credit you deserve even if you don't ask for it.

 

If you want to help in any way with the live development on my mod add me on skype 'statphantom' or post here :) thanks.

Link to post
Share on other sites

Hey everyone, thanks for the support so far. Question does onBlockDestroyedEvent(HarvestDropsEvent event)  called on every block destroyed? e.g. creeper explosions, quarry, etc?

 

also, how hard is it to add stuff to world gen? I would like to add some fibrous plants such as Jute etc. just wondering if it is something I could do soon or if it's really hard something I should do much later.

Link to post
Share on other sites
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.




  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • don't use this in separate classes, use the EventBusSubscriber annotation instead https://mcforge.readthedocs.io/en/latest/events/intro/#events
    • Im playing with MultiMC. I get to the "Loading world, Bulding Terrain..." screen and then it goes to minecraft dindn't respond. I've been at this for two hour now. I can't find any articles that deal with this error. I also have OptiFine installed, I tried deleting the options text file and restarting but still no luck. I dunno which information is important so I'll post the full log. ---- Minecraft Crash Report ---- WARNING: coremods are present:   LucraftCoreCoreMod (LucraftCore-1.12.2-2.4.16.jar)   MalisisCorePlugin (malisiscore-1.12.2-6.5.1.jar) Contact their authors BEFORE contacting forge // My bad. Time: 7/23/21 5:25 PM Description: Ticking player java.lang.NoSuchMethodError: lucraft.mods.lucraftcore.superpowers.abilities.Ability.getCurrentPlayerAbilities(Lnet/minecraft/entity/player/EntityPlayer;)Ljava/util/List;     at lucraft.mods.speedsterheroes.abilities.AbilityPhasing$EventHandler.onLivingUpdate(AbilityPhasing.java:82)     at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_54_EventHandler_onLivingUpdate_LivingUpdateEvent.invoke(.dynamic)     at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)     at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)     at net.minecraftforge.common.ForgeHooks.onLivingUpdate(ForgeHooks.java:581)     at net.minecraft.entity.EntityLivingBase.func_70071_h_(EntityLivingBase.java:2095)     at net.minecraft.entity.player.EntityPlayer.func_70071_h_(EntityPlayer.java:234)     at net.minecraft.entity.player.EntityPlayerMP.func_71127_g(EntityPlayerMP.java:382)     at net.minecraft.network.NetHandlerPlayServer.func_73660_a(NetHandlerPlayServer.java:173)     at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.func_73660_a(NetworkDispatcher.java:209)     at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:285)     at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:180)     at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:790)     at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)     at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:279)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)     at java.lang.Thread.run(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Server thread Stacktrace:     at lucraft.mods.speedsterheroes.abilities.AbilityPhasing$EventHandler.onLivingUpdate(AbilityPhasing.java:82)     at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_54_EventHandler_onLivingUpdate_LivingUpdateEvent.invoke(.dynamic)     at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)     at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)     at net.minecraftforge.common.ForgeHooks.onLivingUpdate(ForgeHooks.java:581)     at net.minecraft.entity.EntityLivingBase.func_70071_h_(EntityLivingBase.java:2095)     at net.minecraft.entity.player.EntityPlayer.func_70071_h_(EntityPlayer.java:234) -- Player being ticked -- Details:     Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)     Entity ID: 1844     Entity Name: RedcreeperYT_     Entity's Exact location: 453.50, 4.00, 91.50     Entity's Block location: World: (453,4,91), Chunk: (at 5,0,11 in 28,5; contains blocks 448,0,80 to 463,255,95), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)     Entity's Momentum: 0.00, 0.00, 0.00     Entity's Passengers: []     Entity's Vehicle: ~~ERROR~~ NullPointerException: null Stacktrace:     at net.minecraft.entity.player.EntityPlayerMP.func_71127_g(EntityPlayerMP.java:382)     at net.minecraft.network.NetHandlerPlayServer.func_73660_a(NetHandlerPlayServer.java:173)     at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.func_73660_a(NetworkDispatcher.java:209)     at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:285) -- Ticking connection -- Details:     Connection: net.minecraft.network.NetworkManager@29c7e996 Stacktrace:     at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:180)     at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:790)     at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668)     at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:279)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)     at java.lang.Thread.run(Unknown Source) -- System Details -- Details:     Minecraft Version: 1.12.2     Operating System: Windows 10 (amd64) version 10.0     Java Version: 1.8.0_291, Oracle Corporation     Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation     Memory: 1306579696 bytes (1246 MB) / 2693267456 bytes (2568 MB) up to 3817865216 bytes (3641 MB)     JVM Flags: 3 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xms512m -Xmx4096m     IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0     FML: MCP 9.42 Powered by Forge 14.23.5.2855 Optifine OptiFine_1.12.2_HD_U_G6_pre1 19 mods loaded, 19 mods active     States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored     | State  | ID              | Version               | Source                                   | Signature                                |     |:------ |:--------------- |:--------------------- |:---------------------------------------- |:---------------------------------------- |     | LCHIJA | minecraft       | 1.12.2                | minecraft.jar                            | None                                     |     | LCHIJA | mcp             | 9.42                  | minecraft.jar                            | None                                     |     | LCHIJA | FML             | 8.0.99.99             | forge-1.12.2-14.23.5.2855-universal.jar  | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LCHIJA | forge           | 14.23.5.2855          | forge-1.12.2-14.23.5.2855-universal.jar  | e3c3d50c7c986df74c645c0ac54639741c90a557 |     | LCHIJA | securitycraft   | v1.8.22.2             | [1.12.2]+SecurityCraft+v1.8.22.2.jar     | None                                     |     | LCHIJA | customspawner   | 3.11.4                | Custom-Mob-Spawner-Mod-1.12.2.jar        | None                                     |     | LCHIJA | ptrmodellib     | 1.0.4                 | PTRLib-1.0.4.jar                         | None                                     |     | LCHIJA | props           | 2.6.3                 | Decocraft-2.6.3_1.12.2.jar               | None                                     |     | LCHIJA | jei             | 4.16.1.302            | jei_1.12.2-4.16.1.302.jar                | None                                     |     | LCHIJA | speedsterheroes | 1.12.2-2.0.7          | Quicksilver-Mod-1.12.2.jar               | None                                     |     | LCHIJA | lucraftcore     | 1.12.2-2.4.16         | LucraftCore-1.12.2-2.4.16.jar            | None                                     |     | LCHIJA | malisiscore     | 1.12.2-6.5.1-SNAPSHOT | malisiscore-1.12.2-6.5.1.jar             | None                                     |     | LCHIJA | malisisdoors    | 1.12.2-7.3.0          | malisisdoors-1.12.2-7.3.0.jar            | None                                     |     | LCHIJA | mocreatures     | 12.0.5                | Mo-Creatures-Mod-1.12.2.jar              | None                                     |     | LCHIJA | movingelevators | 1.2.34                | movingelevators-1.2.34-mc1.12.jar        | None                                     |     | LCHIJA | scp             | 2.4.0                 | SCP_Lockdown-1.12.2-2.4.0-hotfix.jar     | None                                     |     | LCHIJA | scple           | 1.0                   | scple-1.0.jar                            | None                                     |     | LCHIJA | thejungle       | 1.2006.1222           | Welcome-to-the-Jungle-Mod-1.12.2.jar     | None                                     |     | LCHIJA | worldedit       | 6.1.10                | worldedit-forge-mc1.12.2-6.1.10-dist.jar | None                                     |     Loaded coremods (and transformers):  LucraftCoreCoreMod (LucraftCore-1.12.2-2.4.16.jar)   lucraft.mods.lucraftcore.core.LCTransformer MalisisCorePlugin (malisiscore-1.12.2-6.5.1.jar)        GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.     Profiler Position: N/A (disabled)     Player Count: 1 / 8; [EntityPlayerMP['RedcreeperYT_'/1844, l='New World', x=453.50, y=4.00, z=91.50]]     Type: Integrated Server (map_client.txt)     Is Modded: Definitely; Client brand changed to 'fml,forge'     OptiFine Version: OptiFine_1.12.2_HD_U_G6_pre1     OptiFine Build: 20210323-161358     Render Distance Chunks: 8     Mipmaps: 4     Anisotropic Filtering: 1     Antialiasing: 0     Multitexture: false     Shaders: null     OpenGlVersion: 4.6.0 NVIDIA 466.27     OpenGlRenderer: NVIDIA GeForce GTX 1650 SUPER/PCIe/SSE2     OpenGlVendor: NVIDIA Corporation     CpuCount: 4
    • Goal: when Entity attacks player, it dies. Code: public class EventHandler { @SubscribeEvent public static void onLivingAttackEvent(LivingAttackEvent event) { if (event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == ItemInit.LAVA_HELMET.get() && event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ItemInit.LAVA_CHEST.get() && event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.LEGS).getItem() == ItemInit.LAVA_LEGGINGS.get() && event.getEntityLiving().getItemStackFromSlot(EquipmentSlotType.FEET).getItem() == ItemInit.LAVA_BOOTS.get()) { if (event.getSource().getTrueSource().getEntity() instanceof MobEntity) { event.getSource().getTrueSource().getEntity().onKillCommand(); } } } } And: @Mod(LavaArmor.MODID) public class LavaArmor { public static final String MODID = "lavaarmor"; public LavaArmor() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); ItemInit.ITEMS.register(bus); MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(EventHandler.class); } @SuppressWarnings("deprecation") private void setup(final FMLCommonSetupEvent event) { } } I think I've done everything I've needed. Moreover, the exact same code works fine in my another project. What's wrong?
    • The same question. The only thing I could find is CommentedFileConfig.preserveInsertionOrder(), but either it doesn't work, or I'm doing something wrong...
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.