Skip to content

Commit

Permalink
cleanup, swap to accessors/invokers from AWs
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWinABagel committed Dec 30, 2023
1 parent 97d1412 commit 466b252
Show file tree
Hide file tree
Showing 31 changed files with 130 additions and 291 deletions.
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import net.darkhax.curseforgegradle.TaskPublishCurseForge

plugins {
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
Expand All @@ -25,7 +23,6 @@ repositories {
name = "Porting Lib"
url = "https://mvn.devos.one/snapshots/"
content {

}
}
maven {
Expand Down Expand Up @@ -60,8 +57,8 @@ dependencies {
modImplementation(include("io.github.fabricators_of_create.Porting-Lib:transfer:${project.port_lib_version}"))

// Mixin Extras + Mixin^2 for mod compat
implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:0.2.0"))
implementation(annotationProcessor("com.github.bawnorton.mixinsquared:mixinsquared-fabric:0.1.1"))
include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.mixin_extras_version}")))
include(implementation(annotationProcessor("com.github.bawnorton.mixinsquared:mixinsquared-fabric:${project.mixin_squared_version}")))

modImplementation "com.ptsmods:devlogin:3.4.1"
}
Expand Down
10 changes: 6 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ org.gradle.parallel=true
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
loader_version=0.14.22
loader_version=0.14.25

# Mod Properties
mod_version=0.0.9
mod_version=0.1.0.3
maven_group=dev.shadowsoffire.placebo
archives_base_name=fakerlib

# Dependencies
fabric_version=0.90.4+1.20.1
fabric_version=0.91.0+1.20.1
#todo remove port lib dep
port_lib_version=2.1.1127+1.20
mixin_extras_version=0.1.1
mixin_extras_version=0.2.0
mixin_squared_version=0.1.1
reach_lib_version=2.4.0
5 changes: 3 additions & 2 deletions src/main/java/dev/shadowsoffire/placebo/Placebo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.shadowsoffire.placebo.events.ServerEvents;
import dev.shadowsoffire.placebo.json.GearSetRegistry;
import dev.shadowsoffire.placebo.loot.StackLootEntry;
import dev.shadowsoffire.placebo.mixin.getters.TextColorGetter;
import dev.shadowsoffire.placebo.packets.ButtonClickMessage;
import dev.shadowsoffire.placebo.packets.PatreonDisableMessage;
import dev.shadowsoffire.placebo.patreon.TrailsManager;
Expand All @@ -14,7 +15,6 @@
import dev.shadowsoffire.placebo.util.PlaceboUtil;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.network.chat.TextColor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -34,7 +34,8 @@ public void onInitialize() {
ButtonClickMessage.init();
PatreonDisableMessage.initServer();
registerCommands();
TextColor.NAMED_COLORS = new HashMap<>(TextColor.NAMED_COLORS);
TextColorGetter.setNAMED_COLORS(new HashMap<>(TextColorGetter.getNAMED_COLORS()));
//TextColor.NAMED_COLORS = new HashMap<>(TextColor.NAMED_COLORS);
PlaceboUtil.registerCustomColor(GradientColor.RAINBOW);
DynamicRegistry.sync();
GearSetRegistry.INSTANCE.register();
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/dev/shadowsoffire/placebo/PlaceboClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ public void onInitializeClient() {
PatreonDisableMessage.initClient();
}


public static long ticks = 0;


public static float getColorTicks() {
return (ticks + Minecraft.getInstance().getDeltaFrameTime()) / 0.5F;
}


}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import dev.shadowsoffire.placebo.mixin.getters.MinecraftServerAccessor;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
Expand All @@ -26,7 +27,7 @@ public class SerializeLootTableCommand {
public static void register(LiteralArgumentBuilder<CommandSourceStack> builder) {
builder.then(Commands.literal("serialize_loot_table").requires(s -> s.hasPermission(2)).then(Commands.argument("loot_table", ResourceLocationArgument.id()).suggests(LootCommand.SUGGEST_LOOT_TABLE).executes(ctx -> {
ResourceLocation id = ResourceLocationArgument.getId(ctx, "loot_table");
LootTable table = ctx.getSource().getServer().resources.managers().getLootData().getLootTable(id);
LootTable table = ((MinecraftServerAccessor) ctx.getSource().getServer()).getResources().managers().getLootData().getLootTable(id);
if (table == LootTable.EMPTY) throw NOT_FOUND.create(id);
String path = "fakerlib_serialized/" + id.getNamespace() + "/loot_tables/" + id.getPath() + ".json";
File file = new File(FabricLoader.getInstance().getGameDir().toFile(), path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package dev.shadowsoffire.placebo.commands;

import java.io.IOException;
import java.io.StringWriter;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.serialization.JsonOps;

import dev.shadowsoffire.placebo.Placebo;
import dev.shadowsoffire.placebo.json.NBTAdapter;
import net.minecraft.commands.CommandBuildContext;
Expand All @@ -21,11 +17,14 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.storage.loot.Deserializers;

import java.io.IOException;
import java.io.StringWriter;

public class StringToObjCommand {

public static final Gson GSON = Deserializers.createLootTableSerializer().setPrettyPrinting().create();

public static final DynamicCommandExceptionType NOT_FOUND = new DynamicCommandExceptionType(arg -> Component.translatable("placebo.cmd.not_found", arg));
public static final DynamicCommandExceptionType NOT_FOUND = new DynamicCommandExceptionType(arg -> Component.translatable("fakerlib.cmd.not_found", arg));

public static void register(LiteralArgumentBuilder<CommandSourceStack> builder, CommandBuildContext buildCtx) {
builder.then(Commands.literal("string_to_obj").requires(src -> src.hasPermission(2)).then(Commands.argument("nbt_item", ItemArgument.item(buildCtx)).executes(ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@ public static InteractionResult onItemUse(ItemStack stack, UseOnContext ctx) {
return null;
}

/**
* Called from {link IForgeItemStack#getEnchantmentLevel(Enchantment)}
* Injected via coremods/get_ench_level_event_specific.js
*/
public static int getEnchantmentLevelSpecific(int level, ItemStack stack, Enchantment ench) {
var enchMap = new HashMap<Enchantment, Integer>();
enchMap.put(ench, level);
var eventResult = GetEnchantmentLevelEvent.GET_ENCHANTMENT_LEVEL.invoker().onEnchantRequest(enchMap, stack);
return eventResult.get(ench);
}

/**
* Called from {link IForgeItemStack#getAllEnchantments()}
* Injected via coremods/get_ench_level_event.js
*/
public static Map<Enchantment, Integer> getEnchantmentLevel(Map<Enchantment, Integer> enchantments, ItemStack stack) {
enchantments = new HashMap<>(enchantments);
GetEnchantmentLevelEvent.GET_ENCHANTMENT_LEVEL.invoker().onEnchantRequest(enchantments, stack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation;

import java.lang.reflect.Type;
import java.util.Objects;
import java.util.Random;
import java.util.UUID;

public record RandomAttributeModifier(Attribute attribute, Operation op, StepFunction value, UUID id) {
Expand Down Expand Up @@ -54,8 +52,8 @@ public void apply(RandomSource rand, LivingEntity entity) {
AttributeModifier modif = this.create(rand);
AttributeInstance inst = entity.getAttribute(this.attribute);
if (inst == null) {
Placebo.LOGGER
.trace(String.format("Attempted to apply a random attribute modifier to an entity (%s) that does not have that attribute (%s)!", EntityType.getKey(entity.getType()), BuiltInRegistries.ATTRIBUTE.getKey(this.attribute)));
Placebo.LOGGER.trace(String.format("Attempted to apply a random attribute modifier to an entity (%s) that does not have that attribute (%s)!",
EntityType.getKey(entity.getType()), BuiltInRegistries.ATTRIBUTE.getKey(this.attribute)));
return;
}
inst.addPermanentModifier(modif);
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/dev/shadowsoffire/placebo/loot/PoolBuilder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.shadowsoffire.placebo.loot;

import dev.shadowsoffire.placebo.mixin.getters.BuilderAccessor;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
Expand All @@ -18,17 +19,17 @@ public PoolBuilder(int minRolls, int maxRolls) {
}

public PoolBuilder addEntries(LootPoolEntryContainer... entries) {
this.entries.addAll(Arrays.asList(entries));
((BuilderAccessor) this).getEntries().addAll(Arrays.asList(entries));
return this;
}

public PoolBuilder addCondition(LootItemCondition... conditions) {
this.conditions.addAll(Arrays.asList(conditions));
((BuilderAccessor) this).getConditions().addAll(Arrays.asList(conditions));
return this;
}

public PoolBuilder addFunc(LootItemFunction... conditions) {
this.functions.addAll(Arrays.asList(conditions));
((BuilderAccessor) this).getFunctions().addAll(Arrays.asList(conditions));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.base.Predicates;
import io.github.fabricators_of_create.porting_lib.transfer.item.ItemStackHandler;
import io.github.fabricators_of_create.porting_lib.transfer.item.SlotItemHandler;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

import java.util.function.Predicate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.shadowsoffire.placebo.menu;

import dev.shadowsoffire.placebo.Placebo;
import dev.shadowsoffire.placebo.mixin.AbstractContainerMenuInvoker;
import dev.shadowsoffire.placebo.mixin.getters.AbstractContainerMenuInvoker;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.Slot;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package dev.shadowsoffire.placebo.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.sugar.Local;
import dev.shadowsoffire.placebo.Placebo;
import dev.shadowsoffire.placebo.events.PlaceboEventFactory;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
Expand All @@ -20,10 +18,7 @@ public class EnchantmentHelperMixin {
private static void initializeEnchLevelEvent(Enchantment enchantment, ItemStack stack, CallbackInfoReturnable<Integer> cir, @Local CompoundTag compoundTag){
if (stack.isEmpty()) return;
int result = PlaceboEventFactory.getEnchantmentLevelSpecific(EnchantmentHelper.getEnchantmentLevel(compoundTag), stack, enchantment);
//Placebo.LOGGER.info("Enchantment level: {}, old: {}", result, EnchantmentHelper.getEnchantmentLevel(compoundTag));
cir.setReturnValue(result);
}



}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.shadowsoffire.placebo.mixin;

import dev.shadowsoffire.placebo.PlaceboClient;
import dev.shadowsoffire.placebo.mixin.getters.LivingEntityRendererAccessor;
import dev.shadowsoffire.placebo.patreon.wings.Wing;
import dev.shadowsoffire.placebo.patreon.wings.WingLayer;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
Expand Down Expand Up @@ -35,7 +36,7 @@ private static void addLayers(EntityRendererProvider.Context context, Map<String
Wing.INSTANCE = new Wing(context.getModelSet().bakeLayer(PlaceboClient.WING_LOC));
for (String s : skins.keySet()) {
LivingEntityRenderer skin = (LivingEntityRenderer) skins.get(s);
skin.addLayer(new WingLayer(skin));
((LivingEntityRendererAccessor) skin).callAddLayer(new WingLayer(skin));
}
}
}
Loading

0 comments on commit 466b252

Please sign in to comment.