-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
93 changed files
with
934 additions
and
293 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
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 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 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 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 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,77 @@ | ||
package minicraft.entity.furniture; | ||
|
||
import minicraft.entity.Direction; | ||
import minicraft.entity.mob.Player; | ||
import minicraft.gfx.SpriteLinker; | ||
import minicraft.item.Item; | ||
import minicraft.item.Items; | ||
import minicraft.item.StackableItem; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class Composter extends Furniture { | ||
private static final SpriteLinker.LinkedSprite sprite = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Entity, "composter"); | ||
private static final SpriteLinker.LinkedSprite spriteFilled = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Entity, "composter_filled"); | ||
private static final SpriteLinker.LinkedSprite spriteFull = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Entity, "composter_full"); | ||
private static final SpriteLinker.LinkedSprite itemSprite = new SpriteLinker.LinkedSprite(SpriteLinker.SpriteType.Item, "composter"); | ||
|
||
private static final int MAX_COMPOST = 7; | ||
private int compost = 0; | ||
|
||
public Composter() { | ||
super("Composter", sprite, itemSprite); | ||
} | ||
|
||
@Override | ||
public boolean interact(Player player, @Nullable Item item, Direction attackDir) { | ||
if (compost == MAX_COMPOST) { | ||
compost = 0; | ||
StackableItem i = (StackableItem) Items.get("Fertilizer").copy(); | ||
i.count = 1; | ||
player.getLevel().dropItem(x, y, i); | ||
refreshStatus(); | ||
return true; | ||
} | ||
|
||
if (item instanceof StackableItem) { | ||
// 100% compost as they are heavy food | ||
if (item.getName().equalsIgnoreCase("Baked Potato") || item.getName().equalsIgnoreCase("Bread")) { | ||
compost++; | ||
((StackableItem) item).count--; | ||
refreshStatus(); | ||
return true; | ||
|
||
// 75% compost as they are crop food | ||
} else if (item.getName().equalsIgnoreCase("Wheat") || item.getName().equalsIgnoreCase("Rose") || | ||
item.getName().equalsIgnoreCase("Flower") || item.getName().equalsIgnoreCase("Apple") || | ||
item.getName().equalsIgnoreCase("Potato") || item.getName().equalsIgnoreCase("Carrot")) { | ||
if (random.nextInt(4) != 0) { // 75% | ||
compost++; | ||
((StackableItem) item).count--; | ||
refreshStatus(); | ||
return true; | ||
} | ||
|
||
// 66.7& compost as they are seeds | ||
} else if (item.getName().equalsIgnoreCase("Acorn") || item.getName().equalsIgnoreCase("Cactus") || | ||
item.getName().equalsIgnoreCase("Wheat Seeds") || item.getName().equalsIgnoreCase("Grass Seeds")) { | ||
if (random.nextInt(3) != 0) { // 66.7% | ||
compost++; | ||
((StackableItem) item).count--; | ||
refreshStatus(); | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private void refreshStatus() { | ||
if (compost == 0) | ||
super.sprite = sprite; | ||
else if (compost < MAX_COMPOST) | ||
super.sprite = spriteFilled; | ||
else | ||
super.sprite = spriteFull; | ||
} | ||
} |
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 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 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 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 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 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
58 changes: 58 additions & 0 deletions
58
src/client/java/minicraft/entity/particle/WaterParticle.java
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,58 @@ | ||
package minicraft.entity.particle; | ||
|
||
import minicraft.gfx.SpriteLinker; | ||
|
||
public class WaterParticle extends Particle { | ||
private final int destX; | ||
private final int destY; | ||
private int count; | ||
private boolean stopped; | ||
|
||
public WaterParticle(int x, int y, int lifetime, SpriteLinker.LinkedSprite sprite, int destX, int destY) { | ||
super(x, y, lifetime, sprite); | ||
this.destX = destX; | ||
this.destY = destY; | ||
count = 0; | ||
stopped = false; | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
move: | ||
if (!stopped) { | ||
count++; | ||
if (x == destX && y == destY) { | ||
stopped = true; | ||
break move; | ||
} | ||
if (count == 2) { | ||
int diffX = destX - x; | ||
int diffY = destY - y; | ||
if (Math.abs(diffX) < 3 && Math.abs(diffY) < 3) { | ||
move(destX, destY); | ||
stopped = true; | ||
break move; | ||
} | ||
|
||
double phi = Math.atan2(diffY, diffX); | ||
double moveX = Math.cos(phi); | ||
double moveY = Math.sin(phi); | ||
int moveXI = 0; | ||
int moveYI = 0; | ||
if (Math.abs(moveX / moveY) > 1.4) moveXI = (int) Math.signum(moveX); // Difference in X is greater. | ||
else if (Math.abs(moveY / moveX) > 1.4) | ||
moveYI = (int) Math.signum(moveY); // Difference in Y is greater. | ||
else { // The difference is small. | ||
moveXI = (int) Math.signum(moveX); | ||
moveYI = (int) Math.signum(moveY); | ||
} | ||
|
||
if (!move(moveXI, moveYI)) | ||
stopped = true; | ||
count = 0; | ||
} | ||
} | ||
|
||
super.tick(); | ||
} | ||
} |
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
Oops, something went wrong.