-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
177 additions
and
57 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/com/hugman/lucky_block/lucky_event/LootLuckyEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.hugman.lucky_block.lucky_event; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.loot.LootTable; | ||
import net.minecraft.loot.context.LootContextParameters; | ||
import net.minecraft.loot.context.LootContextTypes; | ||
import net.minecraft.loot.context.LootWorldContext; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Lucky event that drops the content of a loot table. | ||
* | ||
* @author Hugman | ||
* @since 1.0.0 | ||
*/ | ||
public record LootLuckyEvent(RegistryKey<LootTable> lootTable) implements LuckyEvent { | ||
public static final MapCodec<LootLuckyEvent> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( | ||
RegistryKey.createCodec(RegistryKeys.LOOT_TABLE).fieldOf("loot_table").forGetter(LootLuckyEvent::lootTable) | ||
).apply(instance, LootLuckyEvent::new)); | ||
|
||
public void trigger(ServerWorld world, PlayerEntity player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity) { | ||
getLoots(world, pos, player, player.getMainHandStack()).forEach((stack) -> Block.dropStack(world, pos, stack)); | ||
} | ||
|
||
public List<ItemStack> getLoots(ServerWorld world, BlockPos pos, @Nullable Entity entity, ItemStack stack) { | ||
return world.getServer().getReloadableRegistries().getLootTable(this.lootTable) | ||
.generateLoot(new LootWorldContext.Builder(world) | ||
.add(LootContextParameters.ORIGIN, Vec3d.ofCenter(pos)) | ||
.add(LootContextParameters.TOOL, stack) | ||
.add(LootContextParameters.BLOCK_STATE, world.getBlockState(pos)) | ||
.addOptional(LootContextParameters.BLOCK_ENTITY, world.getBlockEntity(pos)) | ||
.addOptional(LootContextParameters.THIS_ENTITY, entity) | ||
.build(LootContextTypes.BLOCK)); | ||
} | ||
|
||
@Override | ||
public LuckyEventType<?> getType() { | ||
return LuckyEventTypes.LOOT; | ||
} | ||
} |
55 changes: 0 additions & 55 deletions
55
src/main/java/com/hugman/lucky_block/lucky_event/LootTableLuckyEvent.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/resources/data/lucky_block/loot_table/lucky_sword.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"type": "minecraft:block", | ||
"pools": [ | ||
{ | ||
"bonus_rolls": 0, | ||
"conditions": [ | ||
{ | ||
"condition": "minecraft:survives_explosion" | ||
} | ||
], | ||
"entries": [ | ||
{ | ||
"type": "minecraft:item", | ||
"name": "minecraft:golden_sword", | ||
"expand": true, | ||
"functions": [ | ||
{ | ||
"function": "minecraft:enchant_randomly", | ||
"only_compatible": true | ||
}, | ||
{ | ||
"function": "minecraft:set_name", | ||
"name": "Lucky Sword" | ||
} | ||
], | ||
"conditions": [] | ||
} | ||
], | ||
"rolls": 1 | ||
} | ||
], | ||
"random_sequence": "lucky_block:lucky_item" | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/data/lucky_block/lucky_block/lucky_event/loot_lucky_sword.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "lucky_block:loot", | ||
"loot_table": "lucky_block:lucky_sword" | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/resources/data/lucky_block/lucky_block/lucky_event/summon_bob.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"type": "lucky_block:summon_entity", | ||
"data": { | ||
"id": "minecraft:zombie", | ||
"CustomName": "Bob", | ||
"ArmorItems": [ | ||
{ | ||
"id": "minecraft:diamond_boots", | ||
"count": 1, | ||
"components": { | ||
"minecraft:enchantments": { | ||
"minecraft:protection": 4, | ||
"minecraft:unbreaking": 3 | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "minecraft:diamond_leggings", | ||
"count": 1, | ||
"components": { | ||
"minecraft:enchantments": { | ||
"minecraft:protection": 4, | ||
"minecraft:unbreaking": 3 | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "minecraft:diamond_chestplate", | ||
"count": 1, | ||
"components": { | ||
"minecraft:enchantments": { | ||
"minecraft:protection": 4, | ||
"minecraft:unbreaking": 3 | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "minecraft:diamond_helmet", | ||
"count": 1, | ||
"components": { | ||
"minecraft:enchantments": { | ||
"minecraft:protection": 4, | ||
"minecraft:unbreaking": 3 | ||
} | ||
} | ||
} | ||
], | ||
"HandItems": [ | ||
{ | ||
"id": "minecraft:diamond_sword", | ||
"count": 1, | ||
"components": { | ||
"minecraft:enchantments": { | ||
"minecraft:sharpness": 5, | ||
"minecraft:unbreaking": 3, | ||
"minecraft:fire_aspect": 2 | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "minecraft:shield", | ||
"count": 1, | ||
"components": { | ||
"minecraft:enchantments": { | ||
"minecraft:unbreaking": 3 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/data/lucky_block/lucky_block/lucky_event/summon_one_tnt.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "lucky_block:summon_entity", | ||
"data": "{\"id\": \"minecraft:tnt\",\"fuse\": 20,\"Motion\":[0.0, 0.5, 0.0]}" | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/data/lucky_block/lucky_block/lucky_event/summon_one_wind_charge.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type": "lucky_block:summon_entity", | ||
"data": "{\"id\": \"minecraft:wind_charge\",\"Motion\":[0.0, -0.5, 0.0]}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters