diff --git a/carlsjr.js b/carlsjr.js index c0c2eab..41b6622 100644 --- a/carlsjr.js +++ b/carlsjr.js @@ -1,8 +1,25 @@ var TraderTweaker = libcd.require("Tradesmen.TraderTweaker"); +var TweakerUtils = libcd.require("libcd.util.TweakerUtils"); +var newPickStack = TweakerUtils.createItemStack("minecraft:diamond_pickaxe"); +newPickStack = TweakerUtils.setDamage(newPickStack, 1430); +newPickStack = TweakerUtils.setName(newPickStack, "Patched Pickaxe"); +newPickStack = TweakerUtils.enchant(newPickStack, "minecraft:fortune", 1); TraderTweaker.addTrader("tradesmen:beef_trader","entity.tradesmen.carltwo.name", "tradesmen:textures/entity/taco_man.png", "minecraft:cow",[ - TraderTweaker.makeTrade("minecraft:rotten_flesh",1,4,4,1) + TraderTweaker.makeTrade("minecraft:rotten_flesh@4",1,4,1) ], [ - TraderTweaker.makeTrade("minecraft:cooked_beef",1,4,4,1), + TraderTweaker.makeTrade("minecraft:cooked_beef@2",[ "minecraft:emerald","minecraft:rotten_flesh@4"],4,1), ]); +TraderTweaker.addTrader("tradesmen:fish_trader","Sad Fishman", "", "minecraft:cod",[ + TraderTweaker.makeTrade(newPickStack,1,4,4,1) + ], + [ + TraderTweaker.makeTrade("minecraft:cooked_cod@1",newPickStack,4,1), + ]); +TraderTweaker.addTrader("tradesmen:pig_trader","Wigby", "", "minecraft:pig",[ + TraderTweaker.makeTrade("minecraft:porkchop",1,4,4,1) + ], + [ + TraderTweaker.makeTrade("minecraft:cooked_porkchop",1,4,4,1), + ]); \ No newline at end of file diff --git a/src/main/java/mod/linguardium/tradesmen/Tradesmen.java b/src/main/java/mod/linguardium/tradesmen/Tradesmen.java index 460f49a..35c6fd7 100644 --- a/src/main/java/mod/linguardium/tradesmen/Tradesmen.java +++ b/src/main/java/mod/linguardium/tradesmen/Tradesmen.java @@ -1,7 +1,10 @@ package mod.linguardium.tradesmen; import io.github.cottonmc.libcd.api.tweaker.TweakerManager; +import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; +import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer; import mod.linguardium.tradesmen.api.TraderTweaker; +import mod.linguardium.tradesmen.config.ModConfig; import mod.linguardium.tradesmen.entities.InitEntities; import net.fabricmc.api.ModInitializer; @@ -26,10 +29,14 @@ public class Tradesmen implements ModInitializer { @Override public void onInitialize() { log(Level.INFO, "Initializing"); + AutoConfig.register(ModConfig.class, JanksonConfigSerializer::new); InitEntities.init(); TweakerManager.INSTANCE.addTweaker("Tradesmen.TraderTweaker", new TraderTweaker()); + log(Level.INFO, "Welcome to The Tradesmen"); + } + public static ModConfig getConfig() { + return AutoConfig.getConfigHolder(ModConfig.class).getConfig(); } - public static void log(Level level, String message){ LOGGER.log(level, "["+MOD_NAME+"] " + message); } diff --git a/src/main/java/mod/linguardium/tradesmen/api/TraderTweaker.java b/src/main/java/mod/linguardium/tradesmen/api/TraderTweaker.java index 0e419fb..4829091 100644 --- a/src/main/java/mod/linguardium/tradesmen/api/TraderTweaker.java +++ b/src/main/java/mod/linguardium/tradesmen/api/TraderTweaker.java @@ -3,7 +3,13 @@ import blue.endless.jankson.JsonObject; import blue.endless.jankson.JsonPrimitive; +import io.github.cottonmc.libcd.api.CDSyntaxError; import io.github.cottonmc.libcd.api.tweaker.Tweaker; +import io.github.cottonmc.libcd.api.tweaker.recipe.RecipeParser; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.recipe.Recipe; import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourceNotFoundException; import net.minecraft.util.Identifier; @@ -26,7 +32,7 @@ public void applyReload(ResourceManager resourceManager, Executor executor) { @Override public String getApplyMessage() { - return String.valueOf(TradesmenManager.Traders.size()) + " traders"; + return String.valueOf(TradesmenManager.Traders.size()-1) + " traders"; } @Override @@ -39,22 +45,24 @@ public void addTrader(String Id, String name, String texture, String animal, tra TradesmenTradeOffers.SellItemFactory[] rareTrades = new TradesmenTradeOffers.SellItemFactory[rare.length]; int i=0; for (tradeObject trade : common) { - Identifier ItemId = Identifier.tryParse(trade.get(String.class, "item")); - if (ItemId == null) { - throw(new ResourceNotFoundException(null,trade.get(String.class, "item"))); + TradesmenTradeOffers.SellItemFactory sale=null; + if (!trade.saleItem.isEmpty() && !trade.priceItem[0].isEmpty()) { + sale = new TradesmenTradeOffers.SellItemFactory(trade.saleItem, trade.priceItem, trade.maxUses, trade.experience, trade.multiplier); + } + if (sale != null) { + commonTrades[i] = sale; } - TradesmenTradeOffers.SellItemFactory sale = new TradesmenTradeOffers.SellItemFactory(Registry.ITEM.get(ItemId), trade.getInt("price", 1), trade.getInt("count", 1), trade.getInt("maxUses", 1), trade.getInt("experience", 1)); - commonTrades[i] = sale; i++; } i=0; for (tradeObject trade : rare) { - Identifier ItemId = Identifier.tryParse(trade.get(String.class, "item")); - if (ItemId == null) { - throw(new ResourceNotFoundException(null,trade.get(String.class, "item"))); + TradesmenTradeOffers.SellItemFactory sale=null; + if (!trade.saleItem.isEmpty() && !trade.priceItem[0].isEmpty()) { + sale = new TradesmenTradeOffers.SellItemFactory(trade.saleItem, trade.priceItem, trade.maxUses, trade.experience, trade.multiplier); + } + if (sale!=null) { + rareTrades[i] = sale; } - TradesmenTradeOffers.SellItemFactory sale = new TradesmenTradeOffers.SellItemFactory(Registry.ITEM.get(ItemId), trade.getInt("price", 1), trade.getInt("count", 1), trade.getInt("maxUses", 1), trade.getInt("experience", 1)); - rareTrades[i] = sale; i++; } @@ -63,44 +71,70 @@ public void addTrader(String Id, String name, String texture, String animal, tra public tradeObject makeTrade() { return new tradeObject(); } - public tradeObject makeTrade(String item, int price, int count, int maxUses, int experience) { - tradeObject retObj = new tradeObject(); - retObj.put("item",new JsonPrimitive(item)); - retObj.put("price",new JsonPrimitive(price)); - retObj.put("count",new JsonPrimitive(count)); - retObj.put("maxUses",new JsonPrimitive(maxUses)); - retObj.put("experience",new JsonPrimitive(experience)); + public tradeObject makeTrade(Object item, Object[] price, int maxUses, int experience) throws CDSyntaxError { + tradeObject retObj = new tradeObject() + .item(item) + .price(price) + .maxUses(maxUses) + .experience(experience); return retObj; } - public JsonObject makeTrade(String item, int price, int count, int maxUses) { - return makeTrade(item,price,count,maxUses,1); - } - public JsonObject makeTrade(String item, int price, int count) { - return makeTrade(item,price,count,1,1); + public tradeObject makeTrade(Object item, Object price, int maxUses, int experience) throws CDSyntaxError { + tradeObject retObj = new tradeObject() + .item(item) + .price(price) + .maxUses(maxUses) + .experience(experience); + return retObj; } - public JsonObject makeTrade(String item, int price) { - return makeTrade(item,price,1,1,1); + public tradeObject makeTrade(Object item, Object price, int count, int maxUses, int experience) throws CDSyntaxError { + tradeObject retObj = new tradeObject() + .item(item) + .count(count) + .price(price) + .maxUses(maxUses) + .experience(experience); + return retObj; } - public class tradeObject extends JsonObject { - public tradeObject item(String item) { - this.put("item",new JsonPrimitive(item)); + public class tradeObject { + ItemStack saleItem=ItemStack.EMPTY; + ItemStack[] priceItem= new ItemStack[]{new ItemStack((Item)null,0),new ItemStack((Item)null,0)}; + Integer maxUses = 1; + Integer experience=0; + Float multiplier=0.05F; + public tradeObject item(Object item) throws CDSyntaxError { + saleItem = RecipeParser.processItemStack(item).copy(); + return this; + } + public tradeObject price(Object[] price) throws CDSyntaxError { + for (int i = 0; i< price.length && i<2 ; i++) { + priceItem[i]=RecipeParser.processItemStack(price[i]).copy(); + } + return this; + } + public tradeObject price(Object price) throws CDSyntaxError { + if (price instanceof Integer) { + this.priceItem[0] = new ItemStack(Items.EMERALD, (Integer) price); + }else { + this.priceItem[0] = RecipeParser.processItemStack(price).copy(); + } return this; } - public tradeObject price(int price) { - this.put("price",new JsonPrimitive(price)); + public tradeObject secondPriceStack(Object price) throws CDSyntaxError { + priceItem[1] = RecipeParser.processItemStack(price); return this; } public tradeObject count(int count) { - this.put("count", new JsonPrimitive(count)); + this.saleItem.setCount(count); return this; } public tradeObject maxUses(int maxUses) { - this.put("maxUses", new JsonPrimitive(maxUses)); + this.maxUses=maxUses; return this; } public tradeObject experience(int experience) { - this.put("experience",new JsonPrimitive(experience)); + this.experience=experience; return this; } } diff --git a/src/main/java/mod/linguardium/tradesmen/api/TradesmenManager.java b/src/main/java/mod/linguardium/tradesmen/api/TradesmenManager.java index 8b79ac6..902b24c 100644 --- a/src/main/java/mod/linguardium/tradesmen/api/TradesmenManager.java +++ b/src/main/java/mod/linguardium/tradesmen/api/TradesmenManager.java @@ -9,6 +9,7 @@ import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; @@ -23,12 +24,12 @@ import net.minecraft.world.poi.PointOfInterestType; import org.apache.logging.log4j.Level; +import java.io.DataOutput; +import java.io.IOException; import java.util.*; public class TradesmenManager implements WorldTickCallback { private HashMap WorldManagers = new HashMap<>(); - public static final int SPAWN_DELAY_CONSTANT = 24000; // 24000 - public static final int SPAWN_CHANCE_CONSTANT = 25; // 25 public static HashMap Traders = new HashMap<>(); public TradesmenManager() { Tradesmen.log(Level.INFO,"Trader Manager Initialized"); @@ -47,11 +48,11 @@ public WorldTradesmenManager(ServerWorld world) { this.world = world; this.tickCount = 1200; //LevelProperties levelProperties = world.getLevelProperties(); - this.spawnDelay = TradesmenManager.SPAWN_DELAY_CONSTANT;//levelProperties.getWanderingTraderSpawnDelay(); - this.spawnChance = TradesmenManager.SPAWN_CHANCE_CONSTANT;//levelProperties.getWanderingTraderSpawnChance(); + this.spawnDelay = Tradesmen.getConfig().spawnDelay;//levelProperties.getWanderingTraderSpawnDelay(); + this.spawnChance = Tradesmen.getConfig().spawnChance;//levelProperties.getWanderingTraderSpawnChance(); if (this.spawnDelay == 0 && this.spawnChance == 0) { - this.spawnDelay = TradesmenManager.SPAWN_DELAY_CONSTANT; - this.spawnChance = TradesmenManager.SPAWN_CHANCE_CONSTANT; + this.spawnDelay = Tradesmen.getConfig().spawnDelay; + this.spawnChance = Tradesmen.getConfig().spawnChance; } } @@ -62,13 +63,13 @@ public void tick() { this.tickCount = 1200; this.spawnDelay -= 1200; if (this.spawnDelay <= 0) { - this.spawnDelay = TradesmenManager.SPAWN_DELAY_CONSTANT; + this.spawnDelay = Tradesmen.getConfig().spawnDelay; if (this.world.getGameRules().getBoolean(GameRules.DO_MOB_SPAWNING)) { int i = this.spawnChance; this.spawnChance = MathHelper.clamp(this.spawnChance + 25, 25, 75); if (this.random.nextInt(100) <= i) { if (this.spawnRoamingTrader()) { - this.spawnChance = TradesmenManager.SPAWN_CHANCE_CONSTANT; + this.spawnChance = Tradesmen.getConfig().spawnChance; } } @@ -106,7 +107,7 @@ private boolean spawnRoamingTrader() { this.SpawnAnimal(traderEntity.getTraderAnimal(),traderEntity, 4); //this.world.getLevelProperties().setWanderingTraderId(wanderingTraderEntity.getUuid()); - traderEntity.setDespawnDelay(SPAWN_DELAY_CONSTANT); + traderEntity.setDespawnDelay((int)(Tradesmen.getConfig().spawnDelay*0.75F)); traderEntity.setWanderTarget(blockPos2); traderEntity.setPositionTarget(blockPos2, 16); return true; @@ -116,12 +117,13 @@ private boolean spawnRoamingTrader() { return false; } } - private void SpawnAnimal(String AnimalId, LivingEntity ownerTrader, int distance) { + private void SpawnAnimal(String AnimalId, TradesmenEntity ownerTrader, int distance) { BlockPos blockPos = this.getPosDistanceFrom(new BlockPos(ownerTrader), distance); if (blockPos != null) { MobEntity traderAnimalEntity = (MobEntity)(EntityType.get(AnimalId).orElse(EntityType.TRADER_LLAMA)).spawn(this.world, (CompoundTag)null, (Text)null, (PlayerEntity)null, blockPos, SpawnType.EVENT, false, false); if (traderAnimalEntity != null) { traderAnimalEntity.attachLeash(ownerTrader, true); + ownerTrader.setAnimalUUID(traderAnimalEntity.getUuidAsString()); } } } diff --git a/src/main/java/mod/linguardium/tradesmen/api/TradesmenTradeOffers.java b/src/main/java/mod/linguardium/tradesmen/api/TradesmenTradeOffers.java index b5e8d89..f7b22e4 100644 --- a/src/main/java/mod/linguardium/tradesmen/api/TradesmenTradeOffers.java +++ b/src/main/java/mod/linguardium/tradesmen/api/TradesmenTradeOffers.java @@ -14,7 +14,7 @@ public class TradesmenTradeOffers { static class SellItemFactory implements TradeOffers.Factory { private ItemStack sell; - private int price; + private ItemStack[] price; private int count; private int maxUses; private int experience; @@ -29,34 +29,42 @@ public SellItemFactory(SellItemFactory from) { this.multiplier=from.multiplier; } public SellItemFactory(Block block, int price, int count, int maxUses, int experience) { - this(new ItemStack(block), price, count, maxUses, experience); + this(new ItemStack(block, count), price, maxUses, experience); } public SellItemFactory(Item item, int price, int count, int experience) { - this((ItemStack) (new ItemStack(item)), price, count, 12, experience); + this(new ItemStack(item, count), price, 12, experience); } public SellItemFactory(Item item, int price, int count, int maxUses, int experience) { - this(new ItemStack(item), price, count, maxUses, experience); + this(new ItemStack(item, count), price, maxUses, experience); } - public SellItemFactory(ItemStack itemStack, int price, int count, int maxUses, int experience) { - this(itemStack, price, count, maxUses, experience, 0.05F); + public SellItemFactory(ItemStack itemStack, int price, int maxUses, int experience) { + this(itemStack, price, maxUses, experience, 0.05F); } - public SellItemFactory(ItemStack itemStack, int price, int count, int maxUses, int experience, float multiplier) { + public SellItemFactory(ItemStack itemStack, int price, int maxUses, int experience, float multiplier) { + this(itemStack,new ItemStack(Items.EMERALD, price), maxUses,experience,multiplier); + } + public SellItemFactory(ItemStack itemStack, ItemStack price, int maxUses, int experience) { + this(itemStack,price, maxUses,experience,0.05F); + } + + public SellItemFactory(ItemStack itemStack, ItemStack price, int maxUses, int experience, float multiplier) { + this(itemStack,new ItemStack[]{price,ItemStack.EMPTY},maxUses,experience,multiplier); + } + public SellItemFactory(ItemStack itemStack, ItemStack[] price, int maxUses, int experience, float multiplier) { this.sell = itemStack; this.price = price; - this.count = count; this.maxUses = maxUses; this.experience = experience; this.multiplier = multiplier; } - public TradeOffer create(Entity entity, Random random) { - return new TradeOffer(new ItemStack(Items.EMERALD, this.price), - new ItemStack(this.sell.getItem(), this.count), this.maxUses, this.experience, this.multiplier); + return new TradeOffer(this.price[0],this.price[1], + this.sell, this.maxUses, this.experience, this.multiplier); } } diff --git a/src/main/java/mod/linguardium/tradesmen/config/ConfigMenu.java b/src/main/java/mod/linguardium/tradesmen/config/ConfigMenu.java new file mode 100644 index 0000000..4295e56 --- /dev/null +++ b/src/main/java/mod/linguardium/tradesmen/config/ConfigMenu.java @@ -0,0 +1,24 @@ +package mod.linguardium.tradesmen.config; + +import io.github.prospector.modmenu.api.ModMenuApi; +import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; +import mod.linguardium.tradesmen.Tradesmen; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.screen.Screen; + +import java.util.Optional; +import java.util.function.Supplier; + +@Environment(EnvType.CLIENT) +public class ConfigMenu implements ModMenuApi { + @Override + public String getModId() { + return Tradesmen.MOD_ID; + } + + @Override + public Optional> getConfigScreen(Screen screen) { + return Optional.of(AutoConfig.getConfigScreen(ModConfig.class, screen)); + } +} diff --git a/src/main/java/mod/linguardium/tradesmen/config/ModConfig.java b/src/main/java/mod/linguardium/tradesmen/config/ModConfig.java new file mode 100644 index 0000000..cd83b9a --- /dev/null +++ b/src/main/java/mod/linguardium/tradesmen/config/ModConfig.java @@ -0,0 +1,20 @@ +package mod.linguardium.tradesmen.config; + +import me.sargunvohra.mcmods.autoconfig1u.ConfigData; +import me.sargunvohra.mcmods.autoconfig1u.annotation.Config; +import me.sargunvohra.mcmods.autoconfig1u.annotation.ConfigEntry; + +@Config.Gui.Background("minecraft:textures/block/orange_shulker_box.png") +@Config(name = "tradesmen") +public class ModConfig implements ConfigData { + + public boolean disableWanderingTrader = false; + public boolean despawnAnimals = true; + @ConfigEntry.Gui.Tooltip + public int spawnDelay = 24000; + + @ConfigEntry.BoundedDiscrete(max=100,min=1) + public int spawnChance = 25; + + +} \ No newline at end of file diff --git a/src/main/java/mod/linguardium/tradesmen/entities/TradesmenEntity.java b/src/main/java/mod/linguardium/tradesmen/entities/TradesmenEntity.java index 6f9f519..2fefbd5 100644 --- a/src/main/java/mod/linguardium/tradesmen/entities/TradesmenEntity.java +++ b/src/main/java/mod/linguardium/tradesmen/entities/TradesmenEntity.java @@ -1,20 +1,32 @@ package mod.linguardium.tradesmen.entities; +import mod.linguardium.tradesmen.Tradesmen; import mod.linguardium.tradesmen.api.TradesmenManager; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.mob.MobEntity; +import net.minecraft.entity.passive.TraderLlamaEntity; import net.minecraft.entity.passive.WanderingTraderEntity; import net.minecraft.nbt.CompoundTag; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.Box; +import net.minecraft.util.registry.Registry; import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOffers; import net.minecraft.village.TraderOfferList; import net.minecraft.world.World; +import java.util.List; +import java.util.UUID; + public class TradesmenEntity extends WanderingTraderEntity { private static final TrackedData TRADER_TYPE= DataTracker.registerData(TradesmenEntity.class, TrackedDataHandlerRegistry.STRING);; + private static final TrackedData TRADER_SPAWNED_ANIMAL= DataTracker.registerData(TradesmenEntity.class, TrackedDataHandlerRegistry.STRING);; + private int despawnDelay; public TradesmenEntity(EntityType entityType, World world) { super(entityType, world); @@ -25,6 +37,15 @@ public void setTraderType(String type) { public String getTraderType() { return this.getDataTracker().get(TRADER_TYPE); } + public void setAnimalUUID(String id) { + this.getDataTracker().set(TRADER_SPAWNED_ANIMAL,id); + } + public void setAnimalUUID(UUID id) { + this.getDataTracker().set(TRADER_SPAWNED_ANIMAL,id.toString()); + } + public String getAnimalIdentifier() { + return this.getDataTracker().get(TRADER_SPAWNED_ANIMAL); + } public String getTraderAnimal() { String animal = ""; if (!this.getTraderType().isEmpty()) { @@ -64,17 +85,62 @@ protected Text getDefaultName() { protected void initDataTracker() { super.initDataTracker(); this.getDataTracker().startTracking(TRADER_TYPE,""); + this.getDataTracker().startTracking(TRADER_SPAWNED_ANIMAL,null); } @Override public void writeCustomDataToTag(CompoundTag tag) { super.writeCustomDataToTag(tag); tag.putString("TraderType",this.getTraderType()); + tag.putString("AnimalUUID",this.getAnimalIdentifier()); } @Override public void readCustomDataFromTag(CompoundTag tag) { super.readCustomDataFromTag(tag); this.setTraderType(tag.getString("TraderType")); + this.setAnimalUUID(tag.getString("AnimalUUID")); + } + + @Override + public void setDespawnDelay(int delay) { + this.despawnDelay=delay; + } + + @Override + public int getDespawnDelay() { + return despawnDelay; + } + + @Override + public void tickMovement() { + if (!this.world.isClient) { + this.tickDespawnDelay(); + super.setDespawnDelay(2000); // effectively disable despawn timer of super. Unsure if its necessary. + } + super.tickMovement(); + } + + private void tickDespawnDelay() { + if (this.despawnDelay > 0 && !this.hasCustomer() && --this.despawnDelay == 0) { + String animalId = this.getAnimalIdentifier(); + if (Tradesmen.getConfig().despawnAnimals) { + if (animalId != null && !animalId.isEmpty()) { + List ents = world.getEntities(MobEntity.class,new Box(this.getBlockPos().add(10,10,10),this.getBlockPos().add(-10,-10,-10)), + (entity)->entity.getUuidAsString().equals(animalId) + ); + for (MobEntity e : ents) { + if (e.getUuidAsString().equals(animalId)) { + if (e.getHoldingEntity().equals(this)) { + e.detachLeash(true,false); + e.remove(); + } + } + } + } + } + this.remove(); + } + } } diff --git a/src/main/java/mod/linguardium/tradesmen/mixins/WanderingTraderManagerMixin.java b/src/main/java/mod/linguardium/tradesmen/mixins/WanderingTraderManagerMixin.java new file mode 100644 index 0000000..48874b9 --- /dev/null +++ b/src/main/java/mod/linguardium/tradesmen/mixins/WanderingTraderManagerMixin.java @@ -0,0 +1,19 @@ +package mod.linguardium.tradesmen.mixins; + +import mod.linguardium.tradesmen.Tradesmen; +import net.minecraft.world.WanderingTraderManager; +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.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(WanderingTraderManager.class) +public abstract class WanderingTraderManagerMixin { + @Inject(at=@At("HEAD"),method="tick", cancellable = true) + public void tickCanceller(CallbackInfo info){ + if (Tradesmen.getConfig().disableWanderingTrader) { + info.cancel(); + } + } +} diff --git a/src/main/resources/assets/tradesmen/lang/en_us.json b/src/main/resources/assets/tradesmen/lang/en_us.json index f94ef8c..01e9bed 100644 --- a/src/main/resources/assets/tradesmen/lang/en_us.json +++ b/src/main/resources/assets/tradesmen/lang/en_us.json @@ -1,3 +1,8 @@ { - "entity.tradesmen.carltwo.name": "Carl II" -} \ No newline at end of file + "entity.tradesmen.carltwo.name": "Carl II", + "text.autoconfig.tradesmen.option.spawnDelay": "Ticks between spawn attempts", + "text.autoconfig.tradesmen.option.spawnDelay@Tooltip": "Also used for despawn timer", + "text.autoconfig.tradesmen.option.spawnChance": "Chance (in %%) of spawning a trader", + "text.autoconfig.tradesmen.option.disableWanderingTrader": "Disable Vanilla Wandering Trader", + "text.autoconfig.tradesmen.option.despawnAnimals": "Despawn trader animal if leashed" +} diff --git a/src/main/resources/data/tradesmen/Traders/TacoTrader.txt b/src/main/resources/data/tradesmen/Traders/TacoTrader.txt index 8203f5c..7309f3e 100644 --- a/src/main/resources/data/tradesmen/Traders/TacoTrader.txt +++ b/src/main/resources/data/tradesmen/Traders/TacoTrader.txt @@ -1,17 +1,17 @@ -static { - TACO_TRADER_TRADES = copyToFastUtilMap(ImmutableMap.of(1, - new TradeOffers.Factory[]{ - new TacoTradeOffers.SellItemFactory(ModItems.TORTILLA, 1, 4, 4, 1), - new TacoTradeOffers.SellItemFactory(ModItems.TORTILLA_DOUGH, 1, 8, 4, 1), - new TacoTradeOffers.SellItemFactory(ModItems.CORN_SEED, 1, 3, 1, 1) - }, 2, new TradeOffers.Factory[]{ - new TacoTradeOffers.SellItemFactory(ModItems.STEAK_TACO, 4, 3, 4, 1), - new TacoTradeOffers.SellItemFactory(ModItems.FISH_TACO, 2, 3, 4, 1), - new TacoTradeOffers.SellItemFactory(ModItems.CRUNCHY_TACO, 4, 3, 4, 1), - new TacoTradeOffers.SellItemFactory(ModItems.CHICKEN_TACO, 2, 3, 4, 1), - new TacoTradeOffers.SellItemFactory(ModItems.CHEESY_TACO, 2, 3, 4, 1), - new TacoTradeOffers.SellItemFactory(ModItems.CARNITAS_TACO, 3, 3, 4, 1), - new TacoTradeOffers.SellItemFactory(ModItems.AL_PASTOR_TACO, 3, 3, 4, 1), - new TacoTradeOffers.SellItemFactory(ModItems.GOLDEN_TACO, 10, 1, 2, 3) - })); - } \ No newline at end of file + + TraderTweaker.addTrader("tradesmen:tacoman","Taco Jubilee", "", "minecraft:bee",[ + TraderTweaker.makeTrade("tacocraft:steak_taco@3",4,4,1), + TraderTweaker.makeTrade("tacocraft:fish_taco@3",2,4,1), + TraderTweaker.makeTrade("tacocraft:crunchy_taco@3",4,4,1), + TraderTweaker.makeTrade("tacocraft:chicken_taco@3",2,4,1), + TraderTweaker.makeTrade("tacocraft:cheesy_taco@3",3,4,1), + TraderTweaker.makeTrade("tacocraft:carnitas_taco@3",3,4,1), + TraderTweaker.makeTrade("tacocraft:al_pastor_taco@3",3,4,1), + + ], + [ + TraderTweaker.makeTrade("tacocraft:tortilla@4",1,4,1), + TraderTweaker.makeTrade("tacocraft:tortilla_dough@8",1,4,1), + TraderTweaker.makeTrade("tacocraft:corn_seed@3",1,4,1), + TraderTweaker.makeTrade("tacocraft:golden_taco@1",10,4,1), + ]); \ No newline at end of file diff --git a/src/main/resources/data/tradesmen/tweakers/default_trader.js b/src/main/resources/data/tradesmen/tweakers/default_trader.js index a013a43..625b556 100644 --- a/src/main/resources/data/tradesmen/tweakers/default_trader.js +++ b/src/main/resources/data/tradesmen/tweakers/default_trader.js @@ -2,4 +2,8 @@ var TraderTweaker = libcd.require("Tradesmen.TraderTweaker"); TraderTweaker.addTrader("default:default_trader","Dirty Hobo", "", "",[ TraderTweaker.makeTrade("minecraft:dirt",64,1,1,0)], - [ ]); + [ + TraderTweaker.makeTrade().item("minecraft:dirt@64").price(["minecraft:cobblestone","minecraft:sand"]).maxUses(4), + TraderTweaker.makeTrade().item("minecraft:dirt").price("minecraft:emerald").count(4).maxUses(4), + TraderTweaker.makeTrade().item("minecraft:dirt@64").price(1).maxUses(4) + ]); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 931e8a8..b1498ce 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -3,7 +3,7 @@ "id": "tradesmen", "version": "${version}", "name": "Wandering Tradesmen", - "description": "Adds customizable wandering traders", + "description": "Adds customizable wandering traders", "authors": [ "Linguardium" ], @@ -17,8 +17,14 @@ "mod.linguardium.tradesmen.Tradesmen" ], "client": ["mod.linguardium.tradesmen.TradesmenClient"], - "server": [] + "server": [], + "modmenu": [ + "mod.linguardium.tradesmen.config.ConfigMenu" + ] }, + "mixins": [ + "tradesmen.mixins.json" + ], "depends": { "fabricloader": ">=0.4.0", "fabric": "*", diff --git a/src/main/resources/tradesmen.mixins.json b/src/main/resources/tradesmen.mixins.json new file mode 100644 index 0000000..bce0538 --- /dev/null +++ b/src/main/resources/tradesmen.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "package": "mod.linguardium.tradesmen.mixins", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "WanderingTraderManagerMixin" + ], + "client": [], + "injectors": { + "defaultRequire": 1 + } +}