-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Old Nose, optional modmenu, spawn items
also added linkbacks to github
- Loading branch information
1 parent
b3f6151
commit 4b62742
Showing
17 changed files
with
246 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/mod/linguardium/tradesmen/items/ModItems.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
src/main/java/mod/linguardium/tradesmen/items/SpawnEggSpawner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
118
src/main/java/mod/linguardium/tradesmen/items/TradesmenSpawnEgg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/tradesmen/models/item/spawn_egg.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"parent": "item/template_spawn_egg" | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/tradesmen/models/item/spawn_egg_spawner.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"parent": "item/bookshelf" | ||
} |
Oops, something went wrong.