Skip to content

Commit b6a6d8c

Browse files
committed
allow fruits to be placed
1 parent 747d048 commit b6a6d8c

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "dev.jsinco.brewery.garden"
10-
version = "BX3.4.5-RV2"
10+
version = "BX3.4.6"
1111

1212
repositories {
1313
mavenCentral()
@@ -16,7 +16,7 @@ repositories {
1616
}
1717

1818
dependencies {
19-
compileOnly("com.dre.brewery:BreweryX:3.4.5-SNAPSHOT#4")
19+
compileOnly("com.dre.brewery:BreweryX:3.4.6")
2020
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
2121

2222
compileOnly("org.projectlombok:lombok:1.18.30")

src/main/java/dev/jsinco/brewery/garden/BreweryGarden.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.List;
1919
import java.util.Random;
2020

21-
@AddonInfo(name = "BreweryGarden", version = "BX3.4.5", author = "Jsinco", description = "Adds plants to BreweryX, lightweight ExoticGarden.")
21+
@AddonInfo(name = "BreweryGarden", version = "BX3.4.6", author = "Jsinco", description = "Adds plants to BreweryX, lightweight ExoticGarden.")
2222
public final class BreweryGarden extends BreweryAddon {
2323

2424
// TODO:

src/main/java/dev/jsinco/brewery/garden/constants/PlantType.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import io.papermc.paper.datacomponent.item.FoodProperties;
1010
import io.papermc.paper.datacomponent.item.ResolvableProfile;
1111
import lombok.Getter;
12+
import net.kyori.adventure.text.Component;
13+
import net.kyori.adventure.text.format.NamedTextColor;
1214
import net.kyori.adventure.text.minimessage.MiniMessage;
1315
import org.bukkit.Bukkit;
1416
import org.bukkit.Material;
@@ -33,7 +35,6 @@
3335
@Getter
3436
public final class PlantType extends GenericPlantType {
3537

36-
// TODO: get some plant base64 textures
3738
public static final PlantType BERRY = new PlantType(
3839
"<dark_purple>Berry",
3940
fromHashCode("1e4883a1e22c324e753151e2ac424c74f1cc646eec8ea0db3420f1dd1d8b")
@@ -117,11 +118,29 @@ public ItemStack getItemStack(int amount) {
117118

118119
// TODO: Ask in Paper discord how to use PDC with new ItemMeta API
119120
ItemMeta meta = item.getItemMeta();
121+
meta.lore(List.of(Component.text("A sweet fruit").color(NamedTextColor.DARK_GRAY)));
120122
meta.getPersistentDataContainer().set(PERSISTENT_DATA_KEY, PersistentDataType.STRING, FIELD_NAME);
121123
item.setItemMeta(meta);
122124
return item;
123125
}
124126

127+
public void setDataOnPlayerSkullBlock(Block block) {
128+
if (block.getType() != Material.PLAYER_HEAD) {
129+
return;
130+
}
131+
Skull skull = (Skull) block.getState();
132+
skull.getPersistentDataContainer().set(PERSISTENT_DATA_KEY, PersistentDataType.STRING, FIELD_NAME);
133+
skull.update();
134+
}
135+
136+
public static boolean isPlayerSkullBlock(Block block) {
137+
if (block.getType() != Material.PLAYER_HEAD) {
138+
return false;
139+
}
140+
Skull skull = (Skull) block.getState();
141+
return skull.getPersistentDataContainer().has(PERSISTENT_DATA_KEY);
142+
}
143+
125144
private PlayerProfile getPlayerProfile() {
126145
PlayerProfile profile = Bukkit.createProfile(CONSTANT_UUID);
127146
profile.getProperties().add(new ProfileProperty("textures", base64));
@@ -143,6 +162,15 @@ public static PlantType getPlantType(ItemStack item) {
143162
return valueOf(field_name);
144163
}
145164

165+
@Nullable
166+
public static PlantType getPlantType(Block block) {
167+
if (block.getType() != Material.PLAYER_HEAD) return null;
168+
Skull skull = (Skull) block.getState();
169+
String field_name = skull.getPersistentDataContainer().get(PERSISTENT_DATA_KEY, PersistentDataType.STRING);
170+
if (field_name == null) return null;
171+
return valueOf(field_name);
172+
}
173+
146174

147175

148176
// Reflect

src/main/java/dev/jsinco/brewery/garden/constants/PlantTypeSeeds.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.papermc.paper.datacomponent.DataComponentTypes;
66
import lombok.Getter;
77
import net.kyori.adventure.text.Component;
8+
import net.kyori.adventure.text.format.NamedTextColor;
89
import net.kyori.adventure.text.minimessage.MiniMessage;
910
import org.bukkit.Material;
1011
import org.bukkit.NamespacedKey;
@@ -64,6 +65,7 @@ public ItemStack getItemStack(int amount) {
6465

6566
// TODO: Ask in Paper discord how to use PDC with new ItemMeta API
6667
ItemMeta meta = item.getItemMeta();
68+
meta.lore(List.of(Component.text("Rough seeds").color(NamedTextColor.DARK_GRAY)));
6769
meta.getPersistentDataContainer().set(PERSISTENT_DATA_KEY, PersistentDataType.STRING, FIELD_NAME);
6870
item.setItemMeta(meta);
6971
return item;

src/main/java/dev/jsinco/brewery/garden/events/EventListeners.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public void onBlockBreak(BlockBreakEvent event) {
5353
// Drop a seed
5454
block.getWorld().dropItemNaturally(block.getLocation(),
5555
seedsList.get(RANDOM.nextInt(seedsList.size())).getItemStack(1));
56+
} else if (PlantType.isPlayerSkullBlock(block)) {
57+
PlantType plantType = PlantType.getPlantType(block);
58+
event.setDropItems(false);
59+
block.getWorld().dropItemNaturally(block.getLocation(), plantType.getItemStack(1));
5660
}
5761

5862
GardenPlant gardenPlant = gardenManager.getByLocation(block);
@@ -90,7 +94,8 @@ public void onPlayerInteract(PlayerInteractEvent event) {
9094
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
9195
public void onBlockPlace(BlockPlaceEvent event) {
9296
if (PlantType.isPlant(event.getItemInHand())) {
93-
event.setCancelled(true);
97+
PlantType plantType = PlantType.getPlantType(event.getItemInHand());
98+
plantType.setDataOnPlayerSkullBlock(event.getBlock());
9499
}
95100
}
96101

0 commit comments

Comments
 (0)