-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5bf2a3
commit de92cea
Showing
12 changed files
with
295 additions
and
0 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
src/main/java/org/confluence/mod/client/renderer/entity/FinchMinionRenderer.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,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(); | ||
} | ||
} |
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
58 changes: 58 additions & 0 deletions
58
src/main/java/org/confluence/mod/entity/minion/FinchMinionEntity.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,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
59
src/main/java/org/confluence/mod/entity/minion/MinionEntity.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,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); | ||
} | ||
} |
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
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
67
src/main/java/org/confluence/mod/item/staff/SummonerStaffItem.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 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); | ||
} | ||
} |
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