-
Notifications
You must be signed in to change notification settings - Fork 12
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
f506afb
commit bcb35b9
Showing
20 changed files
with
858 additions
and
18 deletions.
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
src/main/java/net/medievalweapons/entity/FranciscaEntity.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,168 @@ | ||
package net.medievalweapons.entity; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.levelz.access.PlayerStatsManagerAccess; | ||
import net.levelz.init.ConfigInit; | ||
import net.levelz.stats.Skill; | ||
import net.medievalweapons.init.CompatInit; | ||
import net.medievalweapons.init.EntityInit; | ||
import net.medievalweapons.item.FranciscaItem; | ||
import net.medievalweapons.mixin.client.PersistentProjectileEntityAccessor; | ||
import net.minecraft.enchantment.EnchantmentHelper; | ||
import net.minecraft.enchantment.Enchantments; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.FlyingItemEntity; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.entity.data.DataTracker; | ||
import net.minecraft.entity.data.TrackedData; | ||
import net.minecraft.entity.data.TrackedDataHandlerRegistry; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.projectile.PersistentProjectileEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.sound.SoundEvent; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.hit.EntityHitResult; | ||
import net.minecraft.world.World; | ||
|
||
public class FranciscaEntity extends PersistentProjectileEntity implements FlyingItemEntity { | ||
private static final TrackedData<Boolean> ENCHANTMENT_GLINT; | ||
private ItemStack francisca; | ||
|
||
public FranciscaEntity(EntityType<? extends FranciscaEntity> entityType, World world, FranciscaItem item) { | ||
super(entityType, world); | ||
this.francisca = new ItemStack(item); | ||
} | ||
|
||
public FranciscaEntity(World world, LivingEntity owner, FranciscaItem item, ItemStack stack) { | ||
// super(item.getType(), owner, world); | ||
super(); | ||
this.francisca = new ItemStack(item); | ||
this.francisca = stack.copy(); | ||
this.dataTracker.set(ENCHANTMENT_GLINT, stack.hasGlint()); | ||
} | ||
|
||
@Environment(EnvType.CLIENT) | ||
public FranciscaEntity(World world, double x, double y, double z, FranciscaItem item) { | ||
super(item.getType(), x, y, z, world); | ||
this.francisca = new ItemStack(item); | ||
} | ||
|
||
@Override | ||
protected void initDataTracker() { | ||
super.initDataTracker(); | ||
this.dataTracker.startTracking(ENCHANTMENT_GLINT, false); | ||
} | ||
|
||
@Override | ||
protected ItemStack asItemStack() { | ||
return this.francisca.copy(); | ||
} | ||
|
||
@Environment(EnvType.CLIENT) | ||
public boolean enchantingGlint() { | ||
return this.dataTracker.get(ENCHANTMENT_GLINT); | ||
} | ||
|
||
@Override | ||
protected void onEntityHit(EntityHitResult entityHitResult) { | ||
Entity hitEntity = entityHitResult.getEntity(); | ||
|
||
float damage = ((FranciscaItem) this.francisca.getItem()).getAttackDamage() * 2.3F; | ||
|
||
int sharpnessLevel = EnchantmentHelper.getLevel(Enchantments.SHARPNESS, this.francisca); | ||
if (sharpnessLevel > 0) { | ||
damage += sharpnessLevel * 0.6F; | ||
} | ||
|
||
Entity owner = this.getOwner(); | ||
if (CompatInit.isLevelZLoaded && owner instanceof PlayerEntity) { | ||
int archeryLevel = ((PlayerStatsManagerAccess) owner).getPlayerStatsManager().getSkillLevel(Skill.ARCHERY); | ||
damage += archeryLevel >= ConfigInit.CONFIG.maxLevel && ConfigInit.CONFIG.archeryDoubleDamageChance > this.getWorld().getRandom().nextFloat() ? damage | ||
: (double) archeryLevel * ConfigInit.CONFIG.archeryBowExtraDamage; | ||
} | ||
|
||
DamageSource damageSource = createDamageSource(this, owner == null ? this : owner); | ||
SoundEvent soundEvent = SoundEvents.ITEM_TRIDENT_HIT; | ||
if (hitEntity.damage(damageSource, damage)) { | ||
if (hitEntity.getType() == EntityType.ENDERMAN) { | ||
return; | ||
} | ||
|
||
if (hitEntity instanceof LivingEntity) { | ||
LivingEntity hitLivingEntity = (LivingEntity) hitEntity; | ||
if (owner instanceof LivingEntity) { | ||
EnchantmentHelper.onUserDamaged(hitLivingEntity, owner); | ||
EnchantmentHelper.onTargetDamaged((LivingEntity) owner, hitLivingEntity); | ||
} | ||
|
||
int fireAspectLevel = EnchantmentHelper.getLevel(Enchantments.FIRE_ASPECT, this.francisca); | ||
if (fireAspectLevel > 0) { | ||
hitLivingEntity.setOnFireFor(fireAspectLevel * 4); | ||
} | ||
this.playSound(soundEvent, 1.0F, 1.0F); | ||
this.onHit(hitLivingEntity); | ||
} | ||
} | ||
|
||
this.setVelocity(this.getVelocity().multiply(0.75)); | ||
} | ||
|
||
@Override | ||
public void onPlayerCollision(PlayerEntity player) { | ||
Entity entity = this.getOwner(); | ||
if (entity == null || entity.getUuid() == player.getUuid()) { | ||
super.onPlayerCollision(player); | ||
} | ||
} | ||
|
||
@Override | ||
public void readCustomDataFromNbt(NbtCompound nbt) { | ||
super.readCustomDataFromNbt(nbt); | ||
if (nbt.contains("francisca", 10)) { | ||
this.francisca = ItemStack.fromNbt(nbt.getCompound("francisca")); | ||
this.dataTracker.set(ENCHANTMENT_GLINT, this.francisca.hasGlint()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void writeCustomDataToNbt(NbtCompound nbt) { | ||
super.writeCustomDataToNbt(nbt); | ||
nbt.put("francisca", this.francisca.writeNbt(new NbtCompound())); | ||
} | ||
|
||
@Override | ||
public void age() { | ||
if (this.pickupType != PersistentProjectileEntity.PickupPermission.ALLOWED) { | ||
super.age(); | ||
} | ||
} | ||
|
||
@Override | ||
@Environment(EnvType.CLIENT) | ||
public boolean shouldRender(double cameraX, double cameraY, double cameraZ) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public ItemStack getStack() { | ||
return francisca; | ||
} | ||
|
||
public boolean inGround() { | ||
return ((PersistentProjectileEntityAccessor) this).getInGround(); | ||
} | ||
|
||
static { | ||
ENCHANTMENT_GLINT = DataTracker.registerData(FranciscaEntity.class, TrackedDataHandlerRegistry.BOOLEAN); | ||
} | ||
|
||
private DamageSource createDamageSource(Entity source, Entity attacker) { | ||
return attacker.getDamageSources().create(EntityInit.FRANCISCA, source, attacker); | ||
} | ||
|
||
} |
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,45 @@ | ||
package net.medievalweapons.item; | ||
|
||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.medievalweapons.init.CompatInit; | ||
import net.minecraft.client.item.TooltipContext; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.SwordItem; | ||
import net.minecraft.item.ToolMaterial; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.util.UseAction; | ||
import net.minecraft.world.World; | ||
|
||
public class BigAxeItem extends SwordItem { | ||
|
||
public BigAxeItem(ToolMaterial toolMaterial, int attackDamage, float attackSpeed, Settings settings) { | ||
super(toolMaterial, attackDamage, attackSpeed, settings); | ||
} | ||
|
||
@Override | ||
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) { | ||
super.appendTooltip(stack, world, tooltip, context); | ||
if (!CompatInit.isBetterCombatLoaded) { | ||
tooltip.add(Text.translatable("item.medievalweapons.double_handed.tooltip")); | ||
} | ||
} | ||
|
||
@Override | ||
public UseAction getUseAction(ItemStack stack) { | ||
return UseAction.BLOCK; | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { | ||
ItemStack itemStack = user.getStackInHand(hand); | ||
user.setCurrentHand(hand); | ||
return TypedActionResult.consume(itemStack); | ||
} | ||
|
||
} |
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,69 @@ | ||
package net.medievalweapons.item; | ||
|
||
import java.util.UUID; | ||
|
||
import com.google.common.collect.ImmutableMultimap; | ||
import com.google.common.collect.Multimap; | ||
|
||
import net.medievalweapons.init.CompatInit; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.attribute.EntityAttribute; | ||
import net.minecraft.entity.attribute.EntityAttributeInstance; | ||
import net.minecraft.entity.attribute.EntityAttributeModifier; | ||
import net.minecraft.entity.attribute.EntityAttributes; | ||
import net.minecraft.entity.effect.StatusEffects; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.SwordItem; | ||
import net.minecraft.item.ToolMaterial; | ||
import net.minecraft.world.World; | ||
|
||
public class DaggerItem extends SwordItem { | ||
private static final UUID ATTACK_BONUS_MODIFIER_ID = UUID.fromString("fbd4e4e4-62f7-4108-9be3-eb6781231298"); | ||
private static final EntityAttributeModifier ATTACK_BONUS_MODIFIER; | ||
private final ToolMaterial material; | ||
private final float attackDamage; | ||
public final Multimap<EntityAttribute, EntityAttributeModifier> attributeModifiers; | ||
|
||
public DaggerItem(ToolMaterial material, int attackDamage, float attackSpeed, Settings settings) { | ||
super(material, settings); | ||
// super(material, attackDamage, attackSpeed, settings); | ||
this.material = material; | ||
this.attackDamage = attackDamage + material.getAttackDamage(); | ||
|
||
ImmutableMultimap.Builder<EntityAttribute, EntityAttributeModifier> builder = ImmutableMultimap.builder(); | ||
builder.put(EntityAttributes.GENERIC_ATTACK_DAMAGE, new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_ID, "Tool modifier", this.attackDamage, EntityAttributeModifier.Operation.ADDITION)); | ||
builder.put(EntityAttributes.GENERIC_ATTACK_SPEED, new EntityAttributeModifier(ATTACK_SPEED_MODIFIER_ID, "Tool modifier", attackSpeed, EntityAttributeModifier.Operation.ADDITION)); | ||
CompatInit.addRange(-1.0D, builder); | ||
this.attributeModifiers = builder.build(); | ||
} | ||
|
||
@Override | ||
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot equipmentSlot) { | ||
return equipmentSlot == EquipmentSlot.MAINHAND ? attributeModifiers : super.getAttributeModifiers(equipmentSlot); | ||
} | ||
|
||
@Override | ||
public ToolMaterial getMaterial() { | ||
return this.material; | ||
} | ||
|
||
@Override | ||
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) { | ||
if (!world.isClient() && entity instanceof PlayerEntity player) { | ||
Boolean extra = player.isSneaking() || player.hasStatusEffect(StatusEffects.INVISIBILITY); | ||
if (selected && extra && !player.getAttributes().hasModifierForAttribute(EntityAttributes.GENERIC_ATTACK_DAMAGE, ATTACK_BONUS_MODIFIER_ID)) { | ||
EntityAttributeInstance entityAttributeInstance = player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE); | ||
entityAttributeInstance.addTemporaryModifier(ATTACK_BONUS_MODIFIER); | ||
} else if (player.getAttributes().hasModifierForAttribute(EntityAttributes.GENERIC_ATTACK_DAMAGE, ATTACK_BONUS_MODIFIER_ID) && !extra) { | ||
player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).removeModifier(ATTACK_BONUS_MODIFIER_ID); | ||
} | ||
} | ||
} | ||
|
||
static { | ||
ATTACK_BONUS_MODIFIER = new EntityAttributeModifier(ATTACK_BONUS_MODIFIER_ID, "Sneaking attack bonus", 2.0D, EntityAttributeModifier.Operation.ADDITION); | ||
} | ||
|
||
} |
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,82 @@ | ||
package net.medievalweapons.item; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import net.medievalweapons.entity.FranciscaEntity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.projectile.PersistentProjectileEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.SwordItem; | ||
import net.minecraft.item.ToolMaterial; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.stat.Stats; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.util.UseAction; | ||
import net.minecraft.world.World; | ||
|
||
public class FranciscaItem extends SwordItem { | ||
|
||
private final Supplier<EntityType<FranciscaEntity>> typeSupplier; | ||
private EntityType<FranciscaEntity> cachedType = null; | ||
|
||
public FranciscaItem(ToolMaterial toolMaterial, float attackDamage, float attackSpeed, Supplier<EntityType<FranciscaEntity>> typeSupplier, Settings settings) { | ||
super(toolMaterial, (int) attackDamage, attackSpeed, settings); | ||
this.typeSupplier = typeSupplier; | ||
} | ||
|
||
public EntityType<FranciscaEntity> getType() { | ||
if (cachedType == null) { | ||
cachedType = typeSupplier.get(); | ||
} | ||
return cachedType; | ||
} | ||
|
||
@Override | ||
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) { | ||
if (user instanceof PlayerEntity playerEntity) { | ||
int i = this.getMaxUseTime(stack) - remainingUseTicks; | ||
if (i >= 10) { | ||
if (!world.isClient()) { | ||
stack.damage(1, playerEntity, entity -> entity.sendToolBreakStatus(user.getActiveHand())); | ||
FranciscaEntity francisca_Entity = new FranciscaEntity(world, playerEntity, this, stack); | ||
francisca_Entity.setVelocity(playerEntity, playerEntity.getPitch(), playerEntity.getYaw(), 0.0F, 1.5F, 1.0F); | ||
if (playerEntity.isCreative()) { | ||
francisca_Entity.pickupType = PersistentProjectileEntity.PickupPermission.CREATIVE_ONLY; | ||
} | ||
world.spawnEntity(francisca_Entity); | ||
world.playSoundFromEntity(null, francisca_Entity, SoundEvents.ITEM_TRIDENT_THROW, SoundCategory.PLAYERS, 1.0F, 1.0F); | ||
if (!playerEntity.isCreative()) { | ||
playerEntity.getInventory().removeOne(stack); | ||
} | ||
} | ||
|
||
playerEntity.incrementStat(Stats.USED.getOrCreateStat(this)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { | ||
ItemStack itemStack = user.getStackInHand(hand); | ||
if (itemStack.getDamage() >= itemStack.getMaxDamage() - 1) { | ||
return TypedActionResult.fail(itemStack); | ||
} else { | ||
user.setCurrentHand(hand); | ||
return TypedActionResult.consume(itemStack); | ||
} | ||
} | ||
|
||
@Override | ||
public UseAction getUseAction(ItemStack stack) { | ||
return UseAction.SPEAR; | ||
} | ||
|
||
@Override | ||
public int getMaxUseTime(ItemStack stack) { | ||
return 72000; | ||
} | ||
} |
Oops, something went wrong.