Skip to content

Commit

Permalink
初步完成女仆钓鱼设计
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Oct 7, 2024
1 parent 2124e87 commit b096c49
Show file tree
Hide file tree
Showing 10 changed files with 807 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
org.gradle.jvmargs=-Xmx6G
org.gradle.daemon=false
mod_version=1.1.12-hotfix2
mod_version=1.1.13
forge_version=1.20.1-47.1.0
mc_version=1.20.1
jei_version=15.0.0.12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.entity.projectile.EntityDanmaku;
import com.github.tartaricacid.touhoulittlemaid.entity.projectile.EntityThrowPowerPoint;
import com.github.tartaricacid.touhoulittlemaid.entity.projectile.MaidFishingHook;
import com.github.tartaricacid.touhoulittlemaid.tileentity.*;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.entity.EntityRenderers;
Expand All @@ -34,6 +35,7 @@ public static void onEntityRenderers(EntityRenderersEvent.RegisterRenderers evt)
EntityRenderers.register(EntityTombstone.TYPE, EntityTombstoneRenderer::new);
EntityRenderers.register(EntitySit.TYPE, EntitySitRenderer::new);
EntityRenderers.register(EntityBroom.TYPE, EntityBroomRender::new);
EntityRenderers.register(MaidFishingHook.TYPE, MaidFishingHookRenderer::new);

EntityRenderers.register(EntityType.SLIME, EntityYukkuriSlimeRender::new);
EntityRenderers.register(EntityType.MAGMA_CUBE, EntityMarisaYukkuriSlimeRender::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.github.tartaricacid.touhoulittlemaid.client.renderer.entity;

import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.entity.projectile.MaidFishingHook;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
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.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.joml.Matrix3f;
import org.joml.Matrix4f;

@OnlyIn(Dist.CLIENT)
public class MaidFishingHookRenderer extends EntityRenderer<MaidFishingHook> {
private static final ResourceLocation TEXTURE_LOCATION = new ResourceLocation("textures/entity/fishing_hook.png");
private static final RenderType RENDER_TYPE = RenderType.entityCutout(TEXTURE_LOCATION);
private static final double VIEW_BOBBING_SCALE = 960.0D;

public MaidFishingHookRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
}

public void render(MaidFishingHook pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight) {
EntityMaid maid = pEntity.getPlayerOwner();
if (maid != null) {
pPoseStack.pushPose();
pPoseStack.pushPose();
pPoseStack.scale(0.5F, 0.5F, 0.5F);
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();
int i = maid.getMainArm() == HumanoidArm.RIGHT ? 1 : -1;
ItemStack itemstack = maid.getMainHandItem();
if (!itemstack.canPerformAction(net.minecraftforge.common.ToolActions.FISHING_ROD_CAST)) {
i = -i;
}

float f = maid.getAttackAnim(pPartialTicks);
float f1 = Mth.sin(Mth.sqrt(f) * (float) Math.PI);
float f2 = Mth.lerp(pPartialTicks, maid.yBodyRotO, maid.yBodyRot) * ((float) Math.PI / 180F);
double d0 = (double) Mth.sin(f2);
double d1 = (double) Mth.cos(f2);
double d2 = (double) i * 0.35D;
double d3 = 0.8D;
double d4;
double d5;
double d6;
float f3;

{
d4 = Mth.lerp((double) pPartialTicks, maid.xo, maid.getX()) - d1 * d2 - d0 * 0.8D;
d5 = maid.yo + (double) maid.getEyeHeight() + (maid.getY() - maid.yo) * (double) pPartialTicks - 0.45D;
d6 = Mth.lerp((double) pPartialTicks, maid.zo, maid.getZ()) - d0 * d2 + d1 * 0.8D;
f3 = -0.1875F;
}

double d9 = Mth.lerp((double) pPartialTicks, pEntity.xo, pEntity.getX());
double d10 = Mth.lerp((double) pPartialTicks, pEntity.yo, pEntity.getY()) + 0.25D;
double d8 = Mth.lerp((double) pPartialTicks, pEntity.zo, pEntity.getZ());
float f4 = (float) (d4 - d9);
float f5 = (float) (d5 - d10) + f3;
float f6 = (float) (d6 - d8);
VertexConsumer vertexconsumer1 = pBuffer.getBuffer(RenderType.lineStrip());
PoseStack.Pose posestack$pose1 = pPoseStack.last();
int j = 16;

for (int k = 0; k <= 16; ++k) {
stringVertex(f4, f5, f6, vertexconsumer1, posestack$pose1, fraction(k, 16), fraction(k + 1, 16));
}

pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}
}

private static float fraction(int pNumerator, int pDenominator) {
return (float) pNumerator / (float) pDenominator;
}

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.5F, 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();
}

private static void stringVertex(float pX, float pY, float pZ, VertexConsumer pConsumer, PoseStack.Pose pPose, float p_174124_, float p_174125_) {
float f = pX * p_174124_;
float f1 = pY * (p_174124_ * p_174124_ + p_174124_) * 0.5F + 0.25F;
float f2 = pZ * p_174124_;
float f3 = pX * p_174125_ - f;
float f4 = pY * (p_174125_ * p_174125_ + p_174125_) * 0.5F + 0.25F - f1;
float f5 = pZ * p_174125_ - f2;
float f6 = Mth.sqrt(f3 * f3 + f4 * f4 + f5 * f5);
f3 /= f6;
f4 /= f6;
f5 /= f6;
pConsumer.vertex(pPose.pose(), f, f1, f2).color(0, 0, 0, 255).normal(pPose.normal(), f3, f4, f5).endVertex();
}

/**
* Returns the location of an entity's texture.
*/
public ResourceLocation getTextureLocation(MaidFishingHook pEntity) {
return TEXTURE_LOCATION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.ride;

import com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task.MaidCheckRateTask;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.entity.projectile.MaidFishingHook;
import com.google.common.collect.ImmutableMap;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.Tags;

public class MaidRideFindWaterTask extends MaidCheckRateTask {
private static final int MAX_DELAY_TIME = 20;

private final int verticalSearchRange;
private final int searchRange;

protected int verticalSearchStart;
private BlockPos waterPos = null;

public MaidRideFindWaterTask(int searchRange, int verticalSearchRange) {
super(ImmutableMap.of());
this.searchRange = searchRange;
this.verticalSearchRange = verticalSearchRange;
this.setMaxCheckRate(MAX_DELAY_TIME);
}

@Override
protected boolean checkExtraStartConditions(ServerLevel worldIn, EntityMaid owner) {
return super.checkExtraStartConditions(worldIn, owner) && owner.fishing == null;
}

@Override
protected void start(ServerLevel worldIn, EntityMaid maid, long gameTimeIn) {
if (hasFishingRod(maid)) {
if (waterPos == null) {
this.searchForDestination(worldIn, maid);
return;
}
if (!waterPosCheck(maid)) {
waterPos = null;
return;
}
if (isWater(worldIn, waterPos)) {
ItemStack mainHandItem = maid.getMainHandItem();
Vec3 centerPos = Vec3.atCenterOf(this.waterPos);

worldIn.playSound(null, maid.getX(), maid.getY(), maid.getZ(), SoundEvents.FISHING_BOBBER_THROW, SoundSource.NEUTRAL, 0.5F, 0.4F / (worldIn.getRandom().nextFloat() * 0.4F + 0.8F));
int lureSpeedBonus = EnchantmentHelper.getFishingSpeedBonus(mainHandItem);
int luckBonus = EnchantmentHelper.getFishingLuckBonus(mainHandItem);
MaidFishingHook fishingHook = new MaidFishingHook(maid, worldIn, luckBonus, lureSpeedBonus);
fishingHook.moveTo(centerPos);
worldIn.addFreshEntity(fishingHook);
maid.getLookControl().setLookAt(centerPos);
maid.swing(InteractionHand.MAIN_HAND);
} else {
waterPos = null;
}
}
}

protected final void searchForDestination(ServerLevel worldIn, EntityMaid maid) {
BlockPos centrePos = maid.getBrainSearchPos();
BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
for (int y = this.verticalSearchStart; y <= this.verticalSearchRange; y = y > 0 ? -y : 1 - y) {
for (int i = 0; i < searchRange; ++i) {
for (int x = 0; x <= i; x = x > 0 ? -x : 1 - x) {
for (int z = x < i && x > -i ? i : 0; z <= i; z = z > 0 ? -z : 1 - z) {
mutableBlockPos.setWithOffset(centrePos, x, y - 1, z);
if (maid.isWithinRestriction(mutableBlockPos) && isWater(worldIn, mutableBlockPos)) {
maid.getLookControl().setLookAt(mutableBlockPos.getX(), mutableBlockPos.getY(), mutableBlockPos.getZ());
this.waterPos = mutableBlockPos;
this.setNextCheckTickCount(5);
return;
}
}
}
}
}
}

private boolean hasFishingRod(EntityMaid entityMaid) {
ItemStack mainHandItem = entityMaid.getMainHandItem();
return mainHandItem.is(Tags.Items.TOOLS_FISHING_RODS);
}

private boolean isWater(ServerLevel worldIn, BlockPos basePos) {
BlockState blockState = worldIn.getBlockState(basePos);
return blockState.is(Blocks.WATER);
}

private boolean waterPosCheck(EntityMaid maid) {
int distanceSqr = this.searchRange * this.searchRange;
Vec3 waterVec = new Vec3(this.waterPos.getX(), this.waterPos.getY(), this.waterPos.getZ());
return maid.distanceToSqr(waterVec) < distanceSqr && maid.isWithinRestriction(this.waterPos);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.github.tartaricacid.touhoulittlemaid.entity.ai.brain.task;

import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityChair;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.google.common.collect.ImmutableMap;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ai.behavior.BehaviorUtils;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
import net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities;

public class MaidFindChairTask extends MaidCheckRateTask {
private static final int MAX_DELAY_TIME = 12;
private final float speedModifier;
private EntityChair chairEntity = null;

public MaidFindChairTask(float speedModifier) {
super(ImmutableMap.of(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, MemoryStatus.VALUE_PRESENT,
MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT));
this.speedModifier = speedModifier;
this.setMaxCheckRate(MAX_DELAY_TIME);
}

@Override
protected boolean checkExtraStartConditions(ServerLevel worldIn, EntityMaid owner) {
return super.checkExtraStartConditions(worldIn, owner) && owner.getVehicle() == null;
}

@Override
protected void start(ServerLevel worldIn, EntityMaid maid, long gameTimeIn) {
this.chairEntity = null;
this.getEntities(maid)
.find(e -> maid.isWithinRestriction(e.blockPosition()))
.filter(Entity::isAlive)
.filter(e -> e instanceof EntityChair chair && chair.getPassengers().isEmpty())
.findFirst()
.ifPresent(chairEntity -> {
this.chairEntity = (EntityChair) chairEntity;
BehaviorUtils.setWalkAndLookTargetMemories(maid, this.chairEntity, this.speedModifier, 0);
});

if (chairEntity != null && chairEntity.isAlive() && chairEntity.closerThan(maid, 2)) {
if (chairEntity.getPassengers().isEmpty()) {
maid.startRiding(this.chairEntity);
}
this.chairEntity = null;
}
}

private NearestVisibleLivingEntities getEntities(EntityMaid maid) {
return maid.getBrain().getMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES).orElse(NearestVisibleLivingEntities.empty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.github.tartaricacid.touhoulittlemaid.entity.info.ServerCustomPackLoader;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityPowerPoint;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityTombstone;
import com.github.tartaricacid.touhoulittlemaid.entity.projectile.MaidFishingHook;
import com.github.tartaricacid.touhoulittlemaid.entity.task.TaskIdle;
import com.github.tartaricacid.touhoulittlemaid.entity.task.TaskManager;
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
Expand Down Expand Up @@ -198,6 +199,7 @@ public class EntityMaid extends TamableAnimal implements CrossbowAttackMob, IMai

public final ItemStack[] handItemsForAnimation = new ItemStack[]{ItemStack.EMPTY, ItemStack.EMPTY};
public boolean guiOpening = false;
public MaidFishingHook fishing = null;

private List<SendEffectMessage.EffectData> effects = Lists.newArrayList();
private IMaidTask task = TaskManager.getIdleTask();
Expand All @@ -219,7 +221,7 @@ public EntityMaid(Level worldIn) {
}

public static AttributeSupplier.Builder createAttributes() {
return LivingEntity.createLivingAttributes().add(Attributes.FOLLOW_RANGE, 64).add(Attributes.ATTACK_KNOCKBACK).add(Attributes.ATTACK_DAMAGE);
return LivingEntity.createLivingAttributes().add(Attributes.FOLLOW_RANGE, 64).add(Attributes.ATTACK_KNOCKBACK).add(Attributes.ATTACK_DAMAGE).add(Attributes.LUCK);
}

public static boolean canInsertItem(ItemStack stack) {
Expand Down Expand Up @@ -314,8 +316,8 @@ public void rideTick() {
super.rideTick();
if (this.getVehicle() != null) {
Entity vehicle = this.getVehicle();
this.setYHeadRot(vehicle.getYRot());
this.setYBodyRot(vehicle.getYRot());
//this.setYHeadRot(vehicle.getYRot());
//this.setYBodyRot(vehicle.getYRot());
}
}

Expand Down Expand Up @@ -1668,6 +1670,10 @@ public void setTaskData(CompoundTag compoundTag) {
this.entityData.set(TASK_DATA_INFO, compoundTag, true);
}

public float getLuck() {
return (float) this.getAttributeValue(Attributes.LUCK);
}

public List<SendEffectMessage.EffectData> getEffects() {
return effects;
}
Expand Down
Loading

0 comments on commit b096c49

Please sign in to comment.