Jump to content

[1.15.2] [Solved] Custom arrow entity not rendering


squidlex

Recommended Posts

I am trying to create a custom arrow however when it is fired from the bow the arrow itself is not rendered.

The entity is created however.

Here's my code:

 

Combat.java

@Mod("combat")
public class Combat {
	public static final Logger LOGGER = LogManager.getLogger();
	public static final String MODID = "combat";
	public static Combat instance;

	public static EntityType<CustomArrowEntity> CUSTOM_ARROW_ENTITY_TYPE = EntityType.Builder
			.<CustomArrowEntity>create(CustomArrowEntity::new, EntityClassification.MISC).size(0.5f, 0.5f)
			.build("custom_arrow");

	public Combat() {
		final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
		modEventBus.addListener(this::setup);
		modEventBus.addListener(this::doClientStuff);

		ModEntityTypes.ENTITY_TYPES.register(modEventBus);

		instance = this;

		ModLoadingContext.get().registerConfig(net.minecraftforge.fml.config.ModConfig.Type.SERVER, ModConfig.SPEC);
		ModConfig.init(FMLPaths.CONFIGDIR.get().resolve(MODID + "-server.toml"));
		MinecraftForge.EVENT_BUS.register(this);
	}

	private void setup(final FMLCommonSetupEvent event) {
		Keybinds.register();
		MinecraftForge.EVENT_BUS.register(new CombatGui());
	}

	private void doClientStuff(final FMLClientSetupEvent event) {
		LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);

	}

	// Register Entities
	@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
	public static class RegistryEvents {
		@SubscribeEvent
		public static void registerEntityTypes(final RegistryEvent.Register<EntityType<?>> event) {
			event.getRegistry().register(
					CUSTOM_ARROW_ENTITY_TYPE.setRegistryName(new ResourceLocation("combat", "custom_arrow")));
		}
	}

	@SubscribeEvent
	public void onServerStarting(FMLServerStartingEvent event) {
		LOGGER.info("HELLO from server starting");
	}

}

 

CustomArrowEntity.java

public class CustomArrowEntity extends AbstractArrowEntity {

	public CustomArrowEntity(EntityType<? extends CustomArrowEntity> p_i50172_1_, World p_i50172_2_) {
		super(p_i50172_1_, p_i50172_2_);
	}

	public CustomArrowEntity(World worldIn, double x, double y, double z) {
		super(Combat.CUSTOM_ARROW_ENTITY_TYPE, x, y, z, worldIn);
	}

	public CustomArrowEntity(World worldIn, LivingEntity shooter) {
		super(Combat.CUSTOM_ARROW_ENTITY_TYPE, shooter, worldIn);
	}

	protected void arrowHit(LivingEntity living) {
		super.arrowHit(living);

	}

	protected ItemStack getArrowStack() {
		return new ItemStack(ItemInit.custom_arrow);
	}

}

 

ModelHandler.java

@EventBusSubscriber(value = Dist.CLIENT, modid = Combat.MODID, bus = EventBusSubscriber.Bus.MOD)
public class ModelHandler {

	@SubscribeEvent
	public static void registerModels(ModelRegistryEvent event) {
		RenderingRegistry.registerEntityRenderingHandler(Combat.CUSTOM_ARROW_ENTITY_TYPE, CustomArrowRenderer::new);
	}
}

 

 

CustomArrowRenderer.java

@OnlyIn(Dist.CLIENT)
public class CustomArrowRenderer<T extends CustomArrowEntity> extends ArrowRenderer<T> {


	public static final ResourceLocation CUSTOM_ARROW_RL = new ResourceLocation(Combat.MODID, "textures/entity/projectiles/custom_arrow.png");

	public CustomArrowRenderer(EntityRendererManager renderManagerIn) {
		super(renderManagerIn);
	}

	@Override
	public ResourceLocation getEntityTexture(CustomArrowEntity entity) {
		return CUSTOM_ARROW_RL;
	}
}

 

Apologies for the long question.

Thank you for your help!

Edited by squidlex
Solved!
Link to comment
Share on other sites

8 hours ago, diesieben07 said:
  • Do not create registry entries within a static initializer. Use DeferredRegister.
  • That is not where registerEntityRenderingHandler tells you to call it.

  • Do not use @OnlyIn.

  • Custom non-living entities must override createSpawnPacket and call NetworkHooks.getEntitySpawningPacket.

Thanks for all your help, I've made every fix suggested.

Unfortunately my arrow still isn't rendering so I will try and look through some source code to see how other people have achieved it.

 

Thanks again.

Link to comment
Share on other sites

I have seen that some people are able to use the actual entity class itself in registerEntityRenderingHandler

RenderingRegistry.registerEntityRenderingHandler(CustomArrowEntity.class, CustomArrowRenderer::new);

However I get the error

The method registerEntityRenderingHandler(EntityType<T>, IRenderFactory<? super T>) in the type RenderingRegistry is not applicable for the arguments (Class<CustomngArrowEntity>, IRenderFactory<? super T>)

When I attempt this.

Link to comment
Share on other sites

2 minutes ago, diesieben07 said:

It is not the class itself, it is a constructor reference. Learn about lambdas, method- and constructor references in Java if you want to use this approach.

 

Please show your updated code with the fixes applied.

Thanks for all your help diesieben07 but I ended up just using the vanilla EntityType.ARROW for now.

Are there any issues with this approach if I'm happy with my arrow looking like the vanilla one?

 

I'll take a look at those, thanks for the advice :)

Link to comment
Share on other sites

3 hours ago, diesieben07 said:

Your entity will be saved to disk as a vanilla arrow as well.

You might as well just use the vanilla arrow.

Ah that's not what I'm after, I'll rewrite my code for the entity type and get back to you.

Many thanks.

 

Edit: Turns out I didn't set up my deffered register correctly, works a charm now!

Thanks for the support.

Edited by squidlex
Fixed it
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

    • How to fix file server-1.20.1-20230612.114412-srg.jar  
    • Just a few months ago I was creating my own plugin for Minecraft 1.20.2 spigot that did the same thing, but the skins were not saved, if you can understand this code that I made a long time ago it may help you.   //This is a class method private static String APIRequest(String value, String url, String toSearch) { try { URL api = new URL(url + value); HttpURLConnection connection = (HttpURLConnection) api.openConnection(); connection.setRequestMethod("GET"); int responseCode = connection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder(); for (String responseChar; (responseChar = reader.readLine()) != null; ) response.append(responseChar); reader.close(); JSONObject responseObject = new JSONObject(response.toString()); if (!toSearch.equals("id")) return responseObject .getJSONArray("properties") .getJSONObject(0) .getString("value"); else return responseObject.getString("id"); } else { AntiGianka.ConsoleMessage(ChatColor.RED, String.format( "Could not get %s. Response code: %s", ((toSearch.equals("id")) ? "UUID" : "texture"), responseCode )); } } catch (MalformedURLException error) { AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error); } catch (IOException error) { AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while attempting to connect to the URL. Error: " + error); } return ""; } //other class method private void SkinGetter() { String uuid; String textureCoded; if ((uuid = APIRequest(args[0], "https://api.mojang.com/users/profiles/minecraft/", "id")).isEmpty() || (textureCoded = APIRequest(uuid, "https://sessionserver.mojang.com/session/minecraft/profile/", "value")).isEmpty() ) sender.sendMessage(ChatColor.RED + String.format( "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.", args[0], args[0] ) ); else SkinSetter(textureCoded); } //other more private void SkinSetter(String textureCoded) { JSONObject profile = new JSONObject(new String(Base64.getDecoder().decode(textureCoded))); try { URL textureUrl = new URL(profile.getJSONObject("textures"). getJSONObject("SKIN"). getString("url")); if (sender instanceof Player && args.length == 1) { PlayerTextures playerTextures = ((Player) sender).getPlayerProfile().getTextures(); playerTextures.setSkin(textureUrl); ((Player) sender).getPlayerProfile().setTextures(playerTextures); if (((Player) sender).getPlayerProfile().getTextures().getSkin() != null) sender.sendMessage(((Player) sender).getPlayerProfile().getTextures().getSkin().toString()); else sender.sendMessage("Null"); sender.sendMessage("Skin changed successfully.a"); } else { } AntiGianka.ConsoleMessage(ChatColor.GREEN, "Skin command executed successfully."); } catch (MalformedURLException error) { sender.sendMessage(ChatColor.RED + String.format( "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.", args[0], args[0] ) ); AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error); } }  
    • Use /locate structure The chat should show all available structures as suggestion For the Ancient City it is /locate structure ancient_city
    • So does it work without this mod? Did you test it with other builds?
  • Topics

×
×
  • Create New...

Important Information

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