Skip to content

Commit

Permalink
Fix isFire and doesAffectCreative damage implementation in builders
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Jan 28, 2023
1 parent 3a371bb commit c725be5
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public BlockDamageSource build() throws IllegalStateException {
if (this.creative) {
accessor.invoker$bypassInvul();
}
if (this.exhaustion != null) {
accessor.accessor$exhaustion(this.exhaustion.floatValue());
}
if (this.fire) {
accessor.invoker$setIsFire();
}
if (this.exhaustion != null) {
accessor.accessor$exhaustion(this.exhaustion.floatValue());
}
return (BlockDamageSource) (Object) damageSource;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,4 @@ public boolean scalesWithDifficulty() {
public float getFoodExhaustion() {
return (float) this.exhaustion();
}


public void bridge$setDamageIsAbsolute() {
this.bypassMagic();
}
public void bridge$setDamageBypassesArmor() {
this.bypassArmor();
}


public void bridge$setHungerDamage(final float exhaustion) {
((DamageSourceAccessor) this).accessor$exhaustion(exhaustion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ public void setEntitySource(final Entity entitySource) {
((EntityDamageSourceAccessor) this).accessor$entity(entitySource);
}

public void bridge$setDamageIsAbsolute() {
this.bypassMagic();
}
public void bridge$setDamageBypassesArmor() {
this.bypassArmor();
}

@Override
public Entity getEntity() {
return (Entity) this.source();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ public void setIndirectSource(final Entity entity) {
((IndirectEntityDamageSourceAccessor) this).accessor$owner(entity);
}


public void bridge$setDamageIsAbsolute() {
this.bypassMagic();
}
public void bridge$setDamageBypassesArmor() {
this.bypassArmor();
}


@Override
public Entity getEntity() {
return (Entity) this.source();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public DamageSource build() throws IllegalStateException {
&& !this.creative
&& !this.fire
&& this.exhaustion == null
&& this.damageType.equals(DamageTypes.DROWN)
&& this.damageType.equals(DamageTypes.DROWN.get())
) {
return (DamageSource) net.minecraft.world.damagesource.DamageSource.DROWN;
}
Expand Down Expand Up @@ -165,12 +165,12 @@ public DamageSource build() throws IllegalStateException {
if (this.explosion) {
source.setExplosion();
}
if (this.exhaustion != null) {
accessor.accessor$exhaustion(this.exhaustion.floatValue());
}
if (this.fire) {
accessor.invoker$setIsFire();
}
if (this.exhaustion != null) {
accessor.accessor$exhaustion(this.exhaustion.floatValue());
}
return (DamageSource) source;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public EntityDamageSource build() throws IllegalStateException {
if (this.explosion) {
damageSource.setExplosion();
}
if (this.fire) {
accessor.invoker$setIsFire();
}
if (this.exhaustion != null) {
accessor.accessor$exhaustion(this.exhaustion.floatValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,17 @@

import java.lang.ref.WeakReference;

public final class SpongeFallingBlockDamgeSourceBuilder extends AbstractDamageSourceBuilder<FallingBlockDamageSource, FallingBlockDamageSource.Builder> implements FallingBlockDamageSource.Builder {
public final class SpongeFallingBlockDamageSourceBuilder extends AbstractDamageSourceBuilder<FallingBlockDamageSource, FallingBlockDamageSource.Builder> implements FallingBlockDamageSource.Builder {

protected WeakReference<Entity> reference = null;

@Override
public SpongeFallingBlockDamgeSourceBuilder entity(final Entity entity) {
public SpongeFallingBlockDamageSourceBuilder entity(final Entity entity) {
checkArgument(entity instanceof FallingBlock);
this.reference = new WeakReference<>(entity);
return this;
}

@Override
public FallingBlockDamageSource.Builder fire() {
return null;
}

@SuppressWarnings("ConstantConditions")
@Override
public FallingBlockDamageSource build() throws IllegalStateException {
Expand All @@ -81,6 +76,9 @@ public FallingBlockDamageSource build() throws IllegalStateException {
if (this.explosion) {
damageSource.setExplosion();
}
if (this.fire) {
accessor.invoker$setIsFire();
}
if (this.exhaustion != null) {
accessor.accessor$exhaustion(this.exhaustion.floatValue());
}
Expand All @@ -95,7 +93,7 @@ public FallingBlockDamageSource.Builder from(final FallingBlockDamageSource valu
}

@Override
public SpongeFallingBlockDamgeSourceBuilder reset() {
public SpongeFallingBlockDamageSourceBuilder reset() {
super.reset();
this.reference = null;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public IndirectEntityDamageSource build() throws IllegalStateException {
if (this.explosion) {
damageSource.setExplosion();
}
if (this.fire) {
accessor.invoker$setIsFire();
}
if (this.exhaustion != null) {
accessor.accessor$exhaustion(this.exhaustion.floatValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
import org.spongepowered.common.event.cause.entity.damage.SpongeDamageSourceBuilder;
import org.spongepowered.common.event.cause.entity.damage.SpongeDamageType;
import org.spongepowered.common.event.cause.entity.damage.SpongeEntityDamageSourceBuilder;
import org.spongepowered.common.event.cause.entity.damage.SpongeFallingBlockDamgeSourceBuilder;
import org.spongepowered.common.event.cause.entity.damage.SpongeFallingBlockDamageSourceBuilder;
import org.spongepowered.common.event.cause.entity.damage.SpongeIndirectEntityDamageSourceBuilder;
import org.spongepowered.common.fluid.SpongeFluidStackBuilder;
import org.spongepowered.common.fluid.SpongeFluidStackSnapshotBuilder;
Expand Down Expand Up @@ -277,7 +277,7 @@ public void registerDefaultBuilders() {
.register(DamageSource.Builder.class, SpongeDamageSourceBuilder::new)
.register(EntityDamageSource.Builder.class, SpongeEntityDamageSourceBuilder::new)
.register(IndirectEntityDamageSource.Builder.class, SpongeIndirectEntityDamageSourceBuilder::new)
.register(FallingBlockDamageSource.Builder.class, SpongeFallingBlockDamgeSourceBuilder::new)
.register(FallingBlockDamageSource.Builder.class, SpongeFallingBlockDamageSourceBuilder::new)
.register(BlockDamageSource.Builder.class, SpongeBlockDamageSourceBuilder::new)
.register(Explosion.Builder.class, SpongeExplosionBuilder::new)
.register(BlockState.Builder.class, SpongeBlockStateBuilder::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor;
import org.spongepowered.common.event.cause.entity.damage.SpongeCommonDamageSource;

/*
Expand All @@ -48,12 +49,15 @@ public abstract class AbstractDamageSourceMixin_API implements DamageSource {
@Inject(method = "<init>", at = @At("RETURN"))
private void api$setUpBridges(final CallbackInfo callbackInfo) {
final SpongeCommonDamageSource commonSource = (SpongeCommonDamageSource) (Object) this;
final DamageSourceAccessor accessor = (DamageSourceAccessor) commonSource;

commonSource.setDamageType(this.type().name());

if (this.isAbsolute()) {
commonSource.bridge$setDamageIsAbsolute();
accessor.invoker$bypassMagic();
}
if (this.isBypassingArmor()) {
commonSource.bridge$setDamageBypassesArmor();
accessor.invoker$bypassArmor();
}
if (this.isExplosive()) {
commonSource.setExplosion();
Expand All @@ -65,11 +69,14 @@ public abstract class AbstractDamageSourceMixin_API implements DamageSource {
commonSource.setScalesWithDifficulty();
}
if (this.doesAffectCreative()) {
commonSource.isBypassInvul();
accessor.invoker$bypassInvul();
}
if (this.isFire()) {
accessor.invoker$setIsFire();
}
// Sets exhaustion last as to allow control if the builder specified a custom exhaustion value

commonSource.bridge$setHungerDamage((float) this.exhaustion());
// Sets exhaustion last as to allow control if the builder specified a custom exhaustion value
accessor.accessor$exhaustion((float) this.exhaustion());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor;
import org.spongepowered.common.event.cause.entity.damage.SpongeCommonEntityDamageSource;

/*
Expand All @@ -49,13 +50,16 @@ public abstract class AbstractEntityDamageSourceMixin_API implements EntityDamag
@Inject(method = "<init>", at = @At("RETURN"))
private void impl$bridgeApiToImplConstruction(final CallbackInfo callbackInfo) {
final SpongeCommonEntityDamageSource commonSource = (SpongeCommonEntityDamageSource) (Object) this;
final DamageSourceAccessor accessor = (DamageSourceAccessor) commonSource;

commonSource.setDamageType(this.type().name());
commonSource.setEntitySource((Entity) this.source());

if (this.isAbsolute()) {
commonSource.bridge$setDamageIsAbsolute();
accessor.invoker$bypassMagic();
}
if (this.isBypassingArmor()) {
commonSource.bridge$setDamageBypassesArmor();
accessor.invoker$bypassArmor();
}
if (this.isExplosive()) {
commonSource.setExplosion();
Expand All @@ -67,8 +71,13 @@ public abstract class AbstractEntityDamageSourceMixin_API implements EntityDamag
commonSource.setScalesWithDifficulty();
}
if (this.doesAffectCreative()) {
commonSource.isBypassInvul();
accessor.invoker$bypassInvul();
}
if (this.isFire()) {
accessor.invoker$setIsFire();
}

accessor.accessor$exhaustion((float) this.exhaustion());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.common.accessor.world.damagesource.DamageSourceAccessor;
import org.spongepowered.common.event.cause.entity.damage.SpongeCommonIndirectEntityDamageSource;

/*
Expand All @@ -48,28 +49,36 @@ public abstract class AbstractIndirectEntityDamageSourceMixin_API implements Ind
@SuppressWarnings("ConstantConditions")
@Inject(method = "<init>", at = @At("RETURN"))
private void api$setUpBridges(final CallbackInfo callbackInfo) {
final SpongeCommonIndirectEntityDamageSource commonIndirect = (SpongeCommonIndirectEntityDamageSource) (Object) this;
commonIndirect.setDamageType(this.type().name());
commonIndirect.setEntitySource((Entity) this.source());
commonIndirect.setIndirectSource((Entity) this.indirectSource());
final SpongeCommonIndirectEntityDamageSource commonSource = (SpongeCommonIndirectEntityDamageSource) (Object) this;
final DamageSourceAccessor accessor = (DamageSourceAccessor) commonSource;

commonSource.setDamageType(this.type().name());
commonSource.setEntitySource((Entity) this.source());
commonSource.setIndirectSource((Entity) this.indirectSource());

if (this.isAbsolute()) {
commonIndirect.bridge$setDamageIsAbsolute();
accessor.invoker$bypassMagic();
}
if (this.isBypassingArmor()) {
commonIndirect.bridge$setDamageBypassesArmor();
accessor.invoker$bypassArmor();
}
if (this.isExplosive()) {
commonIndirect.setExplosion();
commonSource.setExplosion();
}
if (this.isMagic()) {
commonIndirect.setMagic();
commonSource.setMagic();
}
if (this.isScaledByDifficulty()) {
commonIndirect.setScalesWithDifficulty();
commonSource.setScalesWithDifficulty();
}
if (this.doesAffectCreative()) {
commonIndirect.isBypassInvul();
accessor.invoker$bypassInvul();
}
if (this.isFire()) {
accessor.invoker$setIsFire();
}

accessor.accessor$exhaustion((float) this.exhaustion());
}

}

0 comments on commit c725be5

Please sign in to comment.