Оператор If/else выдает проблемы с заменой переменных (Minecraft python)

#python #minecraft

Вопрос:

Моя проблема в том, что когда width > depth я хочу поменять x местами и z переменные, но если width < depth (что будет происходить большую часть времени), то просто создайте его нормально с x помощью as x и z as 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)

 

Комментарии:

1. Разве вы не можете просто использовать self.vec.x, self.vec.z = self.vec.z, self.vec.x в python?

2. Вы говорите, что у вас есть проблемы с этим? В чем заключаются проблемы? На самом деле это не обмен или это что-то другое

3. Я указал проблему; она даже не будет отображать какое-либо здание вообще, если будет выполнено утверждение IF, потому что я пытаюсь создать пул

4. В том, что вы показали, нет ничего очевидного, что заставило бы остальной код вести себя по-другому после того, как вы поменяете эти координаты местами. Возможно, вы также хотите поменять width местами и depth сами ценности, а не только элементы x и z vec ?