forked from Nova-Committee/Re-Avaritia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(avaritia): add fire ball entity and related functionalities
- Implement FireBallEntity class with necessary methods for behavior. - Add client-side rendering for fire balls with FireBallRender class.- Integrate fire ball usage and interaction logic in PlayerUtils and ToolUtils.- Ensure creative mode players can use fire balls without consuming them. - Adjust EndestPearlEntity and EndestPearlItem for compatibility and efficiency.
- Loading branch information
Showing
9 changed files
with
272 additions
and
31 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/java/committee/nova/mods/avaritia/client/render/entity/FireBallRender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package committee.nova.mods.avaritia.client.render.entity; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import com.mojang.math.Axis; | ||
import committee.nova.mods.avaritia.common.entity.FireBallEntity; | ||
import net.minecraft.client.renderer.MultiBufferSource; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.client.renderer.entity.EntityRenderer; | ||
import net.minecraft.client.renderer.entity.EntityRendererProvider; | ||
import net.minecraft.client.renderer.texture.OverlayTexture; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.projectile.DragonFireball; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.joml.Matrix3f; | ||
import org.joml.Matrix4f; | ||
|
||
/** | ||
* @Project: Avaritia | ||
* @Author: cnlimiter | ||
* @CreateTime: 2024/8/7 下午8:49 | ||
* @Description: | ||
*/ | ||
public class FireBallRender extends EntityRenderer<FireBallEntity> { | ||
private static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation("textures/entity/enderdragon/dragon_fireball.png"); | ||
private static final RenderType RENDER_TYPE = RenderType.entityCutoutNoCull(TEXTURE_LOCATION); | ||
|
||
public FireBallRender(EntityRendererProvider.Context pContext) { | ||
super(pContext); | ||
} | ||
|
||
@Override | ||
protected int getBlockLightLevel(@NotNull FireBallEntity pEntity, @NotNull BlockPos pPos) { | ||
return 15; | ||
} | ||
|
||
@Override | ||
public void render(@NotNull FireBallEntity pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight) { | ||
pPoseStack.pushPose(); | ||
pPoseStack.scale(2.0F, 2.0F, 2.0F); | ||
pPoseStack.mulPose(this.entityRenderDispatcher.cameraOrientation()); | ||
pPoseStack.mulPose(Axis.YP.rotationDegrees(180.0F)); | ||
PoseStack.Pose posestack$pose = pPoseStack.last(); | ||
Matrix4f matrix4f = posestack$pose.pose(); | ||
Matrix3f matrix3f = posestack$pose.normal(); | ||
VertexConsumer vertexconsumer = pBuffer.getBuffer(RENDER_TYPE); | ||
vertex(vertexconsumer, matrix4f, matrix3f, pPackedLight, 0.0F, 0, 0, 1); | ||
vertex(vertexconsumer, matrix4f, matrix3f, pPackedLight, 1.0F, 0, 1, 1); | ||
vertex(vertexconsumer, matrix4f, matrix3f, pPackedLight, 1.0F, 1, 1, 0); | ||
vertex(vertexconsumer, matrix4f, matrix3f, pPackedLight, 0.0F, 1, 0, 0); | ||
pPoseStack.popPose(); | ||
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight); | ||
} | ||
|
||
private static void vertex(VertexConsumer pConsumer, Matrix4f pPose, Matrix3f pNormal, int pLightmapUV, float pX, int pY, int pU, int pV) { | ||
pConsumer.vertex(pPose, pX - 0.5F, (float)pY - 0.25F, 0.0F).color(255, 255, 255, 255).uv((float)pU, (float)pV).overlayCoords(OverlayTexture.NO_OVERLAY).uv2(pLightmapUV).normal(pNormal, 0.0F, 1.0F, 0.0F).endVertex(); | ||
} | ||
|
||
/** | ||
* Returns the location of an entity's texture. | ||
*/ | ||
@Override | ||
public @NotNull ResourceLocation getTextureLocation(@NotNull FireBallEntity pEntity) { | ||
return TEXTURE_LOCATION; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/java/committee/nova/mods/avaritia/common/entity/FireBallEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package committee.nova.mods.avaritia.common.entity; | ||
|
||
import committee.nova.mods.avaritia.util.PlayerUtils; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.protocol.Packet; | ||
import net.minecraft.network.protocol.game.ClientGamePacketListener; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.entity.projectile.ThrowableProjectile; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import net.minecraft.world.phys.EntityHitResult; | ||
import net.minecraft.world.phys.HitResult; | ||
import net.minecraftforge.network.NetworkHooks; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @Project: Avaritia | ||
* @Author: cnlimiter | ||
* @CreateTime: 2024/8/7 下午8:26 | ||
* @Description: | ||
*/ | ||
public class FireBallEntity extends ThrowableProjectile { | ||
public FireBallEntity(EntityType<? extends ThrowableProjectile> pEntityType, Level pLevel) { | ||
super(pEntityType, pLevel); | ||
} | ||
|
||
|
||
@Override | ||
protected void onHit(@NotNull HitResult result) { | ||
super.onHit(result); | ||
this.discard(); | ||
} | ||
|
||
@Override | ||
protected void onHitBlock(@NotNull BlockHitResult result) { | ||
super.onHitBlock(result); | ||
if (!this.level().isClientSide) { | ||
Entity owner = this.getOwner(); | ||
if (owner instanceof ServerPlayer player) { | ||
BlockPos pos = result.getBlockPos(); | ||
BlockState state = this.level().getBlockState(pos); | ||
if (state.is(Blocks.OBSIDIAN)) { | ||
this.level().setBlockAndUpdate(pos, Blocks.LAVA.defaultBlockState()); | ||
} else if (state.is(Blocks.SAND)) { | ||
BlockPos.betweenClosedStream(pos.offset(-2, -2, -2), pos.offset(2, 2, 2)).forEach((currentPos) -> { | ||
if (this.level().getBlockState(currentPos).is(Blocks.SAND)) { | ||
PlayerUtils.checkedPlaceBlock(player, pos.immutable(), Blocks.GLASS.defaultBlockState()); | ||
} | ||
|
||
}); | ||
} else { | ||
BlockPos.betweenClosedStream(pos.offset(-1, -1, -1), pos.offset(1, 1, 1)).forEach((currentPos) -> { | ||
if (this.level().isEmptyBlock(currentPos)) { | ||
PlayerUtils.checkedPlaceBlock(player, currentPos.immutable(), Blocks.FIRE.defaultBlockState()); | ||
} | ||
|
||
}); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected void onHitEntity(@NotNull EntityHitResult result) { | ||
super.onHitEntity(result); | ||
if (!this.level().isClientSide) { | ||
Entity owner = this.getOwner(); | ||
if (owner instanceof Player) { | ||
Entity ent = result.getEntity(); | ||
ent.setSecondsOnFire(100); | ||
ent.hurt(this.level().damageSources().inFire(), 50.0F); | ||
} | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public @NotNull Packet<ClientGamePacketListener> getAddEntityPacket() { | ||
return NetworkHooks.getEntitySpawningPacket(this); | ||
} | ||
|
||
@Override | ||
public boolean ignoreExplosion() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void defineSynchedData() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.