Skip to content

Commit

Permalink
Old Nose, optional modmenu, spawn items
Browse files Browse the repository at this point in the history
also added linkbacks to github
  • Loading branch information
Linguardium committed Apr 25, 2020
1 parent b3f6151 commit 4b62742
Show file tree
Hide file tree
Showing 17 changed files with 246 additions and 30 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
modImplementation "io.github.cottonmc:LibCD:${project.libcd_version}"
include "io.github.cottonmc:LibCD:${project.libcd_version}"
//include "io.github.cottonmc:LibCD:${project.libcd_version}" // 270kb

modApi "me.shedaniel.cloth:config-2:${project.cloth_config_version}"
include "me.shedaniel.cloth:config-2:${project.cloth_config_version}"
modImplementation "me.shedaniel.cloth:config-2:${project.cloth_config_version}"
//include "me.shedaniel.cloth:config-2:${project.cloth_config_version}" // ~400kb
modImplementation "io.github.prospector:modmenu:${project.modmenu_version}"
modCompile "me.sargunvohra.mcmods:autoconfig1u:${project.autoconfig_version}"
include "me.sargunvohra.mcmods:autoconfig1u:${project.autoconfig_version}"
modImplementation "me.sargunvohra.mcmods:autoconfig1u:${project.autoconfig_version}"
//include "me.sargunvohra.mcmods:autoconfig1u:${project.autoconfig_version}" // 210kb

}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fabric_api_version = 0.5.1+build.294-1.15
libcd_version = 2.3.0+1.15.2
cloth_config_version = 2.13.2
modmenu_version = 1.10.2+build.32
autoconfig_version = 2.0
autoconfig_version = 2.0.1
File renamed without changes
3 changes: 2 additions & 1 deletion src/main/java/mod/linguardium/tradesmen/Tradesmen.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import mod.linguardium.tradesmen.api.objects.tradeObject;
import mod.linguardium.tradesmen.config.ModConfig;
import mod.linguardium.tradesmen.entities.InitEntities;
import mod.linguardium.tradesmen.items.ModItems;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.world.WorldTickCallback;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -29,6 +29,7 @@ public void onInitialize() {
AutoConfig.register(ModConfig.class, JanksonConfigSerializer::new);
InitEntities.init();
tradeObject.init();
ModItems.init();
WorldTickCallback.EVENT.register(TradesmenManager.INSTANCE);

TweakerManager.INSTANCE.addTweaker("Tradesmen.TraderTweaker", TraderTweaker.INSTANCE);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/mod/linguardium/tradesmen/api/Trader.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static Int2ObjectMap<TradeOffers.Factory[]> copyToFastUtilMap(ImmutableM
public Boolean isTiered = false;
public List<String> allowedWorlds = new ArrayList<>();
public boolean godMode;

public boolean oldNose;

public Trader(String name, String TextureId, String clothesTextureId, float[] clothesColor, String hatTextureId, float[] hatColor, String animal, List<List<TradeOffers.Factory>> trades, List<Integer> tradeCount, Boolean tiered) {
this.name = new TranslatableText(name);
Expand All @@ -54,6 +54,7 @@ public Trader(String name, String TextureId, String clothesTextureId, float[] cl
this.TRADES=trades;
this.godMode=false;
this.animalCount=1;
this.oldNose=false;
}
public Trader() {
this.name=new LiteralText("Tradesman");;
Expand All @@ -66,6 +67,7 @@ public Trader() {
this.allowedWorlds=new ArrayList<>();
this.godMode=false;
this.animalCount=1;
this.oldNose=false;
}
public Trader name(String trader_name) {
this.name=new TranslatableText(trader_name);
Expand Down Expand Up @@ -124,6 +126,8 @@ public Trader godMode(boolean b) {
this.godMode=b;
return this;
}
public Trader oldNose(boolean b) { this.oldNose=b; return this; }

public Trader setTrades(List<List<tradeObject>> trades, List<Integer> tradeCounts) {
List<List<TradeOffers.Factory>> tradeFactories = new ArrayList<List<TradeOffers.Factory>>();
for (int i=0;i<trades.size();i++){
Expand Down Expand Up @@ -158,7 +162,8 @@ public static Trader fromClientTag(CompoundTag tag) throws InvalidObjectExceptio
.clothes(tag.getInt("clothesColor"))
.hat(tag.getString("hatId"))
.hat(tag.getInt("hatColor"))
.tiered(tag.getBoolean("tiered"));
.tiered(tag.getBoolean("tiered"))
.oldNose(tag.getBoolean("oldNose"));
List<List<tradeObject>> trades = new ArrayList<>();
ListTag tradeSetsTag = tag.getList("trades",9); // List Tag Type
for (Tag tradesTag : tradeSetsTag) {
Expand Down Expand Up @@ -193,6 +198,7 @@ public CompoundTag toClientTag(CompoundTag tag) throws InvalidObjectException {
tag.putString("hatId",this.hatTextureId);
tag.putInt("hatColor",ParseColor.toInt(this.hatColor));
tag.putBoolean("tiered",this.isTiered);
tag.putBoolean("oldNose",this.oldNose);
ListTag trades = new ListTag();
for (List<tradeObject> tradeObjects : this.tObjTrades) {
ListTag tradeX = new ListTag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mod.linguardium.tradesmen.Tradesmen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;

import java.util.Optional;
Expand All @@ -19,6 +20,10 @@ public String getModId() {

@Override
public Optional<Supplier<Screen>> getConfigScreen(Screen screen) {
return Optional.of(AutoConfig.getConfigScreen(ModConfig.class, screen));
if (FabricLoader.getInstance().isModLoaded("cloth-config2")) {
return Optional.of(AutoConfig.getConfigScreen(ModConfig.class, screen));
}else{
return Optional.empty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class ModConfig implements ConfigData {

public boolean disableWanderingTrader = false;
public boolean disableWanderingTradesmen = false;
public boolean vanillaNose = false;
public boolean despawnAnimals = true;
@ConfigEntry.Gui.Tooltip
public int spawnDelay = 24000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mod.linguardium.tradesmen.entities;

import mod.linguardium.tradesmen.Tradesmen;
import mod.linguardium.tradesmen.api.Trader;
import mod.linguardium.tradesmen.api.TradesmenManager;
import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -29,6 +30,13 @@ public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsume
if (!livingEntity.isInvisible()) {
Trader traderData = TradesmenManager.getTraderById(((TradesmenEntity)livingEntity).getTraderType());
M entityModel = this.getContextModel();
if ( entityModel instanceof TradesmenEntityModel) {
if (traderData.oldNose || Tradesmen.getConfig().vanillaNose) {
((TradesmenEntityModel) entityModel).setVanillaNose(true);
} else {
((TradesmenEntityModel) entityModel).setVanillaNose(false);
}
}
entityModel.setHatVisible(true); // show head texture changes
if (!traderData.clothesTextureId.isEmpty()) {
renderModel(entityModel, new Identifier(traderData.clothesTextureId), matrixStack, vertexConsumerProvider, i, livingEntity, traderData.clothesColor[0], traderData.clothesColor[1], traderData.clothesColor[2]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TradesmenEntityModel<T extends Entity> extends CompositeEntityModel
protected final ModelPart rightLeg;
protected final ModelPart leftLeg;
protected final ModelPart nose;
protected final ModelPart nose2;

public TradesmenEntityModel(float scale) {
this(scale, 64, 64);
Expand All @@ -39,9 +40,13 @@ public TradesmenEntityModel(float scale, int textureWidth, int textureHeight) {
this.hatpart.pitch = -1.5707964F;
this.hat.addChild(this.hatpart);
this.nose = (new ModelPart(this)).setTextureSize(textureWidth, textureHeight);
this.nose2 = (new ModelPart(this)).setTextureSize(textureWidth, textureHeight);
this.nose2.setPivot(0.0F, -2.0F, 0.0F);
this.nose2.setTextureOffset(24, 0).addCuboid(-1.0F, -1.0F, -6.0F, 2.0F, 4.0F, 2.0F, scale);
this.nose.setPivot(0.0F, -2.0F, 0.0F);
this.nose.setTextureOffset(24, 0).addCuboid(-1.0F, -1.0F, -5.0F, 2.0F, 2.0F, 2.0F, scale);
this.head.addChild(this.nose);
this.head.addChild(this.nose2);
this.torso = (new ModelPart(this)).setTextureSize(textureWidth, textureHeight);
this.torso.setPivot(0.0F, 0.0F, 0.0F);
this.torso.setTextureOffset(16, 20).addCuboid(-4.0F, 0.0F, -3.0F, 8.0F, 12.0F, 6.0F, scale);
Expand Down Expand Up @@ -100,4 +105,13 @@ public void setHatVisible(boolean visible) {
this.hat.visible = visible;
this.hatpart.visible = visible;
}
public void setVanillaNose(boolean enabled) {
if (enabled) {
this.nose.visible=false;
this.nose2.visible=true;
}else{
this.nose.visible=true;
this.nose2.visible=false;
}
}
}
24 changes: 24 additions & 0 deletions src/main/java/mod/linguardium/tradesmen/items/ModItems.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package mod.linguardium.tradesmen.items;

import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

import static mod.linguardium.tradesmen.Tradesmen.MOD_ID;
import static mod.linguardium.tradesmen.entities.InitEntities.TRADESMEN_ENTITY_TYPE;

public class ModItems {
public static final TradesmenSpawnEgg SPAWN_EGG = new TradesmenSpawnEgg(TRADESMEN_ENTITY_TYPE,0x0075db, 0xffe203);
public static final SpawnEggSpawner SPAWN_EGG_SPAWNER = new SpawnEggSpawner();
public static ItemGroup ITEM_GROUP = FabricItemGroupBuilder.create(new Identifier(MOD_ID,"spawneggs")).icon(()->new ItemStack(Items.EMERALD)).appendItems((list)->
{
list.add(new ItemStack(SPAWN_EGG_SPAWNER));
}).build();
public static void init() {
Registry.register(Registry.ITEM,new Identifier(MOD_ID,"spawn_egg"),SPAWN_EGG);
Registry.register(Registry.ITEM,new Identifier(MOD_ID, "spawn_egg_spawner"),SPAWN_EGG_SPAWNER);
}
}
38 changes: 38 additions & 0 deletions src/main/java/mod/linguardium/tradesmen/items/SpawnEggSpawner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mod.linguardium.tradesmen.items;

import mod.linguardium.tradesmen.api.TradesmenManager;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemScatterer;
import net.minecraft.util.TypedActionResult;
import net.minecraft.world.World;

public class SpawnEggSpawner extends Item {
public SpawnEggSpawner() {
super(new Item.Settings().maxCount(1).group(ModItems.ITEM_GROUP));
}

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand);
if (!world.isClient()) {
for (String k : TradesmenManager.Traders.keySet()) {
if (k.equals("default:default_trader"))
continue;
ItemStack i = new ItemStack(ModItems.SPAWN_EGG);
CompoundTag tag = i.getOrCreateTag();
tag.putString("traderType", k);
i.setTag(tag);
if (!user.giveItemStack(i)) {
ItemScatterer.spawn(world, user.getX(), user.getY(), user.getZ(), i);
}
}
stack.decrement(1);
}

return TypedActionResult.success(stack);
}
}
118 changes: 118 additions & 0 deletions src/main/java/mod/linguardium/tradesmen/items/TradesmenSpawnEgg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package mod.linguardium.tradesmen.items;

import mod.linguardium.tradesmen.api.Trader;
import mod.linguardium.tradesmen.api.TradesmenManager;
import mod.linguardium.tradesmen.entities.TradesmenEntity;
import net.minecraft.block.BlockState;
import net.minecraft.block.FluidBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.RayTraceContext;
import net.minecraft.world.World;

import java.util.Objects;

public class TradesmenSpawnEgg extends SpawnEggItem {
public TradesmenSpawnEgg(EntityType<?> type, int primaryColor, int secondaryColor) {
super(type, primaryColor, secondaryColor, new Item.Settings().group(ItemGroup.MISC));
}

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
World world = context.getWorld();
if (!world.isClient) {
ItemStack itemStack = context.getStack();
BlockPos blockPos = context.getBlockPos();
Direction direction = context.getSide();
BlockState blockState = world.getBlockState(blockPos);

BlockPos blockPos3;
if (blockState.getCollisionShape(world, blockPos).isEmpty()) {
blockPos3 = blockPos;
} else {
blockPos3 = blockPos.offset(direction);
}

EntityType<?> entityType2 = this.getEntityType(itemStack.getTag());
Entity e = entityType2.spawnFromItemStack(world, itemStack, context.getPlayer(), blockPos3, SpawnType.SPAWN_EGG, true, !Objects.equals(blockPos, blockPos3) && direction == Direction.UP);
if (e!=null && e instanceof TradesmenEntity) {
((TradesmenEntity) e).setTraderType(this.getTraderType(itemStack));
if (TradesmenManager.getTraderById(getTraderType(itemStack)).isTiered) {
((TradesmenEntity) e).setTraderTier(world.random.nextInt(TradesmenManager.getTraderById(getTraderType(itemStack)).tierTradeCount.size()));
}
((TradesmenEntity)e).setDespawnDelay((int)(600));
}

}
return ActionResult.SUCCESS;
}

public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack itemStack = user.getStackInHand(hand);
HitResult hitResult = rayTrace(world, user, RayTraceContext.FluidHandling.SOURCE_ONLY);
if (hitResult.getType() != HitResult.Type.BLOCK) {
return TypedActionResult.pass(itemStack);
} else if (world.isClient) {
return TypedActionResult.success(itemStack);
} else {
BlockHitResult blockHitResult = (BlockHitResult)hitResult;
BlockPos blockPos = blockHitResult.getBlockPos();
if (!(world.getBlockState(blockPos).getBlock() instanceof FluidBlock)) {
return TypedActionResult.pass(itemStack);
} else if (world.canPlayerModifyAt(user, blockPos) && user.canPlaceOn(blockPos, blockHitResult.getSide(), itemStack)) {
EntityType<?> entityType = this.getEntityType(itemStack.getTag());
Entity e = entityType.spawnFromItemStack(world, itemStack, user, blockPos, SpawnType.SPAWN_EGG, false, false);
if (e!=null && e instanceof TradesmenEntity) {
((TradesmenEntity) e).setTraderType(this.getTraderType(itemStack));
if (TradesmenManager.getTraderById(getTraderType(itemStack)).isTiered) {
((TradesmenEntity) e).setTraderTier(world.random.nextInt(TradesmenManager.getTraderById(getTraderType(itemStack)).tierTradeCount.size()));
}
((TradesmenEntity)e).setDespawnDelay((int)(600));
}
return TypedActionResult.success(itemStack);
} else {
return TypedActionResult.fail(itemStack);
}
}
}

private String getTraderType(ItemStack stack) {
CompoundTag tag = stack.getOrCreateTag();
if (tag.contains("traderType")) {
return tag.getString("traderType");
}else{
return "default:default_trader";
}
}
@Override
public Text getName(ItemStack stack) {
Trader t = TradesmenManager.getTraderById(this.getTraderType(stack));
Text name;
if (t!=null) {
name = t.name.copy();
}else{
name = new LiteralText("Tradesmen");
}
return new TranslatableText(this.getTranslationKey(),name);
}

public boolean isOfSameEntityType(CompoundTag tag, EntityType<?> type) {
return false;
}

//Registry.register(Registry.ITEM, new Identifier("wiki_entity", "cookie_creeper_spawn_egg"), new SpawnEggItem(ModEntities.COOKIE_CREEPER, 0x0DA70B, 0x73420E));
}
5 changes: 4 additions & 1 deletion src/main/resources/assets/tradesmen/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"entity.tradesmen.carltwo.name": "Carl II",
"item.tradesmen.spawn_egg_spawner": "Tradesmen Spawn Egg Pack",
"item.tradesmen.spawn_egg": "%s Spawn Egg",
"itemGroup.tradesmen.spawneggs": "Tradesmen Test Tools",
"text.autoconfig.tradesmen.option.vanillaNose": "Use vanilla's big nose",
"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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "item/template_spawn_egg"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "item/bookshelf"
}
Loading

0 comments on commit 4b62742

Please sign in to comment.