Jump to content

[1.15.1] Holding an item and left click in air


Recommended Posts

Posted (edited)

I want to make an item that can shoot a fireball when left click, but I can't figure out how to make it.

Here is the code.

Please tell me in detail what to do.

package arknights.item;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.potion.Effect;
import net.minecraft.potion.EffectInstance;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.Pair;

import java.util.*;

import static net.minecraft.potion.Effects.*;

public class PureOriginiums extends Item {
    List<Pair<EffectInstance, Float>> effects = new ArrayList<>();
    String playerName = null;

    public PureOriginiums(Properties p_i48476_1_) {
        super(p_i48476_1_);
    }
    
    @Override
    public UseAction getUseAction(ItemStack stack) {
        return UseAction.EAT;
    }

    @Override
    public int getUseDuration(ItemStack stack) {
        return 32;
    }

    //public static final Food PUREORIGINIUMS = (new Food.Builder()).hunger(10).saturation(0.3F).effect(new EffectInstance(Effects.SPEED, 400, 255), 1.0F).build();
    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        this.effects.clear();
        this.playerName = playerIn.getScoreboardName();
        ItemStack itemstack = playerIn.getHeldItem(handIn);
        playerIn.setActiveHand(handIn);
        return ActionResult.func_226249_b_(itemstack);
    }

    @Override
    public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) {
        //String playerName = entityLiving.getScoreboardName()
        int effectId = (int)(1+Math.random()*(10-1+1));
        return onOriginniumsEaten(worldIn, stack, (PlayerEntity) entityLiving);
    }

    public ItemStack onOriginniumsEaten(World p_213357_1_, ItemStack p_213357_2_, PlayerEntity playerEntity) {
        playerEntity.getFoodStats().addStats(20,20);
        playerEntity.addStat(Stats.ITEM_USED.get(p_213357_2_.getItem()));
        p_213357_1_.playSound(null, playerEntity.func_226277_ct_(), playerEntity.func_226278_cu_(), playerEntity.func_226281_cx_(), playerEntity.getEatSound(p_213357_2_), SoundCategory.NEUTRAL, 1.0F, 1.0F + (p_213357_1_.rand.nextFloat() - p_213357_1_.rand.nextFloat()) * 0.4F);
        this.effectsList();
        applyFoodEffects(p_213357_2_, p_213357_1_, playerEntity);
        //playerEntity.setHealth(20.0F);
        //playerEntity.addPotionEffect(new EffectInstance(Effects.SPEED, 600, 10));
        if ( !(playerEntity).abilities.isCreativeMode) {
            p_213357_2_.shrink(1);
        }
        return p_213357_2_;
    }

    private void applyFoodEffects(ItemStack p_213349_1_, World p_213349_2_, LivingEntity p_213349_3_) {
        for(Pair<EffectInstance, Float> pair : this.effects) {
            if (!p_213349_2_.isRemote && pair.getLeft() != null && p_213349_2_.rand.nextFloat() < pair.getRight()) {
                p_213349_3_.addPotionEffect(new EffectInstance(pair.getLeft()));
            }
        }
    }

    void effectsList(){
        if( /*this.playerName == "Dev" || */this.playerName.regionMatches(0, "Dr", 0, 2)){
            addEffectToList(SPEED, 600, 10);
            addEffectToList(HASTE, 600, 255);
            addEffectToList(STRENGTH, 200, 10);
            addEffectToList(JUMP_BOOST, 600, 2);
            addEffectToList(RESISTANCE, 600, 3);
            addEffectToList(FIRE_RESISTANCE, 600, 2);
            addEffectToList(WATER_BREATHING, 600, 1);
            addEffectToList(NIGHT_VISION, 600, 1);
            addEffectToList(DOLPHINS_GRACE, 600, 1);
        } else {
            int random1,random2,random3;
            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            random3 = (int)(1+Math.random()*10);
            switch(random1){
                case 1:
                    addEffectToList(SPEED, random2, random3);
                    break;
                case 2:
                    addEffectToList(SLOWNESS, random2, random3);
                    break;default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            random3 = (int)(1+Math.random()*10);
            switch(random1){
                case 1:
                    addEffectToList(HASTE, random2, random3);
                    break;
                case 2:
                    addEffectToList(MINING_FATIGUE, random2, random3);
                    break;default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            random3 = (int)(1+Math.random()*2);
            switch(random1){
                case 1:
                    addEffectToList(STRENGTH, random2, random3);
                    break;
                case 2:
                    addEffectToList(WEAKNESS, random2, random3);
                    break;default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            random3 = (int)(1+Math.random()*5);
            switch(random1){
                case 1:
                    addEffectToList(JUMP_BOOST, random2, random3);
                    break;
                    default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            //random3 = (int)(1+Math.random()*10);
            switch(random1){
                case 1:
                    addEffectToList(NAUSEA, random2, 2);
                    break;
                default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            random3 = (int)(1+Math.random()*3);
            switch(random1){
                case 1:
                    addEffectToList(RESISTANCE, random2, random3);
                    break;
                default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            //random3 = (int)(1+Math.random()*10);
            switch(random1){
                case 1:
                    addEffectToList(FIRE_RESISTANCE, random2, 1);
                    break;
                default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            //random3 = (int)(1+Math.random()*10);
            switch(random1){
                case 1:
                    addEffectToList(WATER_BREATHING, random2, 1);
                    break;
                default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            //random3 = (int)(1+Math.random()*10);
            switch(random1){
                case 1:
                    addEffectToList(BLINDNESS, random2, 1);
                    break;
                case 2:
                    addEffectToList(NIGHT_VISION, random2, 1);
                    break;default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            //random3 = (int)(1+Math.random()*10);
            switch(random1){
                case 1:
                    addEffectToList(SLOW_FALLING, random2, 1);
                    break;
                default: break;
            }

            random1 = (int)(1+Math.random()*2);
            random2 = (int)(100+Math.random()*1000);
            //random3 = (int)(1+Math.random()*10);
            switch(random1){
                case 1:
                    addEffectToList(DOLPHINS_GRACE, random2, 1);
                    break;
                default: break;
            }

            addEffectToList(WITHER, 800, 2);
        }

    }

    void addEffectToList(Effect effect, int time, int level){
        this.effects.add(Pair.of(new EffectInstance(effect, time, level), 1.0F));
    }
}

Simple introduction to this item:

It can be eaten when right click just like common food, but when you left click, it will become a wand which can shoot fire ball.

If your player name begins with "Dr" you will get good effects, or you will get some random effects and you may probably die because of wither.

 

Thanks for your help : )

Edited by NGYF
Posted
  On 1/16/2020 at 10:40 AM, diesieben07 said:

You can use PlayerInteractEvent.LeftClickEmpty.

Expand  

Thanks for your help, but may I ask you to tell me how to use it in detail?

Actually I have read some posts about it in the forum and try to make an event handler.

 

Should I use PlayerInteractEvent.LeftClickEmpty in this way?

public class LeftClickEventHandler {
	@SubscribeEvent
	public ActionResult<ItemStack> leftClick(LeftClickEmpty event) {
		//spawn a fireball
	}

}

 

It is said that I should use pakets to notify the server. What should I do? I have read the forge documents, but I don't know what to do and I can't find any example in the forum. So could you please give me an example about it?

Posted
  On 1/17/2020 at 10:24 AM, diesieben07 said:

Yes, the empty left click is not automatically sent to the server, so you can only receive that event on the client.

To make it spawn entities, you need to send a packet to the server and then spawn the entity there.

Expand  

Thank you.

But I'm still a bit confused about handling packets.

There are two classes called MyMessage and EntityPlayerMP. I think I should replace EntityPlayerMP with my leftclick class.But if it is right, what does MyMessage refer to?

I will appreciate it if you can tell me how to handle packets properly.?

Posted
  On 1/17/2020 at 10:24 AM, diesieben07 said:

Yes, the empty left click is not automatically sent to the server, so you can only receive that event on the client.

To make it spawn entities, you need to send a packet to the server and then spawn the entity there.

Expand  

Sorry to bother you again.

I try to send packets to server when I left click the item, but it throws an error.

Here is the error:

  Reveal hidden contents

Here is my code:

  Reveal hidden contents

Please tell me how to fix it. Thanks.

Posted
  On 1/21/2020 at 5:24 PM, diesieben07 said:

Network channels must be registered during FMLCommonSetupEvent. Not at some random time during some random static initializer.

Expand  

Sorry...

There is still a strange problem...

 

I add this to my main class, and I think it work.

FMLJavaModLoadingContext.get().getModEventBus().addListener(PacketHandler::register);

But it still throws an error like this:

[08:57:50] [Server thread/ERROR] [ne.mi.fm.ne.si.IndexedMessageCodec/SIMPLENET]: Received empty payload on channel fml:handshake

 

The game will not exit, but there is nothing when I left click my item.

 

Maybe I make some stupid mistakes...

Posted (edited)
  On 1/22/2020 at 9:00 AM, diesieben07 said:

Show more of your code.

Expand  

ok.

Arknights.java

package arknights;

import arknights.network.PacketHandler;
import arknights.network.packets.LeftClickPacket;
import arknights.registry.BlockList;
import arknights.registry.ItemHandler;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.*;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.Collectors;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(Arknights.MODID)

public class Arknights
{
    public static final String MODID = "arknights";
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();

    public static final ItemGroup ARKNIGHTS = new ItemGroup("arknights") {
        @Override
        public ItemStack createIcon() {
            return new ItemStack(ItemHandler.PUREORIGINIUMS);
        }
    };

    //Registry Lists
    private static final BlockList BLOCKLIST = new BlockList();
    private static final ItemHandler ITEMLIST = new ItemHandler();

    //public static final Block ORIGINIUMS_ORE = new Block(Block.Properties.create(Material.GLASS).hardnessAndResistance(3.0F, 3.0F)).setRegistryName(MODID+":originiums_ore");
    //public static final BlockItem ORIGINIUMS_ORE_ITEM = (BlockItem) new BlockItem(ORIGINIUMS_ORE, new Item.Properties().group(ARKNIGHTS)).setRegistryName(MODID+":originiums_ore");

    //public static final Item PUREORIGINIUMS = new PureOriginiums(new Item.Properties().group(ARKNIGHTS)).setRegistryName(MODID+":pure_originiums");

    public Arknights() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(PacketHandler::register);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
        //PacketHandler.HANDLER.registerMessage(PacketHandler.index++, LeftClickPacket.class, LeftClickPacket::encode, LeftClickPacket::decode, LeftClickPacket.Handler::handle);
        // some preinit code
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        // do something that can only be done on the client
        LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
    }

    private void enqueueIMC(final InterModEnqueueEvent event)
    {
        // some example code to dispatch IMC to another mod
        InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
    }

    private void processIMC(final InterModProcessEvent event)
    {
        // some example code to receive and process InterModComms from other mods
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m->m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }
    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        // do something when the server starts
        LOGGER.info("HELLO from server starting");
    }

    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(modid = Arknights.MODID, bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            // register a new block here
            for(Block block : BLOCKLIST.blockList){
                blockRegistryEvent.getRegistry().register(block);
            }

            LOGGER.info("HELLO from Register Block");
        }

        @SubscribeEvent
        public static void onItemsRegistry(final RegistryEvent.Register<Item> itemRegisterEvent) {
            for(Item item : BLOCKLIST.blockItemsList){
                itemRegisterEvent.getRegistry().register(item);
            }
            //MinecraftForge.EVENT_BUS.addListener(ItemHandler::register);
            ItemHandler.register(itemRegisterEvent);
            /*
            for (Item item : ITEMLIST.itemList){
                itemRegisterEvent.getRegistry().register(item);
            }*/
        }
    }
}

 

Nothing has changed in other code.

Thanks.

Edited by NGYF
Posted
  On 1/22/2020 at 10:00 AM, diesieben07 said:

Then you are still registering your network channel in a static initializer.

Expand  

Maybe I need an example... The former code reference ProjectE, and it use the static initializer. And the documentation is static too.

I try to register it in a not static initializer (maybe in a wrong way), and it doesn't work. When I left click, nothing has happened.

 

By the way, the thrown error appears when I join the world, and when I delete the packet registry, it still appears. 

Here is the code:

PacketHandler.java


package arknights.network;

import arknights.network.packets.LeftClickPacket;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;

public final class PacketHandler {
    private static final String PROTOCOL_VERSION = Integer.toString(1);



    public SimpleChannel HANDLER = NetworkRegistry.newSimpleChannel(
            new ResourceLocation("corruption","main")
            ,() -> PROTOCOL_VERSION
            , PROTOCOL_VERSION::equals
            , PROTOCOL_VERSION::equals);

    int id = 0;
    public void register(){
        HANDLER.registerMessage(id++, LeftClickPacket.class, LeftClickPacket::encode, LeftClickPacket::decode, LeftClickPacket.Handler::handle);
    }
}

 

Arknights.java

Here is the whole class.

  Reveal hidden contents

I think there is something not so relevant, so I provide a simple one.

public class Arknights
{
    //something

    //code I add
    public static final PacketHandler PACKETHANDLER = new PacketHandler();

    public Arknights() {
        // Register methods for modloading
       
        //code I add
        PACKETHANDLER.register();

        // Register ourselves for server and other game events we are interested in
    }

 

BaseItem.java

package arknights.item;

import arknights.Arknights;
import arknights.network.PacketHandler;
import arknights.network.packets.LeftClickPacket;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;

public class BaseItem extends Item {

    public BaseItem(Properties p_i48487_1_) {
        super(p_i48487_1_);
        MinecraftForge.EVENT_BUS.addListener(this::emptyLeftClick);
    }

    public void emptyLeftClick(PlayerInteractEvent.LeftClickEmpty event){
        Arknights.PACKETHANDLER.HANDLER.sendToServer(new LeftClickPacket());
    }

    public void leftClick(LivingEntity livingEntity, World worldIn, ItemStack stack){

    }
}

 

Posted
  On 1/22/2020 at 11:00 AM, diesieben07 said:

I don't know how this is so hard to understand.

The registration of your network channel must happen in FMLCommonSetupEvent. You are still not doing that. Now you are calling newSimpleChannel from the constructor of PacketHandler, which you call from the constructor of Arknights. This is not in FMLCommonSetupEvent.

Expand  
private void setup(final FMLCommonSetupEvent event)
{
    PacketHandler.register();
}

Should I do it just like this? (The method is in Arknights.java)

I'm new to modding...

And the problem becomes more and more complicated...

I test the mod with out packet handler but it still tells me "Received empty payload on channel fml:handshake".

I also test the method leftclick in my item. I add "System.out.print("A"); " to the method, and when I left click, an "A" prints to the terminal. Does it means the packet is succesfully sent? If so, why it doesn't spawn an arrow? Could you tell me how to spawn entities properly?

 

Posted
  On 1/22/2020 at 11:25 AM, diesieben07 said:

Post the complete debug.log.

 

How would it? Printing "A" to the console does not tell you anything about the state of your packet.

Expand  

I upload the log.

Here is one part of the log, it appears when I join the game. It starts at line 16620.

[22一月2020 19:05:17.222] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: Dev加入了游戏
[22一月2020 19:05:17.344] [Render thread/DEBUG] [net.minecraftforge.fml.network.FMLLoginWrapper/FMLHANDSHAKE]: Recieved login wrapper packet event for channel fml:handshake with index -1
[22一月2020 19:05:17.344] [Render thread/ERROR] [net.minecraftforge.fml.network.simple.IndexedMessageCodec/SIMPLENET]: Received empty payload on channel fml:handshake
[22一月2020 19:05:18.760] [Server thread/INFO] [net.minecraft.server.integrated.IntegratedServer/]: Saving and pausing game...
[22一月2020 19:05:18.985] [Render thread/INFO] [net.minecraft.advancements.AdvancementList/]: Loaded 12 advancements
[22一月2020 19:05:19.007] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: Saving chunks for level 'RhodesIsland'/minecraft:overworld
[22一月2020 19:05:19.683] [Server thread/DEBUG] [net.minecraftforge.fml.FMLWorldPersistenceHook/WP]: Gathering id map for writing to world save RhodesIsland
[22一月2020 19:05:19.881] [Server thread/DEBUG] [net.minecraftforge.fml.network.FMLLoginWrapper/FMLHANDSHAKE]: Recieved login wrapper packet event for channel fml:handshake with index -1
[22一月2020 19:05:19.881] [Server thread/ERROR] [net.minecraftforge.fml.network.simple.IndexedMessageCodec/SIMPLENET]: Received empty payload on channel fml:handshake

 

The item will send a packet to server when it is left clicked.

The method is in BaseItem.java

public void emptyLeftClick(PlayerInteractEvent.LeftClickEmpty event){
        PacketHandler.HANDLER.sendToServer(new LeftClickPacket());
    }

 

And "leftclick" method will be called like this:

LeftClickPacket.java

package arknights.network.packets;

import arknights.item.BaseItem;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;

import java.util.function.Supplier;

public class LeftClickPacket {
    public static void encode(LeftClickPacket msg, PacketBuffer buf){
    }

    public static LeftClickPacket decode(PacketBuffer buf){
        return new LeftClickPacket();
    }

    public static class Handler {
        public static void handle(LeftClickPacket msg, Supplier<NetworkEvent.Context> ctx){
            ctx.get().enqueueWork(() -> {
                PlayerEntity player = ctx.get().getSender();
                ItemStack item = player.getHeldItemMainhand();
                if(!item.isEmpty() && (item.getItem() instanceof BaseItem)){
                    ((BaseItem) item.getItem()).leftClick(player, player.getEntityWorld(), item);
                }
            });
            ctx.get().setPacketHandled(true);
        }
    }
}

leftClick method (inside my item class):

public void leftClick(LivingEntity livingEntity, World worldIn, ItemStack stack){
        System.out.print("A");

    }

Does it mean the packet is successfully sent?

Posted

A comment, if I may:

  On 1/22/2020 at 11:00 AM, diesieben07 said:

The registration of your network channel must happen in FMLCommonSetupEvent. You are still not doing that. Now you are calling newSimpleChannel from the constructor of PacketHandler, which you call from the constructor of Arknights. This is not in FMLCommonSetupEvent.

Expand  

The problem in your code is that you construct your SimpleChannel at the wrong time. NetworkRegistry::newSimpleChannel should be called from your FMLCommonSetupEvent function, but instead you call it when the class Arknights is constructed -- a long time before FMLCommonSetupEvent will be called.

To fix this, here are the adjustments:
 

  Reveal hidden contents

And the explanations:

  Reveal hidden contents

 

Posted
  On 1/22/2020 at 12:32 PM, sciwhiz12 said:

A comment, if I may:

The problem in your code is that you construct your SimpleChannel at the wrong time. NetworkRegistry::newSimpleChannel should be called from your FMLCommonSetupEvent function, but instead you call it when the class Arknights is constructed -- a long time before FMLCommonSetupEvent

To fix this, here are the adjustments:
 

  Reveal hidden contents

And the explanations:

  Reveal hidden contents

Thank you for your patience! It helps me a lot.

 

Expand  

 

Posted
  On 1/22/2020 at 1:14 PM, NGYF said:

Thank you for your patience! It helps me a lot.

Expand  

You're welcome!

And another thing which I noticed;

You are registering your listener for PlayerInteractEvent.LeftClickEmpty in your BaseItem class. This is a problem: if you create multiple instances of BaseItem, you are registering your listener multiple times, which means that your code will send multiple packets for the same event.

To fix this, I recommend moving that code out of your BaseItem class, and into another class -- either a dedicated EventListener class, or even just inside your Arknights mod class:

  Reveal hidden contents

This fixes the problem, and gives a cleaner way to add more event listeners in the future.

Posted
  On 1/22/2020 at 1:40 PM, sciwhiz12 said:

You're welcome!

And another thing which I noticed;

You are registering your listener for PlayerInteractEvent.LeftClickEmpty in your BaseItem class. This is a problem: if you create multiple instances of BaseItem, you are registering your listener multiple times, which means that your code will send multiple packets for the same event.

To fix this, I recommend moving that code out of your BaseItem class, and into another class -- either a dedicated EventListener class, or even just inside your Arknights mod class:

  Reveal hidden contents

This fixes the problem, and gives a cleaner way to add more event listeners in the future.

Expand  

Thank you! That's useful!

Posted

Holy shit!

I make an very stupid mistake...

I forget to add entity to world! That's why I can't find the arrow.

 

I'm so stupid...

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.