Skip to content

Commit

Permalink
add water
Browse files Browse the repository at this point in the history
  • Loading branch information
HeathLoganCampbell committed Jul 3, 2019
1 parent cf0022f commit c6b6002
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
Binary file modified resources/saved-texturess.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 15 additions & 4 deletions src/com/craftclassic/play/Minecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class Minecraft
private FontRender font;

private List<Runnable> nextTickRunnables;
private List<Runnable> nextSecondRunnables;
private List<Runnable> nextTickRunnablesWater;

private int placeBlockTypeId = 1;

Expand Down Expand Up @@ -102,7 +102,7 @@ public void run()
try
{
this.nextTickRunnables = new ArrayList<>();
this.nextSecondRunnables = new ArrayList<>();
this.nextTickRunnablesWater = new ArrayList<>();
this.world = new World(this, 64, 64, 1);
this.font = new FontRender(this);

Expand All @@ -128,6 +128,16 @@ public void run()
this.nextTickRunnables.clear();
}

if(ticks % 10 == 0)
{
this.nextTickRunnablesWater.forEach(task -> {
task.run();
});
this.nextTickRunnablesWater.clear();
}



Location playerLoc = this.player.getLocation();
float sinYaw = (float)Math.sin(playerLoc.getYaw() + (this.player.preyaw - playerLoc.getYaw()));
float cosYaw = (float)Math.cos(playerLoc.getYaw() + (this.player.preyaw - playerLoc.getYaw()));
Expand Down Expand Up @@ -600,11 +610,12 @@ public void doNextTick(Runnable runnable)
this.nextTickRunnables.add(runnable);
}

public void doNextSecond(Runnable runnable)
public void doNextTickWater(Runnable runnable)
{
this.nextTickRunnables.add(runnable);
this.nextTickRunnablesWater.add(runnable);
}


public void setPixel(int x, int y, int pixel)
{
imageData[x + y * this.quartWidth] = pixel;
Expand Down
2 changes: 1 addition & 1 deletion src/com/craftclassic/play/blocks/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void setId(int id) {
, GRASS = new GrassBlock(2)
, STONE = new StoneBlock(3)
, LAVA = new LavaBlock(4) //solid lava (4)
//Moving lava (5)
, WATER = new WaterBlock(5)
, BEDROCK = new BedrockBlock(6)
, LOG = new LogBlock(7)
, LEAVES = new LeavesBlock(8)
Expand Down
38 changes: 38 additions & 0 deletions src/com/craftclassic/play/blocks/WaterBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.craftclassic.play.blocks;

import com.craftclassic.play.utils.Location;

public class WaterBlock extends Block {

public WaterBlock(int id)
{
super(id, "Water", 13);
this.setBreakable(false);
this.setSelectable(false);
this.setSolid(false);
}

private void flow(Location location, int x, int y, int z)
{
location.add(x, y, z);
if(location.getBlock() == Block.AIR)
{
Location newLoc = location.clone();
location.getWorld().getMinecraft().doNextTickWater(() ->
{
if(newLoc.getBlock() == Block.AIR)
newLoc.setBlock(Block.WATER);
});
}
location.subtract(x, y, z);
}

public void onTick(Location location)
{
flow(location, 1, 0, 0);
flow(location, 0, 0, 1);
flow(location, 0, 0, -1);
flow(location, -1, 0, 0);
flow(location, 0, 1, 0);
}
}

0 comments on commit c6b6002

Please sign in to comment.