aim IAnimatedItem like a bow

This commit is contained in:
George Paton 2025-09-16 09:52:52 +10:00
parent dbd63e706f
commit 2efce806a9
5 changed files with 35 additions and 7 deletions

View File

@ -10,9 +10,12 @@ import net.minecraft.item.ItemStack;
public interface IAnimatedItem<T extends Enum<?>> {
// Fetch the animation for a given type
/** Fetch the animation for a given type */
public BusAnimation getAnimation(T type, ItemStack stack);
/** Should a player holding this item aim it like a gun/bow? */
public boolean shouldPlayerModelAim(ItemStack stack);
// Runtime erasure means we have to explicitly give the class a second time :(
public Class<T> getEnum();

View File

@ -127,4 +127,9 @@ public class ItemBoltgun extends Item implements IAnimatedItem<ToolAnimation> {
.addPos(0, 0, 1, 100));
}
@Override
public boolean shouldPlayerModelAim(ItemStack stack) {
return false;
}
}

View File

@ -75,4 +75,10 @@ public class ItemChainsaw extends ItemToolAbilityFueled implements IHeldSoundPro
public Class<ToolAnimation> getEnum() {
return ToolAnimation.class;
}
@Override
public boolean shouldPlayerModelAim(ItemStack stack) {
return false;
}
}

View File

@ -153,11 +153,9 @@ public class ItemCrucible extends ItemSwordAbility implements IEquipReceiver, IA
if(HbmAnimations.getRelevantTransformation("SWING_ROT")[0] == 0) {
Random rand = Minecraft.getMinecraft().theWorld.rand;
int offset = itemRand.nextInt(80) - 20;
int offset = rand.nextInt(80) - 20;
playSwing(0.8F + rand.nextFloat() * 0.2F);
playSwing(0.8F + itemRand.nextFloat() * 0.2F);
return new BusAnimation()
.addBus("SWING_ROT", new BusAnimationSequence()
@ -186,4 +184,9 @@ public class ItemCrucible extends ItemSwordAbility implements IEquipReceiver, IA
return ToolAnimation.class;
}
@Override
public boolean shouldPlayerModelAim(ItemStack stack) {
return false;
}
}

View File

@ -4,6 +4,7 @@ import com.hbm.blocks.ICustomBlockHighlight;
import com.hbm.config.ClientConfig;
import com.hbm.config.RadiationConfig;
import com.hbm.handler.pollution.PollutionHandler.PollutionType;
import com.hbm.items.IAnimatedItem;
import com.hbm.items.armor.IArmorDisableModel;
import com.hbm.items.armor.IArmorDisableModel.EnumPlayerPart;
import com.hbm.items.weapon.sedna.ItemGunBaseNT;
@ -55,7 +56,7 @@ public class ModEventHandlerRenderer {
private static ModelMan manlyModel;
private static boolean[] partsHidden = new boolean[7];
@SubscribeEvent
public void onRenderTickPre(TickEvent.RenderTickEvent event) { }
@ -187,7 +188,17 @@ public class ModEventHandlerRenderer {
RenderPlayer renderer = event.renderer;
ItemStack held = player.getHeldItem();
if(held != null && player.getHeldItem().getItem() instanceof ItemGunBaseNT) {
if(held == null) return;
if(held.getItem() instanceof IAnimatedItem) {
if(((IAnimatedItem<?>) held.getItem()).shouldPlayerModelAim(held)) {
renderer.modelBipedMain.aimedBow = true;
renderer.modelArmor.aimedBow = true;
renderer.modelArmorChestplate.aimedBow = true;
}
}
if(held.getItem() instanceof ItemGunBaseNT) {
renderer.modelBipedMain.aimedBow = true;
renderer.modelArmor.aimedBow = true;
renderer.modelArmorChestplate.aimedBow = true;