Skip to content

Commit

Permalink
第一人称弓箭gui(万物皆可弓)
Browse files Browse the repository at this point in the history
  • Loading branch information
EDGtheXu committed Oct 9, 2024
1 parent 2583005 commit 4207e25
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.confluence.mod.client.shader;

import com.lowdragmc.shimmer.forge.ShimmerMod;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.renderer.RenderStateShard;
Expand Down Expand Up @@ -79,6 +80,7 @@ public static void onRegisterShaders(RegisterShadersEvent event) throws IOExcept
DefaultVertexFormat.NEW_ENTITY),
shader -> entityDynamic = shader
);

event.registerShader(
new ShaderInstance(
resourceProvider,
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/org/confluence/mod/entity/boss/TerraBossBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.IronGolem;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.client.event.RenderGuiEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;
Expand All @@ -41,6 +44,7 @@
import software.bernie.geckolib.util.GeckoLibUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

Expand All @@ -53,6 +57,9 @@ public abstract class TerraBossBase extends Monster implements GeoEntity {

public float ironGlomResistance = 0.4f;
public float explosionResistance = 0.5f;
public int attackInternal = 20;
private int _attackInternal = 20;

private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
protected ServerBossEvent bossEvent = (ServerBossEvent) new ServerBossEvent(getDisplayName(), BossEvent.BossBarColor.RED, BossEvent.BossBarOverlay.PROGRESS).setDarkenScreen(true);

Expand Down Expand Up @@ -148,6 +155,7 @@ public void tick() {
}
collisionHurt();
super.tick();
attackInternal--;
this.setDeltaMovement(getDeltaMovement().scale(0.95));//空气阻力
}

Expand Down Expand Up @@ -189,8 +197,11 @@ public void collisionHurt() {
var entities = level().getEntities(this, this.getBoundingBox());
if (!entities.isEmpty()) {
for (var e : entities) {
if (canAttack(e))
e.hurt(this.damageSources().mobAttack(this), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
if (canAttack(e)){
attackInternal = _attackInternal;
//测试末影龙
e.hurt(this.damageSources().explosion(new Explosion(level(), this, 0.0f, 0,0,3, List.of(this.blockPosition()))), (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue());
}
}
}
}
Expand All @@ -202,11 +213,13 @@ public boolean hurt(DamageSource pSource, float pAmount) {
if(pSource.is(DamageTypes.EXPLOSION)){
pAmount *= explosionResistance;
}

return super.hurt(pSource,pAmount);
}

public boolean canAttack(Entity entity) {
return entity instanceof Player || getTarget() != null && getTarget().is(entity) && entity != this &&!(entity instanceof TerraBossBase);
return attackInternal < 0 &&
(entity instanceof Player || getTarget() != null && getTarget().is(entity) && entity != this &&!(entity instanceof TerraBossBase));
}


Expand Down
103 changes: 103 additions & 0 deletions src/main/java/org/confluence/mod/event/GuiRenderEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package org.confluence.mod.event;

import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArrowItem;
import net.minecraft.world.item.BowItem;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGuiEvent;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.confluence.mod.item.ModItems;
import org.confluence.mod.util.DelayedTaskExecutor;
import org.joml.Matrix4f;

import static org.confluence.mod.Confluence.MODID;

@Mod.EventBusSubscriber(modid = MODID,value = Dist.CLIENT)
public class GuiRenderEvent {

@SubscribeEvent
public static void RenderGuiEvent(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;

//todo
//ArrowItem arrowItem = mc.player.getProjectile()

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

var pose = event.getPoseStack();

pose.pushPose();
pose.translate(0.3, -0.2, -0.6+offset*0.3);
pose.scale(scale,scale,scale);
pose.mulPose(Axis.YP.rotationDegrees(2));
pose.mulPose(Axis.XP.rotationDegrees(-100));

ItemStack bow = mc.player.getItemInHand(InteractionHand.MAIN_HAND);

//应用抖动
float f7 = (float)bow.getUseDuration() - ((float)mc.player.getUseItemRemainingTicks());
float f11 = f7 / 10.0F;
if (f11 > 1.0F) {
f11 = 1.0F;
}
if (f11 > 0.1F) {
float f14 = Mth.sin((f7 - 0.1F) * 1.3F);
float f17 = f11 - 0.1F;
float f19 = f14 * f17;
pose.translate(0, f19 * 0.004F, 0);
}



ItemInHandRenderer renderer = mc .gameRenderer.itemInHandRenderer;

renderer.renderItem(
mc.player,
mc.player.getItemInHand(InteractionHand.OFF_HAND),
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();
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ public net.minecraft.world.level.chunk.PalettedContainer$Data
public net.minecraft.client.model.geom.ModelPart$Polygon
public net.minecraft.client.model.geom.ModelPart$Vertex
public net.minecraft.world.level.biome.MultiNoiseBiomeSourceParameterList$Preset$SourceProvider

public net.minecraft.client.renderer.ItemInHandRenderer m_109371_(Lnet/minecraft/client/player/AbstractClientPlayer;FFLnet/minecraft/world/InteractionHand;FLnet/minecraft/world/item/ItemStack;FLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V # renderArmWithItem

0 comments on commit 4207e25

Please sign in to comment.