-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaking_mcpi_real.py
91 lines (71 loc) · 3 KB
/
making_mcpi_real.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from time import sleep
from typing_extensions import Literal
from typing import List
import mcpi.minecraft as minecraft
import mcpi.block as block
from keyboard import on_press_key
from gamerules import tnt_explodes
from _classes import Player
game = minecraft.Minecraft.create()
game.saveCheckpoint()
# Set local player as the "admin"
admin: Player = Player.create(game.getPlayerEntityIds()[0], True)
game.player.setting("autojump", False)
players: List[Player] = [admin]
view: Literal["1st", "3rd"] = "1st"
# Quick 'n' dirty 3rd person view shortcut
def toggle_view(_):
global view
# BUG
if view == "1st":
view = "3rd"
# Make the camera "follow" the "admin" (local player)
game.camera.setFollow(admin)
elif view == "3rd":
view = "1st"
game.camera.setNormal(admin)
on_press_key("f5", toggle_view)
op: bool = False # Whether the event was generated by the admin and has op privileges
ticks = 1
print("Started plugin")
game.postToChat('Plugin "making_mcpi_real" activated')
while True:
# Recognizing players
for player in game.getPlayerEntityIds():
# Skip admin and other already initialized players
if player == admin or Player.get_player(player) != None:
continue
players.append(Player.create(player))
events = game.events.pollBlockHits()
# Handles right-clicks w/ sword depending on what is right-clicked
for event in events:
bnd = game.getBlockWithData(event.pos)
block_id = bnd.id
data = bnd.data
op = True if event.entityId == admin.id else False
# Block replacements for "unplaceable" blocks (Only available in creative mode)
if Player.get_player(event.entityId).gamemode == "creative":
if block_id == block.TNT.id and tnt_explodes:
game.setBlock(event.pos, block.TNT.id, 1) # "Primeable" TNT
elif block_id == block.WOOL.id and data == 14: # Red wool
game.setBlock(event.pos, block.GLOWING_OBSIDIAN.id)
elif block_id == block.OBSIDIAN.id and op: # Obsidian
game.setBlock(event.pos, block.BEDROCK.id)
elif block_id == block.WATER_STATIONARY.id and op:
game.setBlock(event.pos, block.ICE.id)
# Setting spawnpoint using bed
elif block_id == block.BED.id and op:
open("rspnpt.dat", 'w').write(str(event.pos))
game.postToChat("Respawn point set")
# TODO Chests
elif block_id == block.CHEST.id:
# Chests will behave kind of like bundles
if game.getBlock(event.pos.x, event.pos.y + 1, event.pos.z) == block.AIR.id:
# Spew out stored contents above it. Probably shouldn't place chests anywhere with a ceiling :D.
pass
else:
# Add contiguous blocks above it to storage
pass
# Max TPS of 20
sleep(1/20)
ticks += 1