@SideOnly(Side.CLIENT)
public void registerRenderers() {
RenderingRegistry.registerEntityRenderingHandler(EntityArrowCustom.class, new RenderSnowball(Minecraft.getMinecraft().getRenderManager(),
new ItemStack(Items.FIREWORK_CHARGE).getItem(), Minecraft.getMinecraft().getRenderItem()));
}
public void generateNether(World world, Random random, int chunkX, int chunkZ) {
}
public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
}
public int addFuel(ItemStack fuel) {
return 0;
}
public void serverLoad(FMLServerStartingEvent event) {
}
public void preInit(FMLPreInitializationEvent event) {
int entityID = MathHelper.getRandomUUID().hashCode();
EntityRegistry.registerModEntity(EntityArrowCustom.class, "entityBulletmusket", entityID, instance, 64, 1, true);
}
@Override
public int getMaxItemUseDuration(ItemStack par1ItemStack) {
return 72000;
}
@Override
public ActionResult<ItemStack> onItemRightClick(final ItemStack par1ItemStack, final World par2World, final EntityPlayer par3EntityPlayer, EnumHand hand){
boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, par1ItemStack) > 0;
if (flag || par3EntityPlayer.inventory.hasItemStack(new ItemStack(mcreator_cartridge.block)))
{
float f = 3.0F;
EntityArrowCustom entityarrow = new EntityArrowCustom(par2World, par3EntityPlayer)
{
@Override
public void onCollideWithPlayer(EntityPlayer entity){
super.onCollideWithPlayer(entity);
int i = MathHelper.floor_double(this.getEntityBoundingBox().minX + 0.001D);
int j = MathHelper.floor_double(this.getEntityBoundingBox().minY + 0.001D);
int k = MathHelper.floor_double(this.getEntityBoundingBox().minZ + 0.001D);
World world = this.worldObj;
}
@Override
public void onUpdate(){
super.onUpdate();
int i = MathHelper.floor_double(this.getEntityBoundingBox().minX + 0.001D);
int j = MathHelper.floor_double(this.getEntityBoundingBox().minY + 0.001D);
int k = MathHelper.floor_double(this.getEntityBoundingBox().minZ + 0.001D);
World world = this.worldObj;
Entity entity = (Entity)par3EntityPlayer;
if (getBlock(this.worldObj, i, j, k) != Blocks.AIR || getBlock(this.worldObj, i, j-1, k) != Blocks.AIR ||
getBlock(this.worldObj, i, j+1, k) != Blocks.AIR ||
getBlock(this.worldObj, i+1, j, k) != Blocks.AIR || getBlock(this.worldObj, i-1, j, k) != Blocks.AIR
|| getBlock(this.worldObj, i, j, k+1) != Blocks.AIR || getBlock(this.worldObj, i, j, k-1) != Blocks.AIR){
I'm not gonna read that code... PLEASE use pastebin or gist and use syntax highlighting. The code just pasted in like that is incredibly hard to read.
However, I've made cooldowns plenty of times. I'm going to presume you want to start the cooldown after you've right clicked the item - here's what you need to do:
The cooldown value will be stored in the item's NBT, so I suggest creating getting and setting methods for the cooldown (that way you can handle if the tag isn't already created too).
In the item's onUpdate() method, get the cooldown and if it's > 0, then subtract 1 from the cooldown and set it to the NBT under the same key.
In the onItemRightClick() method, check if the cooldown is greater than 0. If it is, don't run any of the right click code and just return.
If the cooldown's 0, then you can do your action!
Once the action is done, set the cooldown in the NBT to whatever value you want - it will determine how long the cooldown will last. Don't forget, every 20 on the cooldown is 1 second.
The cooldown has started! Nothing will happen if you right click until the cooldown has gone back to 0. I'd recommend you have a way of showing how long until the cooldown finishes. I tend to override the durability bar or show the cooldown timer (in seconds) in the item tooltip.
The best example I probably have is this item cooldown class. I use it in that mod to easily create items with a custom cooldown after the item has been right clicked. Note that I'm using a helper class to handle the item's NBT. You can take a look at it here though.
So i am trying to make a musket that will shoot a bullet and then takes a few seconds to reload before shooting the next one.
this is what ive come to so far:
(ive set a variable named "needreload" and when the gun is used it sets it to true)
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraft.world.World;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.ActionResult;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.item.EnumAction;
import net.minecraft.init.Items;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Blocks;
import net.minecraft.entity.projectile.EntityTippedArrow;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.Entity;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.block.Block;
import java.util.Random;
public class mcreator_musket {
public mcreator_musket() {
}
public static Item block;
public static Object instance;
public void load(FMLInitializationEvent event) {
if (event.getSide() == Side.CLIENT) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.register(block, 0, new ModelResourceLocation("TestEnvironmentMod:musket", "inventory"));
}
GameRegistry.addRecipe(new ItemStack(block, 1),
new Object[]{"XXX", "345", "XXX", Character.valueOf('3'), mcreator_barrel.block, Character.valueOf('4'), mcreator_trigger.block,
Character.valueOf('5'), mcreator_stock.block,});
}
@SideOnly(Side.CLIENT)
public void registerRenderers() {
RenderingRegistry.registerEntityRenderingHandler(EntityArrowCustom.class, new RenderSnowball(Minecraft.getMinecraft().getRenderManager(),
new ItemStack(Items.FIREWORK_CHARGE).getItem(), Minecraft.getMinecraft().getRenderItem()));
}
public void generateNether(World world, Random random, int chunkX, int chunkZ) {
}
public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
}
public int addFuel(ItemStack fuel) {
return 0;
}
public void serverLoad(FMLServerStartingEvent event) {
}
public void preInit(FMLPreInitializationEvent event) {
int entityID = MathHelper.getRandomUUID().hashCode();
EntityRegistry.registerModEntity(EntityArrowCustom.class, "entityBulletmusket", entityID, instance, 64, 1, true);
}
static {
block = (new ItemgGUN());
}
static class ItemgGUN extends Item {
public ItemgGUN() {
super();
setMaxDamage(144);
maxStackSize = 1;
setFull3D();
setUnlocalizedName("musket");
GameRegistry.registerItem(this, "musket");
setCreativeTab(CreativeTabs.COMBAT);
}
@Override
public int getMaxItemUseDuration(ItemStack par1ItemStack) {
return 72000;
}
@Override
public ActionResult<ItemStack> onItemRightClick(final ItemStack par1ItemStack, final World par2World, final EntityPlayer par3EntityPlayer, EnumHand hand){
boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, par1ItemStack) > 0;
if (flag || par3EntityPlayer.inventory.hasItemStack(new ItemStack(mcreator_cartridge.block)))
{
float f = 3.0F;
EntityArrowCustom entityarrow = new EntityArrowCustom(par2World, par3EntityPlayer)
{
@Override
public void onCollideWithPlayer(EntityPlayer entity){
super.onCollideWithPlayer(entity);
int i = MathHelper.floor_double(this.getEntityBoundingBox().minX + 0.001D);
int j = MathHelper.floor_double(this.getEntityBoundingBox().minY + 0.001D);
int k = MathHelper.floor_double(this.getEntityBoundingBox().minZ + 0.001D);
World world = this.worldObj;
}
@Override
public void onUpdate(){
super.onUpdate();
int i = MathHelper.floor_double(this.getEntityBoundingBox().minX + 0.001D);
int j = MathHelper.floor_double(this.getEntityBoundingBox().minY + 0.001D);
int k = MathHelper.floor_double(this.getEntityBoundingBox().minZ + 0.001D);
World world = this.worldObj;
Entity entity = (Entity)par3EntityPlayer;
if (getBlock(this.worldObj, i, j, k) != Blocks.AIR || getBlock(this.worldObj, i, j-1, k) != Blocks.AIR ||
getBlock(this.worldObj, i, j+1, k) != Blocks.AIR ||
getBlock(this.worldObj, i+1, j, k) != Blocks.AIR || getBlock(this.worldObj, i-1, j, k) != Blocks.AIR
|| getBlock(this.worldObj, i, j, k+1) != Blocks.AIR || getBlock(this.worldObj, i, j, k-1) != Blocks.AIR){
this.kill();
}
}
};
entityarrow.setThrowableHeading(par3EntityPlayer.getLookVec().xCoord,par3EntityPlayer.getLookVec().yCoord,par3EntityPlayer.getLookVec().zCoord,f * 2.0F,0);
entityarrow.setIsCritical(true);
entityarrow.setDamage(3.0);
entityarrow.setKnockbackStrength(2);
if(false){
entityarrow.setFire(100);
}
par1ItemStack.damageItem(1, par3EntityPlayer);
int i = (int)par3EntityPlayer.posX;
int j = (int)par3EntityPlayer.posY;
int k = (int)par3EntityPlayer.posZ;
par2World.playSound((EntityPlayer)null,(double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D, (net.minecraft.util.SoundEvent)net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation(("entity.generic.explode"))), SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
if (flag)
{
entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
}
else
{
par3EntityPlayer.inventory.clearMatchingItems(new ItemStack(mcreator_cartridge.block).getItem(),-1,1,null);
}
if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(entityarrow);
}
World world = par2World;
EntityPlayer entity = par3EntityPlayer;
if(true){
mcreator_VarList%MAINMODNAME%.needreload = true;
}
}
return new ActionResult(EnumActionResult.SUCCESS, par1ItemStack);
}
public Block getBlock(World par1World, int i, int j, int k) {
return par1World.getBlockState(new BlockPos(i, j, k)).getBlock();
}
@Override
public EnumAction getItemUseAction(ItemStack par1ItemStack) {
return EnumAction.BOW;
}
}
public static class EntityArrowCustom extends EntityTippedArrow {
public EntityArrowCustom(World a) {
super(a);
}
public EntityArrowCustom(World worldIn, double x, double y, double z) {
super(worldIn, x, y, z);
}
public EntityArrowCustom(World worldIn, EntityLivingBase shooter) {
super(worldIn, shooter);
}
}
}
I'm not gonna read that code... PLEASE use pastebin or gist and use syntax highlighting. The code just pasted in like that is incredibly hard to read.
However, I've made cooldowns plenty of times. I'm going to presume you want to start the cooldown after you've right clicked the item - here's what you need to do:
The best example I probably have is this item cooldown class. I use it in that mod to easily create items with a custom cooldown after the item has been right clicked. Note that I'm using a helper class to handle the item's NBT. You can take a look at it here though.
Hope this helps!
Sorry about the code, it's my first time doing coding.
Ill try your way and see how it works!
That's alright. Okay, let me know how it goes
Wait... That really looks like a MCerator generated code with all the if(false) and if(true). oh...
You do know that mcreator handles real code really badly?
Why are you trying to break a brick wall when it is clearly not intended to be broken?
Please keep in mind that we do not give out code....
If you are going to use a language than you should first learn it. https://goo.gl/SUx2LP That's how it usually works.
Not doing mc modding that much anymore because I am making a full blown game that does not have limitations that mc has. (rip Magiology for now)
I may come back if MC fixes it's rendering pipeline.