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);
*/
}
}
}
}
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);
}
}
}
}
Aggregations