Skip to content

Commit

Permalink
Added a new Category
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBusyBiscuit committed Apr 26, 2020
1 parent b0324fd commit 0dd6b32
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 195 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>Slimefun4</artifactId>
<version>e3d84de7b9</version>
<version>45ed89c6f5</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down
316 changes: 160 additions & 156 deletions src/main/java/io/github/thebusybiscuit/exoticgarden/ExoticGarden.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.thebusybiscuit.exoticgarden;

public enum PlantType {
enum PlantType {

BUSH,
FRUIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,46 +72,37 @@ public void onGrow(StructureGrowEvent e) {
break;
case ORE_PLANT:
case DOUBLE_PLANT:
item = BlockStorage.check(e.getLocation().getBlock().getRelative(BlockFace.UP));
Block blockAbove = e.getLocation().getBlock().getRelative(BlockFace.UP);
item = BlockStorage.check(blockAbove);
if (item != null) return;

switch (e.getLocation().getBlock().getRelative(BlockFace.UP).getType()) {
case AIR:
case CAVE_AIR:
case OAK_SAPLING:
case SPRUCE_SAPLING:
case BIRCH_SAPLING:
case JUNGLE_SAPLING:
case ACACIA_SAPLING:
case DARK_OAK_SAPLING:
case OAK_LEAVES:
case SPRUCE_LEAVES:
case BIRCH_LEAVES:
case JUNGLE_LEAVES:
case ACACIA_LEAVES:
case DARK_OAK_LEAVES:
case SNOW:
break;
default:
return;
if (!Tag.SAPLINGS.isTagged(blockAbove.getType()) && !Tag.LEAVES.isTagged(blockAbove.getType())) {
switch (blockAbove.getType()) {
case AIR:
case CAVE_AIR:
case SNOW:
break;
default:
return;
}
}

BlockStorage.store(e.getLocation().getBlock().getRelative(BlockFace.UP), berry.getItem());
BlockStorage.store(blockAbove, berry.getItem());
e.getLocation().getBlock().setType(Material.OAK_LEAVES);
e.getLocation().getBlock().getRelative(BlockFace.UP).setType(Material.PLAYER_HEAD);
Rotatable rotatable = (Rotatable) e.getLocation().getBlock().getRelative(BlockFace.UP).getBlockData();
blockAbove.setType(Material.PLAYER_HEAD);
Rotatable rotatable = (Rotatable) blockAbove.getBlockData();
rotatable.setRotation(faces[ThreadLocalRandom.current().nextInt(faces.length)]);
e.getLocation().getBlock().getRelative(BlockFace.UP).setBlockData(rotatable);
blockAbove.setBlockData(rotatable);

SkullBlock.setFromBase64(e.getLocation().getBlock().getRelative(BlockFace.UP), berry.getTexture());
SkullBlock.setFromHash(blockAbove, berry.getTexture());
break;
default:
e.getLocation().getBlock().setType(Material.PLAYER_HEAD);
Rotatable s = (Rotatable) e.getLocation().getBlock().getBlockData();
s.setRotation(faces[new Random().nextInt(faces.length)]);
s.setRotation(faces[ThreadLocalRandom.current().nextInt(faces.length)]);
e.getLocation().getBlock().setBlockData(s);

SkullBlock.setFromBase64(e.getLocation().getBlock(), berry.getTexture());
SkullBlock.setFromHash(e.getLocation().getBlock(), berry.getTexture());
break;
}

Expand Down Expand Up @@ -151,7 +142,7 @@ public void onGenerate(ChunkPopulateEvent e) {
s.setRotation(faces[random.nextInt(faces.length)]);
current.setBlockData(s);

SkullBlock.setFromBase64(current, berry.getTexture());
SkullBlock.setFromHash(current, berry.getTexture());
});
break;
case ORE_PLANT:
Expand All @@ -163,7 +154,7 @@ public void onGenerate(ChunkPopulateEvent e) {
Rotatable s = (Rotatable) current.getRelative(BlockFace.UP).getBlockData();
s.setRotation(faces[random.nextInt(faces.length)]);
current.getRelative(BlockFace.UP).setBlockData(s);
SkullBlock.setFromBase64(current.getRelative(BlockFace.UP), berry.getTexture());
SkullBlock.setFromHash(current.getRelative(BlockFace.UP), berry.getTexture());
});
break;
default:
Expand Down Expand Up @@ -238,6 +229,7 @@ public void onHarvest(BlockBreakEvent e) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onDecay(LeavesDecayEvent e) {
String id = BlockStorage.checkID(e.getBlock());

if (id != null) {
for (Berry berry : ExoticGarden.getBerries()) {
if (id.equalsIgnoreCase(berry.getID())) {
Expand Down Expand Up @@ -271,12 +263,12 @@ public void onInteract(PlayerInteractEvent e) {
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
void onBlockExplode(BlockExplodeEvent e) {
public void onBlockExplode(BlockExplodeEvent e) {
e.blockList().removeAll(getAffectedBlocks(e.blockList()));
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
void onEntityExplode(EntityExplodeEvent e) {
public void onEntityExplode(EntityExplodeEvent e) {
e.blockList().removeAll(getAffectedBlocks(e.blockList()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.github.thebusybiscuit.exoticgarden;
package io.github.thebusybiscuit.exoticgarden.items;

import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.exoticgarden.ExoticGardenRecipeTypes;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;

public class CustomFood extends EGPlant {
public class CustomFood extends ExoticGardenFruit {

private final int food;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.thebusybiscuit.exoticgarden;
package io.github.thebusybiscuit.exoticgarden.items;

import java.util.Optional;

Expand All @@ -15,11 +15,11 @@
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.cscorelib2.inventory.ItemUtils;

public class EGPlant extends HandledBlock {
public class ExoticGardenFruit extends HandledBlock {

private final boolean edible;

public EGPlant(Category category, SlimefunItemStack item, RecipeType recipeType, boolean edible, ItemStack[] recipe) {
public ExoticGardenFruit(Category category, SlimefunItemStack item, RecipeType recipeType, boolean edible, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
this.edible = edible;
}
Expand All @@ -41,6 +41,9 @@ public ItemUseHandler onRightClick() {
if (!material.isInteractable() || e.getPlayer().isSneaking()) {
e.cancel();
}
else {
return;
}
}

if (edible && e.getPlayer().getFoodLevel() < 20) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.thebusybiscuit.exoticgarden;
package io.github.thebusybiscuit.exoticgarden.items;

import java.util.List;

Expand All @@ -15,6 +15,7 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.exoticgarden.ExoticGarden;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
Expand Down

0 comments on commit 0dd6b32

Please sign in to comment.