Jump to content

[1.10.2] Event not working at all.


Bloopers

Recommended Posts

Hello. I've created a custom event with a tutorial from jabelar, that extends MouseEvent, and I've managed to get rid of all error(as the tutorial was for 1.8, there were plenty of errors) - but when I load the game it just doesn't do anything. I think it has to do with the actual registering of the event.

 

In my CommonProxy's init method, I put in

MouseEventHandler handler = new MouseEventHandler();
    	MinecraftForge.EVENT_BUS.register(handler); 

 

Is there a different way to register events in 1.10? I'm a complete noob when it comes to events, only done very basic things with them.

Link to comment
Share on other sites

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Hello. I've created a custom event with a tutorial from jabelar, that extends MouseEvent

 

Welp, there's your problem.  You're not supposed to extend the event classes.  You're supposed to create a single function that takes a single parameter (of any

Event

subtype) and mark it with an

@EventHandler

annotation.

 

Can you please link the tutorial you were using?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Hello. I've created a custom event with a tutorial from jabelar, that extends MouseEvent

 

Welp, there's your problem.  You're not supposed to extend the event classes.  You're supposed to create a single function that takes a single parameter (of any

Event

subtype) and mark it with an

@EventHandler

annotation.

 

Can you please link the tutorial you were using?

http://jabelarminecraft.blogspot.com/p/minecraft-modding-extending-reach-of.html

 

Link to comment
Share on other sites

Aha! Jabelar was extending the reach of a sword, not extending the mouse event class. Go back and take a closer look at the tutorial and then start over.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Aha! Jabelar was extending the reach of a sword, not extending the mouse event class. Go back and take a closer look at the tutorial and then start over.

I removed the part that makes it extend MouseEvent, and then tried launching again and it's the same result. Is there a reason that I should start over?

Link to comment
Share on other sites

Do you have this anywhere:

 

@SubscribeEvent
public void onEvent(MouseEvent event) {
    //...
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Do you have this anywhere:

 

@SubscribeEvent
public void onEvent(MouseEvent event) {
    //...
}

Yes.

And inside it is everything the event should do.

Do you know Java or was that a retorical question?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Post updated code. Are you sure you are subscribing to right MouseEvent?

Are there multiple MouseEvents?

I will post all of the code that was changed from jabelar's tutorial to fit 1.10 in a bit. I'm not on the same computer that has it right now.

MouseEvent should be donenin client proxy because the server doesnt need to know what do you have inside that method? Are you importing the correct MouseEvent?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Post updated code. Are you sure you are subscribing to right MouseEvent?

Are there multiple MouseEvents?

I will post all of the code that was changed from jabelar's tutorial to fit 1.10 in a bit. I'm not on the same computer that has it right now.

MouseEvent should be donenin client proxy because the server doesnt need to know what do you have inside that method? Are you importing the correct MouseEvent?

net.minecraftforge.client.event.MouseEvent is being imported. I moved it from CommonProxy to ClientProxy, still no difference.

 

 

MouseEventHandler:

package bloopers.spearmod.reach;

import java.awt.List;

import org.lwjgl.input.Mouse;

import bloopers.spearmod.SpearMod;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class MouseEventHandler {

    

@SideOnly(Side.CLIENT)
@SubscribeEvent
@EventHandler
public void onEvent(MouseEvent event)
{ 
	int button = event.getButton();
    boolean buttonstate = event.isButtonstate();
    
    
    if (button == 0 && buttonstate)
    {
        Minecraft mc = Minecraft.getMinecraft();
        EntityPlayer thePlayer = mc.thePlayer;
        if (thePlayer != null)
        {
            ItemStack itemstack = thePlayer.getHeldItemMainhand();
            IExtendedReach ieri;
            if (itemstack != null)
            {
                if (itemstack.getItem() instanceof IExtendedReach)
                {
                    ieri = (IExtendedReach) itemstack.getItem();
                } else
                {
                    ieri = null;
                }
   
                if (ieri != null)
                {
                    float reach = ieri.getReach();
                    RayTraceResult mov = getMouseOverExtended(reach); 
                      
                    if (mov != null)
                    {
                        if (mov.entityHit != null && mov.entityHit.hurtResistantTime == 0)
                        {
                            if (mov.entityHit != thePlayer )
                            {
                                SpearMod.network.sendToServer(new MessageExtendedReachAttack(
                                      mov.entityHit.getEntityId()));
                            }
                        }
                    }
                }
            }
        }
    }
}
        
// This is mostly copied from the EntityRenderer#getMouseOver() method
public static RayTraceResult getMouseOverExtended(float dist)
{
    Minecraft mc = FMLClientHandler.instance().getClient();
    Entity theRenderViewEntity = mc.getRenderViewEntity();
    AxisAlignedBB theViewBoundingBox = new AxisAlignedBB(
            theRenderViewEntity.posX-0.5D,
            theRenderViewEntity.posY-0.0D,
            theRenderViewEntity.posZ-0.5D,
            theRenderViewEntity.posX+0.5D,
            theRenderViewEntity.posY+1.5D,
            theRenderViewEntity.posZ+0.5D
            );
    RayTraceResult returnMOP = null;
    if (mc.theWorld != null)
    {
        double var2 = dist;
        returnMOP = theRenderViewEntity.rayTrace(var2, 0);
        double calcdist = var2;
        Vec3d pos = theRenderViewEntity.getPositionEyes(0);
        var2 = calcdist;
        if (returnMOP != null)
        {
            calcdist = returnMOP.hitVec.distanceTo(pos);
        }
         
        Vec3d lookvec = theRenderViewEntity.getLook(0);
        Vec3d var8 = pos.addVector(lookvec.xCoord * var2, 
              lookvec.yCoord * var2, 
              lookvec.zCoord * var2);
        Entity pointedEntity = null;
        float var9 = 1.0F;
        @SuppressWarnings("unchecked")
        java.util.List<Entity> list = mc.theWorld.getEntitiesWithinAABBExcludingEntity(
              theRenderViewEntity, 
              theViewBoundingBox.addCoord(
                    lookvec.xCoord * var2, 
                    lookvec.yCoord * var2, 
                    lookvec.zCoord * var2).expand(var9, var9, var9));
        double d = calcdist;
            
        for (Entity entity : list)
        {
            if (entity.canBeCollidedWith())
            {
                float bordersize = entity.getCollisionBorderSize();
                AxisAlignedBB aabb = new AxisAlignedBB(
                      entity.posX-entity.width/2, 
                      entity.posY, 
                      entity.posZ-entity.width/2, 
                      entity.posX+entity.width/2, 
                      entity.posY+entity.height, 
                      entity.posZ+entity.width/2);
                aabb.expand(bordersize, bordersize, bordersize);
                RayTraceResult mop0 = aabb.calculateIntercept(pos, var8);
                    
                if (aabb.isVecInside(pos))
                {
                    if (0.0D < d || d == 0.0D)
                    {
                        pointedEntity = entity;
                        d = 0.0D;
                    }
                } else if (mop0 != null)
                {
                    double d1 = pos.distanceTo(mop0.hitVec);
                        
                    if (d1 < d || d == 0.0D)
                    {
                        pointedEntity = entity;
                        d = d1;
                    }
                }
            }
        }
           
        if (pointedEntity != null && (d < calcdist || returnMOP == null))
        {
             returnMOP = new RayTraceResult(pointedEntity);
        }
    }
    return returnMOP;
}

}

 

MessageExtendedReachAttack:

package bloopers.spearmod.reach;

import bloopers.spearmod.SpearMod;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class MessageExtendedReachAttack implements IMessage 
{
    private int entityId ;

    public MessageExtendedReachAttack() 
    { 
     // need this constructor
    }

    public MessageExtendedReachAttack(int parEntityId) 
    {
     entityId = parEntityId;
        // DEBUG
        System.out.println("Constructor");
    }

    @Override
    public void fromBytes(ByteBuf buf) 
    {
     entityId = ByteBufUtils.readVarInt(buf, 4);
     // DEBUG
     System.out.println("fromBytes");
    }

    @Override
    public void toBytes(ByteBuf buf) 
    {
     ByteBufUtils.writeVarInt(buf, entityId, 4);
        // DEBUG
        System.out.println("toBytes encoded");
    }

    public static class Handler implements IMessageHandler<MessageExtendedReachAttack, 
          IMessage> 
    {
        @Override
        public IMessage onMessage(final MessageExtendedReachAttack message, 
              MessageContext ctx) 
        {
            // DEBUG
            System.out.println("Message received");
            // Know it will be on the server so make it thread-safe
            final EntityPlayerMP thePlayer = (EntityPlayerMP) SpearMod.proxy.
                  getPlayerEntityFromContext(ctx);
            thePlayer.getServer().addScheduledTask(
                  new Runnable()
                  {
                      @Override
                      public void run() 
                      {
                          Entity theEntity = thePlayer.worldObj.
                                getEntityByID(message.entityId);
                          // DEBUG
                          System.out.println("Entity = "+theEntity);
                          
                          // Need to ensure that hackers can't cause trick kills, 
                          // so double check weapon type and reach
                          if (thePlayer.getHeldItemMainhand() == null)
                          {
                              return;
                          }
                          if (thePlayer.getHeldItemMainhand().getItem() instanceof 
                                IExtendedReach)
                          {
                              IExtendedReach theExtendedReachWeapon = 
                                    (IExtendedReach)thePlayer.getHeldItemMainhand().
                                    getItem();
                              double distanceSq = thePlayer.getDistanceSqToEntity(
                                    theEntity);
                              double reachSq =theExtendedReachWeapon.getReach()*
                                    theExtendedReachWeapon.getReach();
                              if (reachSq >= distanceSq)
                              {
                                  thePlayer.attackTargetEntityWithCurrentItem(
                                        theEntity);
                              }
                          }
                          return; // no response in this case
                      }
                }
            );
            return null; // no response message
        }
    }
}

 

IExtendedReach:

package bloopers.spearmod.reach;

public interface IExtendedReach {

    public float getReach(); // default is 1.0D

}

 

And then in item classes to set the reach:

@Override
    public float getReach() 
    {
        return 15.0F;
    }

 

At 15 for testing.

Link to comment
Share on other sites

Post updated code. Are you sure you are subscribing to right MouseEvent?

Are there multiple MouseEvents?

I will post all of the code that was changed from jabelar's tutorial to fit 1.10 in a bit. I'm not on the same computer that has it right now.

MouseEvent should be donenin client proxy because the server doesnt need to know what do you have inside that method? Are you importing the correct MouseEvent?

net.minecraftforge.client.event.MouseEvent is being imported. I moved it from CommonProxy to ClientProxy, still no difference.

 

 

MouseEventHandler:

package bloopers.spearmod.reach;

import java.awt.List;

import org.lwjgl.input.Mouse;

import bloopers.spearmod.SpearMod;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class MouseEventHandler {

    

@SideOnly(Side.CLIENT)
@SubscribeEvent
@EventHandler
public void onEvent(MouseEvent event)
{ 
	int button = event.getButton();
    boolean buttonstate = event.isButtonstate();
    
    
    if (button == 0 && buttonstate)
    {
        Minecraft mc = Minecraft.getMinecraft();
        EntityPlayer thePlayer = mc.thePlayer;
        if (thePlayer != null)
        {
            ItemStack itemstack = thePlayer.getHeldItemMainhand();
            IExtendedReach ieri;
            if (itemstack != null)
            {
                if (itemstack.getItem() instanceof IExtendedReach)
                {
                    ieri = (IExtendedReach) itemstack.getItem();
                } else
                {
                    ieri = null;
                }
   
                if (ieri != null)
                {
                    float reach = ieri.getReach();
                    RayTraceResult mov = getMouseOverExtended(reach); 
                      
                    if (mov != null)
                    {
                        if (mov.entityHit != null && mov.entityHit.hurtResistantTime == 0)
                        {
                            if (mov.entityHit != thePlayer )
                            {
                                SpearMod.network.sendToServer(new MessageExtendedReachAttack(
                                      mov.entityHit.getEntityId()));
                            }
                        }
                    }
                }
            }
        }
    }
}
        
// This is mostly copied from the EntityRenderer#getMouseOver() method
public static RayTraceResult getMouseOverExtended(float dist)
{
    Minecraft mc = FMLClientHandler.instance().getClient();
    Entity theRenderViewEntity = mc.getRenderViewEntity();
    AxisAlignedBB theViewBoundingBox = new AxisAlignedBB(
            theRenderViewEntity.posX-0.5D,
            theRenderViewEntity.posY-0.0D,
            theRenderViewEntity.posZ-0.5D,
            theRenderViewEntity.posX+0.5D,
            theRenderViewEntity.posY+1.5D,
            theRenderViewEntity.posZ+0.5D
            );
    RayTraceResult returnMOP = null;
    if (mc.theWorld != null)
    {
        double var2 = dist;
        returnMOP = theRenderViewEntity.rayTrace(var2, 0);
        double calcdist = var2;
        Vec3d pos = theRenderViewEntity.getPositionEyes(0);
        var2 = calcdist;
        if (returnMOP != null)
        {
            calcdist = returnMOP.hitVec.distanceTo(pos);
        }
         
        Vec3d lookvec = theRenderViewEntity.getLook(0);
        Vec3d var8 = pos.addVector(lookvec.xCoord * var2, 
              lookvec.yCoord * var2, 
              lookvec.zCoord * var2);
        Entity pointedEntity = null;
        float var9 = 1.0F;
        @SuppressWarnings("unchecked")
        java.util.List<Entity> list = mc.theWorld.getEntitiesWithinAABBExcludingEntity(
              theRenderViewEntity, 
              theViewBoundingBox.addCoord(
                    lookvec.xCoord * var2, 
                    lookvec.yCoord * var2, 
                    lookvec.zCoord * var2).expand(var9, var9, var9));
        double d = calcdist;
            
        for (Entity entity : list)
        {
            if (entity.canBeCollidedWith())
            {
                float bordersize = entity.getCollisionBorderSize();
                AxisAlignedBB aabb = new AxisAlignedBB(
                      entity.posX-entity.width/2, 
                      entity.posY, 
                      entity.posZ-entity.width/2, 
                      entity.posX+entity.width/2, 
                      entity.posY+entity.height, 
                      entity.posZ+entity.width/2);
                aabb.expand(bordersize, bordersize, bordersize);
                RayTraceResult mop0 = aabb.calculateIntercept(pos, var8);
                    
                if (aabb.isVecInside(pos))
                {
                    if (0.0D < d || d == 0.0D)
                    {
                        pointedEntity = entity;
                        d = 0.0D;
                    }
                } else if (mop0 != null)
                {
                    double d1 = pos.distanceTo(mop0.hitVec);
                        
                    if (d1 < d || d == 0.0D)
                    {
                        pointedEntity = entity;
                        d = d1;
                    }
                }
            }
        }
           
        if (pointedEntity != null && (d < calcdist || returnMOP == null))
        {
             returnMOP = new RayTraceResult(pointedEntity);
        }
    }
    return returnMOP;
}

}

 

MessageExtendedReachAttack:

package bloopers.spearmod.reach;

import bloopers.spearmod.SpearMod;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class MessageExtendedReachAttack implements IMessage 
{
    private int entityId ;

    public MessageExtendedReachAttack() 
    { 
     // need this constructor
    }

    public MessageExtendedReachAttack(int parEntityId) 
    {
     entityId = parEntityId;
        // DEBUG
        System.out.println("Constructor");
    }

    @Override
    public void fromBytes(ByteBuf buf) 
    {
     entityId = ByteBufUtils.readVarInt(buf, 4);
     // DEBUG
     System.out.println("fromBytes");
    }

    @Override
    public void toBytes(ByteBuf buf) 
    {
     ByteBufUtils.writeVarInt(buf, entityId, 4);
        // DEBUG
        System.out.println("toBytes encoded");
    }

    public static class Handler implements IMessageHandler<MessageExtendedReachAttack, 
          IMessage> 
    {
        @Override
        public IMessage onMessage(final MessageExtendedReachAttack message, 
              MessageContext ctx) 
        {
            // DEBUG
            System.out.println("Message received");
            // Know it will be on the server so make it thread-safe
            final EntityPlayerMP thePlayer = (EntityPlayerMP) SpearMod.proxy.
                  getPlayerEntityFromContext(ctx);
            thePlayer.getServer().addScheduledTask(
                  new Runnable()
                  {
                      @Override
                      public void run() 
                      {
                          Entity theEntity = thePlayer.worldObj.
                                getEntityByID(message.entityId);
                          // DEBUG
                          System.out.println("Entity = "+theEntity);
                          
                          // Need to ensure that hackers can't cause trick kills, 
                          // so double check weapon type and reach
                          if (thePlayer.getHeldItemMainhand() == null)
                          {
                              return;
                          }
                          if (thePlayer.getHeldItemMainhand().getItem() instanceof 
                                IExtendedReach)
                          {
                              IExtendedReach theExtendedReachWeapon = 
                                    (IExtendedReach)thePlayer.getHeldItemMainhand().
                                    getItem();
                              double distanceSq = thePlayer.getDistanceSqToEntity(
                                    theEntity);
                              double reachSq =theExtendedReachWeapon.getReach()*
                                    theExtendedReachWeapon.getReach();
                              if (reachSq >= distanceSq)
                              {
                                  thePlayer.attackTargetEntityWithCurrentItem(
                                        theEntity);
                              }
                          }
                          return; // no response in this case
                      }
                }
            );
            return null; // no response message
        }
    }
}

 

IExtendedReach:

package bloopers.spearmod.reach;

public interface IExtendedReach {

    public float getReach(); // default is 1.0D

}

 

And then in item classes to set the reach:

@Override
    public float getReach() 
    {
        return 15.0F;
    }

 

At 15 for testing.

What is button 0?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Post updated code. Are you sure you are subscribing to right MouseEvent?

Are there multiple MouseEvents?

I will post all of the code that was changed from jabelar's tutorial to fit 1.10 in a bit. I'm not on the same computer that has it right now.

MouseEvent should be donenin client proxy because the server doesnt need to know what do you have inside that method? Are you importing the correct MouseEvent?

net.minecraftforge.client.event.MouseEvent is being imported. I moved it from CommonProxy to ClientProxy, still no difference.

 

 

MouseEventHandler:

package bloopers.spearmod.reach;

import java.awt.List;

import org.lwjgl.input.Mouse;

import bloopers.spearmod.SpearMod;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class MouseEventHandler {

    

@SideOnly(Side.CLIENT)
@SubscribeEvent
@EventHandler
public void onEvent(MouseEvent event)
{ 
	int button = event.getButton();
    boolean buttonstate = event.isButtonstate();
    
    
    if (button == 0 && buttonstate)
    {
        Minecraft mc = Minecraft.getMinecraft();
        EntityPlayer thePlayer = mc.thePlayer;
        if (thePlayer != null)
        {
            ItemStack itemstack = thePlayer.getHeldItemMainhand();
            IExtendedReach ieri;
            if (itemstack != null)
            {
                if (itemstack.getItem() instanceof IExtendedReach)
                {
                    ieri = (IExtendedReach) itemstack.getItem();
                } else
                {
                    ieri = null;
                }
   
                if (ieri != null)
                {
                    float reach = ieri.getReach();
                    RayTraceResult mov = getMouseOverExtended(reach); 
                      
                    if (mov != null)
                    {
                        if (mov.entityHit != null && mov.entityHit.hurtResistantTime == 0)
                        {
                            if (mov.entityHit != thePlayer )
                            {
                                SpearMod.network.sendToServer(new MessageExtendedReachAttack(
                                      mov.entityHit.getEntityId()));
                            }
                        }
                    }
                }
            }
        }
    }
}
        
// This is mostly copied from the EntityRenderer#getMouseOver() method
public static RayTraceResult getMouseOverExtended(float dist)
{
    Minecraft mc = FMLClientHandler.instance().getClient();
    Entity theRenderViewEntity = mc.getRenderViewEntity();
    AxisAlignedBB theViewBoundingBox = new AxisAlignedBB(
            theRenderViewEntity.posX-0.5D,
            theRenderViewEntity.posY-0.0D,
            theRenderViewEntity.posZ-0.5D,
            theRenderViewEntity.posX+0.5D,
            theRenderViewEntity.posY+1.5D,
            theRenderViewEntity.posZ+0.5D
            );
    RayTraceResult returnMOP = null;
    if (mc.theWorld != null)
    {
        double var2 = dist;
        returnMOP = theRenderViewEntity.rayTrace(var2, 0);
        double calcdist = var2;
        Vec3d pos = theRenderViewEntity.getPositionEyes(0);
        var2 = calcdist;
        if (returnMOP != null)
        {
            calcdist = returnMOP.hitVec.distanceTo(pos);
        }
         
        Vec3d lookvec = theRenderViewEntity.getLook(0);
        Vec3d var8 = pos.addVector(lookvec.xCoord * var2, 
              lookvec.yCoord * var2, 
              lookvec.zCoord * var2);
        Entity pointedEntity = null;
        float var9 = 1.0F;
        @SuppressWarnings("unchecked")
        java.util.List<Entity> list = mc.theWorld.getEntitiesWithinAABBExcludingEntity(
              theRenderViewEntity, 
              theViewBoundingBox.addCoord(
                    lookvec.xCoord * var2, 
                    lookvec.yCoord * var2, 
                    lookvec.zCoord * var2).expand(var9, var9, var9));
        double d = calcdist;
            
        for (Entity entity : list)
        {
            if (entity.canBeCollidedWith())
            {
                float bordersize = entity.getCollisionBorderSize();
                AxisAlignedBB aabb = new AxisAlignedBB(
                      entity.posX-entity.width/2, 
                      entity.posY, 
                      entity.posZ-entity.width/2, 
                      entity.posX+entity.width/2, 
                      entity.posY+entity.height, 
                      entity.posZ+entity.width/2);
                aabb.expand(bordersize, bordersize, bordersize);
                RayTraceResult mop0 = aabb.calculateIntercept(pos, var8);
                    
                if (aabb.isVecInside(pos))
                {
                    if (0.0D < d || d == 0.0D)
                    {
                        pointedEntity = entity;
                        d = 0.0D;
                    }
                } else if (mop0 != null)
                {
                    double d1 = pos.distanceTo(mop0.hitVec);
                        
                    if (d1 < d || d == 0.0D)
                    {
                        pointedEntity = entity;
                        d = d1;
                    }
                }
            }
        }
           
        if (pointedEntity != null && (d < calcdist || returnMOP == null))
        {
             returnMOP = new RayTraceResult(pointedEntity);
        }
    }
    return returnMOP;
}

}

 

MessageExtendedReachAttack:

package bloopers.spearmod.reach;

import bloopers.spearmod.SpearMod;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class MessageExtendedReachAttack implements IMessage 
{
    private int entityId ;

    public MessageExtendedReachAttack() 
    { 
     // need this constructor
    }

    public MessageExtendedReachAttack(int parEntityId) 
    {
     entityId = parEntityId;
        // DEBUG
        System.out.println("Constructor");
    }

    @Override
    public void fromBytes(ByteBuf buf) 
    {
     entityId = ByteBufUtils.readVarInt(buf, 4);
     // DEBUG
     System.out.println("fromBytes");
    }

    @Override
    public void toBytes(ByteBuf buf) 
    {
     ByteBufUtils.writeVarInt(buf, entityId, 4);
        // DEBUG
        System.out.println("toBytes encoded");
    }

    public static class Handler implements IMessageHandler<MessageExtendedReachAttack, 
          IMessage> 
    {
        @Override
        public IMessage onMessage(final MessageExtendedReachAttack message, 
              MessageContext ctx) 
        {
            // DEBUG
            System.out.println("Message received");
            // Know it will be on the server so make it thread-safe
            final EntityPlayerMP thePlayer = (EntityPlayerMP) SpearMod.proxy.
                  getPlayerEntityFromContext(ctx);
            thePlayer.getServer().addScheduledTask(
                  new Runnable()
                  {
                      @Override
                      public void run() 
                      {
                          Entity theEntity = thePlayer.worldObj.
                                getEntityByID(message.entityId);
                          // DEBUG
                          System.out.println("Entity = "+theEntity);
                          
                          // Need to ensure that hackers can't cause trick kills, 
                          // so double check weapon type and reach
                          if (thePlayer.getHeldItemMainhand() == null)
                          {
                              return;
                          }
                          if (thePlayer.getHeldItemMainhand().getItem() instanceof 
                                IExtendedReach)
                          {
                              IExtendedReach theExtendedReachWeapon = 
                                    (IExtendedReach)thePlayer.getHeldItemMainhand().
                                    getItem();
                              double distanceSq = thePlayer.getDistanceSqToEntity(
                                    theEntity);
                              double reachSq =theExtendedReachWeapon.getReach()*
                                    theExtendedReachWeapon.getReach();
                              if (reachSq >= distanceSq)
                              {
                                  thePlayer.attackTargetEntityWithCurrentItem(
                                        theEntity);
                              }
                          }
                          return; // no response in this case
                      }
                }
            );
            return null; // no response message
        }
    }
}

 

IExtendedReach:

package bloopers.spearmod.reach;

public interface IExtendedReach {

    public float getReach(); // default is 1.0D

}

 

And then in item classes to set the reach:

@Override
    public float getReach() 
    {
        return 15.0F;
    }

 

At 15 for testing.

What is button 0?

Jabelar's tutorial says it means left click, so I assume button 1 would also mean right click.

Link to comment
Share on other sites

Why do you have both @SubscribeEvent and @EventHandler?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Question:

Is your event not working or is your code not working?

Put a print at start of event.

2nd: Did you register event?

There are no errors in eclipse, but when I start up the game and test it out, it's as if it doesn't exist.

What is a print?

Yes, I am registering it in the FMLInitizializationEvent method in my CommonProxy. Anime fan suggested client proxy instead but that didn't change anything so I went back to CommonProxy

Link to comment
Share on other sites

Question:

Is your event not working or is your code not working?

Put a print at start of event.

2nd: Did you register event?

Ohh, you mean print to console? I just tested it now, apparently the init method on my CommonProxy doesn't load at all. How can I fix this?

Obviously you need to call it from your main init method in your main mod class.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Question:

Is your event not working or is your code not working?

Put a print at start of event.

2nd: Did you register event?

Ohh, you mean print to console? I just tested it now, apparently the init method on my CommonProxy doesn't load at all. How can I fix this?

Obviously you need to call it from your main init method in your main mod class.

Okay. Now it's in my main mod class init method. Launched the game, tried to hit a mob from far away, and the game crashed. The console tells me that it's line 65 in MouseEventHandler, which is:

SpearMod.network.sendToServer(new MessageExtendedReachAttack(mov.entityHit.getEntityId()));

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

    • rftoolsbuilder:shielding_cutout (from lostcities-1.19-6.0.24.jar),rftoolsstorage:crafting_manager (from lostcities-1.19-6.0.24.jar),deepresonance:dense_glass (from lostcities-1.19-6.0.24.jar),restrictions:oneway (from lostcities-1.19-6.0.24.jar),restrictions:oneway_wall (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_complete (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_complete (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_mossy (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_mossy (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_broken (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_broken (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_broken_mossy (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_broken_mossy (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_vines (from lostcities-1.19-6.0.24.jar),lostruins:glassgray3x2_pane_vines (from lostcities-1.19-6.0.24.jar)[13:50:17] [main/INFO] [minecraft/RecipeManager]: Skipping loading recipe supplementaries:inspirations/blackboard_clear as it's serializer returned null[13:50:17] [main/INFO] [minecraft/RecipeManager]: Skipping loading recipe supplementaries:inspirations/flag_dye as it's serializer returned null[13:50:17] [main/INFO] [minecraft/RecipeManager]: Skipping loading recipe supplementaries:inspirations/flag_clear as it's serializer returned null[13:50:17] [main/INFO] [minecraft/RecipeManager]: Loaded 36 recipes[13:50:17] [main/INFO] [Spartan Weaponry/]: Adding Diamond Weapons to the End City Treasure Loot Table![13:50:17] [main/INFO] [Spartan Weaponry/]: Adding Longbow and Heavy Crossbow related loot to the Village Fletcher Loot Table![13:50:18] [main/INFO] [Spartan Weaponry/]: Adding Iron Weapons to the Village Weaponsmith Loot Table![13:50:18] [main/ERROR] [minecraft/ServerFunctionLibrary]: Failed to load function watching:checkjava.util.concurrent.CompletionException: java.lang.IllegalArgumentException: Whilst parsing command on line 1: Unknown or incomplete command, see below for error at position 0: <--[HERE]at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315) ~[?:?] {re:mixin}at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320) ~[?:?] {re:mixin}at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770) ~[?:?] {}at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760) ~[?:?] {}at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {re:computing_frames}at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {re:computing_frames}at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}Caused by: java.lang.IllegalArgumentException: Whilst parsing command on line 1: Unknown or incomplete command, see below for error at position 0: <--[HERE]at net.minecraft.commands.CommandFunction.m_77984_(CommandFunction.java:63) ~[server-1.19.2-20220805.130853-srg.jar%23299!/:?] {re:classloading}at net.minecraft.server.ServerFunctionLibrary.m_214320_(ServerFunctionLibrary.java:85) ~[server-1.19.2-20220805.130853-srg.jar%23299!/:?] {re:classloading}at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?] {}... 6 more[13:50:18] [main/INFO] [quark/]: [Automatic Recipe Unlock] Removed 3712 recipe advancements[13:50:18] [main/INFO] [minecraft/AdvancementList]: Loaded 684 advancements[13:50:18] [main/INFO] [at.dy.se.ItemLightLevels/]: Clearing item tag to light level mapping cache[13:50:18] [main/INFO] [sl.ma.fl.tr.FluidContainerTransferManager/]: Loaded 0 dynamic modifiers in 0.246528 ms[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/wax_on with 2 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:adventure/kill_a_mob with 3 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/bred_all_animals with 3 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:adventure/kill_all_mobs with 3 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/make_a_sign_glow with 1 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/balanced_diet with 3 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/plant_seed with 1 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:nether/all_effects with 2 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:husbandry/wax_off with 2 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:adventure/adventuring_time with 1 patches[13:50:18] [main/INFO] [quark/]: Modified advancement minecraft:nether/all_potions with 1 patches[13:50:18] [main/INFO] [supplementaries/]: Loaded 8 flute songs[13:50:20] [main/INFO] [Spartan Weaponry/]: Finished initialising Weapon Traits & Attributes! Took 11.202781ms[13:50:20] [main/INFO] [supplementaries/]: Finished additional setup in 103 ms[13:50:20] [main/WARN] [minecraft/DedicatedServerProperties]: Failed to parse level-type biomesoplenty, defaulting to minecraft:normal[13:50:20] [Server thread/INFO] [minecraft/DedicatedServer]: Starting minecraft server version 1.19.2[13:50:20] [Server thread/INFO] [minecraft/DedicatedServer]: Loading properties[13:50:20] [Server thread/INFO] [minecraft/DedicatedServer]: Default game type: SURVIVAL[13:50:20] [Server thread/INFO] [minecraft/MinecraftServer]: Generating keypair[13:50:21] [Server thread/INFO] [minecraft/DedicatedServer]: Starting Minecraft server on :::25983[13:50:21] [Server thread/INFO] [minecraft/ServerConnectionListener]: Using epoll channel type[13:50:21] [Thread-0/INFO] [de.ca.ca.CaveDweller/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.ca.CaveDweller/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.st.SteveDweller/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.st.SteveDweller/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.sk.Skinstalker/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.sk.SkinwalkerOverhaul/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.sk.SkinwalkerOverhaul/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.go.Goatman/]: Server configuration has been reloaded[13:50:21] [Thread-0/INFO] [de.ca.go.Goatman/]: Server configuration has been reloaded[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser identified itemstack 1 torch[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser identified itemstack 1 glowstone[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser finished, item count: 2[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser identified itemstack 1 torch[13:50:21] [Server thread/INFO] [at.dy.se.mo.PlayerSelfLightSource/]: item config parser finished, item count: 1[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser identified itemstack 1 torch[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser identified itemstack 1 glowstone[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser finished, item count: 2[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser identified itemstack 1 torch[13:50:21] [Server thread/INFO] [at.dy.se.mo.DroppedItemsLightSource/]: item config parser finished, item count: 1[13:50:21] [Server thread/INFO] [Framework/]: Loading server configs...[13:50:22] [Server thread/INFO] [terrablender/]: Initialized TerraBlender biomes for level stem minecraft:overworld[13:50:22] [Server thread/INFO] [terrablender/]: Initialized TerraBlender biomes for level stem minecraft:the_nether[13:50:22] [Server thread/INFO] [minecraft/DedicatedServer]: Preparing level "world"[13:50:35] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing start region for dimension minecraft:overworld[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:40] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:41] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:41] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 0%[13:50:42] [Worker-Main-1/INFO] [minecraft/LoggerChunkProgressListener]: Preparing spawn area: 17%[13:50:42] [Server thread/INFO] [minecraft/LoggerChunkProgressListener]: Time elapsed: 7618 ms[13:50:42] [Server thread/INFO] [minecraft/DedicatedServer]: Done (21.501s)! For help, type "help"[13:50:42] [Server thread/INFO] [minecraft/DedicatedServer]: Starting GS4 status listener[13:50:42] [Server thread/INFO] [minecraft/GenericThread]: Thread Query Listener started[13:50:42] [Query Listener #1/INFO] [minecraft/QueryThreadGs4]: Query running on :::25983[13:50:42] [Server thread/INFO] [ne.mi.se.pe.PermissionAPI/]: Successfully initialized permission handler forge:default_handler
    • The conflict arises from discrepancies between different versions of GSON. My suggestion would be to remove your dependency on GSON 2.8.6 and opt for a different approach. Instead of using the static method JsonParser.parseString, you can create a JsonParser object and then use the parse method.   JsonParser jsonParser = new JsonParser(); jsonParser.parse(jsonString)  
    • On the download page, click the button for "Show all versions", point at the little i next to the Installer link, and use the Direct Download link that pops up. That should let you download it if you have issues with the adfocus thingy.
    • I was downloading Forge's installer for the latest Minecraft version. The official Forge page led to the familiar "press skip after countdown" ad page I've gone through many times. This time, the "Skip" button just never showed up after the countdown finished. The page for the ad was clearly bugged, because it showed as a blank white page up to the rows of pixels right at the top, where I saw a sliver of the actual page 2 or so inches tall but with the width of the whole page. I tried different versions (1.20.4 latest and 1.20.2 recommended), refreshing, closing the tab and going there again, to no avail. Then this Forum's signup Security Check wouldn't let me through. I rebooted my PC and now it did work just fine. But the download still doesn't (still no Skip button), even after booting my PC. The the ad was seemingly bugged as well, because it showed as a blank white page up to the rows of pixels right at the top, 2 or so inches tall but the width of the whole page. I even manually scrolled down to its bottom and back up, but that didn't fix it either. I sent a report of the same issue to Adfoc.us, but that led to a page labeled "Just a moment..." that doesn't lead anywhere after 10mins of waiting. Refreshing the page does nothing, and there is no confirmation message in my email. So I don't even know if the report to AdFoc.us went through. I'm stumped.
    • Did some more testing and found workaround. Newest MC and Forge for it didn't have this problem, also isolated that problem is only with fullscreen, meaning there is problem with exclusive fullscreen handling when application gets moved to background/minimized. So installing this mod fixed problem for MC 1.12.2 and forge for it https://www.curseforge.com/minecraft/mc-mods/fullscreen-windowed-borderless-for-minecraft
  • Topics

×
×
  • Create New...

Important Information

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