-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
guidebook interaction packet handling
- Loading branch information
Showing
9 changed files
with
149 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../java/de/dafuqs/spectrum/networking/packet/GuidebookConfirmationButtonPressedPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package de.dafuqs.spectrum.networking.packet; | ||
|
||
import de.dafuqs.spectrum.networking.*; | ||
import de.dafuqs.spectrum.progression.*; | ||
import net.fabricmc.fabric.api.networking.v1.*; | ||
import net.minecraft.network.*; | ||
import net.minecraft.network.codec.*; | ||
import net.minecraft.network.packet.*; | ||
import net.minecraft.server.network.*; | ||
import net.minecraft.sound.*; | ||
|
||
public record GuidebookConfirmationButtonPressedPayload(String confirmationString) implements CustomPayload { | ||
|
||
public static final Id<GuidebookConfirmationButtonPressedPayload> ID = SpectrumC2SPackets.makeId("confirmation_button_pressed"); | ||
public static final PacketCodec<PacketByteBuf, GuidebookConfirmationButtonPressedPayload> CODEC = PacketCodec.tuple(PacketCodecs.STRING, GuidebookConfirmationButtonPressedPayload::confirmationString, GuidebookConfirmationButtonPressedPayload::new); | ||
|
||
@Override | ||
public Id<? extends CustomPayload> getId() { | ||
return ID; | ||
} | ||
|
||
public static ServerPlayNetworking.PlayPayloadHandler<GuidebookConfirmationButtonPressedPayload> getPayloadHandler() { | ||
return (payload, context) -> { | ||
ServerPlayerEntity player = context.player(); | ||
SpectrumAdvancementCriteria.CONFIRMATION_BUTTON_PRESSED.trigger(player, payload.confirmationString); | ||
player.getWorld().playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.PLAYERS, 1.0F, 1.0F); | ||
}; | ||
|
||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/de/dafuqs/spectrum/networking/packet/GuidebookHintBoughtPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package de.dafuqs.spectrum.networking.packet; | ||
|
||
import de.dafuqs.spectrum.helpers.*; | ||
import de.dafuqs.spectrum.networking.*; | ||
import net.fabricmc.fabric.api.networking.v1.*; | ||
import net.minecraft.item.*; | ||
import net.minecraft.network.*; | ||
import net.minecraft.network.codec.*; | ||
import net.minecraft.network.packet.*; | ||
import net.minecraft.recipe.*; | ||
import net.minecraft.server.network.*; | ||
import net.minecraft.sound.*; | ||
import net.minecraft.util.*; | ||
|
||
import java.util.*; | ||
|
||
public record GuidebookHintBoughtPayload(Identifier completionAdvancement, | ||
Ingredient payment) implements CustomPayload { | ||
|
||
public static final Id<GuidebookHintBoughtPayload> ID = SpectrumC2SPackets.makeId("guidebook_hint_bought"); | ||
public static final PacketCodec<RegistryByteBuf, GuidebookHintBoughtPayload> CODEC = PacketCodec.tuple( | ||
Identifier.PACKET_CODEC, GuidebookHintBoughtPayload::completionAdvancement, | ||
Ingredient.PACKET_CODEC, GuidebookHintBoughtPayload::payment, | ||
GuidebookHintBoughtPayload::new); | ||
|
||
@Override | ||
public Id<? extends CustomPayload> getId() { | ||
return ID; | ||
} | ||
|
||
public static ServerPlayNetworking.PlayPayloadHandler<GuidebookHintBoughtPayload> getPayloadHandler() { | ||
return (payload, context) -> { | ||
ServerPlayerEntity player = context.player(); | ||
for (ItemStack remainder : InventoryHelper.removeFromInventoryWithRemainders(List.of(payload.payment()), player.getInventory())) { | ||
InventoryHelper.smartAddToInventory(remainder, player.getInventory(), null); | ||
} | ||
|
||
// give the player the hidden "used_tip" advancement and play a sound | ||
Support.grantAdvancementCriterion(player, "hidden/used_tip", "used_tip"); | ||
Support.grantAdvancementCriterion(player, payload.completionAdvancement(), "hint_purchased"); | ||
player.getWorld().playSound(player, player.getX(), player.getY(), player.getZ(), SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 1.0F, 1.0F); | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters