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

Added custom death messages (#143) #203

Merged
merged 2 commits into from
Jul 16, 2023
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 @@ -29,6 +29,7 @@
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/paneedah/weaponlib/Weapon.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
import static com.paneedah.mwc.utils.ModReference.ID;
import static com.paneedah.mwc.utils.ModReference.LOG;

public class Weapon extends Item implements PlayerItemInstanceFactory<PlayerWeaponInstance, WeaponState>,
AttachmentContainer, Reloadable, Inspectable, Modifiable, Updatable, IModernCrafting {
public class Weapon extends Item implements PlayerItemInstanceFactory<PlayerWeaponInstance, WeaponState>, AttachmentContainer, Reloadable, Inspectable, Modifiable, Updatable, IModernCrafting {

public enum ShellCasingEjectDirection { LEFT, RIGHT };

Expand Down
40 changes: 36 additions & 4 deletions src/main/java/com/paneedah/weaponlib/WeaponSpawnEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.RayTraceResult.Type;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.network.NetworkRegistry;

Expand Down Expand Up @@ -81,10 +84,7 @@ protected void onImpact(final RayTraceResult position) {
//PostProcessPipeline.createDistortionPoint((float) position.hitVec.x,(float) position.hitVec.y, (float) position.hitVec.z, 2f, 3000);
Explosion.createServerSideExplosion(weapon.getModContext(), world, this.getThrower(), this, position.hitVec.x, position.hitVec.y, position.hitVec.z, explosionRadius, false, true, isDestroyingBlocks, explosionParticleAgeCoefficient, smokeParticleAgeCoefficient, explosionParticleScaleCoefficient, smokeParticleScaleCoefficient, weapon.getModContext().getRegisteredTexture(explosionParticleTextureId), weapon.getModContext().getRegisteredTexture(smokeParticleTextureId), weapon.getModContext().getExplosionSound());
} else if (position.entityHit != null) {
if (this.getThrower() != null)
position.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), damage);
else
position.entityHit.attackEntityFrom(new DamageSource("thrown"), damage);
position.entityHit.attackEntityFrom(new ProjectileDamageSource("gun", weapon.getName(), this, this.getThrower()), damage);
Paneedah marked this conversation as resolved.
Show resolved Hide resolved

// Todo: Actually fix this, currently we are reproducing the effect of not apply knockback.
// If you are standing still it's not a big deal everything seems fine.
Expand Down Expand Up @@ -195,4 +195,36 @@ public void shoot(final double x, final double y, final double z, final float ve
public Weapon getWeapon() {
return weapon;
}

public static class ProjectileDamageSource extends DamageSource {

private final String gunName;
private final Entity projectile;
private final Entity shooter;

public ProjectileDamageSource(String damageTypeIn, String gunName, Entity projectile, Entity shooter) {
super(damageTypeIn);
this.gunName = gunName;
this.projectile = projectile;
this.shooter = shooter;
}

@Override
public Entity getTrueSource() {
return this.projectile;
}

@Override
public Entity getImmediateSource() {
return this.shooter;
}

@Override
public ITextComponent getDeathMessage(EntityLivingBase entityLivingBaseIn) {
if (this.shooter == null)
return new TextComponentTranslation("death.attack.gun.noshooter", entityLivingBaseIn.getDisplayName(), this.gunName);

return new TextComponentTranslation("death.attack.gun", entityLivingBaseIn.getDisplayName(), this.shooter.getDisplayName(), this.gunName);
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/mwc/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1130,3 +1130,6 @@ config.rendering.enableFancyRainAndSnow.property.name=On-Screen Rain and Snow
config.rendering.enableFancyRainAndSnow.property.tooltip=Please keep this setting DISABLED as it is currently broken.

overlay.opendoor.name=Open Door

death.attack.gun=%s was shot by %s using %s
death.attack.gun.noshooter=%s was shot to death using %s
Loading