Add item lore data for special stats.

Adds spawn egg drop chance
Adds custom enchantment
This commit is contained in:
Tara 2023-01-22 03:53:16 -07:00
parent 28c60f3a53
commit e7e08902f0
17 changed files with 408 additions and 68 deletions

View file

@ -2,6 +2,7 @@ plugins {
id 'eclipse'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '5.1.+'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id 'java-library'
}
@ -29,7 +30,7 @@ minecraft {
//
// Use non-default mappings at your own risk. They may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'official', version: "${mc_version}"
mappings channel: 'parchment', version: "${parchment_version}-${mc_version}"
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default.
@ -139,6 +140,7 @@ dependencies {
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
implementation 'org.mariadb.jdbc:mariadb-java-client:3.0.8'
compileOnly 'org.mariadb.jdbc:mariadb-java-client'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
// For more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html

View file

@ -3,11 +3,11 @@
org.gradle.jvmargs=-Xmx8G
org.gradle.daemon=false
my_version=1.3.6.2
my_version=1.3.6.3
mc_version=1.19.2
forge_version=43.2.3
libz_version=1.0.2.4
libz_version=1.0.3.4
parchment_version=2022.11.27
jei_version=11.5.0.297
# luckperms_version=5.4

View file

@ -2,5 +2,6 @@ pluginManagement {
repositories {
gradlePluginPortal()
maven { url = 'https://maven.minecraftforge.net/' }
maven { url = 'https://maven.parchmentmc.org' } // Add this line
}
}

View file

@ -48,13 +48,15 @@ import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.configs.Profile;
import dev.zontreck.otemod.database.Database;
import dev.zontreck.otemod.database.Database.DatabaseConnectionException;
import dev.zontreck.otemod.enchantments.ModEnchantments;
import dev.zontreck.otemod.events.EventHandler;
import dev.zontreck.otemod.events.LoreHandlers;
import dev.zontreck.otemod.implementation.inits.ModMenuTypes;
import dev.zontreck.otemod.implementation.scrubber.ScrubberScreen;
import dev.zontreck.otemod.implementation.vault.VaultScreen;
import dev.zontreck.otemod.implementation.vault.VaultWatcher;
import dev.zontreck.otemod.items.ModItems;
import dev.zontreck.otemod.ore.Modifier.ModifierOfBiomes;
//import dev.zontreck.otemod.ore.Modifier.ModifierOfBiomes;
// The value here should match an entry in the META-INF/mods.toml file
@Mod(OTEMod.MOD_ID)
@ -97,13 +99,14 @@ public class OTEMod
// Register ourselves for server and other game events we are interested in
final DeferredRegister<Codec<? extends BiomeModifier>> serializers = DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, OTEMod.MOD_ID);
serializers.register(bus);
serializers.register(MODIFY_BIOMES, ModifierOfBiomes::makeCodec);
//final DeferredRegister<Codec<? extends BiomeModifier>> serializers = DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, OTEMod.MOD_ID);
//serializers.register(bus);
//serializers.register(MODIFY_BIOMES, ModifierOfBiomes::makeCodec);
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new EventHandler());
MinecraftForge.EVENT_BUS.register(new LoreHandlers());
MinecraftForge.EVENT_BUS.register(new ChatServerOverride());
MinecraftForge.EVENT_BUS.register(new CommandRegistry());
MinecraftForge.EVENT_BUS.register(new VaultWatcher());
@ -113,6 +116,7 @@ public class OTEMod
ModBlocks.register(bus);
ModItems.register(bus);
ModEntities.register(bus);
ModEnchantments.register(bus);
//MenuInitializer.register(bus);
}

View file

@ -14,6 +14,7 @@ public class OTEServerConfig {
public static final ForgeConfigSpec SPEC;
public static final ForgeConfigSpec.ConfigValue<List<ItemStack>> INITIAL_ITEMS_TO_GIVE_ON_FIRST_JOIN;
public static final ForgeConfigSpec.ConfigValue<Float> SPAWN_EGG_CHANCE;
public static final ForgeConfigSpec.ConfigValue<String> HOST_ADDR;
public static final ForgeConfigSpec.ConfigValue<Integer> PORT;
@ -45,6 +46,10 @@ public class OTEServerConfig {
BUILDER.push("OTE");
INITIAL_ITEMS_TO_GIVE_ON_FIRST_JOIN = BUILDER.comment("What items, identified by modid:item, to give to a brand new user on the server").define("New Player Gear", defaults);
SPAWN_EGG_CHANCE = BUILDER.comment("What is the chance for a spawn egg to drop from a mob when looting 3 is used? Default: 0.25").define("spawn_egg_chance", 0.25F);
BUILDER.pop();
BUILDER.push("DATABASE");
HOST_ADDR = BUILDER.comment("Database Host (MySQL)").define("host", "127.0.0.1");
PORT = BUILDER.comment("Database Port (MySQL)").define("port", 3306);
USERNAME = BUILDER.comment("Database Username (MySQL)").define("user", "ote");
@ -68,6 +73,7 @@ public class OTEServerConfig {
defDims.add("minecraft:the_end");
defDims.add("minecraft:the_nether");
defDims.add("otemod:resource");
defDims.add("otemod:resource_nether");
EXCLUDE_DIMS = BUILDER.comment("Dimension names (ex. minecraft:overworld) to exclude from the explosion healing events").define("exclude_dimensions", defDims);
BUILDER.pop();

View file

@ -0,0 +1,42 @@
package dev.zontreck.otemod.enchantments;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
public class MobEggEnchantment extends Enchantment
{
public MobEggEnchantment()
{
super(Rarity.VERY_RARE, EnchantmentCategory.WEAPON, new EquipmentSlot[] {EquipmentSlot.MAINHAND});
}
@Override
public int getMaxLevel()
{
return 4;
}
@Override
public int getMinCost(int level)
{
return 28 + (level - 1) * 15;
}
@Override
public int getMaxCost(int level)
{
return this.getMinCost(level) + 15;
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack)
{
return super.canApplyAtEnchantingTable(stack);
}
}

View file

@ -0,0 +1,18 @@
package dev.zontreck.otemod.enchantments;
import dev.zontreck.otemod.OTEMod;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
public class ModEnchantments {
public static final DeferredRegister<Enchantment> REGISTERS = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, OTEMod.MOD_ID);
public static final RegistryObject<Enchantment> MOB_EGGING_ENCHANTMENT = REGISTERS.register("mob_egging", ()->new MobEggEnchantment());
public static void register(IEventBus bus){
REGISTERS.register(bus);
}
}

View file

@ -1,17 +1,23 @@
package dev.zontreck.otemod.events;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.ore.Modifier;
//import dev.zontreck.otemod.ore.OreGenerator;
import net.minecraftforge.eventbus.api.EventPriority;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.enchantments.ModEnchantments;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
@EventBusSubscriber(modid=OTEMod.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE)
public class EventHandler {
/*
@SubscribeEvent(priority = EventPriority.HIGH)
public static void addOresToBiomes(final BiomeLoadingEvent ev){
@ -20,7 +26,29 @@ public class EventHandler {
}*/
@SubscribeEvent
public void onGatherData(GatherDataEvent ev){
Modifier.DoProcess(ev);
public void onEntityKilled(LivingDropsEvent ev){
if(ev.getEntity().level.isClientSide)return;
Entity ent = ev.getSource().getEntity();
if(ent instanceof Player)
{
ServerPlayer play = (ServerPlayer)ent;
LivingEntity killed = ev.getEntity();
int levelOfEgging = play.getMainHandItem().getEnchantmentLevel(ModEnchantments.MOB_EGGING_ENCHANTMENT.get());
float CHANCE = (OTEServerConfig.SPAWN_EGG_CHANCE.get()*1000);
CHANCE += (levelOfEgging * 0.5f);
if(killed.level.random.nextInt(0,100000) <= CHANCE)
{
// .25% chance
// Check enchantment level for looting
int level = play.getMainHandItem().getEnchantmentLevel(Enchantments.MOB_LOOTING);
if(level==3){
ItemStack egg = new ItemStack(ForgeSpawnEggItem.fromEntityType(killed.getType()));
ev.getDrops().add(new ItemEntity(killed.level, killed.getX(), killed.getY(), killed.getZ(), egg));
}
}
}
}
}

View file

@ -0,0 +1,183 @@
package dev.zontreck.otemod.events;
import dev.zontreck.libzontreck.items.lore.LoreContainer;
import dev.zontreck.libzontreck.items.lore.LoreEntry;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.items.tags.ItemStatTag;
import dev.zontreck.otemod.items.tags.ItemStatType;
import dev.zontreck.otemod.items.tags.ItemStatistics;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.animal.Sheep;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.HoeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.ShearsItem;
import net.minecraft.world.item.ShovelItem;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
@EventBusSubscriber(modid=OTEMod.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE)
public class LoreHandlers {
@SubscribeEvent
public void onBlockMined(BlockEvent.BreakEvent ev)
{
if(ev.getLevel().isClientSide())return;
ServerPlayer sp = (ServerPlayer)ev.getPlayer();
ItemStack itemUsed = sp.getItemInHand(InteractionHand.MAIN_HAND);
if(itemUsed.getItem() instanceof PickaxeItem)
{
updateItem(itemUsed, ItemStatType.PICK);
}else if(itemUsed.getItem() instanceof ShovelItem)
{
updateItem(itemUsed, ItemStatType.SHOVEL);
} else if(itemUsed.getItem() instanceof AxeItem)
{
updateItem(itemUsed, ItemStatType.AXE);
}
}
@SubscribeEvent
public void onBlock(BlockEvent.BlockToolModificationEvent ev)
{
if(ev.getLevel().isClientSide())return;
// Check the block right clicked, and the item in hand
ServerPlayer sp = (ServerPlayer)ev.getPlayer();
ItemStack itemUsed = sp.getMainHandItem();
BlockState bs = ev.getState();
if(itemUsed.getItem() instanceof HoeItem)
{
if(bs.is(Blocks.DIRT) || bs.is(Blocks.GRASS_BLOCK))
{
OTEMod.LOGGER.info("DIRT!");
updateItem(itemUsed, ItemStatType.HOE);
}
} else if(itemUsed.getItem() instanceof ShovelItem)
{
if(bs.is(Blocks.GRASS_BLOCK))
{
updateItem(itemUsed, ItemStatType.SHOVELPATH);
}
}
}
@SubscribeEvent
public void onShears(PlayerInteractEvent.EntityInteract ev)
{
if(ev.getLevel().isClientSide)return;
if(ev.getCancellationResult() == InteractionResult.PASS)
{
// Check the entity right clicked, and the item in hand
OTEMod.LOGGER.info("Success");
ServerPlayer sp = (ServerPlayer)ev.getEntity();
ItemStack itemUsed = sp.getMainHandItem();
Entity target = ev.getTarget();
if(itemUsed.getItem() instanceof ShearsItem)
{
OTEMod.LOGGER.info("Shears");
if(target instanceof Sheep)
{
OTEMod.LOGGER.info("Sheep");
updateItem(itemUsed, ItemStatType.SHEARS);
}
}
}
}
@SubscribeEvent
public void onEntityKilled(LivingDeathEvent ev)
{
if(ev.getEntity().level.isClientSide)return;
// Handle two things
// 1. Update mob kill count on a sword if wielded.
// 2. If mob, process randomness. If death by player with looting 3, 0.1% chance for a spawn egg to drop
Entity source = ev.getSource().getEntity();
ServerPlayer sp= null;
if(source instanceof Player)
{
sp = (ServerPlayer)source;
}
if(sp==null)return;
ItemStack weaponUsed = sp.getItemInHand(InteractionHand.MAIN_HAND);
if(weaponUsed.getItem() instanceof SwordItem)
{
updateItem(weaponUsed, ItemStatType.SWORD);
}
}
private void updateItem(ItemStack weaponUsed, ItemStatType type)
{
// Update the mob kill count
CompoundTag props = weaponUsed.getTag();
if(props==null)props=new CompoundTag();
CompoundTag container = props.getCompound(ItemStatTag.STATS_TAG+"_"+type.name().toLowerCase());
LoreContainer contain;
if(container.isEmpty())
{
contain = new LoreContainer(weaponUsed);
}else {
contain = new LoreContainer(container, weaponUsed);
}
ItemStatTag isTag;
try{
isTag = new ItemStatTag(type, container.getInt(ItemStatTag.STATS_TAG+"_"+type.name().toLowerCase()));
}catch (Exception e){
isTag = new ItemStatTag(type, 0);
}
isTag.increment();
LoreEntry entry;
if(contain.miscData.LoreData.size()==0)
{
// Missing entry
entry = new LoreEntry();
entry.text = ItemStatistics.makeText(isTag);
contain.miscData.LoreData.add(entry);
}else {
entry = contain.miscData.LoreData.get(0); // Stat is set at 0
entry.text = ItemStatistics.makeText(isTag);
}
// Update item
contain.commitLore();
// Save the misc data to the item for later
// Reinitialize the container as the contain NBT
container = new CompoundTag();
contain.save(container);
isTag.save(container);
props.put(ItemStatTag.STATS_TAG+"_"+type.name().toLowerCase(), container);
weaponUsed.setTag(props);
}
}

View file

@ -4,6 +4,7 @@ import java.util.Map;
import java.util.UUID;
import dev.zontreck.otemod.OTEMod;
import net.minecraftforge.client.event.ContainerScreenEvent;
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@ -30,5 +31,4 @@ public class VaultWatcher {
}
}
}
}

View file

@ -0,0 +1,28 @@
package dev.zontreck.otemod.items.tags;
import net.minecraft.nbt.CompoundTag;
public class ItemStatTag {
public static final String STATS_TAG = "stat";
public ItemStatType type;
public int value;
public ItemStatTag(ItemStatType t, int tag)
{
type = t;
value = tag;
}
public void increment(){
value++;
}
public void decrement()
{
value--;
}
public void save(CompoundTag tag)
{
tag.putInt(STATS_TAG+"_"+type.name().toLowerCase(), value);
}
}

View file

@ -0,0 +1,12 @@
package dev.zontreck.otemod.items.tags;
public enum ItemStatType {
SWORD,
ARMOR,
PICK,
AXE,
SHOVEL,
SHOVELPATH,
HOE,
SHEARS
}

View file

@ -0,0 +1,44 @@
package dev.zontreck.otemod.items.tags;
import dev.zontreck.libzontreck.chat.ChatColor;
public class ItemStatistics {
public static String makeText(ItemStatTag tag)
{
return makeText(tag.type, tag.value);
}
public static String makeText(ItemStatType type, int val)
{
String lore = ChatColor.doColors("!White!");
switch(type)
{
case SWORD -> {
lore += "Mobs Killed: ";
}
case PICK -> {
lore += "Blocks Mined: ";
}
case ARMOR -> {
lore += "Damage Taken: ";
}
case SHOVEL -> {
lore += "Blocks Dug Up: ";
}
case SHOVELPATH -> {
lore += "Paths Made: ";
}
case AXE -> {
lore += "Wood Chopped: ";
}
case HOE -> {
lore += "Blocks Hoed: ";
}
case SHEARS -> {
lore += "Sheep Shaved: ";
}
}
lore += ChatColor.doColors("!Green!"+val);
return lore;
}
}

View file

@ -0,0 +1,22 @@
package dev.zontreck.otemod.items.tags;
import java.util.UUID;
public enum ModIDs {
NULL(0,0),
ZNI(0x9f, 0x9f),
OTE(5292022,1182023), // The date range of mod creation, then the day when this feature was added
ITEM_STATS(154301182023L, 0x9f);
private UUID ID;
ModIDs(long A, long B)
{
ID=new UUID(A,B);
}
public UUID get()
{
return ID;
}
}

View file

@ -1,52 +0,0 @@
package dev.zontreck.otemod.ore;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.zontreck.otemod.OTEMod;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraftforge.common.world.BiomeModifier;
import net.minecraftforge.common.world.ModifiableBiomeInfo.BiomeInfo.Builder;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
public class Modifier
{
public static void DoProcess(GatherDataEvent ev) {
}
public record ModifierOfBiomes(HolderSet<Biome> biomes, Holder<PlacedFeature> feature) implements BiomeModifier
{
private static final RegistryObject<Codec<? extends BiomeModifier>> SERIALIZER = RegistryObject.create(OTEMod.MODIFY_BIOMES_RL, ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, OTEMod.MOD_ID);
@Override
public void modify(Holder<Biome> biome, Phase phase, Builder builder) {
if(phase == Phase.ADD && biomes.contains(biome)){
builder.getGenerationSettings().addFeature(Decoration.UNDERGROUND_ORES, feature);
}
}
@Override
public Codec<? extends BiomeModifier> codec() {
return SERIALIZER.get();
}
public static Codec<ModifierOfBiomes> makeCodec()
{
return RecordCodecBuilder.create(builder->builder.group(
Biome.LIST_CODEC.fieldOf("biomes").forGetter(ModifierOfBiomes::biomes),
PlacedFeature.CODEC.fieldOf("feature").forGetter(ModifierOfBiomes::feature)
).apply(builder, ModifierOfBiomes::new));
}
}
}

View file

@ -19,7 +19,7 @@ modId="otemod" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="1.3.6.2" #mandatory
version="1.3.6.3" #mandatory
# A display name for the mod
displayName="OTEMod" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/

View file

@ -32,6 +32,8 @@
"block.otemod.scorched_table": "Scorched Table",
"block.otemod.item_scrubber": "Item Scrubber",
"enchantment.otemod.mob_egging": "Mob Egging",
"dev.zontreck.otemod.msgs.only_player": "§cOnly players are allowed to execute this command",
"dev.zontreck.otemod.msgs.command_cooling_down": "This command is currently on cooldown. You must wait for ",