Jump to content

Foxy

Members
  • Posts

    13
  • Joined

  • Last visited

Posts posted by Foxy

  1. Is this what you mean ?

     

     

    package com.foxy.profs.common.profession;

     

    import com.foxy.profs.common.library.ProfLib;

     

    import net.minecraft.entity.Entity;

    import net.minecraft.entity.player.EntityPlayer;

    import net.minecraft.nbt.NBTTagCompound;

    import net.minecraft.world.World;

    import net.minecraftforge.common.IExtendedEntityProperties;

     

    public class Profession implements IExtendedEntityProperties {

     

    protected String name;

    protected static String IDENTIFICATION = "Professions";

    protected int exp, maxExp, level, maxLevel;

     

    public Profession hunting = new Profession("Hunting", 100, 725);

    public Profession woodcutting = new Profession("Woodcutting", 100, 725);

    public Profession mining = new Profession("Mining", 100, 725);

    public Profession herbalism = new Profession("Herbalism", 100, 725);

    public Profession fishing = new Profession("Fishing", 100, 725);

     

    public Profession(String name, int maxExp, int maxLevel){

    this.name = name;

    this.exp = 0;

    this.level = 1;

    this.maxExp = maxExp;

    this.maxLevel = maxLevel;

    }

     

    public static final Profession register(EntityPlayer player){

    return (Profession)player.getExtendedProperties(IDENTIFICATION);

    }

     

    public static final Profession get(EntityPlayer player){

    return (Profession)player.getExtendedProperties(IDENTIFICATION);

    }

     

    @Override

    public void saveNBTData(NBTTagCompound compound) {

    NBTTagCompound profession = new NBTTagCompound();

     

    profession.setInteger("Exp", this.exp);

    profession.setInteger("Max Exp", this.maxExp);

    profession.setInteger("Level", level);

    profession.setInteger("Max Level", this.maxLevel);

     

    compound.setTag(name, profession);

    }

     

    @Override

    public void loadNBTData(NBTTagCompound compound) {

    NBTTagCompound profession = (NBTTagCompound) compound.getTag(name);

     

    this.exp = profession.getInteger("Exp");

    this.level = profession.getInteger("Level");

    this.maxExp = profession.getInteger("Max Exp");

    this.maxLevel = profession.getInteger("Max Level");

     

    System.out.println("[" + ProfLib.MODID + "]Has loaded " + name + " from NBT: [Exp" + this.exp + "/" + this.maxExp + "][Level" + this.level + "/" + this.maxLevel + "]");

     

    }

     

    @Override

    public void init(Entity entity, World world) {

     

    }

     

     

    public String getName(){

    return name;

    }

     

    public int getExp(){

    return exp;

    }

     

    public int getMaxExp(){

    return maxExp;

    }

     

    public int getLevel(){

    return level;

    }

     

    public int getMaxLevel(){

    return maxLevel;

    }

     

    public Profession setName(String name){

    this.name = name;

    return this;

    }

     

    public Profession setExp(int exp){

    this.exp = exp;

    return this;

    }

     

    public Profession setMaxExp(int maxExp){

    this.maxExp = maxExp;

    return this;

    }

     

    public Profession setLevel(int level){

    this.level = level;

    return this;

    }

     

    public Profession setMaxLevel(int maxLevel){

    this.maxLevel = maxLevel;

    return this;

    }

     

     

    public Profession addExp(int exp){

    this.exp += exp;

    return this;

    }

     

    public Profession removeExp(int exp){

    this.exp -= exp;

    return this;

    }

     

    public Profession addExp(int exp, int modifier){

    this.exp += (exp + (modifier * level));

    return this;

    }

     

    public Profession removeExp(int exp, int modifier){

    this.exp -= (exp * modifier);

    return this;

    }

     

    public boolean isLeveledUp(){

    if (level == maxLevel){

    return true;

    }else{

    return false;

    }

    }

     

    public boolean isMaxed(){

    if (exp == maxExp && isLeveledUp()){

    return true;

    }else{

    return false;

    }

    }

     

    public boolean canLevelUp(){

    if (exp >= maxExp && !isLeveledUp()){

    return true;

    }else{

    return false;

    }

    }

     

    public boolean canLevelDown(){

    if (exp < 0){

    if (level != 1){

    return true;

    }else{

    return false;

    }

    }

    return false;

    }

     

    public boolean canEarnExp(){

    if (exp > 0 || exp <= maxExp){

    return true;

    }else{

    return false;

    }

    }

     

    public boolean canLoseExp(){

    if (exp > 0){

    return true;

    }else{

    return false;

    }

    }

     

    public void levelUp(){

    level++;

    exp = (exp - maxExp);

    maxExp = (maxExp + (15 * level));

    }

     

    public void levelDown(){

    level--;

    exp = (maxExp - (exp * -1));

    maxExp = (maxExp + (15 * level));

    }

     

    public void update(){

    while (exp >= maxExp || exp < 0){

    if (canLevelUp()){

    levelUp();

    }else if (canLevelDown()){

    levelDown();

    }

    }

    }

     

    }

     

     

     

    Also should i use datawatchers for exp and level or no ?

     

    EDIT: no need for datawatchers cause players wont need to know about other player exp or level.

     

    EDIT:

    ProfEvent class

     

     

    package com.foxy.profs.common.event;

     

    import com.foxy.profs.common.profession.Profession;

     

    import net.minecraft.block.BlockCrops;

    import net.minecraft.entity.player.EntityPlayer;

    import net.minecraft.init.Blocks;

    import net.minecraft.init.Items;

    import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;

    import net.minecraftforge.event.entity.player.PlayerUseItemEvent;

    import net.minecraftforge.event.world.BlockEvent;

    import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

     

    public class ProfEvents {

     

    @SubscribeEvent

    public void onEntityConstructing(EntityConstructing event){

    if (event.entity instanceof EntityPlayer && Profession.get((EntityPlayer) event.entity) == null){

    Profession.register((EntityPlayer) event.entity);

    }

    }

     

    @SubscribeEvent

    public void onBlockBroken(BlockEvent.BreakEvent event){

    Profession profession = Profession.get((EntityPlayer) event.getPlayer());

     

    if (!event.getPlayer().capabilities.isCreativeMode){

    if (event.state.getBlock() == Blocks.coal_ore || event.state.getBlock() == Blocks.redstone_ore || event.state.getBlock() == Blocks.lit_redstone_ore){

    profession.mining.addExp(2, 2);

    profession.mining.update();

    }else if (event.state.getBlock() == Blocks.iron_ore || event.state.getBlock() == Blocks.lapis_ore || event.state.getBlock() == Blocks.quartz_ore){

    profession.mining.addExp(4, 2);

    profession.mining.update();

    }else if (event.state.getBlock() == Blocks.gold_ore || event.state.getBlock() == Blocks.diamond_ore || event.state.getBlock() == Blocks.emerald_ore){

    profession.mining.addExp(8, 2);

    profession.mining.update();

    }else if (event.state.getBlock() == Blocks.leaves || event.state.getBlock() == Blocks.leaves2){

    profession.woodcutting.addExp(1, 1);

    profession.woodcutting.update();

    }else if (event.state.getBlock() == Blocks.log || event.state.getBlock() == Blocks.log2){

    profession.woodcutting.addExp(3, 1);

    profession.woodcutting.update();

    }else if (event.state.getBlock() == Blocks.wheat || event.state.getBlock() == Blocks.potatoes || event.state.getBlock() == Blocks.carrots){

    int age = (Integer)event.state.getValue(BlockCrops.AGE);

     

    if (age != 7){

    profession.herbalism.removeExp(2, 1);

    profession.herbalism.update();

    }else{

    profession.herbalism.removeExp(3, 1);

    profession.herbalism.update();

    }

    }else if (event.state.getBlock() == Blocks.reeds){

    profession.herbalism.addExp(1, 1);

    }

    }

    }

     

    @SubscribeEvent

    public void onBlockPlaced(BlockEvent.PlaceEvent event){

    Profession profession = Profession.get((EntityPlayer) event.player);

     

    if (!event.player.capabilities.isCreativeMode){

    if (event.placedBlock.getBlock() == Blocks.reeds){

    profession.mining.removeExp(3, 1);

    }

    }

    }

     

    }

     

     

     

    do i need to cast event.player and event.getPlayer() to (EntityPlayer), seeing as they are already players i think they shouldn't.

  2. Okay i finished implementing IExtendedEntityProperties, is this alright:

     

    Profession.java

     

     

    package com.foxy.profs.common.profession;

     

    import com.foxy.profs.common.library.ProfLib;

     

    import net.minecraft.entity.Entity;

    import net.minecraft.entity.player.EntityPlayer;

    import net.minecraft.nbt.NBTTagCompound;

    import net.minecraft.world.World;

    import net.minecraftforge.common.IExtendedEntityProperties;

     

    public class Profession implements IExtendedEntityProperties {

     

    protected String name;

    protected static String IDENTIFICATION = "Professions";

    protected int exp, maxExp, level, maxLevel;

     

    public Profession(String name, int maxExp, int maxLevel){

    this.name = name;

    this.maxExp = maxExp;

    this.level = 1;

    this.maxLevel = maxLevel;

     

    }

     

    public static final Profession register(EntityPlayer player){

    return (Profession)player.getExtendedProperties(IDENTIFICATION);

    }

     

    public static final Profession get(EntityPlayer player){

    return (Profession)player.getExtendedProperties(IDENTIFICATION);

    }

     

    @Override

    public void saveNBTData(NBTTagCompound compound) {

    NBTTagCompound profession = new NBTTagCompound();

     

    profession.setInteger("Exp", this.exp);

    profession.setInteger("Max Exp", this.maxExp);

    profession.setInteger("Level", level);

    profession.setInteger("Max Level", this.maxLevel);

     

    compound.setTag(name, profession);

    }

     

    @Override

    public void loadNBTData(NBTTagCompound compound) {

    NBTTagCompound profession = (NBTTagCompound) compound.getTag(name);

     

    profession.getInteger("Exp");

    profession.getInteger("Max Exp");

    profession.getInteger("Level");

    profession.getInteger("Max Level");

     

    System.out.println("[" + ProfLib.MODID + "]Has loaded " + name + " from NBT: [Exp" + this.exp + "/" + this.maxExp + "][Level" + this.level + "/" + this.maxLevel + "]");

     

    }

     

    @Override

    public void init(Entity entity, World world) {

     

    }

     

     

    public String getName(){

    return name;

    }

     

    public int getExp(){

    return exp;

    }

     

    public int getMaxExp(){

    return maxExp;

    }

     

    public int getLevel(){

    return level;

    }

     

    public int getMaxLevel(){

    return maxLevel;

    }

     

    public Profession setName(String name){

    this.name = name;

    return this;

    }

     

    public Profession setExp(int exp){

    this.exp = exp;

    return this;

    }

     

    public Profession setMaxExp(int maxExp){

    this.maxExp = maxExp;

    return this;

    }

     

    public Profession setLevel(int level){

    this.level = level;

    return this;

    }

     

    public Profession setMaxLevel(int maxLevel){

    this.maxLevel = maxLevel;

    return this;

    }

     

     

    public Profession addExp(int exp){

    this.exp += exp;

    return this;

    }

     

    public Profession removeExp(int exp){

    this.exp -= exp;

    return this;

    }

     

    public Profession addExp(int exp, int modifier){

    this.exp += (exp * modifier);

    return this;

    }

     

    public Profession removeExp(int exp, int modifier){

    this.exp -= (exp * modifier);

    return this;

    }

     

    public boolean isLeveledUp(){

    if (level == maxLevel){

    return true;

    }else{

    return false;

    }

    }

     

    public boolean isMaxed(){

    if (exp == maxExp && isLeveledUp()){

    return true;

    }else{

    return false;

    }

    }

     

    public boolean canLevelUp(){

    if (exp >= maxExp && !isLeveledUp()){

    return true;

    }else{

    return false;

    }

    }

     

    public boolean canLevelDown(){

    if (exp < 0){

    if (level != 1){

    return true;

    }else{

    return false;

    }

    }

    return false;

    }

     

    public boolean canEarnExp(){

    if (exp > 0 || exp <= maxExp){

    return true;

    }else{

    return false;

    }

    }

     

    public boolean canLoseExp(){

    if (exp > 0){

    return true;

    }else{

    return false;

    }

    }

     

    public void levelUp(){

    level++;

    exp = (exp - maxExp);

    maxExp = (maxExp + (15 * level));

    }

     

    public void levelDown(){

    level--;

    exp = (maxExp - (exp * -1));

    maxExp = (maxExp + (15 * level));

    }

     

    public void update(){

    while (exp >= maxExp || exp < 0){

    if (canLevelUp()){

    levelUp();

    }else if (canLevelDown()){

    levelDown();

    }

    }

    }

     

    }

     

     

    ProfEvents.java

     

     

    package com.foxy.profs.common.event;

     

    import com.foxy.profs.common.init.Professions;

    import com.foxy.profs.common.profession.Profession;

     

    import net.minecraft.block.BlockCrops;

    import net.minecraft.entity.player.EntityPlayer;

    import net.minecraft.init.Blocks;

    import net.minecraft.init.Items;

    import net.minecraft.item.ItemStack;

    import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;

    import net.minecraftforge.event.entity.player.PlayerUseItemEvent;

    import net.minecraftforge.event.world.BlockEvent;

    import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

     

    public class ProfEvents {

     

    @SubscribeEvent

    public void onBlockBroken(BlockEvent.BreakEvent event){

    if (!event.getPlayer().capabilities.isCreativeMode){

    if (event.state.getBlock() == Blocks.coal_ore || event.state.getBlock() == Blocks.redstone_ore || event.state.getBlock() == Blocks.lit_redstone_ore){

    Professions.mining.setExp(Professions.mining.getExp() + (2 + (2 * Professions.mining.getLevel())));

    Professions.mining.update();

    }else if (event.state.getBlock() == Blocks.iron_ore || event.state.getBlock() == Blocks.lapis_ore || event.state.getBlock() == Blocks.quartz_ore){

    Professions.mining.setExp(Professions.mining.getExp() + (4 + (2 * Professions.mining.getLevel())));

    Professions.mining.update();

    }else if (event.state.getBlock() == Blocks.gold_ore || event.state.getBlock() == Blocks.diamond_ore || event.state.getBlock() == Blocks.emerald_ore){

    Professions.mining.setExp(Professions.mining.getExp() + (8 + (2 * Professions.mining.getLevel())));

    Professions.mining.update();

    }else if (event.state.getBlock() == Blocks.leaves || event.state.getBlock() == Blocks.leaves2){

    Professions.woodcutting.setExp(Professions.woodcutting.getExp() + (1 + Professions.woodcutting.getLevel()));

    Professions.woodcutting.update();

    }else if (event.state.getBlock() == Blocks.log || event.state.getBlock() == Blocks.log2){

    Professions.woodcutting.setExp(Professions.woodcutting.getExp() + (3 + Professions.woodcutting.getLevel()));

    Professions.woodcutting.update();

    }else if (event.state.getBlock() == Blocks.wheat || event.state.getBlock() == Blocks.potatoes || event.state.getBlock() == Blocks.carrots){

    int age = (Integer)event.state.getValue(BlockCrops.AGE);

     

    if (age != 7){

    Professions.herbalism.setExp(Professions.herbalism.getExp() - (2 * Professions.herbalism.getLevel()));

    Professions.herbalism.update();

    }else{

    Professions.herbalism.setExp(Professions.herbalism.getExp() + (3 * Professions.herbalism.getLevel()));

    Professions.herbalism.update();

    }

    }else if (event.state.getBlock() == Blocks.reeds){

    Professions.herbalism.setExp(Professions.herbalism.getExp() + (1 * Professions.herbalism.getLevel()));

    }

    }

    }

     

    @SubscribeEvent

    public void onFishedUp(PlayerUseItemEvent event){

    if (!event.entityPlayer.capabilities.isCreativeMode){

    if (event.entityPlayer.getHeldItem() != null){

    if (event.entityPlayer.getHeldItem().equals(Items.fishing_rod)){

     

    }

    }

    }

    }

     

     

    @SubscribeEvent

    public void onEntityConstructing(EntityConstructing event){

    if (event.entity instanceof EntityPlayer && Profession.get((EntityPlayer) event.entity) == null){

    Profession.register((EntityPlayer) event.entity);

    }

    }

     

    }

     

     

     

    Professions is init class for all professions...

     

    Professions

     

     

    package com.foxy.profs.common.init;

     

    import com.foxy.profs.common.profession.Fishing;

    import com.foxy.profs.common.profession.Herbalism;

    import com.foxy.profs.common.profession.Hunting;

    import com.foxy.profs.common.profession.Mining;

    import com.foxy.profs.common.profession.Profession;

    import com.foxy.profs.common.profession.Woodcutting;

     

    public class Professions {

     

    public static Profession hunting;

    public static Profession woodcutting;

    public static Profession mining;

    public static Profession herbalism;

    public static Profession fishing;

     

    public static void init(){

    hunting = new Hunting("Hunting", 100, 725);

    woodcutting = new Woodcutting("Woodcutting", 100, 725);

    mining = new Mining("Mining", 100, 725);

    herbalism = new Herbalism("Herbalism", 100, 725);

    fishing = new Fishing("Fishing", 100, 725);

    }

     

    }

     

     

  3. Well, the "Professions.herbalism" makes me suspicious whether you actually handle the fact that there is more than one player.

     

    I don't ... which classes should i check to see how it's done ?

    Btw i added github link

     

    also do i need to initiate save of players current exp and level on server  or world exit or is it automatic, i guess it's not ?

  4. I am beginner programmer so i don't know much but i'm learning.

     

    Here is another try:

     

     

    }else if (event.state.getBlock() == Blocks.wheat || event.state.getBlock() == Blocks.potatoes || event.state.getBlock() == Blocks.carrots){

    int age = (Integer)event.state.getValue(BlockCrops.AGE);

    if (age != 7){

    Professions.herbalism.setExp(Professions.herbalism.getExp() - (2 * Professions.herbalism.getLevel()));

    Professions.herbalism.update();

    }else{

    Professions.herbalism.setExp(Professions.herbalism.getExp() + (3 * Professions.herbalism.getLevel()));

    Professions.herbalism.update();

    }

     

     

     

    This way it works as intended but idk if it's considered right or wrong programming.

  5. @Failender

    I fixed that alredy but diesieben07 said i shouldn't use getMetaFromState so i am experimenting again.

     

    Never ever call getMetaFromState yourself. Interact with the IBlockState, it's there so that you don't have to work with stupid magic numbers (7) anymore.

    The age is stored in the property BlockCrops.AGE.

     

    @diesieben70

    Can you explain why i shouldn't use getMetaFromState ? I also modified if statement, but not sure if it's correct way to do it. Don't really understand how Block States work.

     

     

     

    }else if (event.state.getBlock() == Blocks.wheat || event.state.getBlock() == Blocks.potatoes || event.state.getBlock() == Blocks.carrots){

    if (event.state.getBlock() == event.state.withProperty(BlockCrops.AGE, 7)){

    Professions.herbalism.setExp(Professions.herbalism.getExp() - (2 * Professions.herbalism.getLevel()));

    Professions.herbalism.update();

    }else{

    Professions.herbalism.setExp(Professions.herbalism.getExp() + (3 * Professions.herbalism.getLevel()));

    Professions.herbalism.update();

    }

     

     

  6. I tried checking if metadata is 7 but it still adds exp event if it isn't

     

     

     

    if (event.state.getBlock() == Blocks.wheat){

        if (Blocks.wheat.getMetaFromState() == 7){

            Professions.herbalism.setExp(Professions.herbalism.getExp() + (3 * Professions.herbalism.getLevel()));

          Professions.herbalism.update();

        }else{

            Professions.herbalism.setExp(Professions.herbalism.getExp() - (2 * Professions.herbalism.getLevel()));

          Professions.herbalism.update();

    }

     

     

     

    This isn't only way i checked but still doesn't work.

     

  7. Hi i'm new to modding and i require a bit of help, everything is explained in Professions topic in mods section. Link to GitHub

     

    [sOLVED] Herbalism:

     

     

     

    }else if (event.state.getBlock() == Blocks.wheat || event.state.getBlock() == Blocks.potatoes || event.state.getBlock() == Blocks.carrots){

    int age = (Integer)event.state.getValue(BlockCrops.AGE);

    if (age != 7){

    Professions.herbalism.setExp(Professions.herbalism.getExp() - (2 * Professions.herbalism.getLevel()));

    Professions.herbalism.update();

    }else{

    Professions.herbalism.setExp(Professions.herbalism.getExp() + (3 * Professions.herbalism.getLevel()));

    Professions.herbalism.update();

    }

     

     

  8. Professions mod is inspired by MMORPGs profession and craftting system and some mods like TConstruct, Thaumcraft, Ars Magica and more...

     

    There are currently planned three groups of professions:

    Primary: Hunting, Woodcutting, Mining, Herbalism, Fishing.

    Secondary: Blacksmithing, Engineering, Jewlecrafting, Alchemy, Inscription, Enchantments, Carpentry, Tailoring, Leatherworking and maybe some more in future.

    Passive:Swimming, Combat and similar.

     

    In first version there will be only Primary professions.

     

    I'm currently having problems with Fishing (don't know how to check if player is fishing and if player fished anything) and how can i make it so players can't just place a block and break it to get infinite exp ?

     

    EDIT: [Herbalism Solved]

     

    Here is link to projects GitHub.

     

    Here is link to mod support topic.

     

    If more information is required i'll post, there are currently no images cause nothing major nor any textures has been added.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.