Skip to content

Commit

Permalink
Release (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored May 18, 2024
2 parents eb4173b + 6bf1085 commit f846da2
Show file tree
Hide file tree
Showing 27 changed files with 904 additions and 95 deletions.
6 changes: 5 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ Press `Y` to set query parameters to url of your current game state.
### Notable Things that Power this Project

- [Mineflayer](https://github.com/PrismarineJS/mineflayer) - Handles all client-side communications with the server (including the builtin one) - forked
- [Flying Squid](https://github.com/prismarineJS/flying-squid) - The builtin server that makes single player possible! Here forked version is used.
- [Forked Flying Squid (Space Squid)](https://github.com/zardoy/space-squid) - The builtin offline server that makes single player & P2P possible!
- [Prismarine Provider Anvil](https://github.com/PrismarineJS/prismarine-provider-anvil) - Handles world loading (region format)
- [Prismarine Physics](https://github.com/PrismarineJS/prismarine-physics) - Does all the physics calculations
- [Minecraft Protocol](https://github.com/PrismarineJS/node-minecraft-protocol) - Makes connections to servers possible
- [Peer.js](https://peerjs.com/) - P2P networking (when you open to wan)
- [Three.js](https://threejs.org/) - Helping in 3D rendering

### Alternatives

- [https://github.com/ClassiCube/ClassiCube](ClassiCube - Better C# Rewrite) [DEMO](https://www.classicube.net/server/play/?warned=true)
1 change: 1 addition & 0 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const buildOptions = {
loader: {
// todo use external or resolve issues with duplicating
'.png': 'dataurl',
'.svg': 'dataurl',
'.map': 'empty',
'.vert': 'text',
'.frag': 'text',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"constants-browserify": "^1.0.0",
"contro-max": "^0.1.6",
"contro-max": "^0.1.7",
"crypto-browserify": "^3.12.0",
"cypress": "^10.11.0",
"cypress-esbuild-preprocessor": "^1.0.2",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions prismarine-viewer/viewer/lib/entities.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//@ts-check
const THREE = require('three')
const TWEEN = require('@tweenjs/tween.js')

const Entity = require('./entity/EntityMesh')
const { dispose3 } = require('./dispose')
const EventEmitter = require('events')
import * as THREE from 'three'
import * as TWEEN from '@tweenjs/tween.js'
import * as Entity from './entity/EntityMesh'
import { dispose3 } from './dispose'
import nbt from 'prismarine-nbt'
import EventEmitter from 'events'
import { PlayerObject, PlayerAnimation } from 'skinview3d'
import { loadSkinToCanvas, loadEarsToCanvasFromSkin, inferModelType, loadCapeToCanvas, loadImage } from 'skinview-utils'
// todo replace with url
Expand Down Expand Up @@ -264,7 +264,7 @@ export class Entities extends EventEmitter {

displaySimpleText(jsonLike) {
if (!jsonLike) return
const parsed = mojangson.simplify(mojangson.parse(jsonLike))
const parsed = typeof jsonLike === 'string' ? mojangson.simplify(mojangson.parse(jsonLike)) : nbt.simplify(jsonLike)
const text = flat(parsed).map(x => x.text)
return text.join('')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//@ts-check
import minecraftData from 'minecraft-data'
import minecraftAssets from 'minecraft-assets'
import fs from 'fs'

const latestData = minecraftData('1.20.2')
const latestVersion = minecraftData.versions.pc[0]

const latestData = minecraftData(latestVersion.minecraftVersion)

// dont touch, these are the ones that are already full box
const fullBoxInteractionShapes = [
Expand Down Expand Up @@ -62,7 +65,7 @@ const fullBoxInteractionShapesTemp = [
'white_wall_banner',
]

const shapes = latestData.blockCollisionShapes;
const shapes = latestData.blockCollisionShapes
const fullShape = shapes.shapes[1]
const outputJson = {}

Expand Down Expand Up @@ -97,8 +100,8 @@ const interestedBlocks = latestData.blocksArray.filter(block => {
const { blocksStates, blocksModels } = minecraftAssets(latestData.version.minecraftVersion)

const getShapeFromModel = (block,) => {
const blockStates = JSON.parse(fs.readFileSync('./prismarine-viewer/public/blocksStates/1.19.1.json'))
const blockState = blockStates[block];
const blockStates = JSON.parse(fs.readFileSync('./prismarine-viewer/public/blocksStates/1.19.1.json', 'utf8'))
const blockState = blockStates[block]
const perVariant = {}
for (const [key, variant] of Object.entries(blockState.variants)) {
// const shapes = (Array.isArray(variant) ? variant : [variant]).flatMap((v) => v.model?.elements).filter(Boolean).map(({ from, to }) => [...from, ...to]).reduce((acc, cur) => {
Expand Down Expand Up @@ -146,7 +149,7 @@ outer: for (const interestedBlock of [...interestedBlocksNoStates, ...interested
}
}

const hasStates = interestedBlocksStates.includes(interestedBlock);
const hasStates = interestedBlocksStates.includes(interestedBlock)
if (hasStates) {
const states = blocksStates[interestedBlock]
if (!states) {
Expand All @@ -159,7 +162,7 @@ outer: for (const interestedBlock of [...interestedBlocksNoStates, ...interested
continue
}
let outputStates = {}
for (const {when} of states.multipart) {
for (const { when } of states.multipart) {
if (when) {
for (const [key, value] of Object.entries(when)) {
if (key === 'OR') {
Expand Down
28 changes: 24 additions & 4 deletions src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ import { proxy, subscribe } from 'valtio'
import { ControMax } from 'contro-max/build/controMax'
import { CommandEventArgument, SchemaCommandInput } from 'contro-max/build/types'
import { stringStartsWith } from 'contro-max/build/stringUtils'
import { UserOverridesConfig } from 'contro-max/build/types/store'
import { isGameActive, showModal, gameAdditionalState, activeModalStack, hideCurrentModal, miscUiState } from './globalState'
import { goFullscreen, pointerLock, reloadChunks } from './utils'
import { options } from './optionsStorage'
import { openPlayerInventory } from './inventoryWindows'
import { chatInputValueGlobal } from './react/Chat'
import { fsState } from './loadSave'
import { customCommandsConfig } from './customCommands'
import { CustomCommand } from './react/KeybindingsCustom'
import { showOptionsModal } from './react/SelectOption'
import widgets from './react/widgets'
import { getItemFromBlock } from './botUtils'
import { gamepadUiCursorState, moveGamepadCursorByPx } from './react/GamepadUiCursor'

// todo move this to shared file with component
export const customKeymaps = proxy(JSON.parse(localStorage.keymap || '{}'))

export const customKeymaps = proxy(JSON.parse(localStorage.keymap || '{}')) as UserOverridesConfig
subscribe(customKeymaps, () => {
localStorage.keymap = JSON.parse(customKeymaps)
localStorage.keymap = JSON.stringify(customKeymaps)
})

const controlOptions = {
Expand Down Expand Up @@ -53,7 +56,8 @@ export const contro = new ControMax({
},
advanced: {
lockUrl: ['KeyY'],
}
},
custom: {} as Record<string, SchemaCommandInput & { type: string, input: any[] }>,
// waila: {
// showLookingBlockRecipe: ['Numpad3'],
// showLookingBlockUsages: ['Numpad4']
Expand Down Expand Up @@ -81,6 +85,8 @@ export const contro = new ControMax({
window.controMax = contro
export type Command = CommandEventArgument<typeof contro['_commandsRaw']>['command']

// updateCustomBinds()

export const setDoPreventDefault = (state: boolean) => {
controlOptions.preventDefault = state
}
Expand Down Expand Up @@ -285,6 +291,20 @@ function cycleHotbarSlot (dir: 1 | -1) {
bot.setQuickBarSlot(newHotbarSlot)
}

// custom commands hamdler
const customCommandsHandler = (buttonData: { code?: string, button?: string, state: boolean }) => {
if (!buttonData.state || !isGameActive(true)) return

const codeOrButton = buttonData.code ?? buttonData.button
const inputType = buttonData.code ? 'keys' : 'gamepad'
for (const value of Object.values(contro.userConfig!.custom)) {
if (value[inputType]?.includes(codeOrButton!)) {
customCommandsConfig[(value as CustomCommand).type].handler((value as CustomCommand).inputs)
}
}
}
contro.on('pressedKeyOrButtonChanged', customCommandsHandler)

contro.on('trigger', ({ command }) => {
const willContinue = !isGameActive(true)
alwaysPressedHandledCommand(command)
Expand Down
1 change: 1 addition & 0 deletions src/cross_playstation_console_controller_gamepad_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions src/customCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { guiOptionsScheme, tryFindOptionConfig } from './optionsGuiScheme'
import { options } from './optionsStorage'

export const customCommandsConfig = {
chat: {
input: [
{
type: 'text',
placeholder: 'Command to send e.g. gamemode creative'
}
],
handler ([command]) {
bot.chat(`/${command.replace(/^\//, '')}`)
}
},
setOrToggleSetting: {
input: [
{
type: 'select',
// maybe title case?
options: Object.keys(options)
},
{
type: 'select',
options: ['toggle', 'set']
},
([setting = '', action = ''] = []) => {
const value = options[setting]
if (!action || value === undefined || action === 'toggle') return null
if (action === 'set') {
const getBase = () => {
const config = tryFindOptionConfig(setting as any)
if (config && 'values' in config) {
return {
type: 'select',
options: config.values
}
}
if (config?.type === 'toggle' || typeof value === 'boolean') {
return {
type: 'select',
options: ['true', 'false']
}
}
if (config?.type === 'slider' || value.type === 'number') {
return {
type: 'number',
}
}
return {
type: 'text'
}
}
return {
...getBase(),
placeholder: value
}
}
}
],
handler ([setting, action, value]) {
if (action === 'toggle') {
const value = options[setting]
const config = tryFindOptionConfig(setting)
if (config && 'values' in config && config.values) {
const { values } = config
const currentIndex = values.indexOf(value)
const nextIndex = (currentIndex + 1) % values.length
options[setting] = values[nextIndex]
} else {
options[setting] = typeof value === 'boolean' ? !value : typeof value === 'number' ? value + 1 : value
}
} else {
options[setting] = value
}
}
},
jsScripts: {
input: [
{
type: 'text',
placeholder: 'JavaScript code to run in main thread (sensitive!)'
}
],
handler ([code]) {
// eslint-disable-next-line no-new-func -- this is a feature, not a bug
new Function(code)()
}
},
// openCommandsScreen: {}
}
6 changes: 3 additions & 3 deletions src/globalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { OptionsGroupType } from './optionsGuiScheme'

const notHideableModalsWithoutForce = new Set(['app-status'])

type Modal = ({ elem?: HTMLElement & Record<string, any> } & { reactType?: string })
type Modal = ({ elem?: HTMLElement & Record<string, any> } & { reactType: string })

type ContextMenuItem = { callback; label }

Expand Down Expand Up @@ -57,7 +57,7 @@ const showModalInner = (modal: Modal) => {
}

export const showModal = (elem: /* (HTMLElement & Record<string, any>) | */{ reactType: string }) => {
const resolved = elem instanceof HTMLElement ? { elem: ref(elem) } : elem
const resolved = elem
const curModal = activeModalStack.at(-1)
if (/* elem === curModal?.elem || */(elem.reactType && elem.reactType === curModal?.reactType) || !showModalInner(resolved)) return
if (curModal) defaultModalActions.hide(curModal)
Expand Down Expand Up @@ -123,7 +123,7 @@ export type AppConfig = {
defaultProxy?: string
// defaultProxySave?: string
// defaultVersion?: string
promoteServers?: Array<{ip, description, version?}>
promoteServers?: Array<{ ip, description, version?}>
mapsProvider?: string
}

Expand Down
Loading

0 comments on commit f846da2

Please sign in to comment.