Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Squid Improvements from GTNH BugTorch #508

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ConfigEntities extends ConfigBase {
public static boolean enableNetherEndermen;
public static boolean enableShearableSnowGolems;
public static boolean enableBees;
public static boolean enableSquidInk;

static final String catHostile = "hostile";
static final String catNeutral = "neutral";
Expand Down Expand Up @@ -63,6 +64,7 @@ protected void syncConfigOptions() {
enableVillagerTurnsIntoWitch = getBoolean("enableVillagerTurnsIntoWitch", catMisc, true, "Villagers turn into Witches when struck by lightning");
enableDragonRespawn = getBoolean("enableDragonRespawn", catMisc, true, "Crude implementation of respawning the dragon using four End crystals.");
enableNetherEndermen = getBoolean("enableNetherEndermen", catMisc, true, "Allow endermen to rarely spawn in the Nether");
enableSquidInk = getBoolean("enableSquidInk", catMisc, true, "Squid now produce a cloud of floating black ink particles when attacked.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,29 @@ public void livingUpdate(LivingUpdateEvent event) {
}
}

if (ConfigMixins.stepHeightFix && event.entity.stepHeight == .5F) {
event.entity.stepHeight = .6F;
if (ConfigMixins.stepHeightFix && entity.stepHeight == .5F) {
entity.stepHeight = .6F;
}

if (ConfigMixins.enableElytra && entity instanceof IElytraPlayer) {
((IElytraPlayer) entity).tickElytra();
}

if (EntitySquid.class.equals(entity.getClass())) {
EntitySquid sq = (EntitySquid) entity;

if (ConfigEntities.enableSquidInk && "Nelly".equals(sq.getCustomNameTag())) {
Vec3 a = sq.getLookVec().normalize();
sq.fallDistance = 0.0f;
sq.addVelocity(a.xCoord * 0.08, 0.08, a.zCoord * 0.08);
sq.motionY = 0.08;
sq.velocityChanged = true;
}
}

if (ConfigSounds.armorEquip && !event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer && !(event.entity instanceof FakePlayer)) {
EntityPlayer player = (EntityPlayer) event.entity;

if (ConfigSounds.armorEquip && !entity.worldObj.isRemote && entity instanceof EntityPlayer && !(entity instanceof FakePlayer)) {
EntityPlayer player = (EntityPlayer) entity;

if (!SpectatorMode.isSpectator(player)) {
if (!armorTracker.containsKey(player)) {
Expand Down Expand Up @@ -1585,7 +1597,7 @@ public void entityStruckByLightning(EntityStruckByLightningEvent event) {

@SubscribeEvent
public void livingHurtEvent(LivingHurtEvent event) {
Entity targetEntity = event.entity;
EntityLivingBase targetEntity = event.entityLiving;
if (targetEntity == null) return;
if (ConfigFunctions.enableHayBaleFalls
&& targetEntity.worldObj.getBlock(MathHelper.floor_double(targetEntity.posX), MathHelper.floor_double(targetEntity.posY - 0.20000000298023224D - targetEntity.yOffset), MathHelper.floor_double(targetEntity.posZ)) == Blocks.hay_block
Expand All @@ -1606,9 +1618,7 @@ public void livingHurtEvent(LivingHurtEvent event) {
float attackDamage = (float) playerSource.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
float enchantmentDamage = 0.0F;

if (targetEntity instanceof EntityLivingBase) {
enchantmentDamage = EnchantmentHelper.getEnchantmentModifierLiving(playerSource, (EntityLivingBase) targetEntity);
}
enchantmentDamage = EnchantmentHelper.getEnchantmentModifierLiving(playerSource, targetEntity);

if (attackDamage > 0.0F || enchantmentDamage > 0.0F) {
boolean isStrongAttack = playerSource.getHeldItem() != null && event.ammount >= ConfigSounds.combatSoundStrongThreshold;
Expand Down Expand Up @@ -1658,14 +1668,46 @@ public void livingHurtEvent(LivingHurtEvent event) {
}
}


if (!(targetEntity instanceof EntityLivingBase)) {
return;
if (ConfigBlocksItems.enableTotemUndying) {
handleTotemCheck(targetEntity, event);
}
EntityLivingBase livingEntity = (EntityLivingBase) targetEntity;

if (EntitySquid.class.equals(targetEntity.getClass())) {
World w = targetEntity.worldObj;
Random r = w.rand;
doInk: if (ConfigEntities.enableSquidInk && r.nextDouble() < 0.15 && w instanceof WorldServer serverWorld && targetEntity.isInWater()) {
AxisAlignedBB eBox = targetEntity.boundingBox;
double cx = eBox.maxX - 0.5 * (eBox.maxX - eBox.minX);
double cy = eBox.maxY - 0.5 * (eBox.maxY - eBox.minY);
double cz = eBox.maxZ - 0.5 * (eBox.maxZ - eBox.minZ);

AxisAlignedBB box = AxisAlignedBB.getBoundingBox(-1.5, -1.5, -1.5, 1.5, 1.5, 1.5).offset(cx, cy, cz);
List<EntityLivingBase> around = w.getEntitiesWithinAABB(EntityLivingBase.class, box);

if (around.isEmpty()) {
break doInk;
}

if (ConfigBlocksItems.enableTotemUndying) {
handleTotemCheck(livingEntity, event);
EntityLivingBase target = around.get(r.nextInt(around.size()));
if (target != null && target != targetEntity) {
serverWorld.func_147487_a("largesmoke", cx, cy, cz, 5, 0.0, 0.0, 0.0, 0.08);
if (ConfigMixins.newMobSounds) {
float pitch = (r.nextFloat() - r.nextFloat()) * 0.2F + (target.isChild() ? 1.5F : 1.0F);
w.playSoundAtEntity(target, Reference.MCAssetVer + ":entity.squid.squirt", 0.4F, pitch);
}
if (target.isInWater()) {
PotionEffect activeEff = target.getActivePotionEffect(Potion.blindness);
int time = 20 + r.nextInt(300);
if (activeEff != null) {
if (activeEff.getAmplifier() > 0) {
break doInk;
}
time += activeEff.getDuration();
}
target.addPotionEffect(new PotionEffect(Potion.blindness.id, time));
}
}
}
}

// If the attacker is a player spawn the hearts aligned and facing it
Expand Down