-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
ItemHelperImpl.java
565 lines (522 loc) · 27.4 KB
/
ItemHelperImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
package com.denizenscript.denizen.nms.v1_18.helpers;
import com.denizenscript.denizen.nms.interfaces.ItemHelper;
import com.denizenscript.denizen.nms.util.PlayerProfile;
import com.denizenscript.denizen.nms.util.jnbt.CompoundTag;
import com.denizenscript.denizen.nms.util.jnbt.IntArrayTag;
import com.denizenscript.denizen.nms.util.jnbt.Tag;
import com.denizenscript.denizen.nms.v1_18.ReflectionMappingsInfo;
import com.denizenscript.denizen.nms.v1_18.impl.jnbt.CompoundTagImpl;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.utilities.FormattedTextHelper;
import com.denizenscript.denizen.utilities.inventory.BrewingRecipe;
import com.denizenscript.denizencore.utilities.ReflectionHelper;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedHashMultiset;
import com.google.common.collect.Multiset;
import com.google.common.collect.Multisets;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.core.Registry;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.alchemy.PotionBrewing;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R2.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryPlayer;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftRecipe;
import org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_18_R2.util.CraftNamespacedKey;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import java.lang.reflect.Field;
import java.util.*;
public class ItemHelperImpl extends ItemHelper {
public static net.minecraft.world.item.crafting.Recipe<?> getNMSRecipe(NamespacedKey key) {
ResourceLocation nmsKey = CraftNamespacedKey.toMinecraft(key);
for (Object2ObjectLinkedOpenHashMap<ResourceLocation, net.minecraft.world.item.crafting.Recipe<?>> recipeMap : ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().recipes.values()) {
net.minecraft.world.item.crafting.Recipe<?> recipe = recipeMap.get(nmsKey);
if (recipe != null) {
return recipe;
}
}
return null;
}
public void setMaxStackSize(Material material, int size) {
try {
ReflectionHelper.getFinalSetter(Material.class, "maxStack").invoke(material, size);
ReflectionHelper.getFinalSetter(Item.class, ReflectionMappingsInfo.Item_maxStackSize).invoke(Registry.ITEM.get(CraftNamespacedKey.toMinecraft(material.getKey())), size);
}
catch (Throwable ex) {
Debug.echoError(ex);
}
}
@Override
public Integer burnTime(Material material) {
return AbstractFurnaceBlockEntity.getFuel().get(CraftMagicNumbers.getItem(material));
}
public static Field RECIPE_MANAGER_BY_NAME = ReflectionHelper.getFields(RecipeManager.class).get(ReflectionMappingsInfo.RecipeManager_byName, Map.class);
@Override
public void removeRecipe(NamespacedKey key) {
ResourceLocation nmsKey = CraftNamespacedKey.toMinecraft(key);
RecipeManager recipeManager = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager();
try {
Map<ResourceLocation, net.minecraft.world.item.crafting.Recipe<?>> byName = (Map) RECIPE_MANAGER_BY_NAME.get(recipeManager);
byName.remove(nmsKey);
}
catch (Throwable ex) {
Debug.echoError(ex);
}
for (Object2ObjectLinkedOpenHashMap<ResourceLocation, net.minecraft.world.item.crafting.Recipe<?>> recipeMap : recipeManager.recipes.values()) {
recipeMap.remove(nmsKey);
}
}
@Override
public void clearDenizenRecipes() {
RecipeManager recipeManager = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager();
Map<ResourceLocation, net.minecraft.world.item.crafting.Recipe<?>> byName;
try {
byName = (Map) RECIPE_MANAGER_BY_NAME.get(recipeManager);
}
catch (Throwable ex) {
Debug.echoError(ex);
return;
}
for (Object2ObjectLinkedOpenHashMap<ResourceLocation, net.minecraft.world.item.crafting.Recipe<?>> recipeMap : recipeManager.recipes.values()) {
for (ResourceLocation key : new ArrayList<>(recipeMap.keySet())) {
if (key.getNamespace().equalsIgnoreCase("denizen")) {
recipeMap.remove(key);
byName.remove(key);
}
}
}
}
@Override
public void setShapedRecipeIngredient(ShapedRecipe recipe, char c, ItemStack[] item, boolean exact) {
if (item.length == 1 && item[0].getType() == Material.AIR) {
recipe.setIngredient(c, new RecipeChoice.MaterialChoice(Material.AIR));
}
else if (exact) {
recipe.setIngredient(c, new RecipeChoice.ExactChoice(item));
}
else {
Material[] mats = new Material[item.length];
for (int i = 0; i < item.length; i++) {
mats[i] = item[i].getType();
}
recipe.setIngredient(c, new RecipeChoice.MaterialChoice(mats));
}
}
public static Ingredient itemArrayToRecipe(ItemStack[] items, boolean exact) {
Ingredient.ItemValue[] stacks = new Ingredient.ItemValue[items.length];
for (int i = 0; i < items.length; i++) {
stacks[i] = new Ingredient.ItemValue(CraftItemStack.asNMSCopy(items[i]));
}
Ingredient itemRecipe = new Ingredient(Arrays.stream(stacks));
itemRecipe.exact = exact;
return itemRecipe;
}
@Override
public void registerFurnaceRecipe(String keyName, String group, ItemStack result, ItemStack[] ingredient, float exp, int time, String type, boolean exact, String category) {
ResourceLocation key = new ResourceLocation("denizen", keyName);
Ingredient itemRecipe = itemArrayToRecipe(ingredient, exact);
AbstractCookingRecipe recipe;
if (type.equalsIgnoreCase("smoker")) {
recipe = new SmokingRecipe(key, group, itemRecipe, CraftItemStack.asNMSCopy(result), exp, time);
}
else if (type.equalsIgnoreCase("blast")) {
recipe = new BlastingRecipe(key, group, itemRecipe, CraftItemStack.asNMSCopy(result), exp, time);
}
else if (type.equalsIgnoreCase("campfire")) {
recipe = new CampfireCookingRecipe(key, group, itemRecipe, CraftItemStack.asNMSCopy(result), exp, time);
}
else {
recipe = new SmeltingRecipe(key, group, itemRecipe, CraftItemStack.asNMSCopy(result), exp, time);
}
((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().addRecipe(recipe);
}
@Override
public void registerStonecuttingRecipe(String keyName, String group, ItemStack result, ItemStack[] ingredient, boolean exact) {
ResourceLocation key = new ResourceLocation("denizen", keyName);
Ingredient itemRecipe = itemArrayToRecipe(ingredient, exact);
StonecutterRecipe recipe = new StonecutterRecipe(key, group, itemRecipe, CraftItemStack.asNMSCopy(result));
((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().addRecipe(recipe);
}
@Override
public void registerSmithingRecipe(String keyName, ItemStack result, ItemStack[] baseItem, boolean baseExact, ItemStack[] upgradeItem, boolean upgradeExact) {
ResourceLocation key = new ResourceLocation("denizen", keyName);
Ingredient baseItemRecipe = itemArrayToRecipe(baseItem, baseExact);
Ingredient upgradeItemRecipe = itemArrayToRecipe(upgradeItem, upgradeExact);
UpgradeRecipe recipe = new UpgradeRecipe(key, baseItemRecipe, upgradeItemRecipe, CraftItemStack.asNMSCopy(result));
((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().addRecipe(recipe);
}
@Override
public void registerShapelessRecipe(String keyName, String group, ItemStack result, List<ItemStack[]> ingredients, boolean[] exact, String category) {
ResourceLocation key = new ResourceLocation("denizen", keyName);
ArrayList<Ingredient> ingredientList = new ArrayList<>();
for (int i = 0; i < ingredients.size(); i++) {
ingredientList.add(itemArrayToRecipe(ingredients.get(i), exact[i]));
}
ShapelessRecipe recipe = new ShapelessRecipe(key, group, CraftItemStack.asNMSCopy(result), NonNullList.of(null, ingredientList.toArray(new Ingredient[0])));
((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().addRecipe(recipe);
}
@Override
public String getJsonString(ItemStack itemStack) {
String json = CraftItemStack.asNMSCopy(itemStack).getDisplayName().getStyle().toString().replace("\\", "\\\\").replace("\"", "\\\"");
return json.substring(176, json.length() - 185);
}
@Override
public String getRawHoverText(ItemStack itemStack) {
net.minecraft.nbt.CompoundTag tag = CraftItemStack.asNMSCopy(itemStack).getTag();
if (tag == null) {
return null;
}
return tag.toString();
}
@Override
public PlayerProfile getSkullSkin(ItemStack is) {
net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(is);
if (itemStack.hasTag()) {
net.minecraft.nbt.CompoundTag tag = itemStack.getTag();
if (tag.contains("SkullOwner", 10)) {
GameProfile profile = NbtUtils.readGameProfile(tag.getCompound("SkullOwner"));
if (profile != null) {
Property property = Iterables.getFirst(profile.getProperties().get("textures"), null);
return new PlayerProfile(profile.getName(), profile.getId(),
property != null ? property.getValue() : null,
property != null ? property.getSignature() : null);
}
}
}
return null;
}
@Override
public ItemStack setSkullSkin(ItemStack itemStack, PlayerProfile playerProfile) {
GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
if (playerProfile.hasTexture()) {
gameProfile.getProperties().get("textures").clear();
if (playerProfile.getTextureSignature() != null) {
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
}
else {
gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture()));
}
}
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
net.minecraft.nbt.CompoundTag tag = nmsItemStack.hasTag() ? nmsItemStack.getTag() : new net.minecraft.nbt.CompoundTag();
tag.put("SkullOwner", NbtUtils.writeGameProfile(new net.minecraft.nbt.CompoundTag(), gameProfile));
nmsItemStack.setTag(tag);
return CraftItemStack.asBukkitCopy(nmsItemStack);
}
@Override
public ItemStack addNbtData(ItemStack itemStack, String key, Tag value) {
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
net.minecraft.nbt.CompoundTag tag = nmsItemStack.hasTag() ? nmsItemStack.getTag() : new net.minecraft.nbt.CompoundTag();
CompoundTag compound = CompoundTagImpl.fromNMSTag(tag).createBuilder().put(key, value).build();
nmsItemStack.setTag(((CompoundTagImpl) compound).toNMSTag());
return CraftItemStack.asBukkitCopy(nmsItemStack);
}
@Override
public CompoundTag getNbtData(ItemStack itemStack) {
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
if (nmsItemStack != null && nmsItemStack.hasTag()) {
return CompoundTagImpl.fromNMSTag(nmsItemStack.getTag());
}
return new CompoundTagImpl(new HashMap<>());
}
@Override
public ItemStack setNbtData(ItemStack itemStack, CompoundTag compoundTag) {
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
nmsItemStack.setTag(((CompoundTagImpl) compoundTag).toNMSTag());
return CraftItemStack.asBukkitCopy(nmsItemStack);
}
@Override
public void setInventoryItem(Inventory inventory, ItemStack item, int slot) {
if (inventory instanceof CraftInventoryPlayer && ((CraftInventoryPlayer) inventory).getInventory().player == null) {
((CraftInventoryPlayer) inventory).getInventory().setItem(slot, CraftItemStack.asNMSCopy(item));
}
else {
inventory.setItem(slot, item);
}
}
@Override
public IntArrayTag convertUuidToNbt(UUID id) {
return new IntArrayTag(NbtUtils.createUUID(id).getAsIntArray());
}
@Override
public UUID convertNbtToUuid(IntArrayTag id) {
return NbtUtils.loadUUID(new net.minecraft.nbt.IntArrayTag(id.getValue()));
}
@Override
public String getDisplayName(ItemTag item) {
if (!item.getItemMeta().hasDisplayName()) {
return null;
}
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item.getItemStack());
String jsonText = ((net.minecraft.nbt.CompoundTag) nmsItemStack.getTag().get("display")).getString("Name");
BaseComponent[] nameComponent = ComponentSerializer.parse(jsonText);
return FormattedTextHelper.stringify(nameComponent);
}
@Override
public List<String> getLore(ItemTag item) {
if (!item.getItemMeta().hasLore()) {
return null;
}
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item.getItemStack());
ListTag list = ((net.minecraft.nbt.CompoundTag) nmsItemStack.getTag().get("display")).getList("Lore", 8);
List<String> outList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
BaseComponent[] lineComponent = ComponentSerializer.parse(list.getString(i));
outList.add(FormattedTextHelper.stringify(lineComponent));
}
return outList;
}
@Override
public void setDisplayName(ItemTag item, String name) {
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item.getItemStack());
net.minecraft.nbt.CompoundTag tag = nmsItemStack.getOrCreateTag();
net.minecraft.nbt.CompoundTag display = tag.getCompound("display");
if (!tag.contains("display")) {
tag.put("display", display);
}
if (name == null || name.isEmpty()) {
display.put("Name", null);
return;
}
BaseComponent[] components = FormattedTextHelper.parse(name, ChatColor.WHITE);
display.put("Name", net.minecraft.nbt.StringTag.valueOf(ComponentSerializer.toString(components)));
item.setItemStack(CraftItemStack.asBukkitCopy(nmsItemStack));
}
@Override
public void setLore(ItemTag item, List<String> lore) {
net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item.getItemStack());
net.minecraft.nbt.CompoundTag tag = nmsItemStack.getOrCreateTag();
net.minecraft.nbt.CompoundTag display = tag.getCompound("display");
if (!tag.contains("display")) {
tag.put("display", display);
}
if (lore == null || lore.isEmpty()) {
display.put("Lore", null);
}
else {
ListTag tagList = new ListTag();
for (String line : lore) {
tagList.add(net.minecraft.nbt.StringTag.valueOf(ComponentSerializer.toString(FormattedTextHelper.parse(line, ChatColor.WHITE))));
}
display.put("Lore", tagList);
}
item.setItemStack(CraftItemStack.asBukkitCopy(nmsItemStack));
}
/**
* Copied from MapItem.getCorrectStateForFluidBlock, and rewritten as reflection due to Spigot bug - refer to bottom of BlockHelperImpl for detail.
*/
public static BlockState getCorrectStateForFluidBlock(Level world, BlockState iblockdata, BlockPos blockposition) {
try {
// FluidState fluid = iblockdata.getFluidState();
Object fluid = BlockHelperImpl.BLOCKSTATEBASE_GETFLUIDSTATE.invoke(iblockdata);
//return !fluid.isEmpty() && !iblockdata.isFaceSturdy(world, blockposition, Direction.UP) ? fluid.createLegacyBlock() : iblockdata;
boolean isEmpty = (boolean) BlockHelperImpl.FLUIDSTATE_ISEMPTY.invoke(fluid);
if (!isEmpty && !iblockdata.isFaceSturdy(world, blockposition, Direction.UP)) {
return (BlockState) BlockHelperImpl.FLUIDSTATE_CREATELEGACYBLOCK.invoke(fluid);
}
else {
return iblockdata;
}
}
catch (Throwable ex) {
Debug.echoError(ex);
return iblockdata;
}
}
public static boolean blockStateFluidIsEmpty(BlockState iblockdata) {
try {
// return iblockdata.getFluidState().isEmpty();
Object fluid = BlockHelperImpl.BLOCKSTATEBASE_GETFLUIDSTATE.invoke(iblockdata);
return (boolean) BlockHelperImpl.FLUIDSTATE_ISEMPTY.invoke(fluid);
}
catch (Throwable ex) {
Debug.echoError(ex);
return false;
}
}
/**
* Copied from MapItem.update, redesigned slightly to render totally rather than just relative to a player.
* Some variables manually renamed for readability.
* Also contains reflection fixes for Spigot's FluidState bug.
*/
public static void renderFullMap(MapItemSavedData worldmap, int xMin, int zMin, int xMax, int zMax) {
Level world = ((CraftWorld) worldmap.mapView.getWorld()).getHandle();
int scale = 1 << worldmap.scale;
int mapX = worldmap.x;
int mapZ = worldmap.z;
for (int x = xMin; x < xMax; x++) {
double d0 = 0.0D;
for (int z = zMin; z < zMax; z++) {
int k2 = (mapX / scale + x - 64) * scale;
int l2 = (mapZ / scale + z - 64) * scale;
Multiset<MaterialColor> multiset = LinkedHashMultiset.create();
LevelChunk chunk = world.getChunkAt(new BlockPos(k2, 0, l2));
if (!chunk.isEmpty()) {
ChunkPos chunkcoordintpair = chunk.getPos();
int i3 = k2 & 15;
int j3 = l2 & 15;
int k3 = 0;
double d1 = 0.0D;
if (world.dimensionType().hasCeiling()) {
int l3 = k2 + l2 * 231871;
l3 = l3 * l3 * 31287121 + l3 * 11;
if ((l3 >> 20 & 1) == 0) {
multiset.add(Blocks.DIRT.defaultBlockState().getMapColor(world, BlockPos.ZERO), 10);
}
else {
multiset.add(Blocks.STONE.defaultBlockState().getMapColor(world, BlockPos.ZERO), 100);
}
d1 = 100.0D;
}
else {
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
BlockPos.MutableBlockPos blockposition_mutableblockposition1 = new BlockPos.MutableBlockPos();
for (int i4 = 0; i4 < scale; ++i4) {
for (int j4 = 0; j4 < scale; ++j4) {
int k4 = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i4 + i3, j4 + j3) + 1;
BlockState iblockdata;
if (k4 <= world.getMinBuildHeight() + 1) {
iblockdata = Blocks.BEDROCK.defaultBlockState();
}
else {
do {
--k4;
blockposition_mutableblockposition.set(chunkcoordintpair.getMinBlockX() + i4 + i3, k4, chunkcoordintpair.getMinBlockZ() + j4 + j3);
iblockdata = chunk.getBlockState(blockposition_mutableblockposition);
} while (iblockdata.getMapColor(world, blockposition_mutableblockposition) == MaterialColor.NONE && k4 > world.getMinBuildHeight());
if (k4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata)) {
int l4 = k4 - 1;
blockposition_mutableblockposition1.set(blockposition_mutableblockposition);
BlockState iblockdata1;
do {
blockposition_mutableblockposition1.setY(l4--);
iblockdata1 = chunk.getBlockState(blockposition_mutableblockposition1);
k3++;
} while (l4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata1));
iblockdata = getCorrectStateForFluidBlock(world, iblockdata, blockposition_mutableblockposition);
}
}
worldmap.checkBanners(world, chunkcoordintpair.getMinBlockX() + i4 + i3, chunkcoordintpair.getMinBlockZ() + j4 + j3);
d1 += (double) k4 / (double) (scale * scale);
multiset.add(iblockdata.getMapColor(world, blockposition_mutableblockposition));
}
}
}
k3 /= scale * scale;
double d2 = (d1 - d0) * 4.0D / (double) (scale + 4) + ((double) (x + z & 1) - 0.5D) * 0.4D;
byte b0 = 1;
if (d2 > 0.6D) {
b0 = 2;
}
if (d2 < -0.6D) {
b0 = 0;
}
MaterialColor materialmapcolor = Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
if (materialmapcolor == MaterialColor.WATER) {
d2 = (double) k3 * 0.1D + (double) (x + z & 1) * 0.2D;
b0 = 1;
if (d2 < 0.5D) {
b0 = 2;
}
if (d2 > 0.9D) {
b0 = 0;
}
}
d0 = d1;
worldmap.updateColor(x, z, (byte) (materialmapcolor.id * 4 + b0));
}
}
}
}
@Override
public boolean renderEntireMap(int mapId, int xMin, int zMin, int xMax, int zMax) {
MapItemSavedData worldmap = ((CraftServer) Bukkit.getServer()).getServer().getLevel(net.minecraft.world.level.Level.OVERWORLD).getMapData("map_" + mapId);
if (worldmap == null) {
return false;
}
renderFullMap(worldmap, xMin, zMin, xMax, zMax);
return true;
}
@Override
public BlockData getPlacedBlock(Material material) {
Item nmsItem = Registry.ITEM.getOptional(CraftNamespacedKey.toMinecraft(material.getKey())).orElse(null);
if (nmsItem instanceof BlockItem) {
Block block = ((BlockItem) nmsItem).getBlock();
return CraftBlockData.fromData(block.defaultBlockState());
}
return null;
}
@Override
public boolean isValidMix(ItemStack input, ItemStack ingredient) {
net.minecraft.world.item.ItemStack nmsInput = CraftItemStack.asNMSCopy(input);
net.minecraft.world.item.ItemStack nmsIngredient = CraftItemStack.asNMSCopy(ingredient);
return PotionBrewing.hasMix(nmsInput, nmsIngredient);
}
public static Class<?> PaperPotionMix_CLASS = null;
@Override
public Map<NamespacedKey, BrewingRecipe> getCustomBrewingRecipes() {
Map<NamespacedKey, ?> nmsCustomRecipes = getNMSCustomBrewingRecipes();
Map<NamespacedKey, BrewingRecipe> brewingRecipes = new HashMap<>(nmsCustomRecipes.size());
for (Map.Entry<NamespacedKey, ?> entry : nmsCustomRecipes.entrySet()) {
brewingRecipes.put(entry.getKey(), paperMixToRecipe(entry.getValue()));
}
return brewingRecipes;
}
@Override
public Set<NamespacedKey> getCustomBrewingRecipeIDs() {
return getNMSCustomBrewingRecipes().keySet();
}
@Override
public BrewingRecipe getCustomBrewingRecipe(NamespacedKey recipeKey) {
return paperMixToRecipe(getNMSCustomBrewingRecipes().get(recipeKey));
}
public Map<NamespacedKey, ?> getNMSCustomBrewingRecipes() {
return ReflectionHelper.getFieldValue(PotionBrewing.class, "CUSTOM_MIXES", null);
}
public BrewingRecipe paperMixToRecipe(Object paperMix) {
if (paperMix == null) {
return null;
}
if (PaperPotionMix_CLASS == null) {
PaperPotionMix_CLASS = paperMix.getClass();
}
RecipeChoice ingredient = CraftRecipe.toBukkit(ReflectionHelper.getFieldValue(PaperPotionMix_CLASS, "ingredient", paperMix));
RecipeChoice input = CraftRecipe.toBukkit(ReflectionHelper.getFieldValue(PaperPotionMix_CLASS, "input", paperMix));
ItemStack result = CraftItemStack.asBukkitCopy(ReflectionHelper.getFieldValue(PaperPotionMix_CLASS, "result", paperMix));
return new BrewingRecipe(ingredient, input, result);
}
}