Skip to content

Commit

Permalink
✨ Trades will now be restocked after a period of time
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCrayfish committed Jun 7, 2021
1 parent 7642ca1 commit b8a2fc4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/mrcrayfish/goblintraders/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static class Goblin
public final ForgeConfigSpec.IntValue traderSpawnDelay;
public final ForgeConfigSpec.IntValue traderMinSpawnLevel;
public final ForgeConfigSpec.IntValue traderMaxSpawnLevel;
public final ForgeConfigSpec.IntValue restockDelay;

Goblin(ForgeConfigSpec.Builder builder, String name, String key, int spawnChance, int spawnDelay, int minLevel, int maxLevel)
{
Expand All @@ -43,6 +44,9 @@ public static class Goblin
this.traderMaxSpawnLevel = builder
.comment("The maximum level the trader can spawn")
.defineInRange("traderMaxSpawnLevel", maxLevel, 0, 256);
this.restockDelay = builder
.comment("The amount of ticks before the trader will replenish it's trades")
.defineInRange("restockDelay", 48000, 1, Integer.MAX_VALUE);
builder.pop();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public abstract class AbstractGoblinEntity extends TraderCreatureEntity implemen
private int stunDelay;
private int despawnDelay;
private int fallCounter;
private int restockDelay;

protected AbstractGoblinEntity(EntityType<? extends CreatureEntity> type, World worldIn)
{
Expand Down Expand Up @@ -165,6 +166,14 @@ else if(this.dataManager.get(STUNNED))
{
this.fallCounter = 0;
}
if(!this.world.isRemote())
{
if(++this.restockDelay == this.getMaxRestockDelay())
{
this.getOffers().forEach(MerchantOffer::resetUses);
this.restockDelay = 0;
}
}
}

@Override
Expand Down Expand Up @@ -390,6 +399,10 @@ public void readAdditional(CompoundNBT compound)
{
this.despawnDelay = compound.getInt("DespawnDelay");
}
if(compound.contains("RestockDelay", Constants.NBT.TAG_INT))
{
this.restockDelay = compound.getInt("RestockDelay");
}
}

@Override
Expand All @@ -402,6 +415,7 @@ public void writeAdditional(CompoundNBT compound)
compound.put("Offers", merchantoffers.write());
}
compound.putInt("DespawnDelay", this.despawnDelay);
compound.putInt("RestockDelay", this.restockDelay);
}

private void handleDespawn()
Expand Down Expand Up @@ -444,4 +458,6 @@ public float getStunRotation()
{
return this.dataManager.get(STUN_ROTATION);
}

protected abstract int getMaxRestockDelay();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mrcrayfish.goblintraders.entity;

import com.mrcrayfish.goblintraders.Config;
import com.mrcrayfish.goblintraders.Reference;
import com.mrcrayfish.goblintraders.init.ModEntities;
import com.mrcrayfish.goblintraders.trades.EntityTrades;
Expand Down Expand Up @@ -54,4 +55,10 @@ public ItemStack getFavouriteFood()
{
return new ItemStack(Items.APPLE);
}

@Override
protected int getMaxRestockDelay()
{
return Config.COMMON.goblinTrader.restockDelay.get();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mrcrayfish.goblintraders.entity;

import com.mrcrayfish.goblintraders.Config;
import com.mrcrayfish.goblintraders.Reference;
import com.mrcrayfish.goblintraders.init.ModEntities;
import com.mrcrayfish.goblintraders.trades.EntityTrades;
Expand Down Expand Up @@ -75,4 +76,10 @@ public boolean isImmuneToFire()
{
return true;
}

@Override
protected int getMaxRestockDelay()
{
return Config.COMMON.veinGoblinTrader.restockDelay.get();
}
}

0 comments on commit b8a2fc4

Please sign in to comment.