Skip to content

Commit

Permalink
layer render mixin & wandering trades
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Aug 30, 2023
1 parent fab92f8 commit a4aa762
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 82 deletions.
13 changes: 13 additions & 0 deletions common/src/main/java/galena/thigh_highs_etc/THECommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import com.tterrag.registrate.util.nullness.NonNullFunction;
import galena.thigh_highs_etc.index.THEItems;
import galena.thigh_highs_etc.platform.Services;
import net.minecraft.world.entity.npc.VillagerTrades;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.trading.MerchantOffer;

import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;

public class THECommon {

Expand Down Expand Up @@ -37,4 +42,12 @@ public static <T> Map<DyeColor, T> colored(AbstractRegistrate<?> registrate, Str
return mapColors(color -> factory.apply(registrate.object(prefixWith(id, color)), color));
}

public static void registerWanderingTrades(Consumer<VillagerTrades.ItemListing> consumer) {
consumer.accept((entity, random) -> new MerchantOffer(
new ItemStack(Items.EMERALD, 22), ItemStack.EMPTY,
THEItems.TRADER_THIGH_HIGHS.asStack(),
1, 11, 0.05F
));
}

}

This file was deleted.

This file was deleted.

This file was deleted.

25 changes: 25 additions & 0 deletions common/src/main/java/galena/thigh_highs_etc/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package galena.thigh_highs_etc.mixin;

import galena.thigh_highs_etc.index.THEItems;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.PlayerModelPart;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(Player.class)
public class PlayerMixin {

@Inject(at = @At("HEAD"), method = "isModelPartShown(Lnet/minecraft/world/entity/player/PlayerModelPart;)Z", cancellable = true)
public void onEquip(PlayerModelPart part, CallbackInfoReturnable<Boolean> cir) {
@SuppressWarnings("DataFlowIssue")
var self = (Player) (Object) this;
var boots = self.getItemBySlot(EquipmentSlot.FEET);
if (boots.is(THEItems.THIGH_HIGHS_TAG)) {
cir.setReturnValue(false);
}
}

}
3 changes: 1 addition & 2 deletions common/src/main/resources/thigh_highs_etc.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"minVersion": "0.8",
"refmap": "${mod_id}.refmap.json",
"client": [
"LivingEntityMixin",
"OptionsMixin"
"PlayerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import galena.thigh_highs_etc.THECommon;
import galena.thigh_highs_etc.THEConstants;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;

public class FabricEntrypoint implements ModInitializer {

Expand All @@ -13,6 +14,10 @@ public class FabricEntrypoint implements ModInitializer {
public void onInitialize() {
THECommon.init();
REGISTRATE.register();

TradeOfferHelper.registerWanderingTraderOffers(1, trades ->
THECommon.registerWanderingTrades(trades::add)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import galena.thigh_highs_etc.THEConstants;
import galena.thigh_highs_etc.forge.client.ForgeClientEntrypoint;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.village.WandererTradesEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;

Expand All @@ -19,6 +21,11 @@ public ForgeEntrypoint() {

//noinspection Convert2MethodRef
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ForgeClientEntrypoint.init());

MinecraftForge.EVENT_BUS.addListener((WandererTradesEvent event) -> {
var trades = event.getRareTrades();
THECommon.registerWanderingTrades(trades::add);
});
}

}

0 comments on commit a4aa762

Please sign in to comment.