/*
 * This file is part of Sponge, licensed under the MIT License (MIT).
 *
 * Copyright (c) SpongePowered <https://www.spongepowered.org>
 * Copyright (c) contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.spongepowered.common.event.damage;

import net.minecraft.entity.Entity;
import org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource;
import org.spongepowered.api.event.cause.entity.damage.source.common.AbstractDamageSource;
import org.spongepowered.common.accessor.util.IndirectEntityDamageSourceAccessor;

/*
To summarize, the way this works is that DamageSource isn't directly created, but
rather that any API abstract classes are automatically set up to extend
this class at runtime. All method calls are forwarded to the proper API calls
by definition. Granted, this cannot actively implement the interface,
but it can certainly declare the methods as abstract.

More notes are geared for abstraction of generating the builders, since those
will require sending the builders into the ctors.
 */
public abstract class SpongeCommonIndirectEntityDamageSource extends net.minecraft.util.IndirectEntityDamageSource implements IndirectEntityDamageSource {

    public SpongeCommonIndirectEntityDamageSource() {
        super("SpongeEntityDamageSource", null, null);
    }

    /**
     * Purely for use with {@link AbstractDamageSource} such that
     * the damage type is set after the super constructor is called.
     *
     * @param type The damage type id
     */
    public void setDamageType(final String type) {
        this.damageType = type;
    }

    public void setEntitySource(final Entity entitySource) {
        this.damageSourceEntity = entitySource;
    }

    public void setIndirectSource(final Entity entity) {
        ((IndirectEntityDamageSourceAccessor) this).accessor$setIndirectEntity(entity);
    }


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


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

    @Override
    public boolean isExplosion() {
        return this.isExplosive();
    }

    @Override
    public boolean isUnblockable() {
        return this.isBypassingArmor();
    }

    @Override
    public boolean canHarmInCreative() {
        return this.doesAffectCreative();
    }

    @Override
    public boolean isDamageAbsolute() {
        return this.isAbsolute();
    }

    @Override
    public boolean isDifficultyScaled() {
        return this.isScaledByDifficulty();
    }

    @Override
    public boolean isMagicDamage() {
        return this.isMagic();
    }

    @Override
    public float getHungerDamage() {
        return (float) this.getExhaustion();
    }

}

@@ -1325,16 +1325,83 @@
 Entity;%0A
+import org.spongepowered.accessor.util.EntityDamageSourceAccessor;%0A
 import o
@@ -1565,32 +1565,100 @@
 ctDamageSource;%0A
+import org.spongepowered.common.accessor.util.DamageSourceAccessor;%0A
 import org.spong
@@ -2739,30 +2739,67 @@
 ) %7B%0A        
-this.d
+((DamageSourceAccessor) this).accessor$setD
 amageType = 
@@ -2799,15 +2799,14 @@
 Type
- = 
+(
 type
+)
 ;%0A  
@@ -2879,22 +2879,65 @@
         
-this.d
+((EntityDamageSourceAccessor) this).accessor$setD
 amageSou
@@ -2949,11 +2949,9 @@
 tity
- = 
+(
 enti
@@ -2958,16 +2958,17 @@
 tySource
+)
 ;%0A    %7D%0A

fix SpongeCommonIndirectEntityDamageSource