convert classes to es6

(cherry picked from commit e7615d49a4071fe5b5f192884f142c9f3385211a)
This commit is contained in:
LabyStudio
2022-04-15 05:59:25 +02:00
parent dacd2496ea
commit 45961bbfbb
66 changed files with 319 additions and 210 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
</body> </body>
<script src="src/start.js"></script> <script type="module" src="src/start.js"></script>
</html> </html>
+1 -1
View File
@@ -1,4 +1,4 @@
window.GameSettings = class { export default class GameSettings {
constructor() { constructor() {
this.crouching = 'ShiftLeft'; this.crouching = 'ShiftLeft';
+4 -1
View File
@@ -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) { constructor(minecraft, canvasWrapperId) {
this.minecraft = minecraft; this.minecraft = minecraft;
+24 -3
View File
@@ -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 * Create Minecraft instance and render it on a canvas
*/ */
constructor(canvasWrapperId) { constructor(canvasWrapperId, resources) {
this.resources = resources;
this.currentScreen = null; this.currentScreen = null;
this.loadingScreen = null; this.loadingScreen = null;
@@ -34,10 +52,13 @@ window.Minecraft = class {
this.lastTime = Date.now(); this.lastTime = Date.now();
// Create all blocks // Create all blocks
Block.create(); BlockRegistry.create();
this.itemRenderer.initialize(); this.itemRenderer.initialize();
// Create font renderer
this.fontRenderer = new FontRenderer(this);
// Update window size // Update window size
this.window.updateWindowSize(); this.window.updateWindowSize();
+4 -1
View File
@@ -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) { constructor(minecraft, world) {
this.minecraft = minecraft; this.minecraft = minecraft;
@@ -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) { constructor(minecraft, world) {
super(minecraft, world); super(minecraft, world);
@@ -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"; static name = "PlayerEntity";
+25 -17
View File
@@ -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) { drawRect(stack, left, top, right, bottom, color, alpha = 1) {
stack.save(); stack.save();
@@ -8,18 +32,6 @@ window.Gui = class {
stack.restore(); 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) { drawTexture(stack, texture, x, y, width, height, alpha = 1.0) {
Gui.drawSprite(stack, texture, 0, 0, 256, 256, x, y, width, height, alpha); 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.drawImage(texture, spriteX, spriteY, spriteWidth, spriteHeight, x, y, width, height);
stack.restore(); stack.restore();
} }
static loadTexture(path) {
return document.textures[path];
}
} }
+4 -2
View File
@@ -1,4 +1,6 @@
window.GuiScreen = class extends Gui { import Gui from "./Gui.js";
export default class GuiScreen extends Gui {
constructor() { constructor() {
super(); super();
@@ -25,6 +27,7 @@ window.GuiScreen = class extends Gui {
drawScreen(stack, mouseX, mouseY, partialTicks) { drawScreen(stack, mouseX, mouseY, partialTicks) {
for (let i in this.buttonList) { for (let i in this.buttonList) {
let button = this.buttonList[i]; let button = this.buttonList[i];
button.minecraft = this.minecraft;
button.render(stack, mouseX, mouseY, partialTicks); button.render(stack, mouseX, mouseY, partialTicks);
} }
} }
@@ -53,5 +56,4 @@ window.GuiScreen = class extends Gui {
} }
} }
} }
} }
@@ -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) { constructor(minecraft, window) {
super(); super();
this.minecraft = minecraft; this.minecraft = minecraft;
this.window = window; this.window = window;
this.textureCrosshair = Gui.loadTexture("gui/icons.png"); this.textureCrosshair = minecraft.resources["gui/icons.png"];
this.textureHotbar = Gui.loadTexture("gui/gui.png"); this.textureHotbar = minecraft.resources["gui/gui.png"];
} }
render(stack, mouseX, mouseY, partialTicks) { render(stack, mouseX, mouseY, partialTicks) {
@@ -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) { constructor(previousScreen) {
super(); super();
@@ -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() { constructor() {
super(); super();
@@ -1,9 +1,14 @@
window.GuiLoadingScreen = class extends GuiScreen { import GuiScreen from "../GuiScreen.js";
export default class GuiLoadingScreen extends GuiScreen {
constructor() { constructor() {
super(); super();
}
this.textureBackground = Gui.loadTexture("gui/background.png"); init() {
super.init();
this.textureBackground = this.getTexture("gui/background.png");
} }
drawScreen(stack, mouseX, mouseY, partialTicks) { drawScreen(stack, mouseX, mouseY, partialTicks) {
@@ -53,5 +58,4 @@ window.GuiLoadingScreen = class extends GuiScreen {
keyTyped(key) { keyTyped(key) {
// Cancel key inputs // Cancel key inputs
} }
} }
@@ -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) { constructor(string, x, y, width, height, callback) {
super(); super();
@@ -14,8 +14,10 @@ window.GuiButton = class extends Gui {
} }
render(stack, mouseX, mouseY, partialTicks) { render(stack, mouseX, mouseY, partialTicks) {
let textureGui = this.getTexture("gui/gui.png");
let mouseOver = this.isMouseOver(mouseX, mouseY); 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); this.drawCenteredString(stack, this.string, this.x + this.width / 2, this.y + this.height / 2 - 4);
} }
@@ -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) { constructor(name, key, x, y, width, height, callback) {
super(name + ": " + key, x, y, width, height, _ => callback(this.key)); super(name + ": " + key, x, y, width, height, _ => callback(this.key));
@@ -1,4 +1,4 @@
window.Inventory = class { export default class Inventory {
constructor() { constructor() {
this.selectedSlotIndex = 0; this.selectedSlotIndex = 0;
@@ -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; static CLASSIC_LIGHTNING = false;
@@ -1,4 +1,4 @@
window.Tessellator = class { export default class Tessellator {
constructor() { constructor() {
this.material = new THREE.MeshBasicMaterial({ this.material = new THREE.MeshBasicMaterial({
@@ -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 RENDER_DISTANCE = 4;
static THIRD_PERSON_DISTANCE = 4; static THIRD_PERSON_DISTANCE = 4;
@@ -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) { constructor(worldRenderer) {
this.worldRenderer = worldRenderer; this.worldRenderer = worldRenderer;
@@ -1,4 +1,7 @@
window.EntityRenderer = class { import Tessellator from "../Tessellator.js";
import MathHelper from "../../../util/MathHelper.js";
export default class EntityRenderer {
constructor(model) { constructor(model) {
this.model = model; this.model = model;
@@ -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) { constructor(worldRenderer) {
super(new ModelPlayer()); super(new ModelPlayer());
@@ -1,15 +1,17 @@
window.FontRenderer = class { import Gui from "../../gui/Gui.js";
export default class FontRenderer {
static BITMAP_SIZE = 16; static BITMAP_SIZE = 16;
static FIELD_SIZE = 8; static FIELD_SIZE = 8;
static COLOR_CODE_INDEX_LOOKUP = "0123456789abcdef"; static COLOR_CODE_INDEX_LOOKUP = "0123456789abcdef";
constructor() { constructor(minecraft) {
this.charWidths = []; this.charWidths = [];
this.isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); 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); let bitMap = this.createBitMap(this.texture);
@@ -137,5 +139,3 @@ window.FontRenderer = class {
return canvas.getContext('2d').getImageData(0, 0, img.width, img.height).data; return canvas.getContext('2d').getImageData(0, 0, img.width, img.height).data;
} }
} }
window.FontRenderer.INSTANCE = new FontRenderer();
@@ -1,4 +1,6 @@
window.ItemRenderer = class { import Block from "../../world/block/Block.js";
export default class ItemRenderer {
constructor(minecraft, window) { constructor(minecraft, window) {
this.minecraft = minecraft; this.minecraft = minecraft;
@@ -1,4 +1,4 @@
window.ScreenRenderer = class { export default class ScreenRenderer {
constructor(minecraft, window) { constructor(minecraft, window) {
this.minecraft = minecraft; this.minecraft = minecraft;
@@ -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/ // http://jsfiddle.net/xzL58dha/3/
@@ -1,4 +1,4 @@
window.Point = class { export default class Point {
constructor(x, y) { constructor(x, y) {
this.x = x ? x : 0; this.x = x ? x : 0;
this.y = y ? y : 0; this.y = y ? y : 0;
@@ -1,4 +1,4 @@
window.TextCoord = class { export default class TextCoord {
constructor(u, v) { constructor(u, v) {
this.u = u ? u : 0; this.u = u ? u : 0;
this.v = v ? v : 0; this.v = v ? v : 0;
@@ -1,4 +1,4 @@
window.Triangle = class { export default class Triangle {
constructor(p0, p1, p2, t0, t1, t2) { constructor(p0, p1, p2, t0, t1, t2) {
this.p0 = p0; this.p0 = p0;
this.p1 = p1; this.p1 = p1;
@@ -1,4 +1,4 @@
window.ModelBase = class { export default class ModelBase {
/** /**
* Rebuild the model * Rebuild the model
@@ -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 * Create cubes for the zombie model
@@ -1,4 +1,7 @@
window.ModelRenderer = class { import Polygon from "./Polygon.js";
import Vertex from "./Vertex.js";
export default class ModelRenderer {
/** /**
* Create cube object * Create cube object
@@ -1,4 +1,6 @@
window.Polygon = class { import Vertex from "./Vertex.js";
export default class Polygon {
constructor(vertices, minU, minV, maxU, maxV, textureWidth, textureHeight) { constructor(vertices, minU, minV, maxU, maxV, textureWidth, textureHeight) {
this.vertices = vertices; this.vertices = vertices;
@@ -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 * A vertex contains a 3 float vector position and UV coordinates
@@ -1,4 +1,6 @@
window.SoundManager = class { import Block from "../world/block/Block.js";
export default class SoundManager {
constructor() { constructor() {
this.audioLoader = new THREE.AudioLoader(); this.audioLoader = new THREE.AudioLoader();
+7 -2
View File
@@ -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) { constructor(world, x, z) {
this.world = world; 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, targetY - 1, this.z * 16,
this.x * 16 + 16, targetY + 1, this.z * 16 + 16 this.x * 16 + 16, targetY + 1, this.z * 16 + 16
); );
@@ -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; static SIZE = 16;
+12 -1
View File
@@ -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; static TOTAL_HEIGHT = ChunkSection.SIZE * 8 - 1; // ChunkSection.SIZE * 16 - 1;
@@ -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 blocks = new Map();
static sounds = {}; 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) { constructor(id, textureSlotId = id) {
this.id = id; this.id = id;
this.textureSlotId = textureSlotId; this.textureSlotId = textureSlotId;
@@ -209,5 +194,5 @@ window.Block = class {
static getById(typeId) { static getById(typeId) {
return Block.blocks.get(typeId); return Block.blocks.get(typeId);
} }
} }
@@ -1,4 +1,6 @@
window.BlockDirt = class extends Block { import Block from "./Block.js";
export default class BlockDirt extends Block {
constructor(id, textureSlotId) { constructor(id, textureSlotId) {
super(id, textureSlotId); super(id, textureSlotId);
@@ -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) { constructor(id, textureSlotId) {
super(id, textureSlotId); super(id, textureSlotId);
@@ -1,4 +1,6 @@
window.BlockLeave = class extends Block { import Block from "./Block.js";
export default class BlockLeave extends Block {
constructor(id, textureSlotId) { constructor(id, textureSlotId) {
super(id, textureSlotId); super(id, textureSlotId);
@@ -1,4 +1,6 @@
window.BlockLog = class extends Block { import Block from "./Block.js";
export default class BlockLog extends Block {
constructor(id, textureSlotId) { constructor(id, textureSlotId) {
super(id, textureSlotId); super(id, textureSlotId);
@@ -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)
}
}
@@ -1,4 +1,6 @@
window.BlockSand = class extends Block { import Block from "./Block.js";
export default class BlockSand extends Block {
constructor(id, textureSlotId) { constructor(id, textureSlotId) {
super(id, textureSlotId); super(id, textureSlotId);
@@ -1,4 +1,6 @@
window.BlockStone = class extends Block { import Block from "./Block.js";
export default class BlockStone extends Block {
constructor(id, textureSlotId) { constructor(id, textureSlotId) {
super(id, textureSlotId); super(id, textureSlotId);
@@ -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) { constructor(id, textureSlotId) {
super(id, textureSlotId); super(id, textureSlotId);
@@ -1,4 +1,6 @@
window.BlockWater = class extends Block { import Block from "./Block.js";
export default class BlockWater extends Block {
constructor(id, textureSlotId) { constructor(id, textureSlotId) {
super(id, textureSlotId); super(id, textureSlotId);
@@ -1,4 +1,4 @@
window.Sound = class { export default class Sound {
constructor(name, pitch) { constructor(name, pitch) {
this.name = name; this.name = name;
@@ -1,4 +1,4 @@
window.NoiseGenerator = class { export default class NoiseGenerator {
perlin(x, z) { perlin(x, z) {
} }
@@ -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) { constructor(world, seed) {
this.world = world; this.world = world;
@@ -1,4 +1,6 @@
window.NoiseGeneratorCombined = class extends NoiseGenerator { import NoiseGenerator from "../NoiseGenerator.js";
export default class NoiseGeneratorCombined extends NoiseGenerator {
constructor(firstGenerator, secondGenerator) { constructor(firstGenerator, secondGenerator) {
super(); super();
@@ -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) { constructor(random, octaves) {
super(); super();
@@ -1,4 +1,6 @@
window.NoiseGeneratorPerlin = class extends NoiseGenerator { import NoiseGenerator from "../NoiseGenerator.js";
export default class NoiseGeneratorPerlin extends NoiseGenerator {
constructor(random) { constructor(random) {
super(); super();
+1 -1
View File
@@ -1,4 +1,4 @@
window.BlockRenderType = class { export default class BlockRenderType {
static BLOCK = 0; static BLOCK = 0;
static TORCH = 1; static TORCH = 1;
} }
+1 -1
View File
@@ -1,4 +1,4 @@
window.BoundingBox = class { export default class BoundingBox {
/** /**
* Bounding box * Bounding box
+13 -19
View File
@@ -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) { constructor(x, y, z) {
this.x = x; this.x = x;
@@ -47,24 +54,11 @@ window.EnumBlockFace = class {
return null; return null;
} }
equals(other) {
return this.x === other.x && this.y === other.y && this.z === other.z;
}
static values() { static values() {
return [ return [EnumBlockFace.TOP, EnumBlockFace.BOTTOM, EnumBlockFace.NORTH, EnumBlockFace.EAST, EnumBlockFace.SOUTH, EnumBlockFace.WEST];
EnumBlockFace.TOP,
EnumBlockFace.BOTTOM,
EnumBlockFace.NORTH,
EnumBlockFace.EAST,
EnumBlockFace.SOUTH,
EnumBlockFace.WEST
];
} }
} }
{
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);
}
+1 -1
View File
@@ -1,4 +1,4 @@
window.EnumSkyBlock = class { export default class EnumSkyBlock {
static SKY = 0; static SKY = 0;
static BLOCK = 1; static BLOCK = 1;
} }
+1 -4
View File
@@ -1,17 +1,14 @@
window.Keyboard = class { export default class Keyboard {
static state = {}; static state = {};
static create() { static create() {
window.addEventListener('keydown', function (event) { window.addEventListener('keydown', function (event) {
//event.preventDefault();
Keyboard.state[event.code] = true; Keyboard.state[event.code] = true;
//console.log("Key " + event.code + " down");
}); });
window.addEventListener('keyup', function (event) { window.addEventListener('keyup', function (event) {
event.preventDefault(); event.preventDefault();
delete Keyboard.state[event.code]; delete Keyboard.state[event.code];
//console.log("Key " + event.code + " up");
}); });
}; };
+1 -1
View File
@@ -1,4 +1,4 @@
window.MathHelper = class { export default class MathHelper {
/** /**
* Returns the greatest integer less than or equal to the double argument * Returns the greatest integer less than or equal to the double argument
@@ -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) { constructor(type, x1, y1, z1, x2, y2, z2) {
this.type = type; this.type = type;
@@ -1,4 +1,4 @@
window.MovingObjectPosition = class { export default class MovingObjectPosition {
constructor(vector, face, x, y, z) { constructor(vector, face, x, y, z) {
this.vector = vector; this.vector = vector;
+1 -1
View File
@@ -1,4 +1,4 @@
window.Random = class { export default class Random {
static instances = 0; static instances = 0;
+1 -1
View File
@@ -1,4 +1,4 @@
window.Timer = class { export default class Timer {
static MS_PER_SECOND = 1000; static MS_PER_SECOND = 1000;
static MAX_MS_PER_UPDATE = 1000; static MAX_MS_PER_UPDATE = 1000;
+1 -1
View File
@@ -1,4 +1,4 @@
window.Vector3 = class { export default class Vector3 {
constructor(x = 0, y = 0, z = 0) { constructor(x = 0, y = 0, z = 0) {
this.x = x; this.x = x;
+7 -71
View File
@@ -1,3 +1,7 @@
import Minecraft from './js/net/minecraft/client/Minecraft.js';
let resources = [];
// Browser test function // Browser test function
function isES6() { function isES6() {
try { try {
@@ -42,8 +46,6 @@ function loadTexture(textures) {
let total = textures.length; let total = textures.length;
let index = 0; let index = 0;
document.textures = [];
return textures.reduce((currentPromise, texturePath) => { return textures.reduce((currentPromise, texturePath) => {
return currentPromise.then(() => { return currentPromise.then(() => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -54,7 +56,7 @@ function loadTexture(textures) {
let image = new Image(); let image = new Image();
image.src = "src/resources/" + texturePath; image.src = "src/resources/" + texturePath;
image.onload = () => resolve(); image.onload = () => resolve();
document.textures[texturePath] = image; resources[texturePath] = image;
index++; index++;
}); });
@@ -83,78 +85,12 @@ loadTexture([
// Dependencies // Dependencies
"libraries/three.min.js", "libraries/three.min.js",
"libraries/stats.min.js", "libraries/stats.min.js",
"libraries/context-filter-polyfill.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"
]).then(() => { ]).then(() => {
// Remove pre status // Remove pre status
document.getElementById("pre-status").remove(); document.getElementById("pre-status").remove();
// Start Minecraft // Start Minecraft
window.app = new Minecraft("canvas-container"); window.app = new Minecraft("canvas-container", resources);
}); });
}); });