Posted April 21, 20205 yr 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 April 21, 20205 yr by squidlex Solved!
April 21, 20205 yr Author 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.
April 21, 20205 yr Author 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.
April 21, 20205 yr Author 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
April 21, 20205 yr Author 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 April 21, 20205 yr by squidlex Fixed it
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.