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

Check the distance from a block


IgazHarcos
 Share

Recommended Posts

Hello!

 

I begin developing a Minecraft mod, where you can find lead and uranium ores. When you touch the uranium (after you mine it), it applies poison effect on you, but i want a similar effect, but only with the ores:

 

When I get close, i want it apply poison on player. How to do  it? I tried similar things (google), but nothing works. thanks for any help!

Link to comment
Share on other sites

I try to register the event:

 

 

    @EventHandler

    public void init(FMLInitializationEvent e) {

        this.proxy.init(e);

    // the majority of events use the MinecraftForge event bus:

        MinecraftForge.EVENT_BUS.register(new CheckTick());

    }

 

 

 

My Code in Player Tick so far:

 

 

package com.example.examplemod;

 

import com.example.examplemod.blocks.ModBlocks;

 

import net.minecraft.block.Block;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.util.BlockPos;

import net.minecraft.world.World;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

// RenderTick is client side only, so we can place the SideOnly annotation here if we want:

@SideOnly(Side.CLIENT)

public class CheckTick {

//we only need one method here, and you can name it whatever you want, but

//I like to name it according to the tick to which I am listening:

@SubscribeEvent

public void onCheckTick(PlayerTickEvent event, Entity entity, World world) {

EntityPlayer player = (EntityPlayer) entity;

//now you can do whatever you want during each render tick, such as rotate the player's view

Block checkblock=world.getBlockState(new BlockPos(player.posX,player.posY+1,player.posZ)).getBlock();

 

if (checkblock == ModBlocks.tutorialBlock2){

player.addPotionEffect((new PotionEffect(Potion.poison.getId(), 100, 5)));

}

}

}

 

 

 

I try to get the block under the player.Y, and check is that my custom ore. Is this right?

Link to comment
Share on other sites

Thanks for your advice, but I think my problem is not related to lack of knowledge of java, but lack of knowledge of modding. I do all the beginner tutorial (from item create to structures), but now I try to do something that I never tried before, and maybe never will, and there is not a single tutorial for this. Not to mention that nearly all tutorial outdated (pre-1.8).  You help me a lot - and thank you for that :)

Link to comment
Share on other sites

If you knew Java this would be your thought process:

 

  1. [*]Me: "You get world and player from the event".

[*]You: Ok, let me check that. Ok, my event is "PlayerTickEvent". Let me look at that class. Oh look, there is is:

public final EntityPlayer player;

- that's probably what he meant.

[*]Problem solved!

[*]?

[*]Profit.

Link to comment
Share on other sites

I knew java, but for a really short time, and just because I want develop mod, I not say anithing else. But now I look more into the minecraft classes and find every solution (I not use eclipse too much before too), and now i finish the mod. After all, relly really thanks for your patience and help to finish the mod! :)

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Hi! I know that the get() functions for mod items is sth. like RegistrationClass.ITEM.get(), but what is the equivalent function for vanilla items?
    • no, the way he use it's the way to go
    • Minecraft 1.16 requires java 8-15, you currently using java 16, downgrade your java to 8-15 and the problem should be fixed.
    • Hi So Im trying to set up a Server for 1.16.4 now but when I go to launch it doesn't work, Im using the Life in the Village 2 server pack thats already pre-made but it still wont launch no matter what I try. If I can get some help that would be great thanks. D:\Modded Mc\LITV2-Serverpack-1.28a\LITV2-Serverpack-1.28a>java -Xmx4G -jar forge-1.16.5-36.2.4.jar nogui 2021-11-29 13:43:08,050 main WARN Advanced terminal features are not available in this environment [13:43:08] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.4, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [13:43:08] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 16.0.2 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0x4de5031f) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0x4de5031f at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:41) at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95) at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:41) at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47) at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62) at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55) at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) D:\Modded Mc\LITV2-Serverpack-1.28a\LITV2-Serverpack-1.28a>pause Press any key to continue . . .  
    • Still waiting on the issue.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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