Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.1] Flying Entity Speed
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 2
DavidQF555

[1.16.1] Flying Entity Speed

By DavidQF555, August 1, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 1, 2020
public class CustomEntity extends FlyingEntity {

	public CustomEntity(EntityType<? extends FlyingEntity> type, World worldIn) {
		super(type, worldIn);
		moveController = new FlyingMovementController(this, 60, true);
	}

	public static AttributeModifierMap.MutableAttribute setAttributes(){
		return MobEntity.func_233666_p_()
				.func_233815_a_(Attributes.field_233822_e_, (double) 5.0f)
				.func_233815_a_(Attributes.field_233821_d_, (double) 5.0f)
				.func_233815_a_(Attributes.field_233818_a_, 10);
	}

	@Override
	public void registerGoals() {
		super.registerGoals();
		goalSelector.addGoal(0, new FollowOwnerGoal());
		goalSelector.addGoal(1, new LookAtGoal(this, PlayerEntity.class, 5));
	}

	@Override
	protected PathNavigator createNavigator(World worldIn) {
		return new FlyingPathNavigator(this, worldIn);
	}

	private class FollowOwnerGoal extends Goal {

		private static final int DISTANCE = 5;

		private FollowOwnerGoal() {
			setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
		}

		@Override
		public boolean shouldExecute() {
			return getOwner() != null && getDistanceSq(getOwner()) > DISTANCE * DISTANCE;
		}

		@Override
		public boolean shouldContinueExecuting() {
			return shouldExecute() && !getNavigator().noPath();
		}

		@Override
		public void tick() {
			getNavigator().tryMoveToXYZ(getOwner().getPosX(), getOwner().getPosYEye(), getOwner().getPosZ(), 1);
		}
	}
}
private void setup(final FMLCommonSetupEvent event) {
		DeferredWorkQueue.runLater(() -> {
			GlobalEntityTypeAttributes.put(RegistryHandler.CUSTOM_ENTITY.get(), CustomEntity.setAttributes().func_233813_a_());
		});
	}

This should be all the relevant code. Basically, no matter what the speed attribute of my entity is, it is always insanely slow. I thought it might have to do with the FlyingPathNavigator and MovementController's just not using the right speed, but I also changed the generic movement speed attribute and nothing changed. I feel like I probably needed to override another method or something. What have I done wrong?

  • Quote

Share this post


Link to post
Share on other sites

Dzuchun    11

Dzuchun

Dzuchun    11

  • Stone Miner
  • Dzuchun
  • Members
  • 11
  • 98 posts
Posted August 1, 2020 (edited)
6 hours ago, DavidQF555 said:

getNavigator().tryMoveToXYZ(getOwner().getPosX(), getOwner().getPosYEye(), getOwner().getPosZ(), 1);

A number 1 you pass here is actually double and defines movement speed multiplier.

Resulting movement speed will equal to speed attribute * this parameter, as shown at MovementController::tick.

So, you may try change 1 to 1.0d, and then set there, for example, 2.0d.

Edited August 1, 2020 by Dzuchun
  • Quote

Everything said above may be absolutely wrong. No rights reserved.

Share this post


Link to post
Share on other sites

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 2, 2020
5 hours ago, Dzuchun said:

A number 1 you pass here is actually double and defines movement speed multiplier.

Resulting movement speed will equal to speed attribute * this parameter, as shown at MovementController::tick.

So, you may try change 1 to 1.0d, and then set there, for example, 2.0d.

I changed it to 2.0D and nothing has really changed. Using livingTick() to print out speed, it constantly switches between the number I set in the tryMoveToXYZ() and 0. It just ignores my attribute, and the speed printed is also not really applied to how fast the actual entity is. I put in 100.0D and nothing changed. 

  • Quote

Share this post


Link to post
Share on other sites

Dzuchun    11

Dzuchun

Dzuchun    11

  • Stone Miner
  • Dzuchun
  • Members
  • 11
  • 98 posts
Posted August 2, 2020

Where from do you execute setAttributes method?

It's static, so it does not override something.

Also, you'd better provide full source code(using github, for example), because usually errors are in the places you do not expect them :)

  • Quote

Everything said above may be absolutely wrong. No rights reserved.

Share this post


Link to post
Share on other sites

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 2, 2020
19 minutes ago, Dzuchun said:

Where from do you execute setAttributes method?

It's static, so it does not override something.

Also, you'd better provide full source code(using github, for example), because usually errors are in the places you do not expect them :)

The setAttributes method is in the code I sent, in the Main class. I know it works because FlyingPathNavigator does not even work without a flying speed. Also, its health is actually 10. 

  • Quote

Share this post


Link to post
Share on other sites

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 2, 2020

Let me just post the code of all the classes that have some relevance: 

ublic class CustomEntity extends FlyingEntity {

  private LivingEntity owner;
  
	public CustomEntity(EntityType<? extends FlyingEntity> type, World worldIn, LivingEntity owner) {
		super(type, worldIn);
		moveController = new FlyingMovementController(this, 60, true);
      this.owner = owner;
	}
  
  public LivingEntity getOwner(){
   return owner; 
  }

	public static AttributeModifierMap.MutableAttribute setAttributes(){
		return MobEntity.func_233666_p_()
				.func_233815_a_(Attributes.field_233822_e_, (double) 5.0f)
				.func_233815_a_(Attributes.field_233821_d_, (double) 5.0f)
				.func_233815_a_(Attributes.field_233818_a_, 10);
	}

	@Override
	public void registerGoals() {
		super.registerGoals();
		goalSelector.addGoal(0, new FollowOwnerGoal());
		goalSelector.addGoal(1, new LookAtGoal(this, PlayerEntity.class, 5));
	}

	@Override
	protected PathNavigator createNavigator(World worldIn) {
		return new FlyingPathNavigator(this, worldIn);
	}

	private class FollowOwnerGoal extends Goal {

		private static final int DISTANCE = 5;

		private FollowOwnerGoal() {
			setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
		}

		@Override
		public boolean shouldExecute() {
			return getOwner() != null && getDistanceSq(getOwner()) > DISTANCE * DISTANCE;
		}

		@Override
		public boolean shouldContinueExecuting() {
			return shouldExecute() && !getNavigator().noPath();
		}

		@Override
		public void tick() {
			getNavigator().tryMoveToXYZ(getOwner().getPosX(), getOwner().getPosYEye(), getOwner().getPosZ(), 1);
		}
	}
}
@SuppressWarnings("deprecation")
@Mod("testmod")
public class TestMod {

	public static final String MOD_ID = "testmod";
	public static final ItemGroup TAB = new ItemGroup("testmod") {
		@Override
		public ItemStack createIcon() {
			return new ItemStack(RegistryHandler.RUBY.get());
		}
	};

	public TestMod() {
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

		RegistryHandler.init();

		MinecraftForge.EVENT_BUS.register(this);
	}

	private void setup(final FMLCommonSetupEvent event) {
		DeferredWorkQueue.runLater(() -> {
			GlobalEntityTypeAttributes.put(RegistryHandler.CUSTOM_ENTITY.get(), CustomEntity.setAttributes().func_233813_a_());
		});
	}

	private void doClientStuff(final FMLClientSetupEvent event) {}

}
public class RegistryHandler {

	public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, TestMod.MOD_ID);

	public static final RegistryObject<EntityType<CustomEntity>> CUSTOM_ENTITY = ENTITY_TYPES.register("custom_entity", () -> EntityType.Builder.create(new CustomFactory(), EntityClassification.AMBIENT).size(0.9f, 0.9f).build(new ResourceLocation(TestMod.MOD_ID, "custom_entity").toString()));

	public static void init() {
		IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
		ENTITY_TYPES.register(bus);
	}
public class CustomFactory implements EntityType.IFactory<CustomEntity> {
		@Override
		public CustomEntity create(EntityType<CustomEntity> type, World world) {
			return new CustomEntity(type, world, null);
		}
	}
public class CustomItem extends BasicItem {

	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
		Vector3d spawn = playerIn.getEyePosition(1).add(playerIn.getLookVec().mul(2, 2, 2));
		CustomEntity light = new CustomEntity(RegistryHandler.CUSTOM_ENTITY.get(), worldIn, playerIn);
		if(light.canSpawn(worldIn, SpawnReason.MOB_SUMMONED)) {
			light.setPosition(spawn.x, spawn.y, spawn.z);
			worldIn.addEntity(light);
			ItemStack item = playerIn.getHeldItem(handIn);
			item.setCount(item.getCount() - 1);
			playerIn.setHeldItem(handIn, item);
		}
		return ActionResult.resultPass(playerIn.getHeldItem(handIn));
	}
}

 

  • Quote

Share this post


Link to post
Share on other sites

Dzuchun    11

Dzuchun

Dzuchun    11

  • Stone Miner
  • Dzuchun
  • Members
  • 11
  • 98 posts
Posted August 2, 2020
1 hour ago, DavidQF555 said:

public class CustomFactory implements EntityType.IFactory<CustomEntity> 
{ 
  @Override
  public CustomEntity create(EntityType<CustomEntity> type, World world)
  { 
    return new CustomEntity(type, world, null); 
  } 
}

 

You may use lambda-expression for that.

It won't help you at all, but you'll get rid of some excess code.

1 hour ago, DavidQF555 said:

private class FollowOwnerGoal extends Goal

Minecraft has FollowOwnerGoal for you to have a template (it requires TameableEntity).

The problem may be that you set a new path every tick. Stock FollowOwnerGoal does it every 10 ticks. (not sure)

  • Quote

Everything said above may be absolutely wrong. No rights reserved.

Share this post


Link to post
Share on other sites

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 2, 2020
1 hour ago, Dzuchun said:

You may use lambda-expression for that.

It won't help you at all, but you'll get rid of some excess code.

Minecraft has FollowOwnerGoal for you to have a template (it requires TameableEntity).

The problem may be that you set a new path every tick. Stock FollowOwnerGoal does it every 10 ticks. (not sure)

I checked it, it basically does the same thing except check more conditions like whether sitting or not. I updated my code to: 

private class FollowOwnerGoal extends Goal {

		private static final int DISTANCE = 5;
		private static final int COOLDOWN = 200;
		private int cooldown;

		private FollowOwnerGoal() {
			setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
			cooldown = 0;
		}

		@Override
		public boolean shouldExecute() {
			return getOwner() != null && getDistanceSq(getOwner()) > DISTANCE * DISTANCE;
		}

		@Override
		public boolean shouldContinueExecuting() {
			return shouldExecute() && !getNavigator().noPath();
		}
		
		@Override
		public void resetTask() {
			cooldown = 0;
			getNavigator().clearPath();
		}

		@Override
		public void tick() {
			cooldown = Math.max(0, cooldown - 1);
			if(cooldown == 0) {
				getNavigator().tryMoveToXYZ(getOwner().getPosX(), getOwner().getPosYEye(), getOwner().getPosZ(), 100.0D);
				cooldown = COOLDOWN;
			}
		}
	}

To attempt to replicate the Tameable one, but it still has the same effect. I think it has something to do with either switching to FlyingMovementController or FlyingPathNavigator, but I cannot figure out what the problem is. 

  • Quote

Share this post


Link to post
Share on other sites

Dzuchun    11

Dzuchun

Dzuchun    11

  • Stone Miner
  • Dzuchun
  • Members
  • 11
  • 98 posts
Posted August 2, 2020 (edited)

I used to experiment with creating custom entities at 1.15.2, but seems like not much changed since then*nevermind*. Here is my repository.

Please, do not use it as manual, it's terrible in fact. All you need about AI is at HappyDolphinEntity class, which defines a pink horned flying dolphin that eats flowers accidentally (don't ask me why).

In that class you may see my own WanderingGoal, (because I was to stupid to use existing one, yea) and all sort of things I made to get it working.

I'm really sorry for posting this code here, and once again, THIS IS NOT A MANUAL.

Read sign.

Edited August 2, 2020 by Dzuchun
  • Quote

Everything said above may be absolutely wrong. No rights reserved.

Share this post


Link to post
Share on other sites

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 2, 2020
33 minutes ago, Dzuchun said:

I used to experiment with creating custom entities at 1.15.2, but seems like not much changed since then. Here is my repository.

Please, do not use it as manual, it's terrible in fact. All you need about AI is at HappyDolphinEntity class, which defines a pink horned flying dolphin that eats flowers accidentally (don't ask me why).

In that class you may see my own WanderingGoal, (because I was to stupid to use existing one, yea) and all sort of things I made to get it working.

I'm really sorry for posting this code here, and once again, THIS IS NOT A MANUAL.

Read sign.

private class FollowOwnerGoal extends Goal {

		private static final int DISTANCE = 5;

		private FollowOwnerGoal() {
			setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
		}

		@Override
		public boolean shouldExecute() {
			return getNavigator().noPath() && getOwner() != null && getDistanceSq(getOwner()) > DISTANCE * DISTANCE;
		}

		@Override
		public boolean shouldContinueExecuting() {
			return false;
		}
		
		@Override
		public void startExecuting() {
			super.startExecuting();
			getNavigator().tryMoveToXYZ(getOwner().getPosX(), getOwner().getPosYEye(), getOwner().getPosZ(), 100);
		}
	}

I really simplified mine. Your code has a lot more factors, but I just need it to move, so this should work, but it doesn't consider the speed at all

  • Quote

Share this post


Link to post
Share on other sites

Dzuchun    11

Dzuchun

Dzuchun    11

  • Stone Miner
  • Dzuchun
  • Members
  • 11
  • 98 posts
Posted August 2, 2020
1 minute ago, DavidQF555 said:

@Override
public boolean shouldContinueExecuting() 
{ 
 return false;
}

 

This means that after 1 tick your task gets interrupted and another one selected.

  • Quote

Everything said above may be absolutely wrong. No rights reserved.

Share this post


Link to post
Share on other sites

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 2, 2020
Just now, Dzuchun said:

This means that after 1 tick your task gets interrupted and another one selected.

It doesn't really matter though. It currently only has 1 goal and that goal really only needs to run the starting code

  • Quote

Share this post


Link to post
Share on other sites

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 3, 2020
private class FollowOwnerGoal extends Goal {

		private static final double DISTANCE = 5;

		private FollowOwnerGoal() {
			setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
		}

		@Override
		public boolean shouldExecute() {
			Entity owner = getOwner();
			if (owner == null) {
				return false;
			} else if (owner.isSpectator()) {
				return false;
			} else return !(getDistanceSq(owner) < DISTANCE * DISTANCE);
		}

		/**
		 * Returns whether an in-progress EntityAIBase should continue executing
		 */
		public boolean shouldContinueExecuting() {
			if (getNavigator().noPath() || getOwner() == null) {
				return false;
			} else {
				return !(getDistanceSq(getOwner()) <= DISTANCE * DISTANCE);
			}
		}

		/**
		 * Reset the task's internal state. Called when this task is interrupted by another one
		 */
		public void resetTask() {
		getNavigator().clearPath();
			LOGGER.info("Reset");
		}

		/**
		 * Keep ticking a continuous task that has already been started
		 */
		public void tick() {
			if(getOwner() != null) {
				getLookController().setLookPositionWithEntity(getOwner(), 10.0F, getVerticalFaceSpeed());
				if (!getLeashed() && !isPassenger()) {
					LOGGER.info("controller: " + moveController.getSpeed() + " AI: " + getAIMoveSpeed());
					getNavigator().tryMoveToEntityLiving(getOwner(), 100);

				}
			}
		}
	}

I've basically copied the Tameable version now. Is it normal for the "reset" to be called every 5 ticks? The other logger message is completely normal

  • Quote

Share this post


Link to post
Share on other sites

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 3, 2020

I figured out that the AI Speed in CustomEntity is changing to speed multiplier * attribute, but the speed in moveController was staying to exactly the speed multiplier, but the actual speed moving doesn't change

  • Quote

Share this post


Link to post
Share on other sites

DavidQF555    0

DavidQF555

DavidQF555    0

  • Stone Miner
  • DavidQF555
  • Members
  • 0
  • 51 posts
Posted August 21, 2020

What variable is used by the moveController to determine the actual speed used to fly?

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Draco18s
      What is the method to left click?

      By Draco18s · Posted 27 minutes ago

      There isn't one. Documentation (such as there is) is all inside the code itself.
    • Gubipe
      What is the method to left click?

      By Gubipe · Posted 37 minutes ago

      can you link me to the documentation page for it?
    • ju_
      Minecraft crashes while launching - failed to find service port for display

      By ju_ · Posted 3 hours ago

      Hi, to follow on the subject i have the same issue https://pastebin.com/E47LtT43 it works fine on my end with vanilla or other version. i only have this issue with forge for 1.16
    • poopoodice
      What is the method to left click?

      By poopoodice · Posted 3 hours ago

      Check Minecraft#processKeyBinds where it checks for attack keybind (left mouse).
    • kiou.23
      Mod won't load when in dev environment

      By kiou.23 · Posted 3 hours ago

      You need to update the build.gradle to have your modid instead of the default examplemod you'll want to modify the group, the modid and pretty much everywhere where "examplemod" is shown, you'll want to replace with your own modid   note: you have a static field in your main mod class (Warwolves.java) called MOD_ID, whenever you need the mod id, you should be referencing this field, instead of typing the string every time note 2: don't create an ItemBase class https://championash5357.github.io/ChampionAsh5357/tutorial/minecraft/ciar#code-style-5
  • Topics

    • Gubipe
      3
      What is the method to left click?

      By Gubipe
      Started 4 hours ago

    • schmiddi_0
      16
      Minecraft crashes while launching - failed to find service port for display

      By schmiddi_0
      Started December 14, 2020

    • Silivek
      1
      Mod won't load when in dev environment

      By Silivek
      Started 8 hours ago

    • BoGuBoy
      2
      3rd party hosted Server wont launch

      By BoGuBoy
      Started 8 hours ago

    • Ronshark
      1
      tempête de Neige primal winter

      By Ronshark
      Started 7 hours ago

  • Who's Online (See full list)

    • Caffeinated Pinkie
    • mightymoy
    • anonomous
    • ZetaLuxray
    • Jakans
    • henzo800
    • AubriTheHuman
    • ThatTreeGuy
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.1] Flying Entity Speed
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community