Amir Ax
Amir Ax

Reputation: 11

I have a problem with my python Minecraft copy

I was working with "Ursina Engine" My project is to make a copy of Minecraft, then I found out a problem that every time I run the program and when I want to right-click to place a block, nothing happens.

Thanks to someone who can help me find the issue and tell me how to fix it * Here is my Code:*

    from ursina import *
    from ursina.prefabs.first_person_controller import FirstPersonController
    class Vovel(Button):
        def __init__(self, position = (0,0,0)):
            super().__init__(
                parent=scene,
                position=position,
                model='cube',
                origin_y = 0.5,
                texture= 'white_cube',
                color= color.white,
                highlight_color = color.lime,
            )
        def Input(self, key):
            if self.hovered:
                if key == 'left mouse down':
                    vovel = Vovel(position= self.position + mouse.normal)
                if key == 'right mouse down':
                    destroy(self)
    app = Ursina()
    for z in range(8):
        for x in range(8):
            vovel = Vovel(position=  (x,0,z))
    player = FirstPersonController()
    app.run()

End.

Upvotes: 1

Views: 311

Answers (4)

Raphi-2Code
Raphi-2Code

Reputation: 38

Ah now I'm understanding your problem, you have to change input to Input, the rest is fine.🙂

Upvotes: -1

Raphi-2Code
Raphi-2Code

Reputation: 38

You only have to replace left mouse down with right mouse down and right mouse down with left mouse down, but I'm using this code for "Minecraft": `

from ursina.prefabs.first_person_controller import *
app=Ursina()
FirstPersonController()
Sky()
def voxel(position:Vec3):
    Voxel=Entity(model="assets/block.obj", position=position, collider="box", texture="assets/sand_block.jpg",origin_y=0.5,scale=0.5,on_click=lambda:destroy(Voxel))
for x in range(20):
    for z in range(20):
        voxel(position=Vec3(x,0,z))
def input(key):
    if key=="right mouse down":
        vox=voxel(position=Vec3(round(mouse.world_point.x),ceil(mouse.world_point.y),round(mouse.world_point.z)))
app.run()`

Upvotes: 0

athrb
athrb

Reputation: 121

The input function should be input and not Input, rest of the code is absolutely correct. So, your code should be:

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController


class Vovel(Button):
def __init__(self, position=(0, 0, 0)):
    super().__init__(
        parent=scene,
        position=position,
        model='cube',
        origin_y=0.5,
        texture='white_cube',
        color=color.white,
        highlight_color=color.lime,
    )

def input(self, key):
    if self.hovered:
        if key == 'left mouse down':
            vovel = Vovel(position=self.position + mouse.normal)
        if key == 'right mouse down':
            destroy(self)


app = Ursina()
for z in range(8):
for x in range(8):
    vovel = Vovel(position=(x, 0, z))
player = FirstPersonController()
app.run()

This code works, you can place a block with left click and remove a block with right click!

Upvotes: 4

pokepetter
pokepetter

Reputation: 1489

The name of the input function is wrong. Input should be input

Upvotes: 6

Related Questions