Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…raft-plus-revived into resourcepack
  • Loading branch information
BenCheung0422 committed Jan 19, 2023
2 parents ae7e9a0 + b5e5110 commit 89775b1
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 31 deletions.
29 changes: 25 additions & 4 deletions src/main/java/minicraft/core/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ static void run() {
static void createAndDisplayFrame() {
Renderer.canvas.setMinimumSize(new java.awt.Dimension(1, 1));
Renderer.canvas.setPreferredSize(Renderer.getWindowSize());
Renderer.canvas.setBackground(Color.BLACK);
logoSplash.setMinimumSize(new java.awt.Dimension(1, 1));
logoSplash.setPreferredSize(Renderer.getWindowSize());
JFrame frame = Initializer.frame = new JFrame(NAME);
Expand Down Expand Up @@ -181,11 +182,31 @@ private static class LogoSplashCanvas extends JPanel {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (transparency < 255) g.drawImage(logo, getWidth()/2 - logo.getWidth(frame)*2, getHeight()/2 - logo.getHeight(frame)*2, logo.getWidth(frame)*4, logo.getHeight(frame)*4, frame);
if (transparency > 0) {
g.setColor(new Color(255, 255, 255, transparency));
g.fillRect(0, 0, g.getClipBounds().width, g.getClipBounds().height);
final int w = g.getClipBounds().width;
final int h = g.getClipBounds().height;

// Drawing colorful background.
Graphics2D g2d = (Graphics2D) g;
int n = 6;
float[] fractions = new float[n];
Color[] colors = new Color[n];
for (int x = 0; x < n; x++) {
double sin = Math.sin(Math.PI * (255-transparency)/255.0);
double cos = Math.cos(Math.PI * x/n);
double hue = Math.abs((sin*210 + cos*45) % 360) / 360;
double s = 1 - Math.pow(Math.min(Math.sin(Math.cos(Math.abs(sin - cos))), 1), 4);
fractions[x] = (float) Math.sin((double) x/n * Math.PI/2) * x/n;
colors[x] = Color.getHSBColor((float) hue, (float) s, 1);
}
g2d.setPaint(new LinearGradientPaint(0, 0, w, 0, fractions, colors));
g2d.fillRect(0, 0, w, h);

// Drawing the centered logo.
if (transparency < 255) g.drawImage(logo, w/2 - logo.getWidth(frame)*2, h/2 - logo.getHeight(frame)*2, logo.getWidth(frame)*4, logo.getHeight(frame)*4, frame);

// Fading effect.
g.setColor(new Color(0, 0, 0, Math.max(Math.min(255 - (int) (Math.cos(transparency/255.0 * Math.PI) * 255), 255), 0)));
g.fillRect(0, 0, w, h);

if (inAnimation) {
if (display) {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/minicraft/entity/mob/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1123,4 +1123,21 @@ public Inventory getInventory() {
}

public String getDebugHunger() { return hungerStamCnt + "_" + stamHungerTicks; }

/**
* Trying to add item(s) to the player inventory.
* If no more item(s) can be added to the inventory, drop the item(s) near the player.
*/
public void tryAddToInvOrDrop(@Nullable Item item) {
if (item != null) {
int returned = inventory.add(0, item);
if (item instanceof StackableItem) {
if (((StackableItem)item).count > 0) {
getLevel().dropItem(x, y, item);
}
} else if (returned == 0) {
getLevel().dropItem(x, y, item);
}
}
}
}
7 changes: 7 additions & 0 deletions src/main/java/minicraft/item/ClothingItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player,
if (player.shirtColor == playerCol) {
return false;
} else {
ClothingItem lastClothing = (ClothingItem) getAllInstances().stream().filter(i -> i instanceof ClothingItem && ((ClothingItem) i).playerCol == player.shirtColor)
.findAny().orElse(null);
if (lastClothing == null)
lastClothing = (ClothingItem) Items.get("Reg Clothes");
lastClothing = lastClothing.clone();
lastClothing.count = 1;
player.tryAddToInvOrDrop(lastClothing);
player.shirtColor = playerCol;
return super.interactOn(true);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/minicraft/item/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Random;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import minicraft.entity.furniture.Furniture;
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/minicraft/item/PotionItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player,
if (type.equals(PotionType.Lava)) {
AchievementsDisplay.setAchievement("minicraft.achievement.lava",true);
}
return super.interactOn(applyPotion(player, type, true));
return interactOn(applyPotion(player, type, true), player);
}

protected boolean interactOn(boolean subClassSuccess, Player player) {
if (subClassSuccess)
player.tryAddToInvOrDrop(Items.get("glass bottle"));
return super.interactOn(subClassSuccess);
}

/// Only ever called to load from file
Expand Down
31 changes: 15 additions & 16 deletions src/main/java/minicraft/item/PotionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,45 @@
import minicraft.level.Level;

public enum PotionType {
None (Color.get(1, 41, 51, 255), 0),
Awkward (Color.get(1, 41, 51, 255), 0),

Speed (Color.get(1, 105, 209, 105), 4200) {
public boolean toggleEffect(Player player, boolean addEffect) {
player.moveSpeed += (double)( addEffect ? 1 : (player.moveSpeed > 1 ? -1 : 0) );
return true;
}
},

Light (Color.get(1, 183, 183, 91), 6000),
Swim (Color.get(1, 51, 51, 255), 4800),
Energy (Color.get(1, 237, 110, 78), 8400),
Regen (Color.get(1, 219, 70, 189), 1800),

Health (Color.get(1, 194, 56, 84), 0) {
public boolean toggleEffect(Player player, boolean addEffect) {
if(addEffect) player.heal(5);
return true;
}
},

Time (Color.get(1, 163), 1800),
Lava (Color.get(1, 199, 58, 58), 7200),
Shield (Color.get(1, 84, 84, 204), 5400),
Haste (Color.get(1, 201, 71, 201), 4800),

Escape (Color.get(1, 222, 162, 162), 0) {
public boolean toggleEffect(Player player, boolean addEffect) {
if (addEffect) {
int playerDepth = player.getLevel().depth;

if (playerDepth == 0) {
// player is in overworld
Game.notifications.add("You can't escape from here!");
return false;
}

int depthDiff = playerDepth > 0 ? -1 : 1;

World.scheduleLevelChange(depthDiff, () -> {
Level plevel = World.levels[World.lvlIdx(playerDepth + depthDiff)];
if (plevel != null && !plevel.getTile(player.x >> 4, player.y >> 4).mayPass(plevel, player.x >> 4, player.y >> 4, player))
Expand All @@ -55,25 +55,24 @@ public boolean toggleEffect(Player player, boolean addEffect) {
return true;
}
};

public int dispColor, duration;
public String name;

PotionType(int col, int dur) {
dispColor = col;
duration = dur;
if(this.toString().equals("None")) name = "Potion";
else name = this + " Potion";
name = this + " Potion";
}

public boolean toggleEffect(Player player, boolean addEffect) {
return duration > 0; // If you have no duration and do nothing, then you can't be used.
}

public boolean transmitEffect() {
return true; // Any effect which could be duplicated and result poorly should not be sent to the server.
// For the case of the Health potion, the player health is not transmitted separately until after the potion effect finishes, so having it send just gets the change there earlier.
}

public static final PotionType[] values = PotionType.values();
}
21 changes: 11 additions & 10 deletions src/main/java/minicraft/item/Recipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class Recipes {
furnaceRecipes.add(new Recipe("iron_1", "iron Ore_4", "coal_1"));
furnaceRecipes.add(new Recipe("gold_1", "gold Ore_4", "coal_1"));
furnaceRecipes.add(new Recipe("glass_1", "sand_4", "coal_1"));
furnaceRecipes.add(new Recipe("glass bottle_1", "glass_3"));

ovenRecipes.add(new Recipe("cooked pork_1", "raw pork_1", "coal_1"));
ovenRecipes.add(new Recipe("steak_1", "raw beef_1", "coal_1"));
Expand All @@ -117,16 +118,16 @@ public class Recipes {
ovenRecipes.add(new Recipe("Baked Potato_1", "Potato_1"));

enchantRecipes.add(new Recipe("Gold Apple_1", "apple_1", "gold_8"));
enchantRecipes.add(new Recipe("potion_1", "glass_1", "Lapis_3"));
enchantRecipes.add(new Recipe("speed potion_1", "potion_1", "Cactus_5"));
enchantRecipes.add(new Recipe("light potion_1", "potion_1", "slime_5"));
enchantRecipes.add(new Recipe("swim potion_1", "potion_1", "raw fish_5"));
enchantRecipes.add(new Recipe("haste potion_1", "potion_1", "Wood_5", "Stone_5"));
enchantRecipes.add(new Recipe("lava potion_1", "potion_1", "Lava Bucket_1"));
enchantRecipes.add(new Recipe("energy potion_1", "potion_1", "gem_25"));
enchantRecipes.add(new Recipe("regen potion_1", "potion_1", "Gold Apple_1"));
enchantRecipes.add(new Recipe("Health Potion_1", "potion_1", "GunPowder_2", "Leather Armor_1"));
enchantRecipes.add(new Recipe("Escape Potion_1", "potion_1", "GunPowder_3", "Lapis_7"));
enchantRecipes.add(new Recipe("awkward potion_1", "glass bottle_1", "Lapis_3"));
enchantRecipes.add(new Recipe("speed potion_1", "awkward potion_1", "Cactus_5"));
enchantRecipes.add(new Recipe("light potion_1", "awkward potion_1", "slime_5"));
enchantRecipes.add(new Recipe("swim potion_1", "awkward potion_1", "raw fish_5"));
enchantRecipes.add(new Recipe("haste potion_1", "awkward potion_1", "Wood_5", "Stone_5"));
enchantRecipes.add(new Recipe("lava potion_1", "awkward potion_1", "Lava Bucket_1"));
enchantRecipes.add(new Recipe("energy potion_1", "awkward potion_1", "gem_25"));
enchantRecipes.add(new Recipe("regen potion_1", "awkward potion_1", "Gold Apple_1"));
enchantRecipes.add(new Recipe("Health Potion_1", "awkward potion_1", "GunPowder_2", "Leather Armor_1"));
enchantRecipes.add(new Recipe("Escape Potion_1", "awkward potion_1", "GunPowder_3", "Lapis_7"));
enchantRecipes.add(new Recipe("Totem of Air_1", "gold_10", "gem_10", "Lapis_5","Cloud Ore_5"));
}
}
1 change: 1 addition & 0 deletions src/main/java/minicraft/item/StackableItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected static ArrayList<Item> getAllInstances() {
items.add(new StackableItem("Scale", new LinkedSprite(SpriteType.Item, "scale")));
items.add(new StackableItem("Shard", new LinkedSprite(SpriteType.Item, "shard")));
items.add(new StackableItem("Cloud Ore", new LinkedSprite(SpriteType.Item, "cloud_ore")));
items.add(new StackableItem("Glass Bottle", new LinkedSprite(SpriteType.Item, "glass_bottle")));

return items;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 89775b1

Please sign in to comment.