Jump to content

[1.10.2] Custom arrow can't be fired


Egietje

Recommended Posts

I've added my own custom arrow and I can do /summon dgm.CheeseArrow and it will just spawn but when I have it in my inventory and use a bow it isn't fired but it shoots a normal arrow (in survival)

Arrow item:

package com.Egietje.degeweldigemod.init;

import com.Egietje.degeweldigemod.entities.cheesearrow.EntityCheeseArrow;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.projectile.EntitySpectralArrow;
import net.minecraft.item.ItemArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class CheeseArrow extends ItemArrow {

public CheeseArrow() {
	super();
}

public EntityArrow makeTippedArrow(World world, ItemStack stack, EntityLivingBase shooter) {
        return new EntityCheeseArrow(world, shooter);
    }

}

Arrow entity:

import com.Egietje.degeweldigemod.init.CheeseItems;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.world.World;

public class EntityCheeseArrow extends EntityArrow {
private int duration = 200;

public EntityCheeseArrow(World worldIn) {
	super(worldIn);
}

public EntityCheeseArrow(World worldIn, EntityLivingBase shooter) {
	super(worldIn, shooter);
}

public EntityCheeseArrow(World worldIn, double x, double y, double z) {
	super(worldIn, x, y, z);
}

@Override
public void onUpdate() {
	super.onUpdate();
	if (this.worldObj.isRemote && !this.inGround) {
		this.worldObj.spawnParticle(EnumParticleTypes.END_ROD, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
	}
}

@Override
public ItemStack getArrowStack() {
	return new ItemStack(CheeseItems.CHEESE_ARROW);
}

@Override
public void arrowHit(EntityLivingBase living) {
	super.arrowHit(living);
	World world = living.getEntityWorld();
	if(living != shootingEntity) {
		world.createExplosion(shootingEntity, living.posX, living.posY, living.posZ, 4.0F, true);
	}
}
}

Entity renderer:

package com.Egietje.degeweldigemod.entities.cheesearrow;

import com.Egietje.degeweldigemod.Reference;

import net.minecraft.client.renderer.entity.RenderArrow;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderCheeseArrow extends RenderArrow<EntityCheeseArrow>
{
    public static final ResourceLocation CHEESE_ARROW_TEXTURES = new ResourceLocation(Reference.MODID + ":textures/entity/cheese_arrow.png");

    public RenderCheeseArrow(RenderManager manager) {
        super(manager);
    }

    protected ResourceLocation getEntityTexture(EntityCheeseArrow entity) {
        return CHEESE_ARROW_TEXTURES;
    }
}

Client proxy:

package com.Egietje.degeweldigemod.proxy;

import com.Egietje.degeweldigemod.DeGeweldigeMod;
import com.Egietje.degeweldigemod.Reference;
import com.Egietje.degeweldigemod.entities.cheesearrow.EntityCheeseArrow;
import com.Egietje.degeweldigemod.entities.cheesearrow.RenderingHandlerCheeseArrow;
import com.Egietje.degeweldigemod.entities.cheesecow.*;
import com.Egietje.degeweldigemod.handler.CheeseClientHandler;
import com.Egietje.degeweldigemod.handler.CheeseCommonHandler;
import com.Egietje.degeweldigemod.init.CheeseBlocks;
import com.Egietje.degeweldigemod.init.CheeseItems;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Biomes;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;

@SideOnly(Side.CLIENT)
public class ClientProxy extends CommonProxy {

public void registerModels() {
	registerItemModel(CheeseItems.CHEESE, 0);
	registerItemModel(CheeseItems.CHEESE_COOKED, 0);
	registerItemModel(CheeseItems.BREAD_CHEESE, 0);
	registerItemModel(CheeseItems.CHEESE_APPLE, 0);
	registerItemModel(CheeseItems.CHEESE_BUCKET, 0);

	registerItemModel(CheeseItems.CHEESE_INGOT, 0);
	registerItemModel(CheeseItems.CHEESE_ARROW, 0);

	registerItemModel(CheeseItems.CHEESE_SWORD, 0);
	registerItemModel(CheeseItems.CHEESE_PICKAXE, 0);
	registerItemModel(CheeseItems.CHEESE_AXE, 0);
	registerItemModel(CheeseItems.CHEESE_SHOVEL, 0);
	registerItemModel(CheeseItems.CHEESE_HOE, 0);
	registerItemModel(CheeseItems.CHEESE_FLY_STICK, 0);
	registerItemModel(CheeseItems.CHEESE_BOW, 0);

	registerItemModel(CheeseItems.CHEESE_HELMET, 0);
	registerItemModel(CheeseItems.CHEESE_CHESTPLATE, 0);
	registerItemModel(CheeseItems.CHEESE_LEGGINGS, 0);
	registerItemModel(CheeseItems.CHEESE_BOOTS, 0);

	registerBlockModel(CheeseBlocks.CHEESE_ORE, 0);
	registerBlockModel(CheeseBlocks.CHEESE_ORE_NETHER, 0);
	registerBlockModel(CheeseBlocks.CHEESE_ORE_END, 0);
	registerBlockModel(CheeseBlocks.CHEESE_BLOCK, 0);
	registerBlockModel(CheeseBlocks.QUICK_CHEESE, 0);
	registerBlockModel(CheeseBlocks.COMPLIMENT_MACHINE, 0);
	registerBlockModel(CheeseBlocks.BELGIUM_FLAG, 0);
	registerBlockModel(CheeseBlocks.CHEESE_WORKBENCH, 0);
}

public void registerEventHandler() {
	MinecraftForge.EVENT_BUS.register(new CheeseClientHandler());
}

public void renderEntities() {
	RenderingRegistry.registerEntityRenderingHandler(EntityCheeseCow.class, new RenderingHandlerCheeseCow());
	RenderingRegistry.registerEntityRenderingHandler(EntityCheeseArrow.class, new RenderingHandlerCheeseArrow());
}

private void registerItemModel(Item item, int meta) {
	ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), "inventory"));
}

private void registerBlockModel(Block block, int meta) {
	ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), meta, new ModelResourceLocation(block.getRegistryName(), "inventory"));
}
}

Main class:

package com.Egietje.degeweldigemod;

import org.lwjgl.opengl.Display;

import com.Egietje.degeweldigemod.entities.CheeseSpawnPlacementRegistry;
import com.Egietje.degeweldigemod.entities.cheesearrow.EntityCheeseArrow;
import com.Egietje.degeweldigemod.entities.cheesecow.EntityCheeseCow;
import com.Egietje.degeweldigemod.entities.cheesecow.ModelCheeseCow;
import com.Egietje.degeweldigemod.entities.cheesecow.RenderCheeseCow;
import com.Egietje.degeweldigemod.handler.CheeseCommonHandler;
import com.Egietje.degeweldigemod.init.CheeseBlocks;
import com.Egietje.degeweldigemod.init.CheeseItems;
import com.Egietje.degeweldigemod.proxy.CommonProxy;

import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntitySpawnPlacementRegistry;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.init.Biomes;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, acceptedMinecraftVersions = "[1.10.2]")
public class DeGeweldigeMod {
public static final CheeseTab tabCheeseStuff = new CheeseTab("tabCheeseStuff");

@SidedProxy(clientSide = Reference.CLIENTPROXY, serverSide = Reference.COMMONPROXY)
public static CommonProxy proxy;

@Instance(Reference.MODID)
public static DeGeweldigeMod DGMInstance;

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
	registerModEntityWithEgg(EntityCheeseCow.class, "CheeseCow", 0x917B1B, 0x8E814E, 250);
	EntityRegistry.addSpawn(EntityCheeseCow.class, 8, 4, 4, EnumCreatureType.CREATURE, Biomes.PLAINS);
	EntityRegistry.registerModEntity(EntityCheeseArrow.class, "CheeseArrow", 251, this.DGMInstance, 64, 1, true);

	new CheeseItems();
	new CheeseBlocks();
	new CheeseAchievements();
	new CheeseSpawnPlacementRegistry();

	proxy.registerModels();
	proxy.renderEntities();

	Display.setTitle("Minecraft - 1.10.2 | DeGeweldigeMod - " + Reference.VERSION);
}

@EventHandler
public static void init(FMLInitializationEvent event) {
	new CheeseCraftingAndSmelting();

	proxy.registerEventHandler();

	GameRegistry.registerWorldGenerator(new CheeseGeneration(), 0);
}

@EventHandler
public static void postInit(FMLPostInitializationEvent event) {
}

public void registerModEntityWithEgg(Class entityClass, String entityName, int eggColor, int eggSpotsColor, int entityID) {
    EntityRegistry.registerModEntity(entityClass, entityName, entityID, this.DGMInstance, 80, 3, false);
    EntityRegistry.registerEgg(entityClass, eggColor, eggSpotsColor);
}
}

Link to comment
Share on other sites

CheeseArrow#makeTippedArrow

doesn't override a super method because there is no method with that name in

ItemArrow

. Override

ItemArrow#createArrow

instead.

 

Always annotate override methods with

@Override

so you get a compilation error if the method doesn't actually override a super method.

 

Using rendering-related classes like

Display

in common code will crash the dedicated server since it doesn't use those libraries. Rendering-related code must only run on the client side. Changing the window title is a bit obnoxious, the user doesn't need to be constantly reminded that they're using your mod.

 

Don't access static fields (e.g.

DeGeweldigeMod.DGMInstance

) through instances (e.g.

this

).

 

There's no reason to use the

@Instance

field within your

@Mod

class; the methods are already being called on that instance, so use

this

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Here's a simple example to solve this particular issue: public class ModArmorMaterials { public static final DeferredRegister<ArmorMaterial> ARMORS = DeferredRegister.create(Registries.ARMOR_MATERIAL, MyModName.MOD_ID); public static final RegistryObject<ArmorMaterial> COPPER = registerArmor("copper", Util.make(new EnumMap<>(ArmorItem.Type.class), enumMap -> { enumMap.put(ArmorItem.Type.BOOTS, 1); enumMap.put(ArmorItem.Type.LEGGINGS, 4); enumMap.put(ArmorItem.Type.CHESTPLATE, 5); enumMap.put(ArmorItem.Type.HELMET, 2); enumMap.put(ArmorItem.Type.BODY, 4); }), 12, SoundEvents.ARMOR_EQUIP_IRON, 0.0F, 0.0F, () -> Ingredient.of(Items.COPPER_INGOT)); private static RegistryObject<ArmorMaterial> registerArmor(String pGroup, EnumMap<ArmorItem.Type, Integer> pEnumMap, int pEnchantmentValue, Holder<SoundEvent> pEquipSound, float pToughness, float pKnockbackResistance, Supplier<Ingredient> pRepairIngredient) { List<ArmorMaterial.Layer> pLayerList = List.of(new ArmorMaterial.Layer(new ResourceLocation(pGroup))); return registerArmor(pGroup, pEnumMap, pEnchantmentValue, pEquipSound, pToughness, pKnockbackResistance, pRepairIngredient, pLayerList); } private static RegistryObject<ArmorMaterial> registerArmor( String pGroup, EnumMap<ArmorItem.Type, Integer> pEnumMap, int pEnchantmentValue, Holder<SoundEvent> pEquipSound, float pToughness, float pKnockbackResistance, Supplier<Ingredient> pRepairIngredient, List<ArmorMaterial.Layer> pLayerList) { return ARMORS.register(pGroup, () -> new ArmorMaterial(pEnumMap, pEnchantmentValue, pEquipSound, pRepairIngredient, pLayerList, pToughness, pKnockbackResistance)); } public static void register(IEventBus eventBus) { ARMORS.register(eventBus); } } Essentially, the TierSortingRegistry has been removed and so you now need to set up your own DeferredRegister. Please see the minecraftforge GitHub for more information; I found this solution through their issues (https://github.com/MinecraftForge/MinecraftForge/issues/9961)
    • How did I even leave that in there? I’ll try it in a bit, that very well could be it.
    • Greetings, I met a problem with my Forge server (47.2.0-1.20.1) that I can't join with the following line. (singleplayer world working fine) [net.minecraft.server.network.ServerGamePacketListenerImpl/]: Sharyna lost connection: Internal Exception: io.netty.handler.codec.EncoderException: java.lang.NullPointerException: Cannot invoke "net.minecraft.resources.ResourceLocation.toString()" because "p_130086_" is null   At first it was errored with packet size error, but I fixed that with the Connectivity mod, however, after that this popped up and can't find the source of it. Since the logs are big, I couldn't upload on paste.gg or other site ... so here it is (if the files are deleted, please notice me and I'll upload again. Debug and Latest log
    • Дерево тис
  • Topics

×
×
  • Create New...

Important Information

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