Skip to content

Commit

Permalink
fix: update codebase to 1.20.6 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 committed Jun 1, 2024
1 parent 200296d commit a011e03
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import de.dustplanet.silkspawners.compat.api.NMSProvider;
import net.minecraft.core.Registry;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
Expand All @@ -56,6 +57,7 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.component.CustomData;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.SpawnerBlockEntity;
Expand Down Expand Up @@ -228,7 +230,8 @@ public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
net.minecraft.world.item.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
CompoundTag tag = itemStack.getOrCreateTag();
final CustomData blockData = itemStack.getOrDefault(DataComponents.BLOCK_ENTITY_DATA, CustomData.EMPTY);
CompoundTag tag = blockData.copyTag();

// Check for SilkSpawners key
if (!tag.contains("SilkSpawners")) {
Expand Down Expand Up @@ -269,6 +272,7 @@ public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
}
tag.getCompound("EntityTag").putString("id", prefixedEntity);

itemStack.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(tag));
return CraftItemStack.asCraftMirror(itemStack);
}

Expand All @@ -278,7 +282,8 @@ public String getSilkSpawnersNBTEntityID(final ItemStack item) {
net.minecraft.world.item.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
final CompoundTag tag = itemStack.getTag();
final CustomData blockEntityData = itemStack.getOrDefault(DataComponents.BLOCK_ENTITY_DATA, CustomData.EMPTY);
final CompoundTag tag = blockEntityData.copyTag();

if (tag == null || !tag.contains("SilkSpawners")) {
return null;
Expand All @@ -292,7 +297,8 @@ public String getVanillaNBTEntityID(final ItemStack item) {
net.minecraft.world.item.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
CompoundTag tag = itemStack.getTag();
final CustomData blockEntityData = itemStack.getOrDefault(DataComponents.BLOCK_ENTITY_DATA, CustomData.EMPTY);
CompoundTag tag = blockEntityData.copyTag();

if (tag == null || !tag.contains("BlockEntityTag")) {
return null;
Expand All @@ -316,7 +322,7 @@ public String getVanillaNBTEntityID(final ItemStack item) {
/**
* Return the spawner block the player is looking at, or null if isn't.
*
* @param player the player
* @param player the player
* @param distance the reach distance
* @return the found block or null
*/
Expand Down Expand Up @@ -346,7 +352,8 @@ public ItemStack newEggItem(final String entityID, final int amount, final Strin
net.minecraft.world.item.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
final CompoundTag tag = itemStack.getOrCreateTag();
final CustomData blockEntityData = itemStack.getOrDefault(DataComponents.BLOCK_ENTITY_DATA, CustomData.EMPTY);
final CompoundTag tag = blockEntityData.copyTag();

if (!tag.contains("SilkSpawners")) {
tag.put("SilkSpawners", new CompoundTag());
Expand All @@ -366,6 +373,7 @@ public ItemStack newEggItem(final String entityID, final int amount, final Strin
}
tag.getCompound("EntityTag").putString("id", prefixedEntity);

itemStack.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(tag));
return CraftItemStack.asCraftMirror(itemStack);
}

Expand All @@ -374,7 +382,8 @@ public String getVanillaEggNBTEntityID(final ItemStack item) {
net.minecraft.world.item.ItemStack itemStack = null;
final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
itemStack = CraftItemStack.asNMSCopy(craftStack);
CompoundTag tag = itemStack.getTag();
final CustomData blockEntityData = itemStack.getOrDefault(DataComponents.BLOCK_ENTITY_DATA, CustomData.EMPTY);
CompoundTag tag = blockEntityData.copyTag();

if (tag == null || !tag.contains("EntityTag")) {
final Registry<Item> itemRegistry = BuiltInRegistries.ITEM;
Expand Down

0 comments on commit a011e03

Please sign in to comment.