use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class BrewingStandBlockEntityMixin method impl$onConsumeFuel.
// @Formatter:on
@Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILEXCEPTION, slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/BrewingStandBlockEntity;isBrewable()Z")), at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/BrewingStandBlockEntity;setChanged()V"))
private void impl$onConsumeFuel(CallbackInfo ci, ItemStack fuelStack) {
final Cause currentCause = Sponge.server().causeStackManager().currentCause();
fuelStack.grow(1);
final ItemStackSnapshot originalStack = ItemStackUtil.snapshotOf(fuelStack);
fuelStack.shrink(1);
final Transaction<ItemStackSnapshot> fuelTransaction = new Transaction<>(originalStack, ItemStackUtil.snapshotOf(fuelStack));
final ItemStackSnapshot ingredientStack = ItemStackUtil.snapshotOf(this.items.get(3));
final BrewingEvent.ConsumeFuel event = SpongeEventFactory.createBrewingEventConsumeFuel(currentCause, (BrewingStand) this, fuelTransaction, ingredientStack);
if (Sponge.eventManager().post(event)) {
fuelStack.grow(1);
this.fuel = 0;
} else if (event.fuel().custom().isPresent()) {
final ItemStackSnapshot finalFuel = event.fuel().finalReplacement();
this.items.set(4, ItemStackUtil.fromSnapshotToNative(finalFuel));
}
}
use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class AbstractFurnaceBlockEntityMixin method impl$callInteruptSmeltEvent.
private void impl$callInteruptSmeltEvent() {
if (this.cookingProgress > 0) {
final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(this.items.get(1));
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final AbstractCookingRecipe recipe = this.impl$getCurrentRecipe();
final CookingEvent.Interrupt event = SpongeEventFactory.createCookingEventInterrupt(cause, (FurnaceBlockEntity) this, Optional.of(fuel), Optional.ofNullable((CookingRecipe) recipe));
SpongeCommon.post(event);
}
}
use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class AbstractFurnaceBlockEntityMixin method impl$throwFuelEventIfOrShrink.
// @Formatter:on
// Shrink Fuel
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;shrink(I)V"))
private void impl$throwFuelEventIfOrShrink(final ItemStack itemStack, final int quantity) {
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final ItemStackSnapshot fuel = ItemStackUtil.snapshotOf(itemStack);
final ItemStackSnapshot shrinkedFuel = ItemStackUtil.snapshotOf(ItemStackUtil.cloneDefensive(itemStack, itemStack.getCount() - 1));
final Transaction<ItemStackSnapshot> transaction = new Transaction<>(fuel, shrinkedFuel);
final AbstractCookingRecipe recipe = this.impl$getCurrentRecipe();
final CookingEvent.ConsumeFuel event = SpongeEventFactory.createCookingEventConsumeFuel(cause, (FurnaceBlockEntity) this, Optional.of(fuel), Optional.of((CookingRecipe) recipe), Collections.singletonList(transaction));
SpongeCommon.post(event);
if (event.isCancelled()) {
this.cookingTotalTime = 0;
return;
}
if (!transaction.isValid()) {
return;
}
if (transaction.custom().isPresent()) {
this.items.set(1, ItemStackUtil.fromSnapshotToNative(transaction.finalReplacement()));
} else {
// vanilla
itemStack.shrink(quantity);
}
}
use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class SpongeCommandManager method init.
public void init() {
final Cause cause = PhaseTracker.getCauseStackManager().currentCause();
final Set<TypeToken<?>> usedTokens = new HashSet<>();
Sponge.game().registry(RegistryTypes.COMMAND_REGISTRAR_TYPE).streamEntries().forEach(entry -> {
final CommandRegistrarType<?> type = entry.value();
// someone's gonna do it, let's not let them take us down.
final TypeToken<?> handledType = type.handledType();
if (handledType == null) {
SpongeCommon.logger().error("Registrar '{}' did not provide a handledType, skipping...", type.getClass());
} else if (usedTokens.add(handledType)) {
// we haven't done it yet
// Add the command registrar
final CommandRegistrar<?> registrar = type.create(this);
this.knownRegistrars.put(GenericTypeReflector.erase(type.handledType().getType()), registrar);
if (registrar instanceof BrigadierCommandRegistrar) {
this.brigadierRegistrar = (BrigadierCommandRegistrar) registrar;
} else if (registrar instanceof SpongeParameterizedCommandRegistrar) {
this.registerInternalCommands((SpongeParameterizedCommandRegistrar) registrar);
}
this.game.eventManager().post(this.createEvent(cause, this.game, registrar));
} else {
SpongeCommon.logger().warn("Command type '{}' has already been collected, skipping request from {}", handledType.toString(), type.getClass());
}
});
if (this.brigadierRegistrar == null) {
throw new IllegalStateException("Brigadier registrar was not detected");
}
}
use of org.spongepowered.api.event.Cause in project SpongeCommon by SpongePowered.
the class QueryThreadGs4Mixin method impl$basicSendTo.
@Inject(method = "buildRuleResponse", cancellable = true, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/rcon/NetworkDataOutputStream;reset()V"))
public void impl$basicSendTo(DatagramPacket datagramPacket, CallbackInfoReturnable<byte[]> cir) throws IOException {
final Cause currentCause = Sponge.server().causeStackManager().currentCause();
final QueryServerEvent.Full event = SpongeEventFactory.createQueryServerEventFull(currentCause, (InetSocketAddress) datagramPacket.getSocketAddress(), new LinkedHashMap<>(), "MINECRAFT", "SMP", this.worldName, this.serverName, Arrays.asList(this.serverInterface.getPlayerNames()), this.serverInterface.getPluginNames(), this.serverInterface.getServerVersion(), this.maxPlayers, this.serverInterface.getPlayerCount());
Sponge.eventManager().post(event);
this.rulesResponse.reset();
this.rulesResponse.write(0);
this.rulesResponse.writeBytes(this.shadow$getIdentBytes(event.address()));
this.rulesResponse.writeString("splitnum");
this.rulesResponse.write(128);
this.rulesResponse.write(0);
this.rulesResponse.writeString("hostname");
this.rulesResponse.writeString(event.motd());
this.rulesResponse.writeString("gametype");
this.rulesResponse.writeString(event.gameType());
this.rulesResponse.writeString("game_id");
this.rulesResponse.writeString(event.gameId());
this.rulesResponse.writeString("version");
this.rulesResponse.writeString(event.version());
this.rulesResponse.writeString("plugins");
this.rulesResponse.writeString(event.plugins());
this.rulesResponse.writeString("map");
this.rulesResponse.writeString(event.map());
this.rulesResponse.writeString("numplayers");
this.rulesResponse.writeString("" + event.playerCount());
this.rulesResponse.writeString("maxplayers");
this.rulesResponse.writeString("" + event.maxPlayerCount());
this.rulesResponse.writeString("hostport");
this.rulesResponse.writeString("" + this.serverPort);
this.rulesResponse.writeString("hostip");
this.rulesResponse.writeString(this.hostIp);
this.rulesResponse.write(0);
this.rulesResponse.write(1);
this.rulesResponse.writeString("player_");
this.rulesResponse.write(0);
final List<String> var3 = event.players();
for (String var4 : var3) {
this.rulesResponse.writeString(var4);
}
this.rulesResponse.write(0);
cir.setReturnValue(this.rulesResponse.toByteArray());
}
Aggregations