From 45961bbfbb2aa12e27231b530eea9c6d713e1b84 Mon Sep 17 00:00:00 2001 From: LabyStudio Date: Fri, 15 Apr 2022 05:59:25 +0200 Subject: [PATCH] convert classes to es6 (cherry picked from commit e7615d49a4071fe5b5f192884f142c9f3385211a) --- index.html | 2 +- src/js/net/minecraft/client/GameSettings.js | 2 +- src/js/net/minecraft/client/GameWindow.js | 5 +- src/js/net/minecraft/client/Minecraft.js | 27 ++++++- src/js/net/minecraft/client/entity/Entity.js | 5 +- .../minecraft/client/entity/EntityLiving.js | 5 +- .../minecraft/client/entity/PlayerEntity.js | 10 ++- src/js/net/minecraft/client/gui/Gui.js | 42 ++++++---- src/js/net/minecraft/client/gui/GuiScreen.js | 6 +- .../net/minecraft/client/gui/IngameOverlay.js | 9 ++- .../client/gui/screens/GuiControls.js | 6 +- .../client/gui/screens/GuiIngameMenu.js | 6 +- .../client/gui/screens/GuiLoadingScreen.js | 10 ++- .../minecraft/client/gui/widgets/GuiButton.js | 8 +- .../client/gui/widgets/GuiKeyButton.js | 4 +- .../minecraft/client/inventory/Inventory.js | 2 +- .../minecraft/client/render/BlockRenderer.js | 8 +- .../minecraft/client/render/Tessellator.js | 2 +- .../minecraft/client/render/WorldRenderer.js | 8 +- .../render/entity/EntityRenderManager.js | 5 +- .../client/render/entity/EntityRenderer.js | 5 +- .../render/entity/entity/PlayerRenderer.js | 6 +- .../client/render/gui/FontRenderer.js | 12 +-- .../client/render/gui/ItemRenderer.js | 4 +- .../client/render/gui/ScreenRenderer.js | 2 +- .../render/isometric/IsometricRenderer.js | 6 +- .../client/render/isometric/Point.js | 2 +- .../client/render/isometric/TextCoord.js | 2 +- .../client/render/isometric/Triangle.js | 2 +- .../client/render/model/ModelBase.js | 2 +- .../client/render/model/model/ModelPlayer.js | 6 +- .../render/model/renderer/ModelRenderer.js | 5 +- .../client/render/model/renderer/Polygon.js | 4 +- .../client/render/model/renderer/Vertex.js | 4 +- .../minecraft/client/sound/SoundManager.js | 4 +- src/js/net/minecraft/client/world/Chunk.js | 9 ++- .../minecraft/client/world/ChunkSection.js | 5 +- src/js/net/minecraft/client/world/World.js | 13 +++- .../net/minecraft/client/world/block/Block.js | 29 ++----- .../minecraft/client/world/block/BlockDirt.js | 4 +- .../client/world/block/BlockGrass.js | 5 +- .../client/world/block/BlockLeave.js | 4 +- .../minecraft/client/world/block/BlockLog.js | 4 +- .../client/world/block/BlockRegistry.js | 33 ++++++++ .../minecraft/client/world/block/BlockSand.js | 4 +- .../client/world/block/BlockStone.js | 4 +- .../client/world/block/BlockTorch.js | 7 +- .../client/world/block/BlockWater.js | 4 +- .../client/world/block/sound/Sound.js | 2 +- .../client/world/generator/NoiseGenerator.js | 2 +- .../client/world/generator/WorldGenerator.js | 8 +- .../generator/noise/NoiseGeneratorCombined.js | 4 +- .../generator/noise/NoiseGeneratorOctaves.js | 5 +- .../generator/noise/NoiseGeneratorPerlin.js | 4 +- src/js/net/minecraft/util/BlockRenderType.js | 2 +- src/js/net/minecraft/util/BoundingBox.js | 2 +- src/js/net/minecraft/util/EnumBlockFace.js | 34 ++++---- src/js/net/minecraft/util/EnumSkyBlock.js | 2 +- src/js/net/minecraft/util/Keyboard.js | 5 +- src/js/net/minecraft/util/MathHelper.js | 2 +- .../net/minecraft/util/MetadataChunkBlock.js | 6 +- .../minecraft/util/MovingObjectPosition.js | 2 +- src/js/net/minecraft/util/Random.js | 2 +- src/js/net/minecraft/util/Timer.js | 4 +- src/js/net/minecraft/util/Vector3.js | 2 +- src/start.js | 78 ++----------------- 66 files changed, 319 insertions(+), 210 deletions(-) create mode 100644 src/js/net/minecraft/client/world/block/BlockRegistry.js diff --git a/index.html b/index.html index 718dfae..4d9f942 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,7 @@ - + diff --git a/src/js/net/minecraft/client/GameSettings.js b/src/js/net/minecraft/client/GameSettings.js index 94c2e4c..380f9e8 100644 --- a/src/js/net/minecraft/client/GameSettings.js +++ b/src/js/net/minecraft/client/GameSettings.js @@ -1,4 +1,4 @@ -window.GameSettings = class { +export default class GameSettings { constructor() { this.crouching = 'ShiftLeft'; diff --git a/src/js/net/minecraft/client/GameWindow.js b/src/js/net/minecraft/client/GameWindow.js index e39b74f..c040392 100644 --- a/src/js/net/minecraft/client/GameWindow.js +++ b/src/js/net/minecraft/client/GameWindow.js @@ -1,4 +1,7 @@ -window.GameWindow = class { +import GuiIngameMenu from "./gui/screens/GuiIngameMenu.js"; +import Keyboard from "../util/Keyboard.js"; + +export default class GameWindow { constructor(minecraft, canvasWrapperId) { this.minecraft = minecraft; diff --git a/src/js/net/minecraft/client/Minecraft.js b/src/js/net/minecraft/client/Minecraft.js index 69769ae..bc066b8 100644 --- a/src/js/net/minecraft/client/Minecraft.js +++ b/src/js/net/minecraft/client/Minecraft.js @@ -1,9 +1,27 @@ -window.Minecraft = class { +import Timer from "../util/Timer.js"; +import GameSettings from "./GameSettings.js"; +import GameWindow from "./GameWindow.js"; +import WorldRenderer from "./render/WorldRenderer.js"; +import ScreenRenderer from "./render/gui/ScreenRenderer.js"; +import ItemRenderer from "./render/gui/ItemRenderer.js"; +import IngameOverlay from "./gui/IngameOverlay.js"; +import GuiLoadingScreen from "./gui/screens/GuiLoadingScreen.js"; +import PlayerEntity from "./entity/PlayerEntity.js"; +import SoundManager from "./sound/SoundManager.js"; +import World from "./world/World.js"; +import Block from "./world/block/Block.js"; +import BoundingBox from "../util/BoundingBox.js"; +import {BlockRegistry} from "./world/block/BlockRegistry.js"; +import FontRenderer from "./render/gui/FontRenderer.js"; + +export default class Minecraft { /** * Create Minecraft instance and render it on a canvas */ - constructor(canvasWrapperId) { + constructor(canvasWrapperId, resources) { + this.resources = resources; + this.currentScreen = null; this.loadingScreen = null; @@ -34,10 +52,13 @@ window.Minecraft = class { this.lastTime = Date.now(); // Create all blocks - Block.create(); + BlockRegistry.create(); this.itemRenderer.initialize(); + // Create font renderer + this.fontRenderer = new FontRenderer(this); + // Update window size this.window.updateWindowSize(); diff --git a/src/js/net/minecraft/client/entity/Entity.js b/src/js/net/minecraft/client/entity/Entity.js index e9263eb..77fca87 100644 --- a/src/js/net/minecraft/client/entity/Entity.js +++ b/src/js/net/minecraft/client/entity/Entity.js @@ -1,4 +1,7 @@ -window.Entity = class { +import BoundingBox from "../../util/BoundingBox.js"; +import MathHelper from "../../util/MathHelper.js"; + +export default class Entity { constructor(minecraft, world) { this.minecraft = minecraft; diff --git a/src/js/net/minecraft/client/entity/EntityLiving.js b/src/js/net/minecraft/client/entity/EntityLiving.js index 20b3114..dbc486d 100644 --- a/src/js/net/minecraft/client/entity/EntityLiving.js +++ b/src/js/net/minecraft/client/entity/EntityLiving.js @@ -1,4 +1,7 @@ -window.EntityLiving = class extends Entity { +import Entity from "./Entity.js"; +import MathHelper from "../../util/MathHelper.js"; + +export default class EntityLiving extends Entity { constructor(minecraft, world) { super(minecraft, world); diff --git a/src/js/net/minecraft/client/entity/PlayerEntity.js b/src/js/net/minecraft/client/entity/PlayerEntity.js index 7d26171..b4f8fb8 100644 --- a/src/js/net/minecraft/client/entity/PlayerEntity.js +++ b/src/js/net/minecraft/client/entity/PlayerEntity.js @@ -1,4 +1,12 @@ -window.PlayerEntity = class extends EntityLiving { +import Inventory from "../inventory/Inventory.js"; +import EntityLiving from "./EntityLiving.js"; +import BoundingBox from "../../util/BoundingBox.js"; +import Block from "../world/block/Block.js"; +import MathHelper from "../../util/MathHelper.js"; +import Keyboard from "../../util/Keyboard.js"; +import Vector3 from "../../util/Vector3.js"; + +export default class PlayerEntity extends EntityLiving { static name = "PlayerEntity"; diff --git a/src/js/net/minecraft/client/gui/Gui.js b/src/js/net/minecraft/client/gui/Gui.js index f909664..969a898 100644 --- a/src/js/net/minecraft/client/gui/Gui.js +++ b/src/js/net/minecraft/client/gui/Gui.js @@ -1,4 +1,28 @@ -window.Gui = class { +import Point from "../render/isometric/Point.js"; +import IsometricRenderer from "../render/isometric/IsometricRenderer.js"; +import EnumBlockFace from "../../util/EnumBlockFace.js"; + +export default class Gui { + + constructor(minecraft = null) { + this.minecraft = minecraft; + } + + getTexture(id) { + return this.minecraft.resources[id]; + } + + drawCenteredString(stack, string, x, y, color = -1) { + this.minecraft.fontRenderer.drawString(stack, string, x - this.getStringWidth(stack, string) / 2, y, color); + } + + drawString(stack, string, x, y, color = -1) { + this.minecraft.fontRenderer.drawString(stack, string, x, y, color); + } + + getStringWidth(stack, string) { + return this.minecraft.fontRenderer.getStringWidth(string); + } drawRect(stack, left, top, right, bottom, color, alpha = 1) { stack.save(); @@ -8,18 +32,6 @@ window.Gui = class { stack.restore(); } - drawCenteredString(stack, string, x, y, color = -1) { - FontRenderer.INSTANCE.drawString(stack, string, x - this.getStringWidth(stack, string) / 2, y, color); - } - - drawString(stack, string, x, y, color = -1) { - FontRenderer.INSTANCE.drawString(stack, string, x, y, color); - } - - getStringWidth(stack, string) { - return FontRenderer.INSTANCE.getStringWidth(string); - } - drawTexture(stack, texture, x, y, width, height, alpha = 1.0) { Gui.drawSprite(stack, texture, 0, 0, 256, 256, x, y, width, height, alpha); } @@ -109,8 +121,4 @@ window.Gui = class { stack.drawImage(texture, spriteX, spriteY, spriteWidth, spriteHeight, x, y, width, height); stack.restore(); } - - static loadTexture(path) { - return document.textures[path]; - } } \ No newline at end of file diff --git a/src/js/net/minecraft/client/gui/GuiScreen.js b/src/js/net/minecraft/client/gui/GuiScreen.js index 8b211f8..85b2cf9 100644 --- a/src/js/net/minecraft/client/gui/GuiScreen.js +++ b/src/js/net/minecraft/client/gui/GuiScreen.js @@ -1,4 +1,6 @@ -window.GuiScreen = class extends Gui { +import Gui from "./Gui.js"; + +export default class GuiScreen extends Gui { constructor() { super(); @@ -25,6 +27,7 @@ window.GuiScreen = class extends Gui { drawScreen(stack, mouseX, mouseY, partialTicks) { for (let i in this.buttonList) { let button = this.buttonList[i]; + button.minecraft = this.minecraft; button.render(stack, mouseX, mouseY, partialTicks); } } @@ -53,5 +56,4 @@ window.GuiScreen = class extends Gui { } } } - } \ No newline at end of file diff --git a/src/js/net/minecraft/client/gui/IngameOverlay.js b/src/js/net/minecraft/client/gui/IngameOverlay.js index 5dfbba5..79534e0 100644 --- a/src/js/net/minecraft/client/gui/IngameOverlay.js +++ b/src/js/net/minecraft/client/gui/IngameOverlay.js @@ -1,12 +1,15 @@ -window.IngameOverlay = class extends Gui { +import Gui from "./Gui.js"; +import Block from "../world/block/Block.js"; + +export default class IngameOverlay extends Gui { constructor(minecraft, window) { super(); this.minecraft = minecraft; this.window = window; - this.textureCrosshair = Gui.loadTexture("gui/icons.png"); - this.textureHotbar = Gui.loadTexture("gui/gui.png"); + this.textureCrosshair = minecraft.resources["gui/icons.png"]; + this.textureHotbar = minecraft.resources["gui/gui.png"]; } render(stack, mouseX, mouseY, partialTicks) { diff --git a/src/js/net/minecraft/client/gui/screens/GuiControls.js b/src/js/net/minecraft/client/gui/screens/GuiControls.js index 6872628..c27e574 100644 --- a/src/js/net/minecraft/client/gui/screens/GuiControls.js +++ b/src/js/net/minecraft/client/gui/screens/GuiControls.js @@ -1,4 +1,8 @@ -window.GuiControls = class extends GuiScreen { +import GuiScreen from "../GuiScreen.js"; +import GuiKeyButton from "../widgets/GuiKeyButton.js"; +import GuiButton from "../widgets/GuiButton.js"; + +export default class GuiControls extends GuiScreen { constructor(previousScreen) { super(); diff --git a/src/js/net/minecraft/client/gui/screens/GuiIngameMenu.js b/src/js/net/minecraft/client/gui/screens/GuiIngameMenu.js index 61cee71..c004f9f 100644 --- a/src/js/net/minecraft/client/gui/screens/GuiIngameMenu.js +++ b/src/js/net/minecraft/client/gui/screens/GuiIngameMenu.js @@ -1,4 +1,8 @@ -window.GuiIngameMenu = class extends GuiScreen { +import GuiButton from "../widgets/GuiButton.js"; +import GuiControls from "./GuiControls.js"; +import GuiScreen from "../GuiScreen.js"; + +export default class GuiIngameMenu extends GuiScreen { constructor() { super(); diff --git a/src/js/net/minecraft/client/gui/screens/GuiLoadingScreen.js b/src/js/net/minecraft/client/gui/screens/GuiLoadingScreen.js index 067f950..f6f47e9 100644 --- a/src/js/net/minecraft/client/gui/screens/GuiLoadingScreen.js +++ b/src/js/net/minecraft/client/gui/screens/GuiLoadingScreen.js @@ -1,9 +1,14 @@ -window.GuiLoadingScreen = class extends GuiScreen { +import GuiScreen from "../GuiScreen.js"; + +export default class GuiLoadingScreen extends GuiScreen { constructor() { super(); + } - this.textureBackground = Gui.loadTexture("gui/background.png"); + init() { + super.init(); + this.textureBackground = this.getTexture("gui/background.png"); } drawScreen(stack, mouseX, mouseY, partialTicks) { @@ -53,5 +58,4 @@ window.GuiLoadingScreen = class extends GuiScreen { keyTyped(key) { // Cancel key inputs } - } \ No newline at end of file diff --git a/src/js/net/minecraft/client/gui/widgets/GuiButton.js b/src/js/net/minecraft/client/gui/widgets/GuiButton.js index c8c707f..51f2994 100644 --- a/src/js/net/minecraft/client/gui/widgets/GuiButton.js +++ b/src/js/net/minecraft/client/gui/widgets/GuiButton.js @@ -1,6 +1,6 @@ -window.GuiButton = class extends Gui { +import Gui from "../Gui.js"; - static textureGui = Gui.loadTexture("gui/gui.png"); +export default class GuiButton extends Gui { constructor(string, x, y, width, height, callback) { super(); @@ -14,8 +14,10 @@ window.GuiButton = class extends Gui { } render(stack, mouseX, mouseY, partialTicks) { + let textureGui = this.getTexture("gui/gui.png"); + let mouseOver = this.isMouseOver(mouseX, mouseY); - this.drawSprite(stack, GuiButton.textureGui, 0, 66 + (mouseOver ? 20 : 0), 200, 20, this.x, this.y, this.width, this.height); + this.drawSprite(stack, textureGui, 0, 66 + (mouseOver ? 20 : 0), 200, 20, this.x, this.y, this.width, this.height); this.drawCenteredString(stack, this.string, this.x + this.width / 2, this.y + this.height / 2 - 4); } diff --git a/src/js/net/minecraft/client/gui/widgets/GuiKeyButton.js b/src/js/net/minecraft/client/gui/widgets/GuiKeyButton.js index d425927..a1131f3 100644 --- a/src/js/net/minecraft/client/gui/widgets/GuiKeyButton.js +++ b/src/js/net/minecraft/client/gui/widgets/GuiKeyButton.js @@ -1,4 +1,6 @@ -window.GuiKeyButton = class extends GuiButton { +import GuiButton from "./GuiButton.js"; + +export default class GuiKeyButton extends GuiButton { constructor(name, key, x, y, width, height, callback) { super(name + ": " + key, x, y, width, height, _ => callback(this.key)); diff --git a/src/js/net/minecraft/client/inventory/Inventory.js b/src/js/net/minecraft/client/inventory/Inventory.js index 0693259..01ddc24 100644 --- a/src/js/net/minecraft/client/inventory/Inventory.js +++ b/src/js/net/minecraft/client/inventory/Inventory.js @@ -1,4 +1,4 @@ -window.Inventory = class { +export default class Inventory { constructor() { this.selectedSlotIndex = 0; diff --git a/src/js/net/minecraft/client/render/BlockRenderer.js b/src/js/net/minecraft/client/render/BlockRenderer.js index 97246ec..e47557c 100644 --- a/src/js/net/minecraft/client/render/BlockRenderer.js +++ b/src/js/net/minecraft/client/render/BlockRenderer.js @@ -1,4 +1,10 @@ -window.BlockRenderer = class { +import EnumBlockFace from "../../util/EnumBlockFace.js"; +import BlockRenderType from "../../util/BlockRenderType.js"; +import Tessellator from "./Tessellator.js"; +import MathHelper from "../../util/MathHelper.js"; +import Block from "../world/block/Block.js"; + +export default class BlockRenderer { static CLASSIC_LIGHTNING = false; diff --git a/src/js/net/minecraft/client/render/Tessellator.js b/src/js/net/minecraft/client/render/Tessellator.js index cb62497..1579d20 100644 --- a/src/js/net/minecraft/client/render/Tessellator.js +++ b/src/js/net/minecraft/client/render/Tessellator.js @@ -1,4 +1,4 @@ -window.Tessellator = class { +export default class Tessellator { constructor() { this.material = new THREE.MeshBasicMaterial({ diff --git a/src/js/net/minecraft/client/render/WorldRenderer.js b/src/js/net/minecraft/client/render/WorldRenderer.js index 96ae66b..16f67dc 100644 --- a/src/js/net/minecraft/client/render/WorldRenderer.js +++ b/src/js/net/minecraft/client/render/WorldRenderer.js @@ -1,4 +1,10 @@ -window.WorldRenderer = class { +import BlockRenderer from "./BlockRenderer.js"; +import EntityRenderManager from "./entity/EntityRenderManager.js"; +import MathHelper from "../../util/MathHelper.js"; +import ChunkSection from "../world/ChunkSection.js"; +import Block from "../world/block/Block.js"; + +export default class WorldRenderer { static RENDER_DISTANCE = 4; static THIRD_PERSON_DISTANCE = 4; diff --git a/src/js/net/minecraft/client/render/entity/EntityRenderManager.js b/src/js/net/minecraft/client/render/entity/EntityRenderManager.js index 5116008..6baaf7c 100644 --- a/src/js/net/minecraft/client/render/entity/EntityRenderManager.js +++ b/src/js/net/minecraft/client/render/entity/EntityRenderManager.js @@ -1,4 +1,7 @@ -window.EntityRenderManager = class { +import PlayerRenderer from "./entity/PlayerRenderer.js"; +import PlayerEntity from "../../entity/PlayerEntity.js"; + +export default class EntityRenderManager { constructor(worldRenderer) { this.worldRenderer = worldRenderer; diff --git a/src/js/net/minecraft/client/render/entity/EntityRenderer.js b/src/js/net/minecraft/client/render/entity/EntityRenderer.js index 867f9a9..4b383fd 100644 --- a/src/js/net/minecraft/client/render/entity/EntityRenderer.js +++ b/src/js/net/minecraft/client/render/entity/EntityRenderer.js @@ -1,4 +1,7 @@ -window.EntityRenderer = class { +import Tessellator from "../Tessellator.js"; +import MathHelper from "../../../util/MathHelper.js"; + +export default class EntityRenderer { constructor(model) { this.model = model; diff --git a/src/js/net/minecraft/client/render/entity/entity/PlayerRenderer.js b/src/js/net/minecraft/client/render/entity/entity/PlayerRenderer.js index 4b3c861..31b55ed 100644 --- a/src/js/net/minecraft/client/render/entity/entity/PlayerRenderer.js +++ b/src/js/net/minecraft/client/render/entity/entity/PlayerRenderer.js @@ -1,4 +1,8 @@ -window.PlayerRenderer = class extends EntityRenderer { +import ModelPlayer from "../../model/model/ModelPlayer.js"; +import EntityRenderer from "../EntityRenderer.js"; +import Block from "../../../world/block/Block.js"; + +export default class PlayerRenderer extends EntityRenderer { constructor(worldRenderer) { super(new ModelPlayer()); diff --git a/src/js/net/minecraft/client/render/gui/FontRenderer.js b/src/js/net/minecraft/client/render/gui/FontRenderer.js index 421e7d5..cdbac30 100644 --- a/src/js/net/minecraft/client/render/gui/FontRenderer.js +++ b/src/js/net/minecraft/client/render/gui/FontRenderer.js @@ -1,15 +1,17 @@ -window.FontRenderer = class { +import Gui from "../../gui/Gui.js"; + +export default class FontRenderer { static BITMAP_SIZE = 16; static FIELD_SIZE = 8; static COLOR_CODE_INDEX_LOOKUP = "0123456789abcdef"; - constructor() { + constructor(minecraft) { this.charWidths = []; this.isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); - this.texture = Gui.loadTexture("gui/font.png") + this.texture = minecraft.resources["gui/font.png"]; let bitMap = this.createBitMap(this.texture); @@ -136,6 +138,4 @@ window.FontRenderer = class { canvas.getContext('2d').drawImage(img, 0, 0, img.width, img.height); return canvas.getContext('2d').getImageData(0, 0, img.width, img.height).data; } -} - -window.FontRenderer.INSTANCE = new FontRenderer(); +} \ No newline at end of file diff --git a/src/js/net/minecraft/client/render/gui/ItemRenderer.js b/src/js/net/minecraft/client/render/gui/ItemRenderer.js index c11ab65..56ac632 100644 --- a/src/js/net/minecraft/client/render/gui/ItemRenderer.js +++ b/src/js/net/minecraft/client/render/gui/ItemRenderer.js @@ -1,4 +1,6 @@ -window.ItemRenderer = class { +import Block from "../../world/block/Block.js"; + +export default class ItemRenderer { constructor(minecraft, window) { this.minecraft = minecraft; diff --git a/src/js/net/minecraft/client/render/gui/ScreenRenderer.js b/src/js/net/minecraft/client/render/gui/ScreenRenderer.js index 081cfb5..ab5a62e 100644 --- a/src/js/net/minecraft/client/render/gui/ScreenRenderer.js +++ b/src/js/net/minecraft/client/render/gui/ScreenRenderer.js @@ -1,4 +1,4 @@ -window.ScreenRenderer = class { +export default class ScreenRenderer { constructor(minecraft, window) { this.minecraft = minecraft; diff --git a/src/js/net/minecraft/client/render/isometric/IsometricRenderer.js b/src/js/net/minecraft/client/render/isometric/IsometricRenderer.js index f3eb1f7..8f60df1 100644 --- a/src/js/net/minecraft/client/render/isometric/IsometricRenderer.js +++ b/src/js/net/minecraft/client/render/isometric/IsometricRenderer.js @@ -1,4 +1,8 @@ -window.IsometricRenderer = class { +import TextCoord from "./TextCoord.js"; +import Point from "./Point.js"; +import Triangle from "./Triangle.js"; + +export default class IsometricRenderer { // http://jsfiddle.net/xzL58dha/3/ diff --git a/src/js/net/minecraft/client/render/isometric/Point.js b/src/js/net/minecraft/client/render/isometric/Point.js index 0798a87..3cf3976 100644 --- a/src/js/net/minecraft/client/render/isometric/Point.js +++ b/src/js/net/minecraft/client/render/isometric/Point.js @@ -1,4 +1,4 @@ -window.Point = class { +export default class Point { constructor(x, y) { this.x = x ? x : 0; this.y = y ? y : 0; diff --git a/src/js/net/minecraft/client/render/isometric/TextCoord.js b/src/js/net/minecraft/client/render/isometric/TextCoord.js index 306913d..5aba111 100644 --- a/src/js/net/minecraft/client/render/isometric/TextCoord.js +++ b/src/js/net/minecraft/client/render/isometric/TextCoord.js @@ -1,4 +1,4 @@ -window.TextCoord = class { +export default class TextCoord { constructor(u, v) { this.u = u ? u : 0; this.v = v ? v : 0; diff --git a/src/js/net/minecraft/client/render/isometric/Triangle.js b/src/js/net/minecraft/client/render/isometric/Triangle.js index d57300a..69b0f04 100644 --- a/src/js/net/minecraft/client/render/isometric/Triangle.js +++ b/src/js/net/minecraft/client/render/isometric/Triangle.js @@ -1,4 +1,4 @@ -window.Triangle = class { +export default class Triangle { constructor(p0, p1, p2, t0, t1, t2) { this.p0 = p0; this.p1 = p1; diff --git a/src/js/net/minecraft/client/render/model/ModelBase.js b/src/js/net/minecraft/client/render/model/ModelBase.js index 3f1c7d0..6d7a5ae 100644 --- a/src/js/net/minecraft/client/render/model/ModelBase.js +++ b/src/js/net/minecraft/client/render/model/ModelBase.js @@ -1,4 +1,4 @@ -window.ModelBase = class { +export default class ModelBase { /** * Rebuild the model diff --git a/src/js/net/minecraft/client/render/model/model/ModelPlayer.js b/src/js/net/minecraft/client/render/model/model/ModelPlayer.js index 57cc6f0..56c909b 100644 --- a/src/js/net/minecraft/client/render/model/model/ModelPlayer.js +++ b/src/js/net/minecraft/client/render/model/model/ModelPlayer.js @@ -1,4 +1,8 @@ -window.ModelPlayer = class extends ModelBase { +import ModelRenderer from "../renderer/ModelRenderer.js"; +import MathHelper from "../../../../util/MathHelper.js"; +import ModelBase from "../ModelBase.js"; + +export default class ModelPlayer extends ModelBase { /** * Create cubes for the zombie model diff --git a/src/js/net/minecraft/client/render/model/renderer/ModelRenderer.js b/src/js/net/minecraft/client/render/model/renderer/ModelRenderer.js index a6fd787..0235729 100644 --- a/src/js/net/minecraft/client/render/model/renderer/ModelRenderer.js +++ b/src/js/net/minecraft/client/render/model/renderer/ModelRenderer.js @@ -1,4 +1,7 @@ -window.ModelRenderer = class { +import Polygon from "./Polygon.js"; +import Vertex from "./Vertex.js"; + +export default class ModelRenderer { /** * Create cube object diff --git a/src/js/net/minecraft/client/render/model/renderer/Polygon.js b/src/js/net/minecraft/client/render/model/renderer/Polygon.js index 46f48b0..198a8f4 100644 --- a/src/js/net/minecraft/client/render/model/renderer/Polygon.js +++ b/src/js/net/minecraft/client/render/model/renderer/Polygon.js @@ -1,4 +1,6 @@ -window.Polygon = class { +import Vertex from "./Vertex.js"; + +export default class Polygon { constructor(vertices, minU, minV, maxU, maxV, textureWidth, textureHeight) { this.vertices = vertices; diff --git a/src/js/net/minecraft/client/render/model/renderer/Vertex.js b/src/js/net/minecraft/client/render/model/renderer/Vertex.js index af70637..796942c 100644 --- a/src/js/net/minecraft/client/render/model/renderer/Vertex.js +++ b/src/js/net/minecraft/client/render/model/renderer/Vertex.js @@ -1,4 +1,6 @@ -window.Vertex = class { +import Vector3 from "../../../../util/Vector3.js"; + +export default class Vertex { /** * A vertex contains a 3 float vector position and UV coordinates diff --git a/src/js/net/minecraft/client/sound/SoundManager.js b/src/js/net/minecraft/client/sound/SoundManager.js index 46239de..54ddd7b 100644 --- a/src/js/net/minecraft/client/sound/SoundManager.js +++ b/src/js/net/minecraft/client/sound/SoundManager.js @@ -1,4 +1,6 @@ -window.SoundManager = class { +import Block from "../world/block/Block.js"; + +export default class SoundManager { constructor() { this.audioLoader = new THREE.AudioLoader(); diff --git a/src/js/net/minecraft/client/world/Chunk.js b/src/js/net/minecraft/client/world/Chunk.js index a4f0898..c22be53 100644 --- a/src/js/net/minecraft/client/world/Chunk.js +++ b/src/js/net/minecraft/client/world/Chunk.js @@ -1,4 +1,9 @@ -window.Chunk = class { +import EnumSkyBlock from "../../util/EnumSkyBlock.js"; +import Block from "./block/Block.js"; +import World from "./World.js"; +import ChunkSection from "./ChunkSection.js"; + +export default class Chunk { constructor(world, x, z) { this.world = world; @@ -92,7 +97,7 @@ window.Chunk = class { } } - this.world.updateLight(EnumSkyBlock.Block, + this.world.updateLight(EnumSkyBlock.BLOCK, this.x * 16, targetY - 1, this.z * 16, this.x * 16 + 16, targetY + 1, this.z * 16 + 16 ); diff --git a/src/js/net/minecraft/client/world/ChunkSection.js b/src/js/net/minecraft/client/world/ChunkSection.js index b366aad..d82abe4 100644 --- a/src/js/net/minecraft/client/world/ChunkSection.js +++ b/src/js/net/minecraft/client/world/ChunkSection.js @@ -1,4 +1,7 @@ -window.ChunkSection = class { +import EnumSkyBlock from "../../util/EnumSkyBlock.js"; +import Block from "./block/Block.js"; + +export default class ChunkSection { static SIZE = 16; diff --git a/src/js/net/minecraft/client/world/World.js b/src/js/net/minecraft/client/world/World.js index 1fc1fc4..a68898d 100644 --- a/src/js/net/minecraft/client/world/World.js +++ b/src/js/net/minecraft/client/world/World.js @@ -1,4 +1,15 @@ -window.World = class { +import ChunkSection from "./ChunkSection.js"; +import WorldGenerator from "./generator/WorldGenerator.js"; +import Chunk from "./Chunk.js"; +import MathHelper from "../../util/MathHelper.js"; +import BoundingBox from "../../util/BoundingBox.js"; +import MetadataChunkBlock from "../../util/MetadataChunkBlock.js"; +import EnumSkyBlock from "../../util/EnumSkyBlock.js"; +import Block from "./block/Block.js"; +import EnumBlockFace from "../../util/EnumBlockFace.js"; +import Vector3 from "../../util/Vector3.js"; + +export default class World { static TOTAL_HEIGHT = ChunkSection.SIZE * 8 - 1; // ChunkSection.SIZE * 16 - 1; diff --git a/src/js/net/minecraft/client/world/block/Block.js b/src/js/net/minecraft/client/world/block/Block.js index 37f85fa..f0bc39c 100644 --- a/src/js/net/minecraft/client/world/block/Block.js +++ b/src/js/net/minecraft/client/world/block/Block.js @@ -1,29 +1,14 @@ -window.Block = class { +import BlockRenderType from "../../../util/BlockRenderType.js"; +import EnumBlockFace from "../../../util/EnumBlockFace.js"; +import MovingObjectPosition from "../../../util/MovingObjectPosition.js"; +import BoundingBox from "../../../util/BoundingBox.js"; + +export default class Block { static blocks = new Map(); static sounds = {}; - static create() { - // Sounds - Block.sounds.stone = new Sound("stone", 1.0); - Block.sounds.wood = new Sound("wood", 1.0); - Block.sounds.gravel = new Sound("gravel", 1.0); - Block.sounds.grass = new Sound("grass", 1.0); - Block.sounds.cloth = new Sound("cloth", 1.0); - Block.sounds.sand = new Sound("sand", 1.0); - - // Blocks - Block.STONE = new BlockStone(1, 0); - Block.GRASS = new BlockGrass(2, 1); - Block.DIRT = new BlockDirt(3, 2); - Block.LOG = new BlockLog(17, 4); - Block.LEAVE = new BlockLeave(18, 6); - Block.WATER = new BlockWater(9, 7); - Block.SAND = new BlockSand(12, 8) - Block.TORCH = new BlockTorch(50, 9) - } - constructor(id, textureSlotId = id) { this.id = id; this.textureSlotId = textureSlotId; @@ -209,5 +194,5 @@ window.Block = class { static getById(typeId) { return Block.blocks.get(typeId); } +} -} \ No newline at end of file diff --git a/src/js/net/minecraft/client/world/block/BlockDirt.js b/src/js/net/minecraft/client/world/block/BlockDirt.js index 232e010..7c56ae9 100644 --- a/src/js/net/minecraft/client/world/block/BlockDirt.js +++ b/src/js/net/minecraft/client/world/block/BlockDirt.js @@ -1,4 +1,6 @@ -window.BlockDirt = class extends Block { +import Block from "./Block.js"; + +export default class BlockDirt extends Block { constructor(id, textureSlotId) { super(id, textureSlotId); diff --git a/src/js/net/minecraft/client/world/block/BlockGrass.js b/src/js/net/minecraft/client/world/block/BlockGrass.js index 408d63e..cf51c46 100644 --- a/src/js/net/minecraft/client/world/block/BlockGrass.js +++ b/src/js/net/minecraft/client/world/block/BlockGrass.js @@ -1,4 +1,7 @@ -window.BlockGrass = class extends Block { +import Block from "./Block.js"; +import EnumBlockFace from "../../../util/EnumBlockFace.js"; + +export default class BlockGrass extends Block { constructor(id, textureSlotId) { super(id, textureSlotId); diff --git a/src/js/net/minecraft/client/world/block/BlockLeave.js b/src/js/net/minecraft/client/world/block/BlockLeave.js index b69ec12..256cd1b 100644 --- a/src/js/net/minecraft/client/world/block/BlockLeave.js +++ b/src/js/net/minecraft/client/world/block/BlockLeave.js @@ -1,4 +1,6 @@ -window.BlockLeave = class extends Block { +import Block from "./Block.js"; + +export default class BlockLeave extends Block { constructor(id, textureSlotId) { super(id, textureSlotId); diff --git a/src/js/net/minecraft/client/world/block/BlockLog.js b/src/js/net/minecraft/client/world/block/BlockLog.js index 6e09af6..eb5b2ec 100644 --- a/src/js/net/minecraft/client/world/block/BlockLog.js +++ b/src/js/net/minecraft/client/world/block/BlockLog.js @@ -1,4 +1,6 @@ -window.BlockLog = class extends Block { +import Block from "./Block.js"; + +export default class BlockLog extends Block { constructor(id, textureSlotId) { super(id, textureSlotId); diff --git a/src/js/net/minecraft/client/world/block/BlockRegistry.js b/src/js/net/minecraft/client/world/block/BlockRegistry.js new file mode 100644 index 0000000..c19297c --- /dev/null +++ b/src/js/net/minecraft/client/world/block/BlockRegistry.js @@ -0,0 +1,33 @@ +import BlockLog from "./BlockLog.js"; +import BlockStone from "./BlockStone.js"; +import BlockGrass from "./BlockGrass.js"; +import BlockDirt from "./BlockDirt.js"; +import BlockLeave from "./BlockLeave.js"; +import BlockWater from "./BlockWater.js"; +import BlockSand from "./BlockSand.js"; +import BlockTorch from "./BlockTorch.js"; +import Sound from "./sound/Sound.js"; +import Block from "./Block.js"; + +export class BlockRegistry { + + static create() { + // Sounds + Block.sounds.stone = new Sound("stone", 1.0); + Block.sounds.wood = new Sound("wood", 1.0); + Block.sounds.gravel = new Sound("gravel", 1.0); + Block.sounds.grass = new Sound("grass", 1.0); + Block.sounds.cloth = new Sound("cloth", 1.0); + Block.sounds.sand = new Sound("sand", 1.0); + + // Blocks + Block.STONE = new BlockStone(1, 0); + Block.GRASS = new BlockGrass(2, 1); + Block.DIRT = new BlockDirt(3, 2); + Block.LOG = new BlockLog(17, 4); + Block.LEAVE = new BlockLeave(18, 6); + Block.WATER = new BlockWater(9, 7); + Block.SAND = new BlockSand(12, 8) + Block.TORCH = new BlockTorch(50, 9) + } +} \ No newline at end of file diff --git a/src/js/net/minecraft/client/world/block/BlockSand.js b/src/js/net/minecraft/client/world/block/BlockSand.js index fd3bc49..9f045dd 100644 --- a/src/js/net/minecraft/client/world/block/BlockSand.js +++ b/src/js/net/minecraft/client/world/block/BlockSand.js @@ -1,4 +1,6 @@ -window.BlockSand = class extends Block { +import Block from "./Block.js"; + +export default class BlockSand extends Block { constructor(id, textureSlotId) { super(id, textureSlotId); diff --git a/src/js/net/minecraft/client/world/block/BlockStone.js b/src/js/net/minecraft/client/world/block/BlockStone.js index f7be028..2e3cee5 100644 --- a/src/js/net/minecraft/client/world/block/BlockStone.js +++ b/src/js/net/minecraft/client/world/block/BlockStone.js @@ -1,4 +1,6 @@ -window.BlockStone = class extends Block { +import Block from "./Block.js"; + +export default class BlockStone extends Block { constructor(id, textureSlotId) { super(id, textureSlotId); diff --git a/src/js/net/minecraft/client/world/block/BlockTorch.js b/src/js/net/minecraft/client/world/block/BlockTorch.js index 9051a87..b1abfca 100644 --- a/src/js/net/minecraft/client/world/block/BlockTorch.js +++ b/src/js/net/minecraft/client/world/block/BlockTorch.js @@ -1,4 +1,9 @@ -window.BlockTorch = class extends Block { +import BoundingBox from "../../../util/BoundingBox.js"; +import Block from "./Block.js"; +import EnumBlockFace from "../../../util/EnumBlockFace.js"; +import BlockRenderType from "../../../util/BlockRenderType.js"; + +export default class BlockTorch extends Block { constructor(id, textureSlotId) { super(id, textureSlotId); diff --git a/src/js/net/minecraft/client/world/block/BlockWater.js b/src/js/net/minecraft/client/world/block/BlockWater.js index 24ece1b..a95ea49 100644 --- a/src/js/net/minecraft/client/world/block/BlockWater.js +++ b/src/js/net/minecraft/client/world/block/BlockWater.js @@ -1,4 +1,6 @@ -window.BlockWater = class extends Block { +import Block from "./Block.js"; + +export default class BlockWater extends Block { constructor(id, textureSlotId) { super(id, textureSlotId); diff --git a/src/js/net/minecraft/client/world/block/sound/Sound.js b/src/js/net/minecraft/client/world/block/sound/Sound.js index d4f8753..dfcd468 100644 --- a/src/js/net/minecraft/client/world/block/sound/Sound.js +++ b/src/js/net/minecraft/client/world/block/sound/Sound.js @@ -1,4 +1,4 @@ -window.Sound = class { +export default class Sound { constructor(name, pitch) { this.name = name; diff --git a/src/js/net/minecraft/client/world/generator/NoiseGenerator.js b/src/js/net/minecraft/client/world/generator/NoiseGenerator.js index d69ae96..b65ba91 100644 --- a/src/js/net/minecraft/client/world/generator/NoiseGenerator.js +++ b/src/js/net/minecraft/client/world/generator/NoiseGenerator.js @@ -1,4 +1,4 @@ -window.NoiseGenerator = class { +export default class NoiseGenerator { perlin(x, z) { } diff --git a/src/js/net/minecraft/client/world/generator/WorldGenerator.js b/src/js/net/minecraft/client/world/generator/WorldGenerator.js index 1fe3429..e6891af 100644 --- a/src/js/net/minecraft/client/world/generator/WorldGenerator.js +++ b/src/js/net/minecraft/client/world/generator/WorldGenerator.js @@ -1,4 +1,10 @@ -window.WorldGenerator = class { +import Random from "../../../util/Random.js"; +import NoiseGeneratorCombined from "./noise/NoiseGeneratorCombined.js"; +import NoiseGeneratorOctaves from "./noise/NoiseGeneratorOctaves.js"; +import ChunkSection from "../ChunkSection.js"; +import Block from "../block/Block.js"; + +export default class WorldGenerator { constructor(world, seed) { this.world = world; diff --git a/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorCombined.js b/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorCombined.js index e29885f..ae8e9ec 100644 --- a/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorCombined.js +++ b/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorCombined.js @@ -1,4 +1,6 @@ -window.NoiseGeneratorCombined = class extends NoiseGenerator { +import NoiseGenerator from "../NoiseGenerator.js"; + +export default class NoiseGeneratorCombined extends NoiseGenerator { constructor(firstGenerator, secondGenerator) { super(); diff --git a/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorOctaves.js b/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorOctaves.js index 59f5123..0948459 100644 --- a/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorOctaves.js +++ b/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorOctaves.js @@ -1,4 +1,7 @@ -window.NoiseGeneratorOctaves = class extends NoiseGenerator { +import NoiseGenerator from "../NoiseGenerator.js"; +import NoiseGeneratorPerlin from "./NoiseGeneratorPerlin.js"; + +export default class NoiseGeneratorOctaves extends NoiseGenerator { constructor(random, octaves) { super(); diff --git a/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorPerlin.js b/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorPerlin.js index f5bf6f3..c7b6043 100644 --- a/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorPerlin.js +++ b/src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorPerlin.js @@ -1,4 +1,6 @@ -window.NoiseGeneratorPerlin = class extends NoiseGenerator { +import NoiseGenerator from "../NoiseGenerator.js"; + +export default class NoiseGeneratorPerlin extends NoiseGenerator { constructor(random) { super(); diff --git a/src/js/net/minecraft/util/BlockRenderType.js b/src/js/net/minecraft/util/BlockRenderType.js index f902edf..27dd063 100644 --- a/src/js/net/minecraft/util/BlockRenderType.js +++ b/src/js/net/minecraft/util/BlockRenderType.js @@ -1,4 +1,4 @@ -window.BlockRenderType = class { +export default class BlockRenderType { static BLOCK = 0; static TORCH = 1; } \ No newline at end of file diff --git a/src/js/net/minecraft/util/BoundingBox.js b/src/js/net/minecraft/util/BoundingBox.js index 79c5e8d..dc4095b 100644 --- a/src/js/net/minecraft/util/BoundingBox.js +++ b/src/js/net/minecraft/util/BoundingBox.js @@ -1,4 +1,4 @@ -window.BoundingBox = class { +export default class BoundingBox { /** * Bounding box diff --git a/src/js/net/minecraft/util/EnumBlockFace.js b/src/js/net/minecraft/util/EnumBlockFace.js index ffb362b..0ea0157 100644 --- a/src/js/net/minecraft/util/EnumBlockFace.js +++ b/src/js/net/minecraft/util/EnumBlockFace.js @@ -1,4 +1,11 @@ -window.EnumBlockFace = class { +export default class EnumBlockFace { + + static TOP = new EnumBlockFace(0, 1, 0); + static BOTTOM = new EnumBlockFace(0, -1, 0); + static NORTH = new EnumBlockFace(0, 0, -1); + static EAST = new EnumBlockFace(1, 0, 0); + static SOUTH = new EnumBlockFace(0, 0, 1); + static WEST = new EnumBlockFace(-1, 0, 0); constructor(x, y, z) { this.x = x; @@ -47,24 +54,11 @@ window.EnumBlockFace = class { return null; } - static values() { - return [ - EnumBlockFace.TOP, - EnumBlockFace.BOTTOM, - EnumBlockFace.NORTH, - EnumBlockFace.EAST, - EnumBlockFace.SOUTH, - EnumBlockFace.WEST - ]; + equals(other) { + return this.x === other.x && this.y === other.y && this.z === other.z; } -} -{ - let c = window.EnumBlockFace; - c.TOP = new EnumBlockFace(0, 1, 0); - c.BOTTOM = new EnumBlockFace(0, -1, 0); - c.NORTH = new EnumBlockFace(0, 0, -1); - c.EAST = new EnumBlockFace(1, 0, 0); - c.SOUTH = new EnumBlockFace(0, 0, 1); - c.WEST = new EnumBlockFace(-1, 0, 0); -} + static values() { + return [EnumBlockFace.TOP, EnumBlockFace.BOTTOM, EnumBlockFace.NORTH, EnumBlockFace.EAST, EnumBlockFace.SOUTH, EnumBlockFace.WEST]; + } +} \ No newline at end of file diff --git a/src/js/net/minecraft/util/EnumSkyBlock.js b/src/js/net/minecraft/util/EnumSkyBlock.js index d17fd00..e07fcc9 100644 --- a/src/js/net/minecraft/util/EnumSkyBlock.js +++ b/src/js/net/minecraft/util/EnumSkyBlock.js @@ -1,4 +1,4 @@ -window.EnumSkyBlock = class { +export default class EnumSkyBlock { static SKY = 0; static BLOCK = 1; } \ No newline at end of file diff --git a/src/js/net/minecraft/util/Keyboard.js b/src/js/net/minecraft/util/Keyboard.js index 83003bb..57e06bd 100644 --- a/src/js/net/minecraft/util/Keyboard.js +++ b/src/js/net/minecraft/util/Keyboard.js @@ -1,17 +1,14 @@ -window.Keyboard = class { +export default class Keyboard { static state = {}; static create() { window.addEventListener('keydown', function (event) { - //event.preventDefault(); Keyboard.state[event.code] = true; - //console.log("Key " + event.code + " down"); }); window.addEventListener('keyup', function (event) { event.preventDefault(); delete Keyboard.state[event.code]; - //console.log("Key " + event.code + " up"); }); }; diff --git a/src/js/net/minecraft/util/MathHelper.js b/src/js/net/minecraft/util/MathHelper.js index 3dd5c7f..6809284 100644 --- a/src/js/net/minecraft/util/MathHelper.js +++ b/src/js/net/minecraft/util/MathHelper.js @@ -1,4 +1,4 @@ -window.MathHelper = class { +export default class MathHelper { /** * Returns the greatest integer less than or equal to the double argument diff --git a/src/js/net/minecraft/util/MetadataChunkBlock.js b/src/js/net/minecraft/util/MetadataChunkBlock.js index bb7fd99..4ef3a92 100644 --- a/src/js/net/minecraft/util/MetadataChunkBlock.js +++ b/src/js/net/minecraft/util/MetadataChunkBlock.js @@ -1,4 +1,8 @@ -window.MetadataChunkBlock = class { +import Block from "../client/world/block/Block.js"; +import EnumSkyBlock from "./EnumSkyBlock.js"; +import World from "../client/world/World.js"; + +export default class MetadataChunkBlock { constructor(type, x1, y1, z1, x2, y2, z2) { this.type = type; diff --git a/src/js/net/minecraft/util/MovingObjectPosition.js b/src/js/net/minecraft/util/MovingObjectPosition.js index d24d496..a13452a 100644 --- a/src/js/net/minecraft/util/MovingObjectPosition.js +++ b/src/js/net/minecraft/util/MovingObjectPosition.js @@ -1,4 +1,4 @@ -window.MovingObjectPosition = class { +export default class MovingObjectPosition { constructor(vector, face, x, y, z) { this.vector = vector; diff --git a/src/js/net/minecraft/util/Random.js b/src/js/net/minecraft/util/Random.js index ca8e88d..6714957 100644 --- a/src/js/net/minecraft/util/Random.js +++ b/src/js/net/minecraft/util/Random.js @@ -1,4 +1,4 @@ -window.Random = class { +export default class Random { static instances = 0; diff --git a/src/js/net/minecraft/util/Timer.js b/src/js/net/minecraft/util/Timer.js index b0ef972..216e960 100644 --- a/src/js/net/minecraft/util/Timer.js +++ b/src/js/net/minecraft/util/Timer.js @@ -1,4 +1,4 @@ -window.Timer = class { +export default class Timer { static MS_PER_SECOND = 1000; static MAX_MS_PER_UPDATE = 1000; @@ -63,4 +63,4 @@ window.Timer = class { this.passedTime -= this.ticks; this.partialTicks = this.passedTime; } -} +} \ No newline at end of file diff --git a/src/js/net/minecraft/util/Vector3.js b/src/js/net/minecraft/util/Vector3.js index 0d0cc8b..939b3ca 100644 --- a/src/js/net/minecraft/util/Vector3.js +++ b/src/js/net/minecraft/util/Vector3.js @@ -1,4 +1,4 @@ -window.Vector3 = class { +export default class Vector3 { constructor(x = 0, y = 0, z = 0) { this.x = x; diff --git a/src/start.js b/src/start.js index 2782cb3..7439910 100644 --- a/src/start.js +++ b/src/start.js @@ -1,3 +1,7 @@ +import Minecraft from './js/net/minecraft/client/Minecraft.js'; + +let resources = []; + // Browser test function function isES6() { try { @@ -42,8 +46,6 @@ function loadTexture(textures) { let total = textures.length; let index = 0; - document.textures = []; - return textures.reduce((currentPromise, texturePath) => { return currentPromise.then(() => { return new Promise((resolve, reject) => { @@ -54,7 +56,7 @@ function loadTexture(textures) { let image = new Image(); image.src = "src/resources/" + texturePath; image.onload = () => resolve(); - document.textures[texturePath] = image; + resources[texturePath] = image; index++; }); @@ -83,78 +85,12 @@ loadTexture([ // Dependencies "libraries/three.min.js", "libraries/stats.min.js", - "libraries/context-filter-polyfill.min.js", - - // Minecraft Source - "src/js/net/minecraft/util/EnumBlockFace.js", - "src/js/net/minecraft/util/Timer.js", - "src/js/net/minecraft/util/Random.js", - "src/js/net/minecraft/util/EnumBlockFace.js", - "src/js/net/minecraft/util/EnumSkyBlock.js", - "src/js/net/minecraft/util/MetadataChunkBlock.js", - "src/js/net/minecraft/util/Vector3.js", - "src/js/net/minecraft/util/MovingObjectPosition.js", - "src/js/net/minecraft/util/MathHelper.js", - "src/js/net/minecraft/util/BoundingBox.js", - "src/js/net/minecraft/util/Keyboard.js", - "src/js/net/minecraft/util/BlockRenderType.js", - "src/js/net/minecraft/client/gui/Gui.js", - "src/js/net/minecraft/client/gui/GuiScreen.js", - "src/js/net/minecraft/client/gui/widgets/GuiButton.js", - "src/js/net/minecraft/client/gui/widgets/GuiKeyButton.js", - "src/js/net/minecraft/client/gui/IngameOverlay.js", - "src/js/net/minecraft/client/gui/screens/GuiLoadingScreen.js", - "src/js/net/minecraft/client/gui/screens/GuiControls.js", - "src/js/net/minecraft/client/gui/screens/GuiIngameMenu.js", - "src/js/net/minecraft/client/GameWindow.js", - "src/js/net/minecraft/client/sound/SoundManager.js", - "src/js/net/minecraft/client/world/block/sound/Sound.js", - "src/js/net/minecraft/client/world/block/Block.js", - "src/js/net/minecraft/client/world/block/BlockStone.js", - "src/js/net/minecraft/client/world/block/BlockGrass.js", - "src/js/net/minecraft/client/world/block/BlockDirt.js", - "src/js/net/minecraft/client/world/block/BlockLog.js", - "src/js/net/minecraft/client/world/block/BlockLeave.js", - "src/js/net/minecraft/client/world/block/BlockWater.js", - "src/js/net/minecraft/client/world/block/BlockSand.js", - "src/js/net/minecraft/client/world/block/BlockTorch.js", - "src/js/net/minecraft/client/world/ChunkSection.js", - "src/js/net/minecraft/client/world/Chunk.js", - "src/js/net/minecraft/client/world/World.js", - "src/js/net/minecraft/client/world/generator/NoiseGenerator.js", - "src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorPerlin.js", - "src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorOctaves.js", - "src/js/net/minecraft/client/world/generator/noise/NoiseGeneratorCombined.js", - "src/js/net/minecraft/client/world/generator/WorldGenerator.js", - "src/js/net/minecraft/client/entity/Entity.js", - "src/js/net/minecraft/client/entity/EntityLiving.js", - "src/js/net/minecraft/client/entity/PlayerEntity.js", - "src/js/net/minecraft/client/inventory/Inventory.js", - "src/js/net/minecraft/client/GameSettings.js", - "src/js/net/minecraft/client/Minecraft.js", - "src/js/net/minecraft/client/render/isometric/IsometricRenderer.js", - "src/js/net/minecraft/client/render/isometric/Point.js", - "src/js/net/minecraft/client/render/isometric/TextCoord.js", - "src/js/net/minecraft/client/render/isometric/Triangle.js", - "src/js/net/minecraft/client/render/gui/FontRenderer.js", - "src/js/net/minecraft/client/render/gui/ScreenRenderer.js", - "src/js/net/minecraft/client/render/gui/ItemRenderer.js", - "src/js/net/minecraft/client/render/Tessellator.js", - "src/js/net/minecraft/client/render/model/ModelBase.js", - "src/js/net/minecraft/client/render/model/renderer/Vertex.js", - "src/js/net/minecraft/client/render/model/renderer/Polygon.js", - "src/js/net/minecraft/client/render/model/renderer/ModelRenderer.js", - "src/js/net/minecraft/client/render/model/model/ModelPlayer.js", - "src/js/net/minecraft/client/render/entity/EntityRenderer.js", - "src/js/net/minecraft/client/render/entity/entity/PlayerRenderer.js", - "src/js/net/minecraft/client/render/entity/EntityRenderManager.js", - "src/js/net/minecraft/client/render/WorldRenderer.js", - "src/js/net/minecraft/client/render/BlockRenderer.js" + "libraries/context-filter-polyfill.min.js" ]).then(() => { // Remove pre status document.getElementById("pre-status").remove(); // Start Minecraft - window.app = new Minecraft("canvas-container"); + window.app = new Minecraft("canvas-container", resources); }); }); \ No newline at end of file