Jump to content

Recommended Posts

Posted

Hi,

 

I've got some code to get the nearby entity but for some reason it never adds the player to the list and only

adds stuff to the list when I am in survival mode. When I'm in creative mode it can't find any animals nearby or does

not add them to the list.

 

What should the code do?

1. Find all nearby entities

2. Add all nearby entities except for spectator and creative players

3. Should ignore the searching entity

 

The code:

        ArrayList<Entity> output = new ArrayList<Entity>();
        List<Entity> foundOnes = worldIn.getEntitiesWithinAABB(clazz, new AxisAlignedBB(pos).expand(range, range, range));
        
        if(foundOnes.size() > 0) {
            for(Object e : foundOnes) {
                Entity result = (Entity) e;
                
                if(result != null && result.getEntityId() != entity.getEntityId()) {
                    if(result instanceof EntityPlayer) {
                        EntityPlayer player = (EntityPlayer) result;
                        
                        if(!player.isSpectator() && !player.isCreative())
                            output.add(result);
                    } else
                        output.add(result);
                }
            }
        }
        
        return output;

 

Method header:

    public static ArrayList<Entity> getEntitiesInRange(World worldIn, Entity entity, Class<? extends Entity> clazz, BlockPos pos, int range) {

 

Get's called by this:

getEntitiesInRange(this.worldObj, this, Entity.class, this.getPosition(), 20);

 

So what am I doing wrong and is so much code required or is there something else I could use to do the same?

 

Thx in advance.

Bektor

Developer of Primeval Forest.

Posted

public static <T extends Entity> List<T> getEntitiesInRange(World world, Entity exclude, Class<T> clazz, BlockPos pos, int range) {
    return world.getEntitiesWithinAABB(
        clazz,
        new AxisAlignedBB(pos).expandXyz(range),
        Predicates.and(e -> e != exclude, EntitySelectors.CAN_AI_TARGET)
    );
}

Ok, but the exclude thing is not working and could you explain the code?

Developer of Primeval Forest.

Posted

Define "not working".

As for the code:

 

expandXyz(a)

is the same as

expand(a, a, a)

.

Predicates.and

combines two predicates into one that only returns true if both return true. The first predicate I pass in is a Lambda Expression from Java 8, you could use an anonymous class here or

Predicates.not(Predicates.equalTo(exclude))

, but these are both pretty clunky imho.

The 2nd predicate is

CAN_AI_TARGET

, which as you can check, checks if the entity is either not a player of it they are a player checks if they are neither in spectator nor survival mode.

Ok, so what is the first predicate for? And what is an predicate?

The problem is: exclude cannot be resolved to a variable

This happens even when I'm copying our code.

 

Ok, nevermind, figured it out myself and thanks for the help. ;)

Developer of Primeval Forest.

Posted

Ok, the thing with exclude is working... just got a typo in the parameter list.

But for some reason, the code which calls the method does not affect the player, but it does effect all other entities. (I'm in survival)

The list tells me also that there was one entity found (the player), but it does not move the player.

 

        Iterator<Entity> i = this.nearby.iterator();
        
        while(i.hasNext()) {
            Entity entity = (Entity) i.next();
            
            if(entity == null || entity.isDead)
                return;
            
            double moveX = (this.posX + .5d) - (entity.posX + .5d);
            double moveY = (this.posY + .5d) - (entity.posY + .5d);
            double moveZ = (this.posZ + .5d) - (entity.posZ + .5d);
            
            double distanceSqrt = Math.sqrt(moveX * moveX + moveY * moveY + moveZ * moveZ);
            entity.motionX += moveX / distanceSqrt * .5f;
            entity.motionY += moveY / distanceSqrt * .5f;
            entity.motionZ += moveZ / distanceSqrt * .5f;
        }

So what is wrong there? nearby is the list which calls getEntitiesInRange.

Developer of Primeval Forest.

Posted

Ok, I've got now a packet which should be send to the client:

 

public class PacketPortal implements IMessage, IMessageHandler<PacketPortal , IMessage>{
    
    private double motionX;
    private double motionY;
    private double motionZ;
    
    public PacketPortal (double motionX, double motionY, double motionZ) {
        this.motionX = motionX;
        this.motionY = motionY;
        this.motionZ = motionZ;
    }
    
    @Override
    public IMessage onMessage(PacketPortal message, MessageContext ctx) {
        return message;
    }
    
    @Override
    public void fromBytes(ByteBuf buf) {
        this.motionX = buf.readDouble();
        this.motionY = buf.readDouble();
        this.motionZ = buf.readDouble();
    }
    
    @Override
    public void toBytes(ByteBuf buf) {
        buf.writeDouble(this.motionX);
        buf.writeDouble(this.motionY);
        buf.writeDouble(this.motionZ);
    }
}

 

So what do I need to put into onMessage to let the player move into that direction and also to check if the player does the right thing.

 

And what is better? Do it that way or use the start and end positions? And if using them, how do I have to modify my packet and my other code which calles the packet (which is in the entity update).

Developer of Primeval Forest.

Posted

Well, what I want is to move the player to my entity. So my entity is basically like a black hole. It gets everything nearby and pulls them to my entity.

 

So I'm now wondering what the most performant way is. (oh and with some mods with add more motion then my entity it should be possible to get away from my entity).

 

And how do I get the player?

Developer of Primeval Forest.

Posted

1. You had better provide the position information of the 'black hole' in the packet, and move the player to the direction.

2. The player we control is stored in Minecraft#thePlayer. As far as I know, it is the only entity which is not fully controlled on the server.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

I'm not quite sure if it is a good idea to use Minecraft#thePlayer because it returns EntityPlayerSP and the mod should work in multiplayer worlds also.

(well, the client will recieve the packet, but I'm not sure if this makes a difference)

Developer of Primeval Forest.

Posted

You can use your proxy for that.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Something like Proxy#getDefaultPlayer() with implementation on clientproxy only?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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

    • Reach Out To Rapid Digital: What sapp Info: +1 41 4 80 7 14 85 Email INFO: rap iddi gita lrecov ery @ exe cs. com Hello, my name is Jayson, and I’m 35 years old from the United Kingdom. My family and I recently endured an incredibly challenging experience that I wouldn’t wish on anyone. We became victims of a cryptocurrency investment fraud scheme that saw us lose a staggering $807,000 in USDT and Bitcoins. The fraudsters had created a convincing facade, and we were lured into investing, only to discover later that the platform was a complete scam. We were left devastated, not just financially, but emotionally, as we had trusted these people and believed in the legitimacy of the investment. After the initial shock wore off, we desperately searched for ways to recover the lost funds. It seemed like an impossible task, and we felt as though there was no hope. That’s when, by sheer luck, we stumbled across a post about Rapid Digital Recovery, a cryptocurrency and funds recovery organization with a proven track record in cybersecurity and fraud recovery. We decided to reach out to them, and from the first interaction, we were impressed with their professionalism and transparency. They explained the recovery process in detail and reassured us that they had the skills and expertise to track down the perpetrators and recover our funds. This gave us a renewed sense of hope, something we hadn’t felt in months. What truly stood out during our experience with Rapid Digital Recovery was their dedication to the recovery process. The team went above and beyond, using sophisticated tracking tools and cyber forensics to gather critical information. Within a matter of weeks, they had successfully located the funds and traced the scam back to the fraudsters responsible. They worked with the authorities to ensure the criminals were held accountable for their actions. To our relief, the team at Rapid Digital Recovery was able to recover every single penny we had lost. The funds were returned in full, and the sense of closure we felt was invaluable. We couldn’t have imagined such a positive outcome in the early stages of our recovery journey, and we are deeply grateful for the work they did. If you ever find yourself in a similar situation, I highly recommend contacting Rapid Digital Recovery. Their expertise, transparency, and dedication to their clients make them the go-to choice for anyone seeking to recover lost cryptocurrency or funds. They truly gave us back our financial future.  
    • This is my first time modding anything, so maybe just skill issue. I'm using Forge 54.0.12 and Temurin 21.0.5+11-LTS I wanted to create a custom keybind and to check whether it works I'd like to send a chat message. I tried using Minecraft.getInstance().player.sendSystemMessage(Component.literal("test")); but IntelliJ couldnt resolve sendSystemMessage(...). Since I saw people using it in earlier versions, I tried the same thing with 1.20.6(- 50.1.0), where it works fine, now I can't figure out if this is intentional and whether there are other options for sending chat messages. On that note, is there more documentation than https://docs.minecraftforge.net/en/1.21.x/? It seems very incomplete compared to something like the Oracle Java docs
    • Hi, i'm having this error and I wanna fix it. we try: -Reload drivers -Eliminate .minecraft -Eliminate Java -Restart launcher -Verify if minecraft is using gpu -Mods  in .minecraft is empty -Install the latest and recomended version of forge idk what i have to do, help me pls. the lastest log is: https://mclo.gs/WAMao8x  
    • Read the FAQ, Rule #2. (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/)  
    • The link to your log does not work, it says it is forbidden, Error, this is a private paste or is pending moderation.
  • Topics

×
×
  • Create New...

Important Information

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