Skip to content

Commit

Permalink
血蜘蛛(加动画)
Browse files Browse the repository at this point in the history
  • Loading branch information
EDGtheXu committed Oct 12, 2024
1 parent df57b41 commit 83d1df3
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.confluence.mod.client.renderer.gui;

import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.BowItem;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.client.event.RenderHandEvent;
import org.confluence.mod.item.bow.ShortBowItem;

public class ArrowInBowOverlay {
public static void render(RenderHandEvent event){

if(Minecraft.getInstance().player.isUsingItem() && Minecraft.getInstance().player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof BowItem){
Minecraft mc = Minecraft.getInstance();
float charge = mc.player.getTicksUsingItem() / 20.0f;
if(charge < 0.1f) return;
var pose = event.getPoseStack();
pose.pushPose();
ItemStack bow = mc.player.getItemInHand(InteractionHand.MAIN_HAND);


//拉弓前后位移
float scale = 1f;
float offset = charge < 0.65f? 0:
charge < 0.9f?0.58f:1f;

float f7 = (float)bow.getUseDuration() - ((float)mc.player.getUseItemRemainingTicks());
float f11 = f7 / 10.0F;
f11=Math.min(f11,1);
float f19 = f11 > 0.1F? Mth.sin((f7 - 0.1F) * 1.3F) * (f11 - 0.1F):0;
//应用抖动
// 左右偏移 上下抖动系数
pose.translate(0.29, f19 * 0.004F-0.1,0);
if(bow.getItem() instanceof ShortBowItem){
float f12 = Math.min(f7 / 20.0F,1);
// 前后帧偏移系数
pose.translate(0,0, -0.6 + f12*0.13);
} else{
// 前后阶段偏移系数 前后帧偏移系数
pose.translate(0,0, offset*0.13-0.6 + f11*0.04);
}

pose.scale(scale,scale,scale+f11*0.2f);
pose.mulPose(Axis.YP.rotationDegrees(8));
pose.mulPose(Axis.XP.rotationDegrees(-110));

ItemStack arrowItem = mc.player.getProjectile(bow);
ItemInHandRenderer renderer = mc .gameRenderer.itemInHandRenderer;

renderer.renderItem(
mc.player,
arrowItem,
ItemDisplayContext.FIRST_PERSON_RIGHT_HAND,
false,
pose,
mc .renderBuffers().bufferSource(),
event.getPackedLight()
);

/*
LocalPlayer player = mc.player;
float f = Mth.lerp(1, player.xRotO, player.getXRot());
renderer.renderArmWithItem(
mc.player,
1,
f,
mc .player.getItemInHand(InteractionHand.MAIN_HAND),
0,
event.getPoseStack(),
pose,
ItemDisplayContext.FIRST_PERSON_RIGHT_HAND,
mc .renderBuffers().bufferSource(),
event.getPackedLight()
);
*/
pose.popPose();
}



}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.confluence.mod.entity.BloodCrawler;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
Expand All @@ -10,11 +11,16 @@
import net.minecraft.world.entity.ai.goal.*;
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.IronGolem;
import net.minecraft.world.entity.monster.Spider;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import org.checkerframework.checker.units.qual.A;
import org.confluence.mod.entity.boss.TerraBossBase;
import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.constant.DataTickets;
Expand All @@ -37,15 +43,20 @@ public BloodCrawler(EntityType<? extends Spider> type, Level level) {
this.setHealth(MAX_HEALTH);
}


protected void registerGoals() {
super.registerGoals();

/*
this.goalSelector.addGoal(1, new FloatGoal(this));
this.goalSelector.addGoal(3, new LeapAtTargetGoal(this, 0.4F));
// this.goalSelector.addGoal(4, new Spider.SpiderAttackGoa(this));
this.goalSelector.addGoal(5, new WaterAvoidingRandomStrollGoal(this, 0.8));
this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 8.0F));
this.goalSelector.addGoal(6, new RandomLookAroundGoal(this));
this.targetSelector.addGoal(1, new HurtByTargetGoal(this));
*/

this.targetSelector.removeAllGoals(a->!(a instanceof HurtByTargetGoal));
this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class,false));
this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, IronGolem.class,false));

Expand All @@ -61,7 +72,7 @@ public static AttributeSupplier.Builder createAttributes() {
.add(Attributes.SPAWN_REINFORCEMENTS_CHANCE, 0.01) // 召唤物品的几率
.add(Attributes.KNOCKBACK_RESISTANCE, 0.5); // 击退抗性
}
public static boolean checkBloodCrawlerSpawn(EntityType<? extends Mob> type, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) {
public static boolean checkBloodCrawlerSpawn(EntityType<? extends BloodCrawler> type, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) {
if (!(pLevel instanceof Level level)) {
return false; // 如果 pLevel 不是 Level 的实例,返回 false
}
Expand All @@ -79,7 +90,8 @@ public static boolean checkBloodCrawlerSpawn(EntityType<? extends Mob> type, Lev
}


private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);

private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@Override
public AnimatableInstanceCache getAnimatableInstanceCache() {
return cache;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/org/confluence/mod/entity/utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.confluence.mod.entity;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class utils {

public static boolean checkSpawn(EntityType<? extends Mob> pType, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos) {
BlockPos blockpos = pPos.below();
return pSpawnType == MobSpawnType.SPAWNER || predicate.test(pLevel.getBlockState(blockpos), pLevel, blockpos, pType);
}
static BlockBehaviour.StateArgumentPredicate<EntityType<?>> predicate = (blockstate , blockgetter , blockpos , type) ->
blockstate.isFaceSturdy(blockgetter, blockpos, Direction.UP) && blockgetter.getLightEmission(blockpos) < 14;;



}
67 changes: 2 additions & 65 deletions src/main/java/org/confluence/mod/event/GuiRenderEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.confluence.mod.client.renderer.gui.ArrowInBowOverlay;
import org.confluence.mod.item.ModItems;
import org.confluence.mod.item.bow.Bows;
import org.confluence.mod.item.bow.ShortBowItem;
Expand All @@ -29,73 +30,9 @@ public class GuiRenderEvent {

@SubscribeEvent
public static void RenderGuiEvent(RenderHandEvent event) {
ArrowInBowOverlay.render(event);


if(Minecraft.getInstance().player.isUsingItem() && Minecraft.getInstance().player.getItemInHand(InteractionHand.MAIN_HAND).getItem() instanceof BowItem){
Minecraft mc = Minecraft.getInstance();
float charge = mc.player.getTicksUsingItem() / 20.0f;
if(charge < 0.1f) return;
var pose = event.getPoseStack();
pose.pushPose();
ItemStack bow = mc.player.getItemInHand(InteractionHand.MAIN_HAND);


//拉弓前后位移
float scale = 1f;
float offset = charge < 0.65f? 0:
charge < 0.9f?0.58f:1f;

float f7 = (float)bow.getUseDuration() - ((float)mc.player.getUseItemRemainingTicks());
float f11 = f7 / 10.0F;
f11=Math.min(f11,1);
float f19 = f11 > 0.1F?Mth.sin((f7 - 0.1F) * 1.3F) * (f11 - 0.1F):0;
//应用抖动
// 左右偏移 上下抖动系数
pose.translate(0.29, f19 * 0.004F-0.1,0);
if(bow.getItem() instanceof ShortBowItem){
float f12 = Math.min(f7 / 20.0F,1);
// 前后帧偏移系数
pose.translate(0,0, -0.6 + f12*0.13);
} else{
// 前后阶段偏移系数 前后帧偏移系数
pose.translate(0,0, offset*0.13-0.6 + f11*0.04);
}

pose.scale(scale,scale,scale+f11*0.2f);
pose.mulPose(Axis.YP.rotationDegrees(8));
pose.mulPose(Axis.XP.rotationDegrees(-110));

ItemStack arrowItem = mc.player.getProjectile(bow);
ItemInHandRenderer renderer = mc .gameRenderer.itemInHandRenderer;

renderer.renderItem(
mc.player,
arrowItem,
ItemDisplayContext.FIRST_PERSON_RIGHT_HAND,
false,
pose,
mc .renderBuffers().bufferSource(),
event.getPackedLight()
);

/*
LocalPlayer player = mc.player;
float f = Mth.lerp(1, player.xRotO, player.getXRot());
renderer.renderArmWithItem(
mc.player,
1,
f,
mc .player.getItemInHand(InteractionHand.MAIN_HAND),
0,
event.getPoseStack(),
pose,
ItemDisplayContext.FIRST_PERSON_RIGHT_HAND,
mc .renderBuffers().bufferSource(),
event.getPackedLight()
);
*/
pose.popPose();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
}
}
},
"misc.attack": {
"attack.strike": {
"animation_length": 0.9167,
"bones": {
"hand": {
Expand Down

0 comments on commit 83d1df3

Please sign in to comment.