Jump to content

Bow Renderer - Change time to pull?


Bedrock_Miner

Recommended Posts

Heyho Guys!

 

I want to create a new bow which can be pulled twice as fast as the normal vanilla bow. I created a bow renderer which renders it exactly like the normal one, so it has the three changing textures etc.

The problem is now: I need to change the duration of the animation which rescales the bow while pulling, because this is now much to slow. Also I want to make this shaking effect when the bow is fully pulled out appear when my bow is ready and not after the second which is needed to pull a vanilla bow.

 

Is there a way to change the speed of these animations? If nothing else works, it would be ok to reverse the GL Matrix transformations and apply new ones, but I only want to do this if nothing else works. And even if I have to, I have no idea how.

 

Thanks for your help!

Link to comment
Share on other sites

OK, here is the renderer:

 

package com.bedrockminer.magicum.client.renderer.items;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.IItemRenderer;

import com.bedrockminer.magicum.item.classes.ItemMagicBow;
import com.bedrockminer.magicum.item.materials.MagicBowMaterial;
import com.bedrockminer.minersbasic.client.render.ObjectRenderer;

public class MagicBowRenderer implements IItemRenderer {

private static ObjectRenderer o = ObjectRenderer.instance; //Rendering utility created by myself

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
	return type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON;
}

@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
	return false;
}

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
	if (item != null && item.getItem() != null && item.getItem() instanceof ItemMagicBow) {
		if (type == ItemRenderType.EQUIPPED) {
			o.scale(1.5, 1.5, 1.5);
			o.rotate(-80, 0, 1, 0);
			o.translate(0, 0, -0.4);
			o.rotate(-45, 0, 0, 1);
			o.translate(-0.6, -0.6, 0);
		}
		MagicBowMaterial material = ((ItemMagicBow)item.getItem()).getBowMaterial();
		int use = Minecraft.getMinecraft().thePlayer.getItemInUseDuration();
		IIcon icon = ((ItemMagicBow)item.getItem()).getItemIconForUseDuration(use);
		o.renderSolidifiedFaceWithGlint(icon, 1.0f/16.0f, item.hasEffect(0));
	}
}
}

 

The animation I want to change is applied because of the itemUseAction of the Bow which is EnumAction.bow (I don't want to change this).

BowClass:

 

public class ItemMagicBow extends ItemBow {

public MagicBowMaterial material;

public ItemMagicBow(String unlocalizedName, MagicBowMaterial material) {
	super();
	this.material = material;
	this.setUnlocalizedName(unlocalizedName);
	this.setTextureName(Magicum.MODID + ":" + unlocalizedName);
	this.setCreativeTab(ModCreativeTabs.weapons);
}

@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int duration) {
	super.onPlayerStoppedUsing(stack, world, player, duration);
}

@Override
public IIcon getItemIconForUseDuration(int time) {
	if (time > 0) {
		int pic = time * 2 / this.getBowMaterial().getDrawDuration();
		if (pic > 2)
			pic = 2;
		return super.getItemIconForUseDuration(pic);
	}
	return this.itemIcon;
}

@Override
public int getItemEnchantability() {
	return this.material.getEnchantability();
}

@Override
public int getMaxDamage() {
	return this.material.getDurability();
}

public MagicBowMaterial getBowMaterial() {
	return this.material;
}
}

This class extends ItemBow, so everything else is defined in vanilla source code (Not sure, where exactly the rendering code is)

Link to comment
Share on other sites

You can change itemInUseCount with PlayerUseItemEvent$Tick Event, by its duration.

Decreasing the duration value will make the bow animation faster.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

  • 1 year later...

You can change itemInUseCount with PlayerUseItemEvent$Tick Event, by its duration.

Decreasing the duration value will make the bow animation faster.

Thank you, this worked for me in 1.10.

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

You can change itemInUseCount with PlayerUseItemEvent$Tick Event, by its duration.

Decreasing the duration value will make the bow animation faster.

Thank you, this worked for me in 1.10.

You do know this post is almost 2 years old? Don't reply to it then.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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

    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
  • Topics

×
×
  • Create New...

Important Information

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