Search This Blog

Friday, March 31, 2017

Hi all! This is going to be a quick post to tell you about a forum I just made, where you can ask questions about python. Hopefully we can all benifit from this! You can visit it by clicking here. As always if you have any questions feel free to ask me in the comments!

Monday, March 27, 2017

A who is online notifier.

So I know that people have other things to do other than playing on Minecraft all the time.
So wouldn't it be cool to know if someone is online or not by a computer beep instead of opening the game and checking?
Here is a simple 'beep' function when someone gets on the pycraft server.
1. You will need to put the PyCraft Server IP in the IP part of this script.
2. you need a security key from support@homeschoolhackers.org to run it.


#Check for ppl on the server.
from mc import *
import winsound
import time
mc=Minecraft.create('PYCRAFT_IP')

while True:
    try:
        ctime1= time.ctime()
        EID = mc.getPlayerEntityIds()#returns list [788195]
        print(ctime1,EID)
        Freq = 2500 # Set Frequency To 2500 Hertz
        Dur = 1000 # Set Duration To 1000 ms == 1 second
        winsound.Beep(Freq,Dur)
        time.sleep(20)
    except:
        time.sleep(60)
        ctime1= time.ctime()
        print(ctime1+'-No one is on')
        continue

Saturday, March 25, 2017

Minecraft Chat-bot built with Python

With the pollChat() option in the rbj mod I created a chat-bot named after our assistant in the office Kate. Meet <Kate-Bot> she will go by other names when you need her help. 
She is a work in progress mainly by myself and the students that want to get involved. I have instructions on easy how to's to get started in adding to the project.

To connect to the server you need to enter the IP of our server in the () of Minecraft.connect() or leave blank to use in your game.
It was easy to watch the chat go by with:

while True:
    chat = mc.events.pollChatPosts()
    print(chat)

It would print:
ChatEvent(ChatEvent.POST, 788319, hello)

I couldn't help but want to clean the return up.

chat = mc.events.pollChatPosts()
        if len(str(chat)) > 23:
            log.append(chat)
            ncha=str(chat)
            ncha1 = ncha[35:]
            ncha2 = ncha1[:-2]
            print(ncha2)

We have some students that call out for 'server' to get the attention of Kate or one of us so I thought about building a response to the single string 'server'
so with the following if statement, KateBot was born.

if ncha2 == 'server'"
    mc.postToChat('Please leave a message and server will get back with you')

Since that point I wanted to make her more interactive and fun to talk to so I have a never ending job of testing and trying new responses to questions.

For instance I have a trigger word string, and a response list to choose from.
GREETING_KEYWORDS = ("hello", "hi", "greetings", "sup", "what's up",)
GREETING_RESPONSES = ["<Kate-Bot>'sup PyCrafter", "<Kate-Bot>hey", "<Kate-Bot>*nods*", "<Kate-Bot>Yay PyCraft!!!"]

Then my definition for the greeting:
def greeting():
    if ncha2.lower() in GREETING_KEYWORDS:
        return mc.postToChat(random.choice(GREETING_RESPONSES)) 

So I welcome any submission to the katebot code foundation by either suggesting a trigger and response to it or writing a definition like:


def KB():
    KB_NAMES =('kbot', '<kate-bot>', 'katebot', 'kate-bot', 'kb')
    KB_RESPONSES = ['<Kate-bot>Yo!!', '<Kate-bot>Can I help you?']
    if ncha2.lower() in KB_NAMES:
        return mc.postToChat(random.choice(KB_RESPONSES))

Friday, March 17, 2017

Coding Tips & Tricks

Coding Tips & Tricks? Yes. Hopefully, these will help you keep things organized, and find bugs.


  • Comments. Comments are your best friend. They can help you refine or edit your code, as well as help others edit or refine your code. It is also helpful to someone who is reviewing your code. As you can see in this example, I have placed comments on nearly every line. The lines marked as "Wall 1" or "Wall 2" may seem unclear, but I understand what they mean, and if you have run this yourself you will know that it builds the walls in that order with a short time delay between, so all you have to do is count the walls as it builds them, to see which line builds which wall.
 
this example is a library program I wrote to keep track of all my books, and as you can see there are very few comments. I have put headings, but not comments on each line, and I can see many, many, many places where I should have put comments when I wrote this program.


  • Another thing you can do to help keep your code organized is leave blank spaces between parts of your code.

As you can see from this image, I have drawn lines around "blocks" of code. These are totally subjective. This is just the way I like to lay out my code, but you should change that to fit your needs.

  • The rubber duck method. Yes, this is a real thing. The rubber duck method involves using a rubber duck, toy, stuffed animal, or sibling/parent, to explain your code to. You just explain the code, line by line, to your rubber duck, and this will hopefully help you catch bugs. Now using a rubber duck is ideal, because when you find a bug and say "HOW COULD I NOT SEE THAT?!?!?!" And get mad, and want to throw something (no you are not alone in this feeling) you can throw the rubber duck, while your sibling/parent might object to being thrown. Please pardon the following pun.
Feel free to ask questions, suggest a post, or suggest something else to add to this post!




Friday, March 3, 2017

About: Mods

In case you don't know what a "mod" is, simply put it is a modification to the game. In this instance specifically, mods for Minecraft. I will be talking about one mod in particular in this post: Decocraft. Decocraft has just been installed on our creative server, and some people have been having issues joining after it was added so I will talk a little but about how to install the mod, and then a little about the mod itself and how to use it.

First of all how to install a mod. This is pretty simple, and if you already have Forge and the RJM installed, this should be really easy. I will link a video and give worded instruction so you can choose whichever way you like best. Here is the link to a video made by one of the students, and moderators, heimerdawg. Now as for the written version (Windows version).

  1. Go to this Dropbox link and download "forge-1.10.2-12.18.3.2239-installer-win(1).exe"
  2. Double click the file and select "Install Client" 
  3. After the files download, go back to the Dropbox link and download                         "Decocraft-2.3.4_1.10.2.jar"
  4. Locate your ".minecraft" folder by typing "%appdata%" in the search bar in the lower left-hand corner of your desktop.
  5. You should open the folder that pops up, and find the sub-folder named ".minecraft"
  6. In your ".minecraft" folder find the folder named "mods" if you don't have a "mods" folder, simply make one by right-clicking, selecting "New", and then select "Folder". Make sure to name it "mods" no capitals.
  7. Inside this "mods" folder make another folder named "1.10.2"
  8. Drag and drop the "Decocraft-2.3.4_1.10.2.jar" file you downloaded before into this new "1.10.2" folder.
  9. Load minecraft and select your Forge 1.10.2 profile.
  10. Press play. Lots of things will happen that don't happen when you load normal minecraft. This is normal, so don't freak out and think your minecraft is broken, or you got a virus from this. You WILL NOT get ANY viruses from these downloads. I personally have them, and they are clean.
  11. After it loads, you should have a "Mods" button on the title page. Click this and make sure you have the correct mods installed. There should be one called "Decocraft" and another named "PTRModelsLib" There will be some others too. These are part of Forge itself and don't really modify the game very much, they are just necessary for the loading of the other mods you install. 
  12. You should be able to now play on the creative server!
  13. You can also play on your own worlds, but make sure that if you build with any items from the mod, that you always load that world with the mods installed. If you don't all the items you placed that are from the mod will vanish and you can't get them back.
  14. The video will probably be easier to follow than this, so if you can't get it from this, watch the video, please.
  15. Feel free to ask for help!
Ok now onto how to use the mod! This mod isn't hard to use. All it adds are a bunch of decorations. Basically, you just look in your inventory and find the item you want to use. Hold it in your hand, and you will see an outline of the object. If this outline is red, something is blocking it. If its white you can place it. For more info, you can go to the mod page on the minecraft forum for more info, and a video.

Thanks for reading, and please feel free to ask questions!