Skip to content

Commit

Permalink
Merge branch '1.20.2' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 committed Dec 27, 2023
2 parents 3cd3021 + 20cc085 commit 6798d69
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 112 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Thank you!
- Stopped Crabs from moving when they aren't supposed to
- Renamed the `wilderwild:crab_tempt_items` tag to `wilderwild:crab_food`
- Fixed the Looting enchantment not affecting the Crab claw loot table
- Fixed Display Lanterns not properly saving Fireflies to the item when broken with Silk Touch, and not spawning Fireflies upon breaking without Silk Touch
- Fixed log spam of the Enderman anger sound predicate
- Fixed tags on 1.20.4
- Fixed potted grass loot table on 1.20.4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"name": "wilderwild:display_lantern"
}
],
"functions": [
{
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch"
}
]
}
}
],
"function": "minecraft:copy_nbt",
"ops": [
{
"op": "replace",
"source": "Fireflies",
"target": "BlockEntityTag.Fireflies"
}
],
"source": "block_entity"
},
{
"block": "wilderwild:display_lantern",
"conditions": [
{
"condition": "minecraft:match_tool",
"predicate": {
"enchantments": [
{
"enchantment": "minecraft:silk_touch"
}
]
}
}
],
"function": "minecraft:copy_state",
"properties": [
"display_light"
]
}
],
"rolls": 1.0
}
]
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import net.frozenblock.wilderwild.block.entity.DisplayLanternBlockEntity;
import net.frozenblock.wilderwild.entity.variant.FireflyColor;
import net.frozenblock.wilderwild.item.FireflyBottle;
import net.frozenblock.wilderwild.misc.WilderSharedConstants;
import net.frozenblock.wilderwild.registry.RegisterBlockEntities;
import net.frozenblock.wilderwild.registry.RegisterItems;
import net.frozenblock.wilderwild.registry.RegisterProperties;
Expand All @@ -36,7 +35,6 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -70,18 +68,14 @@
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("deprecation")
public class DisplayLanternBlock extends BaseEntityBlock implements SimpleWaterloggedBlock {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty HANGING = BlockStateProperties.HANGING;
Expand Down Expand Up @@ -287,36 +281,11 @@ public int getAnalogOutputSignal(@NotNull BlockState state, @NotNull Level level
@Override
public void playerDestroy(@NotNull Level level, @NotNull Player player, @NotNull BlockPos pos, @NotNull BlockState state, @Nullable BlockEntity blockEntity, @NotNull ItemStack stack) {
if (!level.isClientSide && blockEntity instanceof DisplayLanternBlockEntity lanternEntity) {
boolean silk = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, stack) == 0 || player.isCreative();
if (!silk && !lanternEntity.getFireflies().isEmpty()) {
if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, stack) == 0) {
lanternEntity.spawnFireflies(level);
}
}
super.playerDestroy(level, player, pos, state, blockEntity, stack);
}

@Override
@NotNull
public List<ItemStack> getDrops(@NotNull BlockState blockState, @NotNull LootParams.Builder builder) {
ResourceLocation resourceLocation = this.getLootTable();
if (builder.getOptionalParameter(LootContextParams.TOOL) != null) {
ItemStack stack = builder.getParameter(LootContextParams.TOOL);
if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, stack) != 0) {
if (builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY) != null) {
BlockEntity blockEntity = builder.getParameter(LootContextParams.BLOCK_ENTITY);
if (blockEntity instanceof DisplayLanternBlockEntity lantern && !lantern.getFireflies().isEmpty()) {
resourceLocation = WilderSharedConstants.id("blocks/display_lantern_fireflies");
}
}
}
}
if (resourceLocation == BuiltInLootTables.EMPTY) {
return Collections.emptyList();
} else {
LootParams lootParams = builder.withParameter(LootContextParams.BLOCK_STATE, blockState).create(LootContextParamSets.BLOCK);
ServerLevel serverLevel = lootParams.getLevel();
LootTable lootTable = serverLevel.getServer().getLootData().getLootTable(resourceLocation);
return lootTable.getRandomItems(lootParams);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ public void removeFirefly(@NotNull FireflyInLantern firefly) {
public void spawnFireflies() {
if (this.level != null) {
if (!this.level.isClientSide) {
doFireflySpawns(level);
this.doFireflySpawns(level);
}
}
}

public void spawnFireflies(@NotNull Level level) {
doFireflySpawns(level);
if (!this.getFireflies().isEmpty()) {
this.doFireflySpawns(level);
}
}

private void doFireflySpawns(@NotNull Level level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@

import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;
import net.frozenblock.wilderwild.block.DisplayLanternBlock;
import net.frozenblock.wilderwild.misc.WilderSharedConstants;
import net.frozenblock.wilderwild.registry.RegisterBlocks;
import net.minecraft.advancements.critereon.EnchantmentPredicate;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.functions.CopyBlockState;
import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction;
import net.minecraft.world.level.storage.loot.predicates.MatchTool;
import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
import org.jetbrains.annotations.NotNull;

final class WWBlockLootProvider extends FabricBlockLootTableProvider {
Expand All @@ -36,5 +50,25 @@ public void generate() {
this.dropSelf(RegisterBlocks.PALM_HANGING_SIGN);

this.dropPottedContents(RegisterBlocks.POTTED_GRASS);

this.add(RegisterBlocks.DISPLAY_LANTERN,
LootTable.lootTable().withPool(
LootPool.lootPool()
.setRolls(ConstantValue.exactly(1.0F))
.add(
LootItem.lootTableItem(RegisterBlocks.DISPLAY_LANTERN)
)
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Fireflies", "BlockEntityTag.Fireflies").when(
MatchTool.toolMatches(
ItemPredicate.Builder.item().hasEnchantment(new EnchantmentPredicate(Enchantments.SILK_TOUCH, MinMaxBounds.Ints.ANY))
)
))
.apply(CopyBlockState.copyState(RegisterBlocks.DISPLAY_LANTERN).copy(DisplayLanternBlock.DISPLAY_LIGHT).when(
MatchTool.toolMatches(
ItemPredicate.Builder.item().hasEnchantment(new EnchantmentPredicate(Enchantments.SILK_TOUCH, MinMaxBounds.Ints.ANY))
)
))
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void onInitializeDataGenerator(@NotNull FabricDataGenerator dataGenerator
pack.addProvider(WWItemTagProvider::new);
pack.addProvider(WWEntityTagProvider::new);
pack.addProvider(WWGameEventTagProvider::new);
pack.addProvider(WWLootProvider::new);
pack.addProvider(WWEntityLootProvider::new);
pack.addProvider(WWRecipeProvider::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
import java.util.function.BiConsumer;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.SimpleFabricLootTableProvider;
import net.frozenblock.wilderwild.block.DisplayLanternBlock;
import net.frozenblock.wilderwild.misc.WilderSharedConstants;
import net.frozenblock.wilderwild.registry.RegisterBlocks;
import net.frozenblock.wilderwild.registry.RegisterEntities;
import net.frozenblock.wilderwild.registry.RegisterItems;
import net.minecraft.data.loot.EntityLootSubProvider;
Expand All @@ -32,22 +29,19 @@
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.functions.CopyBlockState;
import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction;
import net.minecraft.world.level.storage.loot.functions.LootingEnchantFunction;
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
import net.minecraft.world.level.storage.loot.functions.SmeltItemFunction;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.predicates.LootItemEntityPropertyCondition;
import net.minecraft.world.level.storage.loot.predicates.LootItemKilledByPlayerCondition;
import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
import org.jetbrains.annotations.NotNull;

public class WWLootProvider extends SimpleFabricLootTableProvider {
public class WWEntityLootProvider extends SimpleFabricLootTableProvider {

public WWLootProvider(FabricDataOutput output) {
public WWEntityLootProvider(FabricDataOutput output) {
super(output, LootContextParamSets.ENTITY);
}

Expand All @@ -66,18 +60,5 @@ public void generate(@NotNull BiConsumer<ResourceLocation, LootTable.Builder> ou
.when(LootItemKilledByPlayerCondition.killedByPlayer())
)
);

output.accept(
WilderSharedConstants.id("blocks/display_lantern_fireflies"),
LootTable.lootTable().withPool(
LootPool.lootPool()
.setRolls(ConstantValue.exactly(1.0F))
.add(
LootItem.lootTableItem(RegisterBlocks.DISPLAY_LANTERN)
.apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Fireflies", "BlockEntityTag.Fireflies"))
.apply(CopyBlockState.copyState(RegisterBlocks.DISPLAY_LANTERN).copy(DisplayLanternBlock.DISPLAY_LIGHT))
)
)
);
}
}

This file was deleted.

0 comments on commit 6798d69

Please sign in to comment.