Skip to content

Commit

Permalink
召唤师
Browse files Browse the repository at this point in the history
  • Loading branch information
Sihuai2412 committed Oct 4, 2024
1 parent c5bf2a3 commit de92cea
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -47,6 +48,8 @@ public AlchemyTableBlock(){

@Override
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
//if (!(pLevel instanceof ServerLevel))
// return super.use(pState, pLevel, pPos, pPlayer, pHand, pHit); //todo开起来渲染失效
if (pState.getBlock() instanceof AlchemyTableBlock && pLevel.getBlockEntity(pPos) instanceof AlchemyTableBlock.Entity entity) {
if (pPlayer.isShiftKeyDown()){
if (entity.firstColor == 0){
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/confluence/mod/client/ModClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ public static void registerEntityRenderers(EntityRenderersEvent.RegisterRenderer
event.registerEntityRenderer(STAR_FURY_PROJECTILE.get(), StarFuryProjectileRenderer::new);
event.registerEntityRenderer(ARROW_PROJECTILE.get(), TerraArrowRenderer::new);

event.registerEntityRenderer(FINCH_MINION.get(), FinchMinionRenderer::new);


event.registerEntityRenderer(STEP_STOOL.get(), StepStoolRenderer::new);
event.registerEntityRenderer(BOMB_ENTITY.get(), BaseBombEntityRenderer::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.confluence.mod.client.renderer.entity;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
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 org.confluence.mod.Confluence;
import org.confluence.mod.client.model.entity.BeeProjectileModel;
import org.confluence.mod.entity.minion.FinchMinionEntity;

public class FinchMinionRenderer extends EntityRenderer<FinchMinionEntity> {
private static final ResourceLocation TEXTURE = Confluence.asResource("textures/entity/bee_projectile.png");
private final BeeProjectileModel model;

public FinchMinionRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
this.model = new BeeProjectileModel(pContext.bakeLayer(BeeProjectileModel.LAYER_LOCATION));
}

@Override
public ResourceLocation getTextureLocation(FinchMinionEntity finchMinionEntity) {
return TEXTURE;
}

@Override
public void render(FinchMinionEntity pEntity, float pEntityYaw, float pPartialTick, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight) {
pPoseStack.pushPose();
pPoseStack.translate(0.00F, 0.125F, -0.125F);
pPoseStack.mulPose(Axis.YP.rotationDegrees(Mth.lerp(pPartialTick, pEntity.yRotO, pEntity.getYRot()) - 90.0F));
pPoseStack.mulPose(Axis.ZP.rotationDegrees(Mth.lerp(pPartialTick, pEntity.xRotO, pEntity.getXRot())));
pPoseStack.mulPose(Axis.YP.rotation(-Mth.HALF_PI));
model.renderToBuffer(pPoseStack, pBuffer.getBuffer(model.renderType(TEXTURE)), pPackedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
pPoseStack.popPose();
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/confluence/mod/entity/ModEntities.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.confluence.mod.entity.fishing.CurioFishingHook;
import org.confluence.mod.entity.fishing.HotlineFishingHook;
import org.confluence.mod.entity.hook.*;
import org.confluence.mod.entity.minion.FinchMinionEntity;
import org.confluence.mod.entity.projectile.*;
import org.confluence.mod.entity.projectile.arrows.BaseArrowEntity;
import org.confluence.mod.entity.projectile.bombs.*;
Expand Down Expand Up @@ -100,6 +101,13 @@ public final class ModEntities {
public static final RegistryObject<EntityType<BaseArrowEntity>> ARROW_PROJECTILE = ENTITIES.register("arrow_projectile", () -> EntityType.Builder.<BaseArrowEntity>of(BaseArrowEntity::new, MobCategory.MISC).sized(0.5F, 0.5F).build("confluence:arrow_projectile"));


public static final RegistryObject<EntityType<FinchMinionEntity>> FINCH_MINION =
ENTITIES.register("finch_minion", () -> EntityType.Builder.<FinchMinionEntity>of
((pType, pLevel) -> new FinchMinionEntity(pLevel), MobCategory.MISC)
.sized(0.5F, 0.5F)
.build("confluence:finch_minion"));




public static final RegistryObject<EntityType<BaseBombEntity>> BOMB_ENTITY = ENTITIES.register("bomb_entity", () -> EntityType.Builder.<BaseBombEntity>of(BaseBombEntity::new, MobCategory.MISC).sized(BaseBombEntity.DIAMETER, BaseBombEntity.DIAMETER).clientTrackingRange(4).updateInterval(10).build("confluence:bomb_entity"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.confluence.mod.entity.minion;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import org.confluence.mod.entity.ModEntities;
import org.confluence.mod.util.ModUtils;
import org.jetbrains.annotations.NotNull;

public class FinchMinionEntity extends MinionEntity{

public FinchMinionEntity(Level pLevel) {
super(ModEntities.FINCH_MINION.get(), pLevel);
}

public static AttributeSupplier.Builder createAttributes() {
return Mob.createMobAttributes()
.add(Attributes.ATTACK_DAMAGE, 1.0)
.add(Attributes.KNOCKBACK_RESISTANCE, 10.00)
.add(Attributes.MAX_HEALTH, 1.0);
}

@Override
public void tick() {
setNoGravity(true);
super.tick();
if (ownerAttack != null){
Vec3 direction = ModUtils.getDirection(position(), ownerAttack.position(), 1.8D);
double[] dirs = {direction.x, direction.y, direction.z};
setDeltaMovement(dirs[0] / 20.5, dirs[1] / 20.5, dirs[2] / 20.5);
setRot(-(ModUtils.dirToRot(direction)[0]), -(ModUtils.dirToRot(direction)[1]));
} else {
if (owner != null){
Vec3 direction = ModUtils.getDirection(position(), owner.position(), 1.8D);
double[] dirs = {direction.x, direction.y, direction.z};
setDeltaMovement(dirs[0] / 20.5, dirs[1] / 20.5, dirs[2] / 20.5);
setRot(-(ModUtils.dirToRot(direction)[0]), -(ModUtils.dirToRot(direction)[1]));
}
}
}

@Override
protected void onHitEntity(@NotNull EntityHitResult entityHitResult) {
Entity entity = entityHitResult.getEntity();
if (level() instanceof ServerLevel){
float damage = 3.8F;
entity.hurt(damageSources().mobAttack(owner), damage);
RandomSource random = level().random;
setDeltaMovement(random.nextFloat() / 2, random.nextFloat() / 2, random.nextFloat() / 2);
}
}
}
59 changes: 59 additions & 0 deletions src/main/java/org/confluence/mod/entity/minion/MinionEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.confluence.mod.entity.minion;

import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class MinionEntity extends LivingEntity {
public LivingEntity ownerAttack;
public LivingEntity owner;

public MinionEntity(EntityType<? extends LivingEntity> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}

@Override
public void tick() {
super.tick();
noPhysics = true;
checkCollision();
}

private void checkCollision() {
HitResult hitResult = ProjectileUtil.getHitResultOnMoveVector(this, entity -> entity.equals(ownerAttack));
if (hitResult.getType() == HitResult.Type.ENTITY) {
onHitEntity((EntityHitResult) hitResult);
}
}

protected void onHitEntity(@NotNull EntityHitResult entityHitResult) {}

@Override
public Iterable<ItemStack> getArmorSlots() { return new ArrayList<>(); }

@Override
public ItemStack getItemBySlot(EquipmentSlot equipmentSlot) { return ItemStack.EMPTY; }

@Override
public void setItemSlot(EquipmentSlot equipmentSlot, ItemStack itemStack) {}

@Override
public HumanoidArm getMainArm() { return null; }

@Override
public boolean hurt(DamageSource pSource, float pAmount) {
return false;
}

@Override
public void kill() {
this.remove(RemovalReason.DISCARDED);
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/confluence/mod/event/ModEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.confluence.mod.entity.boss.geoEntity.CthulhuEye;
import org.confluence.mod.entity.boss.KingSlime;
import org.confluence.mod.entity.demoneye.DemonEye;
import org.confluence.mod.entity.minion.FinchMinionEntity;
import org.confluence.mod.entity.npc.ModVillagers;
import org.confluence.mod.entity.slime.BaseSlime;
import org.confluence.mod.entity.slime.HoneySlime;
Expand Down Expand Up @@ -76,6 +77,8 @@ public static void attributeCreate(EntityAttributeCreationEvent event) {

event.put(ModEntities.TEST_WORM.get(), TestWormEntity.createAttributes().build());
event.put(ModEntities.TEST_WORM_PART.get(), TestWormPart.createAttributes().build());

event.put(ModEntities.FINCH_MINION.get(), FinchMinionEntity.createAttributes().build());
}

@SubscribeEvent
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/confluence/mod/event/PlayerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.confluence.mod.capability.ability.AbilityProvider;
import org.confluence.mod.capability.mana.ManaProvider;
import org.confluence.mod.client.handler.GravitationHandler;
import org.confluence.mod.entity.minion.MinionEntity;
import org.confluence.mod.item.IRangePickup;
import org.confluence.mod.item.common.LifeCrystal;
import org.confluence.mod.item.common.LifeFruit;
Expand All @@ -35,8 +36,10 @@
import org.confluence.mod.misc.ModTags;
import org.confluence.mod.network.s2c.InfoCurioCheckPacketS2C;
import org.confluence.mod.util.CuriosUtils;
import org.confluence.mod.util.ModUtils;
import org.confluence.mod.util.PlayerUtils;

import java.util.List;
import java.util.Optional;

@Mod.EventBusSubscriber(modid = Confluence.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
Expand All @@ -54,6 +57,21 @@ public static void playerLogin(PlayerEvent.PlayerLoggedInEvent event) {
}
}

@SubscribeEvent
public static void playerQuit(PlayerEvent.PlayerLoggedOutEvent event){
List<? extends Entity> entities = ModUtils.getNearbyEntities(Short.MAX_VALUE, event.getEntity().level(),
MinionEntity.class, event.getEntity().getBoundingBox());
for (Entity entity : entities){
if (entity instanceof MinionEntity minion){
if (minion.owner != null){
if (minion.owner.is(event.getEntity())){
minion.kill();
}
}
}
}
}

@SubscribeEvent
public static void playerTick(TickEvent.PlayerTickEvent event) {
if (event.phase == TickEvent.Phase.START) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/confluence/mod/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.confluence.mod.item.mana.ManaWeapons;
import org.confluence.mod.item.pickaxe.Pickaxes;
import org.confluence.mod.item.potion.TerraPotions;
import org.confluence.mod.item.staff.Staffs;
import org.confluence.mod.item.sword.Swords;
import org.confluence.mod.misc.ModRarity;
import org.confluence.mod.misc.ModSoundEvents;
Expand Down Expand Up @@ -167,6 +168,7 @@ public static void register(IEventBus bus) {
GunItems.init();
FlailItems.init();
Bows.init();
Staffs.init();
ITEMS.register(bus);
}
}
30 changes: 30 additions & 0 deletions src/main/java/org/confluence/mod/item/staff/Staffs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.confluence.mod.item.staff;

import net.minecraft.world.item.Item;
import net.minecraftforge.registries.RegistryObject;
import org.confluence.mod.entity.minion.FinchMinionEntity;
import org.confluence.mod.item.ModItems;
import org.confluence.mod.util.EnumRegister;

import java.util.function.Supplier;

public enum Staffs implements EnumRegister<Item> {

FINCH_STAFF("finch_staff",() -> new SummonerStaffItem(FinchMinionEntity::new));


;

private final RegistryObject<Item> value;

Staffs(String id, Supplier<Item> item) {
this.value = ModItems.ITEMS.register(id, item);
}

@Override
public RegistryObject<Item> getValue() {
return value;
}

public static void init() {}
}
67 changes: 67 additions & 0 deletions src/main/java/org/confluence/mod/item/staff/SummonerStaffItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.confluence.mod.item.staff;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.confluence.mod.entity.minion.MinionEntity;
import org.jetbrains.annotations.Nullable;

public class SummonerStaffItem extends Item {
Factory entity;
boolean isSummon = false;
int cooling;
MinionEntity minion;

public SummonerStaffItem(Factory entity) {
super(new Properties());
this.entity = entity;
}

@Override
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
if (!(pLevel instanceof ServerLevel)) return InteractionResultHolder.fail(pPlayer.getItemInHand(pUsedHand));
if (cooling > 0){
return InteractionResultHolder.fail(pPlayer.getItemInHand(pUsedHand));
}
if (!isSummon){
minion = entity.create(pLevel);
minion.setPos(pPlayer.getEyePosition());
pLevel.addFreshEntity(minion);
cooling = 60;
isSummon = true;
} else {
minion.remove(Entity.RemovalReason.DISCARDED);
minion = null;
isSummon = false;
}
return super.use(pLevel, pPlayer, pUsedHand);
}

@Override
public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pSlotId, boolean pIsSelected) {
super.inventoryTick(pStack, pLevel, pEntity, pSlotId, pIsSelected);
if (!(pLevel instanceof ServerLevel)) return;
if (minion != null){
if (pEntity instanceof LivingEntity entity){
minion.ownerAttack = entity.getLastHurtMob();
minion.owner = entity;
}
}
if (cooling > 0){
--cooling;
}
}

@FunctionalInterface
public interface Factory {
MinionEntity create(Level level);
}
}
6 changes: 6 additions & 0 deletions src/main/java/org/confluence/mod/util/ModUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.confluence.mod.Confluence;
import org.confluence.mod.client.color.FloatRGBA;
Expand Down Expand Up @@ -414,4 +415,9 @@ private static void renderPart(PoseStack pPoseStack, VertexConsumer pConsumer, f

pPoseStack.popPose();
}

public static List<? extends Entity> getNearbyEntities(double radius, Level level,
Class<? extends Entity> entity, AABB box) {
return level.getEntitiesOfClass(entity, box.inflate(radius));
}
}

0 comments on commit de92cea

Please sign in to comment.