This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
503 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Builds | ||
build/ | ||
|
||
# Player and world data | ||
player.dat | ||
world.dat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
all: | ||
mkdir -p ./build/mc4k/ | ||
mkdir -p ./build/res/ | ||
javac -d ./build/ ./mc4k/MCApplet.java | ||
javac -d ./build/ ./mc4k/MCTerrainGenerator.java | ||
javac -d ./build/ ./mc4k/MCPlayer.java | ||
javac -d ./build/ ./mc4k/Minecraft4K.java | ||
cp ./res/Manifest.txt ./build/ | ||
cp ./res/textures.dat ./build/res/ | ||
cp ./res/icon.png ./build/res/ | ||
cd build && jar cfm Minecraft4K.jar Manifest.txt mc4k/* res/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
* MCApplet.java - Helper class. | ||
* | ||
* Copyright 2021 Alvarito050506 <[email protected]> | ||
* | ||
*/ | ||
|
||
package mc4k; | ||
|
||
import java.awt.Panel; | ||
import java.awt.Frame; | ||
import java.awt.event.KeyEvent; | ||
import java.awt.event.KeyListener; | ||
import java.awt.event.MouseEvent; | ||
import java.awt.event.MouseListener; | ||
import java.awt.event.MouseMotionListener; | ||
import java.awt.image.BufferedImage; | ||
import java.awt.image.DataBufferInt; | ||
import java.awt.image.ImageObserver; | ||
|
||
class MCEvents { | ||
public int mouseX = 0; | ||
public int mouseY = 0; | ||
public int[] wasd = new int[4]; // WASD | ||
public int[] buttons = new int[2]; // Left, Right | ||
public int[] arrows = new int[2]; // Left, Right | ||
public int[] worldKeys = new int[4]; // Esc, C, G, F2 | ||
public int space = 0; // Space | ||
public int mouseLocked = 1; // 0: Locked, 1: Game not started, 2: Focus lost | ||
} | ||
|
||
public class MCApplet extends Panel implements MouseMotionListener, MouseListener, KeyListener { | ||
public MCEvents events = new MCEvents(); | ||
public static Frame frame = new Frame(); | ||
|
||
@Override | ||
public void mouseDragged(MouseEvent paramEvent) { | ||
if (events.mouseLocked != 0) | ||
{ | ||
return; | ||
} | ||
events.mouseX = paramEvent.getX(); | ||
events.mouseY = paramEvent.getY(); | ||
} | ||
|
||
@Override | ||
public void mouseMoved(MouseEvent paramEvent) { | ||
if (events.mouseLocked != 0) | ||
{ | ||
return; | ||
} | ||
events.mouseX = paramEvent.getX(); | ||
events.mouseY = paramEvent.getY(); | ||
} | ||
|
||
@Override | ||
public void mousePressed(MouseEvent paramEvent) { | ||
if (events.mouseLocked != 0) | ||
{ | ||
return; | ||
} | ||
events.mouseX = paramEvent.getX(); | ||
events.mouseY = paramEvent.getY(); | ||
if ((paramEvent.getModifiers() & 4) <= 0) | ||
events.buttons[0] = 1; | ||
else | ||
events.buttons[1] = 1; | ||
} | ||
|
||
private void setKeyEvent(KeyEvent paramEvent, int val) { | ||
switch (paramEvent.getKeyCode()) { | ||
case 27: | ||
events.worldKeys[0] = val; | ||
break; | ||
case 67: | ||
events.worldKeys[1] = val; | ||
break; | ||
case 71: | ||
events.worldKeys[2] = val; | ||
break; | ||
case 113: | ||
events.worldKeys[3] = val; | ||
break; | ||
case 37: | ||
events.arrows[0] = val; | ||
break; | ||
case 39: | ||
events.arrows[1] = val; | ||
break; | ||
case 87: | ||
events.wasd[0] = val; | ||
break; | ||
case 65: | ||
events.wasd[1] = val; | ||
break; | ||
case 83: | ||
events.wasd[2] = val; | ||
break; | ||
case 68: | ||
events.wasd[3] = val; | ||
break; | ||
case 32: | ||
events.space = val; | ||
break; | ||
} | ||
} | ||
|
||
@Override | ||
public void keyPressed(KeyEvent paramEvent) { | ||
setKeyEvent(paramEvent, 1); | ||
} | ||
|
||
@Override | ||
public void keyReleased(KeyEvent paramEvent) { | ||
setKeyEvent(paramEvent, 0); | ||
} | ||
|
||
@Override | ||
public void mouseExited(MouseEvent paramEvent) { | ||
return; | ||
} | ||
|
||
@Override | ||
public void mouseClicked(MouseEvent paramEvent) { | ||
if (events.mouseLocked == 1) { | ||
events.mouseLocked = 0; | ||
} | ||
return; | ||
} | ||
|
||
@Override | ||
public void mouseEntered(MouseEvent paramEvent) { | ||
return; | ||
} | ||
|
||
@Override | ||
public void mouseReleased(MouseEvent paramEvent) { | ||
return; | ||
} | ||
|
||
@Override | ||
public void keyTyped(KeyEvent paramEvent) { | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* MCPlayer.java - Player inventory and data. | ||
* | ||
* Copyright 2021 Alvarito050506 <[email protected]> | ||
* | ||
*/ | ||
|
||
package mc4k; | ||
|
||
import java.util.Random; | ||
import java.time.Instant; | ||
import java.lang.Math; | ||
import java.io.Serializable; | ||
|
||
public class MCPlayer implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public int blockInHand = 1; | ||
public int diamondCounter = 0; | ||
public float posX = 96.5F; | ||
public float posY = 95.0F; | ||
public float posZ = 96.5F; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* MCTerrainGenerator.java - Terrain generator. | ||
* | ||
* Copyright 2021 Alvarito050506 <[email protected]> | ||
* Copyright 2020 @saca44 at the MCForums | ||
* | ||
*/ | ||
|
||
package mc4k; | ||
|
||
import java.util.Random; | ||
import java.time.Instant; | ||
import java.lang.Math; | ||
|
||
public class MCTerrainGenerator { | ||
Random random = new Random(); | ||
int seed = 0; | ||
int worldSize = 64 * 64 * 64; | ||
int[] worldBlocks = new int[worldSize]; | ||
double[][] heightMap = new double[64][64]; | ||
|
||
public MCTerrainGenerator() { | ||
int i = 0; | ||
int tbsi; | ||
int randomMax = (int)Math.pow(64, 4); | ||
|
||
float fx = 0; | ||
float fy = 0; | ||
|
||
random.setSeed(Instant.now().getEpochSecond()); | ||
for (int y = 0; y < 64; y++) { | ||
fx = 0; | ||
for (int x = 0; x < 64; x++) { | ||
heightMap[x][y] = 32 + (Math.cos(fx) + Math.sin(fy)) * 2; | ||
fx += 0.2f; | ||
} | ||
fy += 0.2f; | ||
} | ||
|
||
for (int y = 0; y < 64; y++) { | ||
for (int x = 0; x < 64; x++) { | ||
for (int z = 0; z < 64; z++) { | ||
int lim = i / 64 % 64; | ||
double mapVal = heightMap[y][z]; | ||
if (heightMap[y][z] > lim) { | ||
worldBlocks[i] = 0; | ||
} else if (mapVal > lim - 1) { | ||
worldBlocks[i] = 1; | ||
} else if (mapVal > lim - 4 + random.nextFloat()) { | ||
worldBlocks[i] = 2; | ||
} else { | ||
if (random.nextInt(randomMax) >= randomMax - randomMax / 128) { | ||
worldBlocks[i] = 3; | ||
} else { | ||
worldBlocks[i] = 4; | ||
} | ||
} | ||
i++; | ||
} | ||
} | ||
} | ||
|
||
for (int x = 0; x < 64; x++) { | ||
for (int z = 0; z < 64; z++) { | ||
tbsi = vecToInt(x, (int)(heightMap[x][z]), z); | ||
if (isTreeAreaBlank(x, (int)(heightMap[x][z]), z) > 0) { | ||
if (random.nextInt(96) == 0) { | ||
tree(x, (int)(heightMap[x][z]), z); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public int vecToInt(int x, int y, int z) { | ||
return z + y * 64 + x * 4096; | ||
} | ||
|
||
public void setBlock(int block, int x, int y, int z) { | ||
int coords = vecToInt(x, y, z); | ||
if (coords > 0 && coords < worldSize) { | ||
worldBlocks[coords] = block; | ||
} | ||
} | ||
|
||
public void fillBlocks(int block, int x, int y, int z, int w, int h, int d) { | ||
w += x; | ||
h += y; | ||
d += z; | ||
for (int xx = x; xx < w; xx++) { | ||
for (int yy = y; yy < h; yy++) { | ||
for (int zz = z; zz < d; zz++) { | ||
setBlock(block, xx, yy, zz); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public int isTreeAreaBlank(int x, int y, int z) { | ||
int coords; | ||
|
||
try { | ||
coords = vecToInt(x, (int)(heightMap[x][z]), z); | ||
if (worldBlocks[coords] != 0) | ||
{ | ||
return 0; | ||
} | ||
coords = vecToInt(x + 1, (int)(heightMap[x][z]), z); | ||
if (worldBlocks[coords] != 0) | ||
{ | ||
return 0; | ||
} | ||
coords = vecToInt(x + 1, (int)(heightMap[x][z]), z + 1); | ||
if (worldBlocks[coords] != 0) | ||
{ | ||
return 0; | ||
} | ||
coords = vecToInt(x, (int)(heightMap[x][z]), z + 1); | ||
if (worldBlocks[coords] != 0) | ||
{ | ||
return 0; | ||
} | ||
} catch (Exception err) { | ||
return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
public void tree(int x, int y, int z) { | ||
fillBlocks(8, x - 2, y - 4, z - 2, 5, 2, 5); | ||
fillBlocks(8, x - 1, y - 6, z - 1, 3, 2, 3); | ||
for (int i = 0; i < 5; i++) { | ||
setBlock(7, x, y - i, z); | ||
} | ||
} | ||
|
||
public int[] getBlocks() { | ||
return worldBlocks; | ||
} | ||
} |
Oops, something went wrong.