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

Commit

Permalink
Add more fun advancements and cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bawnorton committed May 20, 2023
1 parent ed724e0 commit 61e4a62
Show file tree
Hide file tree
Showing 57 changed files with 140 additions and 219 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//file:noinspection GroovyAssignabilityCheck
plugins {
id 'fabric-loom' version '1.1-SNAPSHOT'
id 'maven-publish'
Expand Down
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.3
mod_version=1.2.4
maven_group=com.bawnorton.randoassistant
archives_base_name=randoassistant

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

public class EventManager {

public static KeyBinding highlight = KeyBindingHelper.registerKeyBinding(new KeyBinding(
public static final KeyBinding highlight = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.randoassistant.highlight",
GLFW.GLFW_KEY_V,
"key.categories.randoassistant"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Mixin(ClientPlayNetworkHandler.class)
public abstract class ClientPlayNetworkHandlerMixin {
@Inject(method = "onStatistics", at = @At(value = "INVOKE", target = "Lnet/minecraft/stat/StatHandler;setStat(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/stat/Stat;I)V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void onStatistics(StatisticsS2CPacket packet, CallbackInfo ci, Iterator var2, Map.Entry<Stat<?>, Integer> entry, Stat<?> stat, int i) {
private void onStatistics(StatisticsS2CPacket packet, CallbackInfo ci, Iterator<?> var2, Map.Entry<Stat<?>, Integer> entry, Stat<?> stat, int i) {
if(RandoAssistantStats.isCustom(stat) && i > 0) {
Tracker.getInstance().testAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.client.gui.screen.ingame.CraftingScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private boolean checkWithinLootBookBounds(RecipeBookWidget instance) {
private void onMouseClicked(double mouseX, double mouseY, int button, CallbackInfoReturnable<Boolean> cir) {
LootBookWidget lootBook = LootBookWidget.getInstance();
if (lootBook.mouseClicked(mouseX, mouseY, button)) {
((InventoryScreen) (Object) this).setFocused(lootBook);
setFocused(lootBook);

if(LootTableResultButton.isGraphOpen() && y == (this.height - this.backgroundHeight) / 2) {
y += HEIGHT / 2;
Expand All @@ -179,6 +179,7 @@ private void onMouseClicked(double mouseX, double mouseY, int button, CallbackIn
}
}

@SuppressWarnings("unused")
@Override
protected void onMouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY, CallbackInfoReturnable<Boolean> cir) {
LootBookWidget.getInstance().mouseDragged(mouseX, mouseY, button, deltaX, deltaY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@SuppressWarnings("ALL")
@Mixin(Screen.class)
public abstract class ScreenMixin extends AbstractParentElement {
@Shadow protected abstract <T extends Element & Selectable> T addSelectableChild(T child);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import com.bawnorton.randoassistant.networking.SerializeableInteraction;
import com.bawnorton.randoassistant.networking.SerializeableLootTable;
import com.bawnorton.randoassistant.tracking.Tracker;
import com.bawnorton.randoassistant.tracking.trackable.TrackableCrawler;
import com.bawnorton.randoassistant.util.LootAdvancement;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.minecraft.item.ItemStack;
Expand All @@ -34,9 +32,7 @@ public static void init() {
client.execute(() -> Tracker.getInstance().track(crafting));
});

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

ClientPlayNetworking.registerGlobalReceiver(NetworkingConstants.DEBUG_PACKET, (client, handler, buf, responseSender) -> {
ItemStack stack = buf.readItemStack();
Expand All @@ -47,9 +43,7 @@ public static void init() {
});
});

ClientPlayNetworking.registerGlobalReceiver(NetworkingConstants.HANDSHAKE_PACKET, (client, handler, buf, responseSender) -> {
client.execute(() -> RandoAssistantClient.isInstalledOnServer = true);
});
ClientPlayNetworking.registerGlobalReceiver(NetworkingConstants.HANDSHAKE_PACKET, (client, handler, buf, responseSender) -> client.execute(() -> RandoAssistantClient.isInstalledOnServer = true));
}

public static void requestHandshakePacket() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3i;

public class Cuboid extends Renderer {
private final Line[] edges = new Line[12];
public BlockPos start;
public Vec3i size;
public BlockPos pos;
public final BlockPos start;
public final Vec3i size;

public Cuboid(BlockPos start, Vec3i size, Colour color) {
this.start = start;
this.size = size;
this.pos = this.start.add(this.size.getX() / 2, this.size.getY() / 2, this.size.getZ() / 2);
this.edges[0] = new Line(toVec3d(this.start), toVec3d(this.start.add(this.size.getX(), 0, 0)), color);
this.edges[1] = new Line(toVec3d(this.start), toVec3d(this.start.add(0, this.size.getY(), 0)), color);
this.edges[2] = new Line(toVec3d(this.start), toVec3d(this.start.add(0, 0, this.size.getZ())), color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public class Line extends Renderer {

public Vec3d start;
public Vec3d end;
public Colour colour;
public final Vec3d start;
public final Vec3d end;
public final Colour colour;

public Line(Vec3d start, Vec3d end, Colour colour) {
this.start = start;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.*;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

import java.util.function.Consumer;

import static com.bawnorton.randoassistant.screen.LootTableGraphWidget.HEIGHT;

public class LootBookSettingsWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class LootTableGraphWidget {
private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(10);
private static final int ABSOLUTE_SCALE = 2;

public static int WIDTH = 324;
public static int HEIGHT = 167;
public static final int WIDTH = 324;
public static final int HEIGHT = 167;

private TrackingGraph graph;
private Drawing<TrackingGraph.Vertex, TrackingGraph.Edge> drawing;
Expand Down Expand Up @@ -276,9 +276,11 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
selected.addAll(graph.getChildren(identifier).stream().map(TrackingGraph.Vertex::getIdentifier).collect(Collectors.toSet()));
}
});
return true;
}
} else if(mouseX >= x - 30 && mouseX <= x - 4 && mouseY >= y + 30 && mouseY <= y + 56) {
centreOnTarget();
return true;
} else if(mouseX >= x + WIDTH && mouseX <= x + WIDTH + 26 && mouseY >= y && mouseY <= y + 26) {
LootTableResultButton.getLastClicked().closeGraph();
LootBookWidget lootBook = LootBookWidget.getInstance();
Expand All @@ -288,6 +290,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
TexturedButtonWidget recipeButton = ((InventoryScreenExtender) lootBook.getScreen()).getRecipeBookButton();
lootButton.setY(lootButton.getY() - HEIGHT / 2);
recipeButton.setY(recipeButton.getY() - HEIGHT / 2);
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

import com.bawnorton.randoassistant.tracking.Tracker;
import com.bawnorton.randoassistant.util.IdentifierType;
import com.google.common.collect.Sets;
import net.minecraft.block.Block;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.ToggleButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import static com.bawnorton.randoassistant.screen.LootTableGraphWidget.HEIGHT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ public void clear() {
trackables.clear();
}

public int size() {
return trackables.size();
}

@Override
public String toString() {
return "TrackableMap{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void add(Identifier identifier) {
}

public void connect(Identifier source, Identifier destination) {
if(!contains(source)) add(source);
if(!contains(destination)) add(destination);
if(contains(source)) add(source);
if(contains(destination)) add(destination);
Vertex sourceVertex = getVertex(source);
Vertex destinationVertex = getVertex(destination);
try {
Expand All @@ -81,19 +81,13 @@ public void connect(Identifier source, Identifier destination) {
}
}

public void removeOutgoingEdges(Identifier target) {
Vertex vertex = getVertex(target);
Set<Edge> edges = outgoingEdgesOf(vertex);
removeAllEdges(edges);
}

public boolean contains(Identifier identifier) {
return VERTEX_MAP.containsKey(identifier);
return !VERTEX_MAP.containsKey(identifier);
}

@NotNull
public Vertex getVertex(Identifier identifier) {
if(!contains(identifier)) throw new IllegalArgumentException("Identifier " + identifier + " not found");
if(contains(identifier)) throw new IllegalArgumentException("Identifier " + identifier + " not found");
return VERTEX_MAP.get(identifier);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.bawnorton.randoassistant.util;

import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -82,23 +80,4 @@ public static String getName(Identifier identifier, boolean preferEntity) {
}
};
}

public boolean isItem() {
return this == ITEM;
}

public boolean isBlock() {
if(this == BLOCK) return true;
if(this == ITEM) return Block.getBlockFromItem(Registries.ITEM.get(id)) != Blocks.AIR;
return false;
}

public boolean isEntity() {
if(this == ENTITY) return true;
return isItemAndEntity();
}

public boolean isOther() {
return this == OTHER;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package grapher.graph.drawing;

import com.bawnorton.randoassistant.RandoAssistant;
import grapher.graph.elements.Edge;
import grapher.graph.elements.Vertex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Layouter<V extends Vertex, E extends Edge<V>> {
/**
* Constructs the layouter without populating list ofItems edges and vertices
*/
@SuppressWarnings("unused")
public Layouter() {
layouterFactory = new LayouterFactory<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,16 @@
import com.bawnorton.randoassistant.stat.RandoAssistantStats;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.block.Blocks;
import net.minecraft.block.OxidizableBlock;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.loot.LootManager;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.loot.context.LootContextType;
import net.minecraft.loot.entry.AlternativeEntry;
import net.minecraft.loot.entry.LootPoolEntryType;
import net.minecraft.loot.entry.LootTableEntry;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

@Mixin(AxeItem.class)
public abstract class AxeItemMixin {
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
@Inject(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"), locals = LocalCapture.CAPTURE_FAILHARD)
private void onUseOnBlock(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir, World world, BlockPos blockPos, PlayerEntity playerEntity, BlockState originalState, Optional optional, Optional optional2, Optional optional3, ItemStack itemStack, Optional optional4) {
private void onUseOnBlock(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir, World world, BlockPos blockPos, PlayerEntity playerEntity, BlockState originalState, Optional<BlockState> optional, Optional<BlockState> optional2, Optional<BlockState> optional3, ItemStack itemStack, Optional<Object> optional4) {
if (optional4.isPresent() && playerEntity instanceof ServerPlayerEntity serverPlayer) {
serverPlayer.incrementStat(RandoAssistantStats.INTERACTED.getOrCreateStat(Registries.BLOCK.getId(originalState.getBlock())));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
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;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -19,6 +24,15 @@ 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);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.bawnorton.randoassistant.mixin;

import com.bawnorton.randoassistant.RandoAssistant;
import com.bawnorton.randoassistant.networking.Networking;
import com.bawnorton.randoassistant.networking.SerializeableInteraction;
import com.bawnorton.randoassistant.stat.RandoAssistantStats;
import net.minecraft.block.BlockState;
import net.minecraft.item.HoneycombItem;
Expand Down
Loading

0 comments on commit 61e4a62

Please sign in to comment.