Jump to content

Recommended Posts

Posted

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);
}
}

Posted

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.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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