Search in sources :

Example 1 with Furnace

use of org.spongepowered.api.block.tileentity.carrier.Furnace in project LanternServer by LanternPowered.

the class AdvancementTest method onChangeInventory.

@SuppressWarnings("ConstantConditions")
@Listener
public void onChangeInventory(ChangeInventoryEvent event, @First Player player, @Getter("getTargetInventory") CarriedInventory<?> container) {
    if (!container.getName().get().equals("Furnace")) {
        return;
    }
    final Carrier carrier = container.getCarrier().orElse(null);
    if (!(carrier instanceof Furnace)) {
        return;
    }
    final Furnace furnace = (Furnace) carrier;
    final int passed = furnace.passedBurnTime().get();
    final int max = furnace.maxBurnTime().get();
    if (max <= 0 || passed >= max) {
        return;
    }
    for (SlotTransaction transaction : event.getTransactions()) {
        if (container.getInventoryProperty(transaction.getSlot(), SlotIndex.class).get().getValue() == 0) {
            if (transaction.getFinal().getType() == ItemTypes.DIRT) {
                player.getProgress(this.cookDirtAdvancement).grant();
            } else if (this.suicidalAdvancement != null && (transaction.getFinal().getType() == ItemTypes.TNT || transaction.getFinal().getType() == ItemTypes.TNT_MINECART)) {
                player.getProgress(this.suicidalAdvancement).grant();
            /*
                    final Explosion explosion = Explosion.builder()
                            .location(furnace.getLocation())
                            .shouldBreakBlocks(true)
                            .canCauseFire(true)
                            .shouldDamageEntities(true)
                            .radius(7)
                            .build();
                    explosion.getWorld().triggerExplosion(explosion);
                    */
            }
        }
    }
}
Also used : SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) Carrier(org.spongepowered.api.item.inventory.Carrier) Furnace(org.spongepowered.api.block.tileentity.carrier.Furnace) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Listener(org.spongepowered.api.event.Listener)

Example 2 with Furnace

use of org.spongepowered.api.block.tileentity.carrier.Furnace in project SpongeCommon by SpongePowered.

the class AdvancementTest method onChangeInventory.

@SuppressWarnings("ConstantConditions")
@Listener
public void onChangeInventory(ChangeInventoryEvent event, @First Player player, @Getter("getTargetInventory") CarriedInventory<?> container) {
    if (!container.getName().get().equals("Furnace")) {
        return;
    }
    final Carrier carrier = container.getCarrier().orElse(null);
    if (!(carrier instanceof Furnace)) {
        return;
    }
    final Furnace furnace = (Furnace) carrier;
    final int passed = furnace.passedBurnTime().get();
    final int max = furnace.maxBurnTime().get();
    if (max <= 0 || passed >= max) {
        return;
    }
    for (SlotTransaction transaction : event.getTransactions()) {
        if (transaction.getSlot().getInventoryProperty(SlotIndex.class).get().getValue() == 0) {
            if (transaction.getFinal().getType() == ItemTypes.DIRT) {
                player.getProgress(this.cookDirtAdvancement).grant();
            } else if (this.suicidalAdvancement != null && (transaction.getFinal().getType() == ItemTypes.TNT || transaction.getFinal().getType() == ItemTypes.TNT_MINECART)) {
                player.getProgress(this.suicidalAdvancement).grant();
                final Explosion explosion = Explosion.builder().location(furnace.getLocation()).shouldBreakBlocks(true).canCauseFire(true).shouldDamageEntities(true).radius(7).build();
                explosion.getWorld().triggerExplosion(explosion);
            }
        }
    }
}
Also used : Explosion(org.spongepowered.api.world.explosion.Explosion) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) Carrier(org.spongepowered.api.item.inventory.Carrier) Furnace(org.spongepowered.api.block.tileentity.carrier.Furnace) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) Listener(org.spongepowered.api.event.Listener)

Aggregations

Furnace (org.spongepowered.api.block.tileentity.carrier.Furnace)2 Listener (org.spongepowered.api.event.Listener)2 Carrier (org.spongepowered.api.item.inventory.Carrier)2 SlotIndex (org.spongepowered.api.item.inventory.property.SlotIndex)2 SlotTransaction (org.spongepowered.api.item.inventory.transaction.SlotTransaction)2 Explosion (org.spongepowered.api.world.explosion.Explosion)1