185 lines
11 KiB
Java
185 lines
11 KiB
Java
package com.thebrokenrail.reliccraft;
|
|
|
|
import com.thebrokenrail.reliccraft.advancement.ActivateTeleportationBeaconCriterion;
|
|
import com.thebrokenrail.reliccraft.advancement.ActivateTeleportationRestrictorCriterion;
|
|
import com.thebrokenrail.reliccraft.advancement.DilateTimeCriterion;
|
|
import com.thebrokenrail.reliccraft.advancement.DuplicateTimeDilaterCriterion;
|
|
import com.thebrokenrail.reliccraft.advancement.RevealRelicCriterion;
|
|
import com.thebrokenrail.reliccraft.advancement.UseTargetedEnderPearlCriterion;
|
|
import com.thebrokenrail.reliccraft.advancement.UseTeleportationBeaconCriterion;
|
|
import com.thebrokenrail.reliccraft.block.DragonEggHolderBlockEntity;
|
|
import com.thebrokenrail.reliccraft.block.TeleportationBeaconBlock;
|
|
import com.thebrokenrail.reliccraft.block.TeleportationRestrictorBlock;
|
|
import com.thebrokenrail.reliccraft.entity.RelicEntity;
|
|
import com.thebrokenrail.reliccraft.item.DragonEggHolderBlockItem;
|
|
import com.thebrokenrail.reliccraft.item.GenerateRelicItem;
|
|
import com.thebrokenrail.reliccraft.item.RelicItem;
|
|
import com.thebrokenrail.reliccraft.item.TargetedEnderPearlItem;
|
|
import com.thebrokenrail.reliccraft.item.TimeDilaterItem;
|
|
import com.thebrokenrail.reliccraft.loot.RelicLootTableFunction;
|
|
import com.thebrokenrail.reliccraft.mixin.CriteriaRegistryHook;
|
|
import com.thebrokenrail.reliccraft.recipe.RevealRelicRecipe;
|
|
import com.thebrokenrail.reliccraft.recipe.TimeDilaterRecipe;
|
|
import com.thebrokenrail.reliccraft.structure.TimeTempleFeature;
|
|
import com.thebrokenrail.reliccraft.structure.TimeTempleGenerator;
|
|
import net.earthcomputer.libstructure.LibStructure;
|
|
import net.fabricmc.api.ModInitializer;
|
|
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
|
import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder;
|
|
import net.fabricmc.fabric.api.loot.v1.event.LootTableLoadingCallback;
|
|
import net.fabricmc.fabric.api.tag.TagRegistry;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.entity.BlockEntityType;
|
|
import net.minecraft.entity.EntityType;
|
|
import net.minecraft.entity.SpawnGroup;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemGroup;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.loot.BinomialLootTableRange;
|
|
import net.minecraft.loot.LootTables;
|
|
import net.minecraft.loot.entry.ItemEntry;
|
|
import net.minecraft.loot.function.LootFunctionType;
|
|
import net.minecraft.recipe.SpecialRecipeSerializer;
|
|
import net.minecraft.sound.SoundCategory;
|
|
import net.minecraft.sound.SoundEvent;
|
|
import net.minecraft.sound.SoundEvents;
|
|
import net.minecraft.structure.StructurePieceType;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.registry.Registry;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.biome.Biome;
|
|
import net.minecraft.world.gen.GenerationStep;
|
|
import net.minecraft.world.gen.chunk.StructureConfig;
|
|
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
|
|
import net.minecraft.world.gen.feature.FeatureConfig;
|
|
import net.minecraft.world.gen.feature.StructureFeature;
|
|
|
|
public class RelicCraft implements ModInitializer {
|
|
public static final String NAMESPACE = "reliccraft";
|
|
|
|
public static Item ORB_ITEM;
|
|
public static Item STAFF_ITEM;
|
|
public static Item TIME_DILATER_ITEM;
|
|
public static Item TARGETED_ENDER_PEARL_ITEM;
|
|
public static Item GENERATE_RELIC_ITEM;
|
|
|
|
public static EntityType<RelicEntity> RELIC_ENTITY;
|
|
|
|
public static SpecialRecipeSerializer<RevealRelicRecipe> REVEAL_RELIC_RECIPE;
|
|
public static SpecialRecipeSerializer<TimeDilaterRecipe> TIME_DILATER_RECIPE;
|
|
|
|
public static Block TELEPORTATION_RESTRICTOR_BLOCK;
|
|
public static Block TELEPORTATION_BEACON_BLOCK;
|
|
public static BlockEntityType<DragonEggHolderBlockEntity> DRAGON_EGG_HOLDER_BLOCK_ENTITY;
|
|
|
|
public static final Identifier[] LOOT_TABLES = new Identifier[]{
|
|
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,
|
|
LootTables.STRONGHOLD_LIBRARY_CHEST,
|
|
LootTables.PILLAGER_OUTPOST_CHEST,
|
|
LootTables.WOODLAND_MANSION_CHEST,
|
|
LootTables.BURIED_TREASURE_CHEST,
|
|
LootTables.FISHING_TREASURE_GAMEPLAY
|
|
};
|
|
|
|
public static ActivateTeleportationRestrictorCriterion ACTIVATE_TELEPORTATION_RESTRICTOR_CRITERION;
|
|
public static RevealRelicCriterion REVEAL_RELIC_CRITERION;
|
|
public static DilateTimeCriterion DILATE_TIME_CRITERION;
|
|
public static DuplicateTimeDilaterCriterion DUPLICATE_TIME_DILATER_CRITERION;
|
|
public static ActivateTeleportationBeaconCriterion ACTIVATE_TELEPORTATION_BEACON_CRITERION;
|
|
public static UseTeleportationBeaconCriterion USE_TELEPORTATION_BEACON_CRITERION;
|
|
public static UseTargetedEnderPearlCriterion USE_TARGETED_ENDER_PEARL;
|
|
|
|
private boolean isSelectedLootTable(Identifier lootTable) {
|
|
for (Identifier id : LOOT_TABLES) {
|
|
if (id.equals(lootTable)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static final SoundEvent RELIC_SOUND_EFFECT = SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE;
|
|
private static final SoundEvent INTERACT_TELEPORT_RESTRICTOR_SOUND_EFFECT = SoundEvents.BLOCK_END_PORTAL_FRAME_FILL;
|
|
|
|
public static void playRelicSound(PlayerEntity player) {
|
|
player.playSound(RELIC_SOUND_EFFECT, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
|
}
|
|
|
|
public static void playInteractTeleportRestrictorSound(World world, BlockPos pos) {
|
|
world.playSound(null, pos, INTERACT_TELEPORT_RESTRICTOR_SOUND_EFFECT, SoundCategory.BLOCKS, 1.0f, 1.0f);
|
|
}
|
|
|
|
public static StructureFeature<DefaultFeatureConfig> TIME_TEMPLE_STRUCTURE_FEATURE = new TimeTempleFeature(DefaultFeatureConfig.CODEC);
|
|
public static StructurePieceType TIME_TEMPLE_STRUCTURE_PIECE = TimeTempleGenerator.Piece::new;
|
|
|
|
public static ItemGroup ITEM_GROUP;
|
|
|
|
public final static Identifier TIME_TEMPLE_ID = new Identifier(NAMESPACE, "time_temple");
|
|
|
|
@Override
|
|
public void onInitialize() {
|
|
ITEM_GROUP = FabricItemGroupBuilder.build(new Identifier(NAMESPACE, "item_group"), () -> new ItemStack(TIME_DILATER_ITEM));
|
|
|
|
ORB_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "orb"), new RelicItem());
|
|
STAFF_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "staff"), new RelicItem());
|
|
TIME_DILATER_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "time_dilater"), new TimeDilaterItem());
|
|
TARGETED_ENDER_PEARL_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "targeted_ender_pearl"), new TargetedEnderPearlItem());
|
|
GENERATE_RELIC_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "generate_relic"), new GenerateRelicItem());
|
|
|
|
Identifier entityID = new Identifier(NAMESPACE, "relic_entity");
|
|
RELIC_ENTITY = Registry.register(Registry.ENTITY_TYPE, entityID, EntityType.Builder.create((EntityType.EntityFactory<RelicEntity>) RelicEntity::new, SpawnGroup.MISC).setDimensions(0.25f, 0.25f).build(entityID.toString()));
|
|
|
|
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
|
|
if (isSelectedLootTable(id)) {
|
|
FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
|
|
.rolls(new BinomialLootTableRange(2, 0.5f))
|
|
.withEntry(ItemEntry.builder(ORB_ITEM).build())
|
|
.withEntry(ItemEntry.builder(STAFF_ITEM).build())
|
|
.withFunction(new RelicLootTableFunction.Builder().build());
|
|
|
|
supplier.withPool(poolBuilder.build());
|
|
}
|
|
});
|
|
Registry.register(Registry.LOOT_FUNCTION_TYPE, new Identifier(NAMESPACE, "randomize_relic"), new LootFunctionType(new RelicLootTableFunction.Serializer()));
|
|
|
|
REVEAL_RELIC_RECIPE = Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(NAMESPACE, "reveal_relic"), new SpecialRecipeSerializer<>(RevealRelicRecipe::new));
|
|
TIME_DILATER_RECIPE = Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(NAMESPACE, "time_dilater"), new SpecialRecipeSerializer<>(TimeDilaterRecipe::new));
|
|
|
|
TELEPORTATION_RESTRICTOR_BLOCK = Registry.register(Registry.BLOCK, new Identifier(NAMESPACE, "teleportation_restrictor"), new TeleportationRestrictorBlock());
|
|
TELEPORTATION_BEACON_BLOCK = Registry.register(Registry.BLOCK, new Identifier(NAMESPACE, "teleportation_beacon"), new TeleportationBeaconBlock());
|
|
DRAGON_EGG_HOLDER_BLOCK_ENTITY = Registry.register(Registry.BLOCK_ENTITY_TYPE, new Identifier(NAMESPACE, "dragon_egg_holder"), BlockEntityType.Builder.create(DragonEggHolderBlockEntity::new, TELEPORTATION_RESTRICTOR_BLOCK, TELEPORTATION_BEACON_BLOCK).build(null));
|
|
|
|
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "teleportation_restrictor"), new DragonEggHolderBlockItem(TELEPORTATION_RESTRICTOR_BLOCK));
|
|
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "teleportation_beacon"), new DragonEggHolderBlockItem(TELEPORTATION_BEACON_BLOCK));
|
|
|
|
ACTIVATE_TELEPORTATION_RESTRICTOR_CRITERION = CriteriaRegistryHook.callRegister(new ActivateTeleportationRestrictorCriterion());
|
|
REVEAL_RELIC_CRITERION = CriteriaRegistryHook.callRegister(new RevealRelicCriterion());
|
|
DILATE_TIME_CRITERION = CriteriaRegistryHook.callRegister(new DilateTimeCriterion());
|
|
DUPLICATE_TIME_DILATER_CRITERION = CriteriaRegistryHook.callRegister(new DuplicateTimeDilaterCriterion());
|
|
ACTIVATE_TELEPORTATION_BEACON_CRITERION = CriteriaRegistryHook.callRegister(new ActivateTeleportationBeaconCriterion());
|
|
USE_TELEPORTATION_BEACON_CRITERION = CriteriaRegistryHook.callRegister(new UseTeleportationBeaconCriterion());
|
|
USE_TARGETED_ENDER_PEARL = CriteriaRegistryHook.callRegister(new UseTargetedEnderPearlCriterion());
|
|
|
|
//noinspection ResultOfMethodCallIgnored
|
|
TagRegistry.item(new Identifier(NAMESPACE, "relics"));
|
|
//noinspection ResultOfMethodCallIgnored
|
|
TagRegistry.item(new Identifier(NAMESPACE, "advancement_trigger_items"));
|
|
|
|
Registry.register(Registry.STRUCTURE_PIECE, new Identifier(NAMESPACE, "time_temple"), TIME_TEMPLE_STRUCTURE_PIECE);
|
|
for (Biome biome : Registry.BIOME) {
|
|
if (biome.getCategory() == Biome.Category.PLAINS) {
|
|
biome.addStructureFeature(TIME_TEMPLE_STRUCTURE_FEATURE.configure(FeatureConfig.DEFAULT));
|
|
}
|
|
}
|
|
LibStructure.registerStructure(TIME_TEMPLE_ID, TIME_TEMPLE_STRUCTURE_FEATURE, GenerationStep.Feature.SURFACE_STRUCTURES, new StructureConfig(32, 8, 14357618), TIME_TEMPLE_STRUCTURE_FEATURE.configure(FeatureConfig.DEFAULT));
|
|
}
|
|
}
|