If/else语句与交换变量有关(Minecraft python)

2024-06-08 06:22:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题是,当width > depth我想交换xz变量时,但是如果width < depth(大多数情况下都是这样),那么就正常地用x作为xz作为z来构建它。当width > depth时,它将什么也不构建,但当depth > width时,它就可以了。我的交换变量理论有问题吗

from math import ceil
from Commands.format import getIP
from mcpi.minecraft import Minecraft
from random import *
from mcpi.vec3 import Vec3

ip = getIP()
mc = Minecraft.create()
# mc = Minecraft.create()

#               n        w      s      e
directions = [[0,-1], [-1,0], [0,1], [1,0]]

class Pool():
    def __init__(self):
        self.vec = Vec3(0,0,0)
        self.width = 0
        self.depth = 0
        self.door = Vec3(0,0,0)

    def SwimmingPool(self, vec, width, depth):
        self.vec = vec
        self.width = width
        self.depth = depth

# the issue 
        if width > depth:
            temp = self.vec.x
            self.vec.x = self.vec.z
            self.vec.z = temp

        

        # Creates base of pool
        base_pool = 1
        mc.setBlocks(self.vec.x+1, self.vec.y-6, self.vec.z+1, self.vec.x+width, self.vec.y-2, self.vec.z+depth, base_pool)
        self.vec.y += 1

        # Creates walls of pool 
        wood_type = randint(0, 5)
        mc.setBlocks(self.vec.x+1, self.vec.y-6, self.vec.z+1, self.vec.x+width, self.vec.y-2, self.vec.z+depth, 5, wood_type)

        # Creates logs on the outer edges
        pool_corners = 17
        mc.setBlocks(self.vec.x+1, self.vec.y-6, self.vec.z+1, self.vec.x+1, self.vec.y-2, self.vec.z+1, pool_corners)
        mc.setBlocks(self.vec.x+1, self.vec.y-6, self.vec.z+depth, self.vec.x+1, self.vec.y-2, self.vec.z+depth, pool_corners)
        mc.setBlocks(self.vec.x+width, self.vec.y-6, self.vec.z+1, self.vec.x+width, self.vec.y-2, self.vec.z+1, pool_corners)
        mc.setBlocks(self.vec.x+width, self.vec.y-6, self.vec.z+depth, self.vec.x+width, self.vec.y-2, self.vec.z+depth, pool_corners)

        # Creates boarder around the pool
        pool_boarder = 24,2
        mc.setBlocks(self.vec.x-1, self.vec.y-2, self.vec.z, self.vec.x+width+2, self.vec.y-2, self.vec.z-1, pool_boarder) 
        mc.setBlocks(self.vec.x+width+1, self.vec.y-2, self.vec.z+depth+2, self.vec.x+width+2, self.vec.y-2, self.vec.z, pool_boarder)
        mc.setBlocks(self.vec.x, self.vec.y-2, self.vec.z+1, self.vec.x-1, self.vec.y-2, self.vec.z+depth+2, pool_boarder)
        mc.setBlocks(self.vec.x+width, self.vec.y-2, self.vec.z+depth+1, self.vec.x-1, self.vec.y-2, self.vec.z+depth+2, pool_boarder)

        # Creates fence on boarder
        fence_material = 85
        mc.setBlocks(self.vec.x-1, self.vec.y-1, self.vec.z-1, self.vec.x-1, self.vec.y-1, self.vec.z+depth+2, fence_material)
        mc.setBlocks(self.vec.x+width+2, self.vec.y-1, self.vec.z+depth+2, self.vec.x, self.vec.y-1, self.vec.z+depth+2, fence_material)
        mc.setBlocks(self.vec.x+width+2, self.vec.y-1, self.vec.z-1, self.vec.x+width+2, self.vec.y-1, self.vec.z+depth+2, fence_material)   

        # Places "chair"
        pool_chair = 156
        mc.setBlocks(self.vec.x+width+1, self.vec.y-1, self.vec.z+3, self.vec.x+width+1, self.vec.y-1, self.vec.z+4, pool_chair)
        mc.setBlocks(self.vec.x+width+1, self.vec.y-1, self.vec.z+depth-2, self.vec.x+width+1, self.vec.y-1, self.vec.z+depth-3, pool_chair)
       
        # Umbrella Poles
        umbrella_pole = 85
        mc.setBlocks(self.vec.x+width+1, self.vec.y+2, self.vec.z+5, self.vec.x+width+1, self.vec.y-1, self.vec.z+5, umbrella_pole)
        mc.setBlocks(self.vec.x+width+1, self.vec.y+2, self.vec.z+depth-4, self.vec.x+width+1, self.vec.y-1, self.vec.z+depth-4, umbrella_pole)
        mc.setBlocks(self.vec.x+width+1, self.vec.y+2, self.vec.z+2, self.vec.x+width+1, self.vec.y-1, self.vec.z+2, umbrella_pole)
        mc.setBlocks(self.vec.x+width+1, self.vec.y+2, self.vec.z+depth-1, self.vec.x+width+1, self.vec.y-1, self.vec.z+depth-1, umbrella_pole)
        
        # Umbrella roof
        umbrella_roof = 43,7
        mc.setBlocks(self.vec.x+width+2, self.vec.y+3, self.vec.z+depth-1, self.vec.x+width, self.vec.y+3, self.vec.z+depth-4, umbrella_roof)
        mc.setBlocks(self.vec.x+width+2, self.vec.y+3, self.vec.z+2, self.vec.x+width, self.vec.y+3, self.vec.z+5, umbrella_roof)

        # Fills pool 
        self.fillpool(self.vec.x, self.vec.y, self.vec.z, width, depth)

    def fillpool(self, x, y, z, width, depth):
        #fills pool with water
        fill_pool = 9
        mc.setBlocks(x+2, y-2, z+2, x+width-1, y-6, z+depth-1, fill_pool)


if __name__ == "__main__":
    x, y, z = mc.player.getPos()
    width = 12
    depth = 10
    outside = Pool()
    outside.SwimmingPool(Vec3(x,y,z), width, depth)


Tags: fromimportselfmcwidthpooldepthcreates

热门问题