Jump to content

Recommended Posts

Posted

In the crafted item event i get and player and item and there is method on the player that I can run called hasAchievement, but looking into that it always returns false, in single player, looked in to how entity player mp does and came up with this

 

!Minecraft.getMinecraft().getIntegratedServer().getPlayerList().getPlayerStatsFile(player).hasAchievementUnlocked(achievement)

 

works in singles player but crashes the client on a server

 

Full method

 

private void checkAchivment(Achievement achievement, ItemStack item, ItemStack item1, ItemStack item2,  EntityPlayer player){
        Logging.info("Checking...");
        if(item1.getItem().equals(item2.getItem())){
            Logging.info("Items Match");
            if(Minecraft.getMinecraft().isIntegratedServerRunning()){
                Logging.info("I am single player");
                if(!Minecraft.getMinecraft().getIntegratedServer().getPlayerList().getPlayerStatsFile(player).hasAchievementUnlocked(achievement)){
                    //do stuff                }
            }
            else {
                Logging.info("I am a server");
                if(!player.hasAchievement(achievement)){
                    //do stuff 
                }
            }

        }
    }

 

 

I am not happy was this part of the method and fell there should be better way of checking if the player has an achievement also

if(Minecraft.getMinecraft().isIntegratedServerRunning()){
                Logging.info("I am single player");
                if(!Minecraft.getMinecraft().getIntegratedServer().getPlayerList().getPlayerStatsFile(player).hasAchievementUnlocked(achievement)){
                    //do stuff                }
            }
            else {
                Logging.info("I am a server");
                if(!player.hasAchievement(achievement)){
                    //do stuff 
                }
            }

Edit:

Working method for give a reward with an achievement:

https://gist.github.com/Dijkstra1/30eb97f26aacfd3a1af3258f9a37f2e3

Posted
  On 8/30/2016 at 4:12 PM, Dijkstra said:

!Minecraft.getMinecraft().getIntegratedServer().getPlayerList().getPlayerStatsFile(player).hasAchievementUnlocked(achievement)

 

You can also check if an achievement is unlocked like so, which is how the achievements page fetches the info:

 

Minecraft.getMinecraft().thePlayer.getStatFileWriter().hasAchievementUnlocked(achievement)

Posted

Why call hasAchievement, in single player i always get false, do not know if i am meant to target the method at the integrated server as before my method was like this and do stuff was always being called even after getting the achievement.

private void checkAchivment(Achievement achievement, ItemStack item, ItemStack item1, ItemStack item2,  EntityPlayer player){
        Logging.info("Checking...");
        if(item1.getItem().equals(item2.getItem())){
            Logging.info("Items Match");               
           if(!player.hasachievement(achievement)){
                    //do stuff 
            }
        }
    }

 

P.S. Thanks TheMasterGabriel that looks like it should work on both sides

Posted
@SubscribeEvent
    public void onCraft(PlayerEvent.ItemCraftedEvent e){
        Logging.info("Item CRafted");
        checkAchivment(achievments[0], new ItemStack(Blocks.DIRT, 2), new ItemStack(Blocks.DIAMOND_BLOCK), e.crafting, e.player);
    }

Posted

new ItemStack(Blocks.DIRT, 2), new ItemStack(Blocks.DIAMOND_BLOCK)

if(item1.getItem().equals(item2.getItem())){

 

Gosh.  I wonder why this doesn't return true.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 8/30/2016 at 4:52 PM, diesieben07 said:

Read again, you misread ;)

 

Ah, you're right.  That's what the OP gets for using useless variable names like "item" "item1" and "item2"

FFS, name those something intelligent.  If you're going to number them at least make them "1" "2" and "3"!

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I got something that works!, Draco18s hope the method parameters are more to your liking, I do not know if there is any way to make this more efficient, if there is I would be more than happy to find out.

 

private void checkAchivment(Achievement achievement, ItemStack item, EntityPlayer player) {
        if (!player.worldObj.isRemote && player instanceof EntityPlayerMP && achievement instanceof ModdedAchievement) {
            EntityPlayerMP playerMP = ((EntityPlayerMP) player);
            StatisticsManagerServer file = playerMP.getStatFile();

            if (!file.hasAchievementUnlocked(achievement) && file.canUnlockAchievement(achievement)) {
                ModdedAchievement moddedAchievement = ((ModdedAchievement) achievement);
                if (moddedAchievement.getTarget().getItem().equals(item.getItem())) {
                    if(moddedAchievement.getReward() != null){
                        ItemStack rewrad = moddedAchievement.getReward();
                        if (!player.inventory.addItemStackToInventory(rewrad)) {
                            playerMP.worldObj.spawnEntityInWorld(new EntityItem(playerMP.worldObj, playerMP.posX, playerMP.posY, playerMP.posZ, rewrad));
                        }
                    }
                    playerMP.addStat(achievement);
                }
            }
        }


    }

diesieben07 for my how are my achievements  initialized

 

public class ModdedAchievement extends Achievement {

    private static AchievementPage moddedAchievements;

    public static final Achievement[] achievments = new Achievement[]{
            new ModdedAchievement("blockDiamond", 0, 0, Blocks.DIAMOND_BLOCK, null, itemStack(Blocks.DIRT, 2).copy(), itemStack(Blocks.DIAMOND_BLOCK))
    };

    public static void init(){
        moddedAchievements =  new AchievementPage(MOD_NAME, achievments);
        AchievementPage.registerAchievementPage(moddedAchievements);
    }

}

 

At the moment I have just the one test one that gives you reward of of 2 dirt for making a diamond block

 

Posted

this is what the method getReward does

public ItemStack getReward() {
        return reward.copy();
    }

 

This is in my ModdedAchievement class, item stacks are set in the constructor

 

Is it fine having copying the item stack there

 

or should i do

public ItemStack getReward() {
        return reward;
    }

ItemStack rewrad = moddedAchievement.getReward().copy();

To me it does not seem to make much different

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

ร—   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

ร—   Your link has been automatically embedded.   Display as a link instead

ร—   Your previous content has been restored.   Clear editor

ร—   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Verified users can now unlock a $100 OFF Temu Coupon Code using the verified promo code [ALF401700]. This Temu $100 OFF code works for both new and existing customers and can be used to redeem up to 50% off your next order. Our exclusive Temu coupon code [ALF401700] delivers a flat $100 OFF on top of existing deals. First-time customers using code ALF401700 can save an extra 100% off select items. Returning users also qualify for an automatic $100 OFF discount just by applying this code at checkout. But waitโ€”thereโ€™s more. With our Temu coupon codes for 2025, users can score up to 90% OFF on clearance items. Whether youโ€™re shopping in the USA, Canada, UK, or elsewhere, Temu promo code ALF401700 unlocks extra discounts tailored to your account. Some users are saving 100% on items using this 2025 Temu promo code. ๐Ÿ”ฅ Temu Coupon Highlights Using Code [ALF401700]: Temu new user code โ€“ ALF401700: Save 50% off your first order + $100 OFF. Temu promo for existing customers โ€“ ALF401700: Enjoy flat $100 OFF instantly. Global availability: Works in the USA, UK, Canada, Germany, France, Japan, Chile, Colombia, Malaysia, Mexico, South Korea, Philippines, Saudi Arabia, Qatar, Pakistan, and more. Top 2025 Coupon Deal: Get $200 OFF plus 100% bonus discounts using code ALF401700. Top-Ranked Temu Deals for 2025 (Coupon Code: ALF401700): โœ… Temu $100 OFF Memorial Day Sale โ€” Use ALF401700 โœ… Temu First Order Coupon โ€” Use ALF401700 for 50% + $100 OFF โœ… Temu USA Coupon Code โ€” Save $100 instantly with ALF401700 โœ… Temu Japan, Germany, Chile Codes โ€” All support ALF401700 โœ… Temu Reddit Discount โ€“ $100 OFF: Valid for both new and old users โœ… Temu Coupon Bundle 2025 โ€” $100 OFF + up to 50% slash โœ… 100% OFF Free Gift Code โ€” Use ALF401700, no invite needed โœ… Temu Sign-Up Bonus Promo โ€” Get a welcome $100 OFF instantly โœ… Free Temu Code for New Users โ€” Use ALF401700, no referral required  Temu Clearance Codes 2025 โ€” Use ALF401700 for 85โ€“100% discounts Why ALF401700 is the Best Temu Code in 2025 Using Temu code ALF401700 is your ticket to massive savings, free shipping, first-order discounts, and stackable coupon bundles. Whether you're browsing electronics, fashion, home goods, or beauty products, this verified Temu discount code offers real savingsโ€”up to 90% OFF + $100 OFF on qualified orders. ๐Ÿ’ก Pro Tip: Apply ALF401700 during checkout in the Temu app or website to activate your instant $100 discount, even if youโ€™re not a new user. Temu $100 OFF Code by Country (All Use ALF401700): ๐Ÿ‡บ๐Ÿ‡ธ Temu USA โ€“ ALF401700 ๐Ÿ‡ฏ๐Ÿ‡ต Temu Japan โ€“ ALF401700 ๐Ÿ‡ฒ๐Ÿ‡ฝ Temu Mexico โ€“ ALF401700 ๐Ÿ‡จ๐Ÿ‡ฑ Temu Chile โ€“ ALF401700 ๐Ÿ‡จ๐Ÿ‡ด Temu Colombia โ€“ ALF401700 ๐Ÿ‡ฒ๐Ÿ‡พ Temu Malaysia โ€“ ALF401700 ๐Ÿ‡ต๐Ÿ‡ญ Temu Philippines โ€“ ALF401700 ๐Ÿ‡ฐ๐Ÿ‡ท Temu Korea โ€“ ALF401700 ๐Ÿ‡ต๐Ÿ‡ฐ Temu Pakistan โ€“ ALF401700 ๐Ÿ‡ซ๐Ÿ‡ฎ Temu Finland โ€“ ALF401700 ๐Ÿ‡ธ๐Ÿ‡ฆ Temu Saudi Arabia โ€“ ALF401700 ๐Ÿ‡ถ๐Ÿ‡ฆ Temu Qatar โ€“ ALF401700 ๐Ÿ‡ซ๐Ÿ‡ท Temu France โ€“ ALF401700 ๐Ÿ‡ฉ๐Ÿ‡ช Temu Germany โ€“ ALF401700 ๐Ÿ‡ฎ๐Ÿ‡ฑ Temu Israel โ€“ ALF401700 Temu Coupon Code [ALF401700] Summary for SEO: Temu $100 OFF Code  Temu First Order Discount Code 2025  Temu Verified Promo Code ALF401700  Temu 50% OFF + $100 Bonus  Temu 100% OFF Code 2025  Temu App Promo ALF401700  Temu Working Discount Code 2025 
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
    • You can check the config of Geckolib and Mowzie's Mobs - maybe there is a way to disable some render features
    • You can use the .requires() function  the server also has a permission level of 4, which is the highest permission level.
  • Topics

ร—
ร—
  • Create New...

Important Information

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