Skip to content

Commit

Permalink
Put moonworm on entities head when you hit them with moonworm project…
Browse files Browse the repository at this point in the history
…ile and fix bugs on head duplicating squish drops.
  • Loading branch information
CaliforniaDemise committed Nov 9, 2024
1 parent 3c8b4d0 commit 6de268e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/main/java/twilightforest/entity/EntityTFMoonwormShot.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import net.minecraft.block.Block;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.SoundCategory;
Expand Down Expand Up @@ -121,12 +126,33 @@ protected void onImpact(RayTraceResult ray) {

if (currentState.getBlock().isReplaceable(world, pos)) {
world.setBlockState(pos, TFBlocks.moonworm.getDefaultState().withProperty(BlockDirectional.FACING, ray.sideHit));
// todo sound
this.playSound(TFBlocks.moonworm.getSoundType(TFBlocks.moonworm.getDefaultState(), world, new BlockPos(this), this).getPlaceSound(), 1F, 1F);
}
}

if (ray.entityHit != null) {
ray.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
Entity entity = ray.entityHit;
// TODO Maybe a new damage source
entity.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
if (!entity.isDead && entity instanceof EntityLivingBase) {
EntityLivingBase living = (EntityLivingBase) entity;
ItemStack helmet = living.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
if (helmet.getItem() == Item.getItemFromBlock(TFBlocks.moonworm)) return;
if (!helmet.isEmpty()) {
float chance = 0.5F;
if (helmet.getItem() instanceof ItemArmor) {
ItemArmor.ArmorMaterial material = ((ItemArmor) helmet.getItem()).getArmorMaterial();
if (material.getToughness() > 0.0F) chance /= material.getToughness();
if (material.getDamageReductionAmount(EntityEquipmentSlot.HEAD) > 1) chance -= Math.min(chance, 0.025F * material.getDamageReductionAmount(EntityEquipmentSlot.HEAD));
}
if (rand.nextFloat() < chance) {
living.entityDropItem(helmet, 0.2F);
living.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(TFBlocks.moonworm));
}
return;
}
living.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(TFBlocks.moonworm));
}
}

this.world.setEntityState(this, (byte) 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ protected void initializeCreature(EntityLiving myCreature) {
myCreature.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1024);
myCreature.setHealth(myCreature.getMaxHealth());
}

@Override
protected EntityLiving makeMyCreature() {
return super.makeMyCreature();
}
}

0 comments on commit 6de268e

Please sign in to comment.