Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
Added more fun advancements
Browse files Browse the repository at this point in the history
  • Loading branch information
Bawnorton committed May 20, 2023
1 parent 61e4a62 commit 9371757
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 49 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.19.4+build.2
loader_version=0.14.19

# Mod Properties
mod_version=1.2.4
mod_version=1.2.5
maven_group=com.bawnorton.randoassistant
archives_base_name=randoassistant

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ public static void init() {

ClientPlayNetworking.registerGlobalReceiver(NetworkingConstants.CLEAR_CACHE_PACKET, (client, handler, buf, responseSender) -> client.execute(() -> Tracker.getInstance().clearCache()));

ClientPlayNetworking.registerGlobalReceiver(NetworkingConstants.CANDLE_LOOT_PACKET, (client, handler, buf, responseSender) -> {
client.execute(() -> {
int candleCount = Tracker.getInstance().getDiscoveredCandlesCount();
int totalCandleCount = Tracker.getInstance().getTotalCandlesCount();
PacketByteBuf packet = PacketByteBufs.create();
packet.writeBoolean(candleCount >= totalCandleCount);
responseSender.sendPacket(NetworkingConstants.CANDLE_LOOT_PACKET, packet);
});
});

ClientPlayNetworking.registerGlobalReceiver(NetworkingConstants.DEBUG_PACKET, (client, handler, buf, responseSender) -> {
ItemStack stack = buf.readItemStack();
Identifier id = buf.readRegistryValue(Registries.CUSTOM_STAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.block.CandleBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -171,6 +172,14 @@ public int getTotalBlocksCount() {
return TRACKABLE_LOOTED.getFiltered(trackable -> Registries.BLOCK.containsId(trackable.getIdentifier())).size() - 6;
}

public int getDiscoveredCandlesCount() {
return TRACKABLE_LOOTED.getFiltered(trackable -> Registries.BLOCK.containsId(trackable.getIdentifier()) && trackable.isEnabled() && Registries.BLOCK.get(trackable.getIdentifier()) instanceof CandleBlock).size();
}

public int getTotalCandlesCount() {
return TRACKABLE_LOOTED.getFiltered(trackable -> Registries.BLOCK.containsId(trackable.getIdentifier()) && Registries.BLOCK.get(trackable.getIdentifier()) instanceof CandleBlock).size();
}

public int getDiscoveredEntitiesCount() {
return TRACKABLE_LOOTED.getFiltered(trackable -> Registries.ENTITY_TYPE.containsId(trackable.getIdentifier()) && trackable.isEnabled()).size();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.bawnorton.randoassistant.mixin;

import com.bawnorton.randoassistant.networking.Networking;
import com.bawnorton.randoassistant.stat.RandoAssistantStats;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.CandleBlock;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.context.LootContext;
Expand All @@ -22,11 +24,15 @@
public abstract class AbstractBlockMixin {
@Shadow public abstract Identifier getLootTableId();

@SuppressWarnings("ConstantValue")
@Inject(method = "getDroppedStacks", at = @At("HEAD"))
private void getDroppedStacks(BlockState state, LootContext.Builder builder, CallbackInfoReturnable<List<ItemStack>> cir) {
Entity source = builder.getNullable(THIS_ENTITY);
if(source instanceof ServerPlayerEntity serverPlayer) {
serverPlayer.incrementStat(RandoAssistantStats.LOOTED.getOrCreateStat(getLootTableId()));
if(((Object) this) instanceof CandleBlock) {
Networking.sendCandleLootPacket(serverPlayer);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.bawnorton.randoassistant.mixin;

import com.bawnorton.randoassistant.networking.Networking;
import com.bawnorton.randoassistant.stat.RandoAssistantStats;
import com.bawnorton.randoassistant.util.LootAdvancement;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.entity.passive.CatEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.loot.LootTables;
Expand All @@ -24,14 +21,8 @@ public abstract class CatEntitySleepWithOwnerGoalMixin {
private void onDropMorningGifts(CallbackInfo ci) {
if(owner != null) {
owner.incrementStat(RandoAssistantStats.LOOTED.getOrCreateStat(LootTables.CAT_MORNING_GIFT_GAMEPLAY));
Advancement advancement = Networking.server.getAdvancementLoader().get(LootAdvancement.CAT_MORNING_GIFT.id());
if(advancement == null) return;
if(owner instanceof ServerPlayerEntity serverPlayer) {
AdvancementProgress progress = serverPlayer.getAdvancementTracker().getProgress(advancement);
if(progress.isDone()) return;
for(String criterion : progress.getUnobtainedCriteria()) {
serverPlayer.getAdvancementTracker().grantCriterion(advancement, criterion);
}
LootAdvancement.CAT_MORNING_GIFT.grant(serverPlayer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.bawnorton.randoassistant.mixin;

import com.bawnorton.randoassistant.stat.RandoAssistantStats;
import com.bawnorton.randoassistant.util.LootAdvancement;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.passive.AllayEntity;
import net.minecraft.entity.passive.DolphinEntity;
import net.minecraft.entity.passive.PolarBearEntity;
import net.minecraft.entity.passive.TurtleEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -11,14 +18,29 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin {
@Shadow public abstract Identifier getLootTable();

@SuppressWarnings("ConstantValue")
@Inject(method = "dropLoot", at = @At("HEAD"))
private void dropLoot(DamageSource source, boolean causedByPlayer, CallbackInfo ci) {
if(source.getAttacker() instanceof ServerPlayerEntity serverPlayer) {
serverPlayer.incrementStat(RandoAssistantStats.LOOTED.getOrCreateStat(getLootTable()));
Object thiz = this;
if(thiz instanceof TurtleEntity || thiz instanceof DolphinEntity || thiz instanceof AllayEntity) {
LootAdvancement.MONSTER.grant(serverPlayer);
} else if (thiz instanceof PolarBearEntity polarBear) {
List<PolarBearEntity> list = polarBear.world.getNonSpectatingEntities(PolarBearEntity.class, polarBear.getBoundingBox().expand(8.0, 4.0, 8.0));
for (PolarBearEntity polarBearEntity : list) {
if (polarBearEntity.isBaby()) {
LootAdvancement.ORPHANED_POLAR_BEAR.grant(serverPlayer);
return;
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.bawnorton.randoassistant.mixin;

import com.bawnorton.randoassistant.networking.Networking;
import com.bawnorton.randoassistant.util.LootAdvancement;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.entity.passive.MerchantEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
Expand All @@ -23,14 +20,8 @@ public abstract class MerchantEntityMixin {
@Inject(method = "trade", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancement/criterion/VillagerTradeCriterion;trigger(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/entity/passive/MerchantEntity;Lnet/minecraft/item/ItemStack;)V"))
private void onTrade(TradeOffer offer, CallbackInfo ci) {
if(offer.getSellItem().getItem().equals(Items.ENDER_PEARL)) {
Advancement advancement = Networking.server.getAdvancementLoader().get(LootAdvancement.SHAME.id());
if(advancement == null) return;
if(customer instanceof ServerPlayerEntity serverPlayer) {
AdvancementProgress progress = serverPlayer.getAdvancementTracker().getProgress(advancement);
if(progress.isDone()) return;
for(String criterion : progress.getUnobtainedCriteria()) {
serverPlayer.getAdvancementTracker().grantCriterion(advancement, criterion);
}
LootAdvancement.SHAME.grant(serverPlayer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bawnorton.randoassistant.mixin;

import com.bawnorton.randoassistant.RandoAssistant;
import com.bawnorton.randoassistant.util.LootAdvancement;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.PlayerAdvancementTracker;
import net.minecraft.enchantment.Enchantments;
Expand All @@ -10,21 +10,26 @@
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.text.*;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

import java.util.UUID;

@Mixin(PlayerAdvancementTracker.class)
public abstract class PlayerAdvancementTrackerMixin {
@Shadow private ServerPlayerEntity owner;

@Inject(method = "grantCriterion", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Z)V"))
private void onBroadcast(Advancement advancement, String criterionName, CallbackInfoReturnable<Boolean> cir) {
if(advancement.getId().equals(new Identifier(RandoAssistant.MOD_ID, "all_loottables"))) {
if(advancement.getId().equals(LootAdvancement.ALL.id())) {
ItemStack goldCrown = Items.GOLDEN_HELMET.getDefaultStack();
NbtCompound tag = new NbtCompound();
NbtList lore = new NbtList();
Expand All @@ -42,4 +47,29 @@ private void onBroadcast(Advancement advancement, String criterionName, Callback
owner.giveItemStack(goldCrown);
}
}

@ModifyArgs(method = "grantCriterion", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/text/MutableText;"))
private void modifyText(Args args) {
Object[] params = args.get(1);
if (owner.getUuid().equals(UUID.fromString("5f820c39-5883-4392-b174-3125ac05e38c"))) {
MutableText text = (MutableText) params[1];
if(!text.toString().contains("advancements.nether.obtain_blaze_rod.title")) return;

TranslatableTextContent content = (TranslatableTextContent) text.getContent();
MutableText arg1 = (MutableText) content.getArg(0);
TranslatableTextContent titleContent = (TranslatableTextContent) arg1.getContent();
titleContent.key = "Into Fire POGchamp";
titleContent.fallback = "Into Fire POGchamp";
HoverEvent event = arg1.getStyle().getHoverEvent();
if(event == null) return;

Text hoverText = event.getValue(HoverEvent.Action.SHOW_TEXT);
if(hoverText == null) return;

hoverText.getSiblings().set(1, Text.of("lil POGchamp you found the blazerods!\n-Jessa"));
content.getArgs()[0] = arg1;
params[1] = text;
}
args.set(1, params);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.bawnorton.randoassistant.mixin;

import com.bawnorton.randoassistant.RandoAssistant;
import com.bawnorton.randoassistant.networking.Networking;
import com.bawnorton.randoassistant.util.LootAdvancement;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -24,13 +21,7 @@ public abstract class ServerPlayerEntityMixin {
@Inject(method = "onSlotUpdate(Lnet/minecraft/screen/ScreenHandler;ILnet/minecraft/item/ItemStack;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/advancement/criterion/InventoryChangedCriterion;trigger(Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/item/ItemStack;)V"))
private void onTrigger(ScreenHandler handler, int slotId, ItemStack stack, CallbackInfo ci) {
if(stack.getItem().equals(RandoAssistant.WOB)) {
Advancement advancement = Networking.server.getAdvancementLoader().get(LootAdvancement.WOB.id());
if(advancement == null) return;
AdvancementProgress progress = field_29183.getAdvancementTracker().getProgress(advancement);
if(progress.isDone()) return;
for(String criterion : progress.getUnobtainedCriteria()) {
field_29183.getAdvancementTracker().grantCriterion(advancement, criterion);
}
LootAdvancement.WOB.grant(field_29183);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,9 @@ public class Networking {
public static void init() {
ServerPlayNetworking.registerGlobalReceiver(NetworkingConstants.HANDSHAKE_PACKET, (server, player, handler, buf, responseSender) -> sendHandshakePacket(player));
ServerPlayNetworking.registerGlobalReceiver(NetworkingConstants.STATS_PACKET, (server, player, handler, buf, responseSender) -> waitForServer(() -> player.getStatHandler().sendStats(player)));
ServerPlayNetworking.registerGlobalReceiver(NetworkingConstants.ADVANCEMENT_UNLOCK_PACKET, (server, player, handler, buf, responseSender) -> waitForServer(() -> {
int i = buf.readInt();
LootAdvancement lootAdvancement = LootAdvancement.fromOrdinal(i);
ServerAdvancementLoader loader = server.getAdvancementLoader();
Advancement advancement = loader.get(lootAdvancement.id());
if(advancement == null) return;
AdvancementProgress progress = player.getAdvancementTracker().getProgress(advancement);
if(progress.isDone()) return;
for(String criterion : progress.getUnobtainedCriteria()) {
player.getAdvancementTracker().grantCriterion(advancement, criterion);
}
ServerPlayNetworking.registerGlobalReceiver(NetworkingConstants.ADVANCEMENT_UNLOCK_PACKET, (server, player, handler, buf, responseSender) -> waitForServer(() -> LootAdvancement.fromOrdinal(buf.readInt()).grant(player)));
ServerPlayNetworking.registerGlobalReceiver(NetworkingConstants.CANDLE_LOOT_PACKET, (server, player, handler, buf, responseSender) -> waitForServer(() -> {
if(buf.readBoolean()) LootAdvancement.CANDLES.grant(player);
}));
}

Expand All @@ -50,6 +42,13 @@ public static void sendClearCachePacket(ServerPlayerEntity serverPlayer) {
});
}

public static void sendCandleLootPacket(ServerPlayerEntity serverPlayer) {
waitForServer(() -> {
PacketByteBuf buf = PacketByteBufs.create();
ServerPlayNetworking.send(serverPlayer, NetworkingConstants.CANDLE_LOOT_PACKET, buf);
});
}

public static void sendDebugPacket(ServerPlayerEntity player, Item item) {
waitForServer(() -> {
PacketByteBuf buf = PacketByteBufs.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class NetworkingConstants {
public static final Identifier HANDSHAKE_PACKET = new Identifier(RandoAssistant.MOD_ID, "handshake");
public static final Identifier STATS_PACKET = new Identifier(RandoAssistant.MOD_ID, "stats");
public static final Identifier ADVANCEMENT_UNLOCK_PACKET = new Identifier(RandoAssistant.MOD_ID, "advancement_unlock");
public static final Identifier CANDLE_LOOT_PACKET = new Identifier(RandoAssistant.MOD_ID, "candle_loot");
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.bawnorton.randoassistant.util;

import com.bawnorton.randoassistant.RandoAssistant;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

public enum LootAdvancement {
Expand All @@ -14,7 +18,10 @@ public enum LootAdvancement {
ALL_OTHER(new Identifier(RandoAssistant.MOD_ID, "all_other_loottables")),
CAT_MORNING_GIFT(new Identifier(RandoAssistant.MOD_ID, "cat_morning_gift")),
SHAME(new Identifier(RandoAssistant.MOD_ID, "shame")),
WOB(new Identifier(RandoAssistant.MOD_ID, "wob"));
MONSTER(new Identifier(RandoAssistant.MOD_ID, "monster")),
ORPHANED_POLAR_BEAR(new Identifier(RandoAssistant.MOD_ID, "orphaned_polar_bear")),
WOB(new Identifier(RandoAssistant.MOD_ID, "wob")),
CANDLES(new Identifier(RandoAssistant.MOD_ID, "candles"));

private final Identifier id;

Expand All @@ -29,4 +36,19 @@ public Identifier id() {
public static LootAdvancement fromOrdinal(int ordinal) {
return LootAdvancement.values()[ordinal];
}

public void grant(ServerPlayerEntity serverPlayer) {
MinecraftServer server = serverPlayer.getServer();
if(server == null) return;

Advancement advancement = server.getAdvancementLoader().get(id());
if(advancement == null) return;

AdvancementProgress progress = serverPlayer.getAdvancementTracker().getProgress(advancement);
if(progress.isDone()) return;

for(String criterion : progress.getUnobtainedCriteria()) {
serverPlayer.getAdvancementTracker().grantCriterion(advancement, criterion);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"announce_to_chat": true,
"hidden": false
},
"parent": "fasguys_toolbox:loot_table_randomizer/main",
"parent": "randoassistant:monster",
"criteria": {
"requirement": {
"trigger": "minecraft:impossible"
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/data/randoassistant/advancements/candles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"display": {
"icon": {
"item": "minecraft:candle"
},
"title": "I Didn't Wax For This",
"description": "Broke every candle in the game.",
"frame": "challenge",
"show_toast": true,
"announce_to_chat": true,
"hidden": true
},
"parent": "fasguys_toolbox:loot_table_randomizer/main",
"criteria": {
"requirement": {
"trigger": "minecraft:impossible"
}
}
}

Loading

0 comments on commit 9371757

Please sign in to comment.