Jump to content

SOLVED [1.15.1] Accessing private method in Entity.class


Recommended Posts

Posted

Source code I am porting from 1.14.4 to 1.15.1

package com.kwpugh.gobber2.items.rings;

import java.util.List;

import com.kwpugh.gobber2.util.EnableUtil;
import com.kwpugh.gobber2.util.MagnetRange;

import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ExperienceOrbEntity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;

public class ItemCustomRingAttraction extends Item
{

	public ItemCustomRingAttraction(Properties properties)
	{
		super(properties);
	}
	
	int range;

	public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)
	{		
		if(entity instanceof PlayerEntity && !world.isRemote && EnableUtil.isEnabled(stack))
		{
			PlayerEntity player = (PlayerEntity)entity;
			
			boolean init = MagnetRange.getCurrentlySet(stack);
			
			if(!init)
			{
				range = 0;
			}
			else
			{
				range = MagnetRange.getCurrentRange(stack);
			}			
			
			double x = player.posX;
			double y = player.posY + 1.5;
			double z = player.posZ;

			boolean isPulling;
			
			//Scan for and collect items
			List<ItemEntity> items = entity.world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
			for(ItemEntity e: items)
			{
				if(!player.isCrouching() && !e.getPersistentData().getBoolean("PreventRemoteMovement"))
				//if(!player.isSneaking())
				{
					isPulling = true;							
					double factor = 0.02;
					e.addVelocity((x - e.posX) * factor, (y - e.posY) * factor, (z - e.posZ) * factor);
				}
			}
			
			if(items.isEmpty())
			{
				isPulling = false;
			}
			
			//Scan for and collect XP Orbs
			List<ExperienceOrbEntity> xp = entity.world.getEntitiesWithinAABB(ExperienceOrbEntity.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
			for(ExperienceOrbEntity orb: xp)
			{
				if(!player.isCrouching())
				{
					isPulling = true;							
					double factor = 0.02;
					orb.addVelocity((x - orb.posX) * factor, (y - orb.posY) * factor, (z - orb.posZ) * factor);
                    player.onItemPickup(orb, 1);
                    player.giveExperiencePoints(orb.xpValue);
                    orb.remove();
				}
			}
			
			if(items.isEmpty())
			{
				isPulling = false;
			}
		}
	}
	
	@Override
    public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand)
    {
		ItemStack stack = player.getHeldItem(hand);	
		
		if(!world.isRemote && !(player.isCrouching()))
        {
            EnableUtil.changeEnabled(player, hand);
            player.sendMessage(new StringTextComponent("Attraction ability active: " + EnableUtil.isEnabled(stack)));
            return new ActionResult<ItemStack>(ActionResultType.SUCCESS, player.getHeldItem(hand));
        }		
		
        if(!world.isRemote && player.isCrouching())
        {
			if(range == 0)
			{
				range = 4;
				MagnetRange.setCurrentRange(stack, range);
				player.sendMessage(new StringTextComponent("Attraction range set to: " + MagnetRange.getCurrentRange(stack)));
			}
			else if(range == 4)
			{
				range = 8;
				MagnetRange.setCurrentRange(stack, range);
				player.sendMessage(new StringTextComponent("Attraction range set to: " + MagnetRange.getCurrentRange(stack)));
			}
			else if(range == 8)
			{
				range = 12;
				MagnetRange.setCurrentRange(stack, range);
				player.sendMessage(new StringTextComponent("Attraction range set to: " + MagnetRange.getCurrentRange(stack)));
			}
			else if(range == 12)
			{
				range = 0;
				MagnetRange.setCurrentRange(stack, range);
				player.sendMessage(new StringTextComponent("Attraction range set to: " + MagnetRange.getCurrentRange(stack)));
			}
        }
        
        return super.onItemRightClick(world, player, hand);
    }
    
    @Override
	public void addInformation(ItemStack stack, World world, List<ITextComponent> list, ITooltipFlag flag)
	{
		super.addInformation(stack, world, list, flag);				
		list.add(new StringTextComponent(TextFormatting.BLUE + "Draws dropped items toward the player"));
		list.add(new StringTextComponent(TextFormatting.RED + "Attraction ability active: " + EnableUtil.isEnabled(stack)));
		list.add(new StringTextComponent(TextFormatting.GOLD + "Works while in player inventory"));
		list.add(new StringTextComponent(TextFormatting.GREEN + "Right-click to toggle on/off, sneak + right-click to cycle through ranges"));
	}   

}

 

In the 1.14.4 version, I was calling the public methods for posX, posY, posZ on PlayerEntity, now it is no longer visible due to be changing from public to private within the Entity.class.

 

I am looking for some guidance on how to access these private methods.

 

 

Posted
  On 12/25/2019 at 7:39 PM, kwpugh said:

Source code I am porting from 1.14.4 to 1.15.1

package com.kwpugh.gobber2.items.rings;

import java.util.List;

import com.kwpugh.gobber2.util.EnableUtil;
import com.kwpugh.gobber2.util.MagnetRange;

import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.ExperienceOrbEntity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;

public class ItemCustomRingAttraction extends Item
{

	public ItemCustomRingAttraction(Properties properties)
	{
		super(properties);
	}
	
	int range;

	public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected)
	{		
		if(entity instanceof PlayerEntity && !world.isRemote && EnableUtil.isEnabled(stack))
		{
			PlayerEntity player = (PlayerEntity)entity;
			
			boolean init = MagnetRange.getCurrentlySet(stack);
			
			if(!init)
			{
				range = 0;
			}
			else
			{
				range = MagnetRange.getCurrentRange(stack);
			}			
			
			double x = player.posX;
			double y = player.posY + 1.5;
			double z = player.posZ;

			boolean isPulling;
			
			//Scan for and collect items
			List<ItemEntity> items = entity.world.getEntitiesWithinAABB(ItemEntity.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
			for(ItemEntity e: items)
			{
				if(!player.isCrouching() && !e.getPersistentData().getBoolean("PreventRemoteMovement"))
				//if(!player.isSneaking())
				{
					isPulling = true;							
					double factor = 0.02;
					e.addVelocity((x - e.posX) * factor, (y - e.posY) * factor, (z - e.posZ) * factor);
				}
			}
			
			if(items.isEmpty())
			{
				isPulling = false;
			}
			
			//Scan for and collect XP Orbs
			List<ExperienceOrbEntity> xp = entity.world.getEntitiesWithinAABB(ExperienceOrbEntity.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
			for(ExperienceOrbEntity orb: xp)
			{
				if(!player.isCrouching())
				{
					isPulling = true;							
					double factor = 0.02;
					orb.addVelocity((x - orb.posX) * factor, (y - orb.posY) * factor, (z - orb.posZ) * factor);
                    player.onItemPickup(orb, 1);
                    player.giveExperiencePoints(orb.xpValue);
                    orb.remove();
				}
			}
			
			if(items.isEmpty())
			{
				isPulling = false;
			}
		}
	}
	
	@Override
    public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand)
    {
		ItemStack stack = player.getHeldItem(hand);	
		
		if(!world.isRemote && !(player.isCrouching()))
        {
            EnableUtil.changeEnabled(player, hand);
            player.sendMessage(new StringTextComponent("Attraction ability active: " + EnableUtil.isEnabled(stack)));
            return new ActionResult<ItemStack>(ActionResultType.SUCCESS, player.getHeldItem(hand));
        }		
		
        if(!world.isRemote && player.isCrouching())
        {
			if(range == 0)
			{
				range = 4;
				MagnetRange.setCurrentRange(stack, range);
				player.sendMessage(new StringTextComponent("Attraction range set to: " + MagnetRange.getCurrentRange(stack)));
			}
			else if(range == 4)
			{
				range = 8;
				MagnetRange.setCurrentRange(stack, range);
				player.sendMessage(new StringTextComponent("Attraction range set to: " + MagnetRange.getCurrentRange(stack)));
			}
			else if(range == 8)
			{
				range = 12;
				MagnetRange.setCurrentRange(stack, range);
				player.sendMessage(new StringTextComponent("Attraction range set to: " + MagnetRange.getCurrentRange(stack)));
			}
			else if(range == 12)
			{
				range = 0;
				MagnetRange.setCurrentRange(stack, range);
				player.sendMessage(new StringTextComponent("Attraction range set to: " + MagnetRange.getCurrentRange(stack)));
			}
        }
        
        return super.onItemRightClick(world, player, hand);
    }
    
    @Override
	public void addInformation(ItemStack stack, World world, List<ITextComponent> list, ITooltipFlag flag)
	{
		super.addInformation(stack, world, list, flag);				
		list.add(new StringTextComponent(TextFormatting.BLUE + "Draws dropped items toward the player"));
		list.add(new StringTextComponent(TextFormatting.RED + "Attraction ability active: " + EnableUtil.isEnabled(stack)));
		list.add(new StringTextComponent(TextFormatting.GOLD + "Works while in player inventory"));
		list.add(new StringTextComponent(TextFormatting.GREEN + "Right-click to toggle on/off, sneak + right-click to cycle through ranges"));
	}   

}

 

In the 1.14.4 version, I was calling the public methods for posX, posY, posZ on PlayerEntity, now it is no longer visible due to be changing from public to private within the Entity.class.

 

I am looking for some guidance on how to access these private methods.

 

 

Expand  

When I was coding I had quite same issue, but I saw there was a bunch of new methods just like previosX, chunkPosX and the sames(names of fields are about right, but that's not 100%). I started working on other things so I didn't finished with pos, but these methods from up above may do something samish

  • kwpugh changed the title to SOLVED [1.15.1] Accessing private method in Entity.class

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

    • ⚠️ DON'T CLICK THIS LINK OR ANYTHING RELATED TO THIS, IT HAS MALWARE IN THE LINK AND IT'S LIKELY A SCAM. ⚠️
    • ⚠️ DON'T CLICK THIS LINK OR ANYTHING RELATED TO THIS, IT HAS MALWARE IN THE LINK AND IT'S LIKELY A SCAM. ⚠️
    • I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. Contact : Whats...App : +.1 .4 7.4.3 5.3.7 7..1.9 Website : https://       digitalhackrecovery.com     Mail:            digitalhackrecovery         @techie.       com 
    • I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. I fight fires for a living, it's in my blood as a volunteer firefighter. But nothing could have prepared me for the fire that almost reduced my family's future to ashes. I had secretly accumulated $150,000 worth of Bitcoin over the years, intending to lock up my children's education and provide my wife with some leeway from our constant shift-work life. That was until a phishing attack struck me while I was out fighting a wildfire. The call had been on a hot afternoon. We were dashing to contain wildfires tearing across parched scrub lands. At such frantic moments, my phone pulsed with a security alert message from what looked like my Bitcoin wallet operator. Drenched with sweat, fatigue, and hyper adrenaline, I had clicked on the link and input my log-ins without questioning anything. I was tricked by hackers during my most vulnerable time. Hours later, returning to the station, I emptied my wallet. The harsh reality hit me with more force than any fire could ever have. My carefully saved safety net had vanished. My heart beat faster than the sirens. I felt as though I had failed my family. I explained my terror of burgers at our favorite local diner that evening to my friend. He leaned in close and whispered a single word: Digital Hack Recovery. He swore by their effectiveness, stating they worked miracles when his cousin had crypto stolen from him in a scam. I was skeptical old-school and desperate, so I called them. From the first call, their team treated me like family. They didn't only view figures; they viewed a husband and a father attempting to rectify a horrific error. They labored day and night, following stolen money through blockchain transactions like l detectives. Progress was made every day, translating intricate tech into fireman-speak. Ten days later, I got the call. “We recovered your Bitcoin.” I cried. Right there in the station, surrounded by smoke-stained gear, I let it all out. Relief. Gratitude. Hope they don't stop there. Knowing I worked in emergency services, Digital Hack Recovery offered to run an online security workshop for my entire fire department. They turned my disaster into a lesson that safeguarded my team. These folks don’t just recover wallets; they rebuild lives. They rebuilt mine. Contact : Wh.ats.Ap.p : +1 .4 .7  4 3. 5  3  .7 7.1.9 Website : https://     digitalhackrecovery.   com Mail:       digitalhackrecovery     @         techie.                     com  
    • Ran it one more time just to check, and there's no errors this time on the log??? Log : https://mclo.gs/LnuaAiu I tried allocating more memory to the modpack, around 8000MB and it's still the same; stopping at "LOAD_REGISTRIES". Are some of the mods clashing, maybe? I have no clue what to do LOL
  • Topics

×
×
  • Create New...

Important Information

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