Added Rubber Sapling to wandering trader (#2772)

This commit is contained in:
Ayutac 2022-01-23 19:35:26 +01:00 committed by GitHub
parent f65e4466fe
commit 9fcf9447e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,42 @@
package reborncore.common.util;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.village.TradeOffer;
import net.minecraft.village.TradeOffers;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import java.util.Random;
public class TradeUtils {
private TradeUtils() {/* No instantiation.*/}
public static TradeOffer create(ItemConvertible item, int price, int count, int maxUses, int experience) {
return new TradeOffer(new ItemStack(Items.EMERALD, price), new ItemStack(item, count), maxUses, experience, 0.05F);
}
@Contract("null -> null; !null -> new")
public static TradeOffer copy(TradeOffer tradeOffer) {
if (tradeOffer == null)
return null;
return new TradeOffer(tradeOffer.toNbt());
}
public static TradeOffers.Factory asFactory(TradeOffer tradeOffer) {
return new TradeOffers.Factory() {
private final TradeOffer offer = copy(tradeOffer);
@Nullable
@Override
public TradeOffer create(Entity entity, Random random) {
return copy(offer);
}
};
}
}

View file

@ -25,6 +25,7 @@
package techreborn.events;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;
import net.fabricmc.fabric.api.transfer.v1.item.ItemStorage;
import net.minecraft.block.*;
import net.minecraft.entity.EquipmentSlot;
@ -32,8 +33,11 @@ import net.minecraft.item.Item;
import net.minecraft.item.Item.Settings;
import net.minecraft.item.Items;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.village.TradeOffer;
import net.minecraft.village.TradeOffers;
import reborncore.RebornRegistry;
import reborncore.common.powerSystem.RcEnergyTier;
import reborncore.common.util.TradeUtils;
import team.reborn.energy.api.EnergyStorage;
import techreborn.TechReborn;
import techreborn.blockentity.cable.CableBlockEntity;
@ -56,6 +60,10 @@ import techreborn.items.tool.vanilla.*;
import techreborn.utils.InitUtils;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author drcrazy
@ -69,6 +77,7 @@ public class ModRegistry {
registerFluids();
registerSounds();
registerApis();
registerWanderingTraderTrades();
}
private static void registerBlocks() {
@ -247,4 +256,18 @@ public class ModRegistry {
EnergyStorage.SIDED.registerForBlockEntity(CableBlockEntity::getSideEnergyStorage, TRBlockEntities.CABLE);
ItemStorage.SIDED.registerForBlockEntity(StorageUnitBaseBlockEntity::getExposedStorage, TRBlockEntities.STORAGE_UNIT);
}
private static void registerWanderingTraderTrades() {
List<TradeOffer> extraCommonTrades = new LinkedList<>();
List<TradeOffer> extraRareTrades = new LinkedList<>();
// specify extra trades here
extraCommonTrades.add(TradeUtils.create(TRContent.RUBBER_SAPLING, 5, 1, 8, 1));
// registration of the trades
TradeOfferHelper.registerWanderingTraderOffers(1, allTradesList -> allTradesList.addAll(
extraCommonTrades.stream().map(TradeUtils::asFactory).collect(Collectors.toList())
));
TradeOfferHelper.registerWanderingTraderOffers(2, allTradesList -> allTradesList.addAll(
extraRareTrades.stream().map(TradeUtils::asFactory).collect(Collectors.toList())
));
}
}