Add Rainbow Thing

develop
Alvaro del Castillo San Felix 2020-04-21 00:06:28 +02:00
parent e565d20bf2
commit 406e0e6f86
8 changed files with 196 additions and 0 deletions

View File

29
mcthings_extra/rainbow.py Normal file
View File

@ -0,0 +1,29 @@
from mcpi import block
from mcpi.vec3 import Vec3
from mcthings.scene import Scene
from mcthings.thing import Thing
from math import *
# Based on Rainbow code written by zhuowei and retrieved from URL below:
# http://www.minecraftforum.net/topic/1638036-my-first-script-for-minecraft-pi-api-a-rainbow/
colors = [14, 1, 4, 5, 3, 11, 10]
class Rainbow(Thing):
height = 20
""" Height of the rainbow """
block = block.WOOL.id
def build(self):
mc = Scene.server
mc.setBlocks(-64, 0, 0, 64, self.height + len(colors), 0, 0)
for x in range(0, 128):
for color in range(0, len(colors)):
y = sin((x / 128.0) * pi) * self.height + color
mc.setBlock(self.position.x + x - 64, int(y), self.position.z,
self.block, colors[len(colors) - 1 - color])
end_x = self.position.x - 64 + 128
self._end_position = Vec3(end_x, self.position.y, self.position.z)

10
release.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
# Increment version in setup.py
# Commit and tag with the new version
# Push branch with tags
# Generate pip packages and upload to pip repository
rm dist/*
python setup.py sdist
python setup.py bdist_wheel
twine upload dist/*

46
setup.py Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
import codecs
import os
from setuptools import setup
here = os.path.abspath(os.path.dirname(__file__))
readme_md = os.path.join(here, 'README.md')
# Get the package description from the README.md file
with codecs.open(readme_md, encoding='utf-8') as f:
long_description = f.read()
# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='mcthings',
version='0.0.1',
packages=['mcthings_extra'],
include_package_data=True,
license='ASL',
description='Additional Things for the McThings Python library',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/juntosdesdecasa/mcthings_extra',
author='Alvaro del Castillo',
author_email='alvaro.delcastillo@gmail.com',
keywords="development library minecraft buildings games",
classifiers=[
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Software Development'
],
install_requires=[
'mcpi',
'mcthings >= 0.5.3'
],
python_requires='>=3.4'
)

33
tests/clean_scene.py Normal file
View File

@ -0,0 +1,33 @@
import sys
import mcpi.block
import mcpi.minecraft
from mcthings.scene import Scene
from mcthings.server import Server
from minecraftstuff import MinecraftDrawing
BUILDER_NAME = "ElasticExplorer"
MC_SEVER_HOST = "localhost"
MC_SEVER_PORT = 4711
def main():
try:
server = Server(MC_SEVER_HOST, MC_SEVER_PORT)
server.mc.postToChat("Cleaning a scene")
# Let's load the scene and build it
Scene.load("scene_rainbow.mct")
# Move the scene to the player position
Scene.unbuild()
except mcpi.connection.RequestError:
print("Can't connect to Minecraft server " + MC_SEVER_HOST)
if __name__ == "__main__":
main()
sys.exit(0)

36
tests/load_scene.py Normal file
View File

@ -0,0 +1,36 @@
import sys
import mcpi.block
import mcpi.minecraft
from mcthings.scene import Scene
from mcthings.server import Server
from minecraftstuff import MinecraftDrawing
BUILDER_NAME = "ElasticExplorer"
MC_SEVER_HOST = "localhost"
MC_SEVER_PORT = 4711
def main():
try:
server = Server(MC_SEVER_HOST, MC_SEVER_PORT)
server.mc.postToChat("Building a scene from a file")
pos = server.mc.entity.getTilePos(server.mc.getPlayerEntityId(BUILDER_NAME))
pos.z -= 50
# Let's load the scene and build it
Scene.load("scene_rainbow.mct")
# Move the scene to the player position
Scene.move(pos)
Scene.build()
except mcpi.connection.RequestError:
print("Can't connect to Minecraft server " + MC_SEVER_HOST)
if __name__ == "__main__":
main()
sys.exit(0)

42
tests/scene.py Normal file
View File

@ -0,0 +1,42 @@
import sys
import mcpi.block
import mcpi.minecraft
from mcthings.scene import Scene
from mcthings.pyramid import Pyramid
from mcthings.server import Server
from mcthings_extra.rainbow import Rainbow
BUILDER_NAME = "ElasticExplorer"
MC_SEVER_HOST = "localhost"
MC_SEVER_PORT = 4711
# In this scene Things from McThings and McThings-Drawing are mixed
def main():
try:
server = Server(MC_SEVER_HOST, MC_SEVER_PORT)
server.mc.postToChat("Building a rainbow")
pos = server.mc.entity.getTilePos(server.mc.getPlayerEntityId(BUILDER_NAME))
pos.z -= 20
pyr = Pyramid(pos)
pyr.build()
rainbow = Rainbow(pyr.end_position)
rainbow.build()
Scene.save("scene_rainbow.mct")
except mcpi.connection.RequestError:
print("Can't connect to Minecraft server " + MC_SEVER_HOST)
if __name__ == "__main__":
main()
sys.exit(0)

BIN
tests/scene_rainbow.mct Normal file

Binary file not shown.