2020-03-01 18:19:59 +00:00
|
|
|
package com.thebrokenrail.sorcerycraft;
|
|
|
|
|
2020-03-18 00:42:02 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.advancement.CreateSpellCriterion;
|
|
|
|
import com.thebrokenrail.sorcerycraft.advancement.DiscoverAllSpellsCriterion;
|
2020-03-01 18:19:59 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.block.CastingTableBlock;
|
|
|
|
import com.thebrokenrail.sorcerycraft.command.SpellCommand;
|
|
|
|
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
|
|
|
|
import com.thebrokenrail.sorcerycraft.item.SpellItem;
|
2020-03-18 00:42:02 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.mixin.CriterionRegistryHook;
|
2020-03-01 18:19:59 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket;
|
2020-03-06 23:35:29 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.spell.util.RandomSpellLootTableFunction;
|
2020-03-21 02:05:32 +00:00
|
|
|
import com.thebrokenrail.sorcerycraft.spell.api.registry.Spells;
|
2020-03-16 15:21:06 +00:00
|
|
|
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
|
|
|
import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer;
|
2020-03-01 18:19:59 +00:00
|
|
|
import net.fabricmc.api.ModInitializer;
|
|
|
|
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
|
|
|
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
|
|
|
|
import net.fabricmc.fabric.api.entity.FabricEntityTypeBuilder;
|
|
|
|
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
|
|
|
|
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
|
|
|
|
import net.fabricmc.fabric.api.registry.CommandRegistry;
|
|
|
|
import net.fabricmc.fabric.impl.networking.ServerSidePacketRegistryImpl;
|
2020-03-03 02:43:25 +00:00
|
|
|
import net.minecraft.block.DispenserBlock;
|
|
|
|
import net.minecraft.block.dispenser.ProjectileDispenserBehavior;
|
2020-03-01 18:19:59 +00:00
|
|
|
import net.minecraft.entity.EntityCategory;
|
|
|
|
import net.minecraft.entity.EntityDimensions;
|
|
|
|
import net.minecraft.entity.EntityType;
|
2020-03-03 02:43:25 +00:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2020-03-20 03:06:38 +00:00
|
|
|
import net.minecraft.entity.projectile.ProjectileEntity;
|
2020-03-02 22:11:37 +00:00
|
|
|
import net.minecraft.item.BlockItem;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemGroup;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2020-03-01 18:19:59 +00:00
|
|
|
import net.minecraft.loot.BinomialLootTableRange;
|
|
|
|
import net.minecraft.loot.LootTables;
|
|
|
|
import net.minecraft.loot.entry.ItemEntry;
|
2020-03-03 23:08:22 +00:00
|
|
|
import net.minecraft.sound.SoundCategory;
|
2020-03-03 02:43:25 +00:00
|
|
|
import net.minecraft.sound.SoundEvent;
|
|
|
|
import net.minecraft.sound.SoundEvents;
|
2020-03-10 01:27:10 +00:00
|
|
|
import net.minecraft.stat.StatFormatter;
|
|
|
|
import net.minecraft.stat.Stats;
|
2020-03-01 18:19:59 +00:00
|
|
|
import net.minecraft.util.Identifier;
|
2020-03-03 02:43:25 +00:00
|
|
|
import net.minecraft.util.math.BlockPointer;
|
2020-03-01 18:19:59 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-03-03 02:43:25 +00:00
|
|
|
import net.minecraft.util.math.Position;
|
2020-03-01 18:19:59 +00:00
|
|
|
import net.minecraft.util.registry.Registry;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
2020-03-18 01:30:59 +00:00
|
|
|
public class SorceryCraft implements ModInitializer {
|
2020-03-01 18:19:59 +00:00
|
|
|
public static final String NAMESPACE = "sorcerycraft";
|
2020-03-18 00:42:02 +00:00
|
|
|
|
2020-03-01 18:19:59 +00:00
|
|
|
public static SpellItem SPELL_ITEM;
|
2020-03-18 00:42:02 +00:00
|
|
|
|
2020-03-01 18:19:59 +00:00
|
|
|
public static CastingTableBlock CASTING_TABLE_BLOCK;
|
|
|
|
public static BlockItem CASTING_TABLE_BLOCK_ITEM;
|
2020-03-18 00:42:02 +00:00
|
|
|
|
2020-03-01 18:19:59 +00:00
|
|
|
public static ItemGroup ITEM_GROUP;
|
2020-03-18 00:42:02 +00:00
|
|
|
|
2020-03-01 18:19:59 +00:00
|
|
|
public static EntityType<SpellEntity> SPELL_ENTITY;
|
2020-03-18 00:42:02 +00:00
|
|
|
|
2020-03-02 22:11:37 +00:00
|
|
|
public static final Identifier[] LOOT_TABLES = new Identifier[]{
|
2020-03-01 18:19:59 +00:00
|
|
|
LootTables.SIMPLE_DUNGEON_CHEST,
|
|
|
|
LootTables.END_CITY_TREASURE_CHEST,
|
|
|
|
LootTables.NETHER_BRIDGE_CHEST,
|
|
|
|
LootTables.ABANDONED_MINESHAFT_CHEST,
|
|
|
|
LootTables.SHIPWRECK_TREASURE_CHEST,
|
|
|
|
LootTables.DESERT_PYRAMID_CHEST,
|
|
|
|
LootTables.JUNGLE_TEMPLE_CHEST,
|
2020-03-08 23:49:37 +00:00
|
|
|
LootTables.STRONGHOLD_LIBRARY_CHEST,
|
|
|
|
LootTables.PILLAGER_OUTPOST_CHEST,
|
2020-03-21 17:25:28 +00:00
|
|
|
LootTables.WOODLAND_MANSION_CHEST,
|
|
|
|
LootTables.BURIED_TREASURE_CHEST,
|
|
|
|
LootTables.FISHING_TREASURE_GAMEPLAY
|
2020-03-01 18:19:59 +00:00
|
|
|
};
|
2020-03-18 00:42:02 +00:00
|
|
|
|
|
|
|
public static Identifier INTERACT_WITH_CASTING_TABLE_STAT;
|
|
|
|
public static Identifier CAST_SPELL_STAT;
|
|
|
|
|
|
|
|
public static DiscoverAllSpellsCriterion DISCOVER_ALL_SPELLS_CRITERION;
|
|
|
|
public static CreateSpellCriterion CREATE_SPELL_CRITERION;
|
2020-03-03 02:43:25 +00:00
|
|
|
|
2020-03-16 15:21:06 +00:00
|
|
|
public static ModConfig getConfig() {
|
|
|
|
return AutoConfig.getConfigHolder(ModConfig.class).getConfig();
|
|
|
|
}
|
|
|
|
|
2020-03-01 18:19:59 +00:00
|
|
|
private boolean isSelectedLootTable(Identifier lootTable) {
|
|
|
|
for (Identifier id : LOOT_TABLES) {
|
|
|
|
if (id.equals(lootTable)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInitialize() {
|
2020-03-03 23:08:22 +00:00
|
|
|
new Spells();
|
|
|
|
|
2020-03-16 15:21:06 +00:00
|
|
|
AutoConfig.register(ModConfig.class, GsonConfigSerializer::new);
|
|
|
|
|
2020-03-01 18:19:59 +00:00
|
|
|
ITEM_GROUP = FabricItemGroupBuilder.create(
|
|
|
|
new Identifier(NAMESPACE, "spells"))
|
|
|
|
.icon(() -> new ItemStack(SPELL_ITEM))
|
|
|
|
.build();
|
|
|
|
|
|
|
|
CASTING_TABLE_BLOCK = new CastingTableBlock();
|
|
|
|
CASTING_TABLE_BLOCK_ITEM = new BlockItem(CASTING_TABLE_BLOCK, new Item.Settings().group(ITEM_GROUP));
|
|
|
|
SPELL_ITEM = new SpellItem();
|
|
|
|
|
2020-03-03 02:43:25 +00:00
|
|
|
SPELL_ENTITY = FabricEntityTypeBuilder.create(EntityCategory.MISC, (EntityType.EntityFactory<SpellEntity>) SpellEntity::new).size(EntityDimensions.fixed(0.25f, 0.25f)).build();
|
2020-03-01 18:19:59 +00:00
|
|
|
|
|
|
|
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "spell"), SPELL_ITEM);
|
|
|
|
Registry.register(Registry.BLOCK, new Identifier(NAMESPACE, "casting_table"), CASTING_TABLE_BLOCK);
|
|
|
|
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "casting_table"), CASTING_TABLE_BLOCK_ITEM);
|
|
|
|
Registry.register(Registry.ENTITY_TYPE, new Identifier(NAMESPACE, "spell"), SPELL_ENTITY);
|
|
|
|
|
|
|
|
ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier(NAMESPACE, "casting_table"), (syncId, identifier, player, buf) -> {
|
|
|
|
final World world = player.world;
|
|
|
|
final BlockPos pos = buf.readBlockPos();
|
2020-03-13 22:05:12 +00:00
|
|
|
return Objects.requireNonNull(world.getBlockState(pos).createScreenHandlerFactory(player.world, pos)).createMenu(syncId, player.inventory, player);
|
2020-03-01 18:19:59 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
CommandRegistry.INSTANCE.register(false, SpellCommand::register);
|
|
|
|
|
|
|
|
ServerSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "select_spell"), SelectSpellC2SPacket::handle);
|
|
|
|
|
|
|
|
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
|
|
|
|
if (isSelectedLootTable(id)) {
|
|
|
|
FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
|
|
|
|
.withRolls(new BinomialLootTableRange(2, 0.5f))
|
|
|
|
.withEntry(ItemEntry.builder(SPELL_ITEM))
|
|
|
|
.withFunction(new RandomSpellLootTableFunction.Builder());
|
|
|
|
|
|
|
|
supplier.withPool(poolBuilder);
|
|
|
|
}
|
|
|
|
});
|
2020-03-03 02:43:25 +00:00
|
|
|
|
|
|
|
DispenserBlock.registerBehavior(SorceryCraft.SPELL_ITEM, new ProjectileDispenserBehavior() {
|
|
|
|
@Override
|
2020-03-20 03:06:38 +00:00
|
|
|
protected ProjectileEntity createProjectile(World position, Position stack, ItemStack itemStack) {
|
2020-03-03 02:43:25 +00:00
|
|
|
SpellEntity entity = new SpellEntity(position, stack.getX(), stack.getY(), stack.getZ());
|
|
|
|
entity.setItem(itemStack);
|
|
|
|
return entity;
|
|
|
|
}
|
2020-03-03 23:08:22 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void playSound(BlockPointer pointer) {
|
|
|
|
playSpellSound(pointer);
|
|
|
|
}
|
2020-03-03 02:43:25 +00:00
|
|
|
});
|
2020-03-10 01:27:10 +00:00
|
|
|
|
2020-03-18 00:42:02 +00:00
|
|
|
INTERACT_WITH_CASTING_TABLE_STAT = registerStat("interact_with_casting_table");
|
|
|
|
CAST_SPELL_STAT = registerStat("cast_spell");
|
|
|
|
|
|
|
|
DISCOVER_ALL_SPELLS_CRITERION = CriterionRegistryHook.callRegister(new DiscoverAllSpellsCriterion());
|
|
|
|
CREATE_SPELL_CRITERION = CriterionRegistryHook.callRegister(new CreateSpellCriterion());
|
2020-03-10 01:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private Identifier registerStat(String name) {
|
|
|
|
Identifier statID = new Identifier(NAMESPACE, name);
|
2020-03-23 19:13:17 +00:00
|
|
|
Registry.register(Registry.CUSTOM_STAT, statID, statID);
|
2020-03-10 01:27:10 +00:00
|
|
|
Stats.CUSTOM.getOrCreateStat(statID, StatFormatter.DEFAULT);
|
|
|
|
return statID;
|
2020-03-03 02:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static final SoundEvent SPELL_SOUND_EFFECT = SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE;
|
|
|
|
|
2020-03-04 01:22:40 +00:00
|
|
|
public static void playSpellSound(World world, BlockPos pos) {
|
|
|
|
world.playSound(null, pos, SPELL_SOUND_EFFECT, SoundCategory.BLOCKS, 1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
2020-03-03 23:08:22 +00:00
|
|
|
public static void playSpellSound(BlockPointer block) {
|
2020-03-04 01:22:40 +00:00
|
|
|
playSpellSound(block.getWorld(), block.getBlockPos());
|
2020-03-03 23:08:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 02:43:25 +00:00
|
|
|
public static void playSpellSound(PlayerEntity player) {
|
2020-03-03 23:08:22 +00:00
|
|
|
player.playSound(SPELL_SOUND_EFFECT, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
2020-03-01 18:19:59 +00:00
|
|
|
}
|
|
|
|
}
|