Files
src
build.gradle
gradle.properties
LICENSE
README_RU.md
settings.gradle
Code
10 342
src/main/java/com/example/lethalcompany/LethalCompanyMod.java
package com.example.lethalcompany;
import com.example.lethalcompany.entity.LethalMobEntity;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.item.Item;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.item.ItemGroup;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.block.Blocks;
import net.minecraft.server.command.CommandManager;
public class LethalCompanyMod implements ModInitializer {
public static final String MOD_ID = "lethalcompany";
public static final EntityType<LethalMobEntity> BRACKEN = mob("bracken", 0.7f, 2.0f);
public static final EntityType<LethalMobEntity> COIL_HEAD = mob("coil_head", 0.8f, 2.1f);
public static final EntityType<LethalMobEntity> THUMPER = mob("thumper", 1.2f, 1.0f);
public static final EntityType<LethalMobEntity> JESTER = mob("jester", 0.8f, 1.9f);
public static final EntityType<LethalMobEntity> HYGRODERE = mob("hygrodere", 1.1f, 0.8f);
public static final EntityType<LethalMobEntity> GHOST_GIRL = mob("ghost_girl", 0.6f, 1.8f);
public static final EntityType<LethalMobEntity> HOARDING_BUG = mob("hoarding_bug", 0.7f, 0.9f);
public static final EntityType<LethalMobEntity> SNARE_FLEA = mob("snare_flea", 0.8f, 0.6f);
public static final EntityType<LethalMobEntity> BUNKER_SPIDER = mob("bunker_spider", 1.4f, 0.8f);
public static final EntityType<LethalMobEntity> FOREST_KEEPER = mob("forest_keeper", 2.0f, 4.0f);
private static EntityType<LethalMobEntity> mob(String name, float width, float height) {
return Registry.register(Registries.ENTITY_TYPE, id(name),
EntityType.Builder.create(LethalMobEntity::new, SpawnGroup.MONSTER)
.setDimensions(width, height).maxTrackingRange(10).build(name));
}
public static final ItemGroup ITEM_GROUP = Registry.register(Registries.ITEM_GROUP, id("items"),
FabricItemGroup.builder().displayName(Text.literal("Lethal Company"))
.icon(() -> new ItemStack(Blocks.IRON_BLOCK)).entries((context, entries) -> {
entries.add(new ItemStack(spawnEgg(BRACKEN, 0x27352b, 0x91a67c, "bracken")));
entries.add(new ItemStack(spawnEgg(COIL_HEAD, 0xb8b8b8, 0x555555, "coil_head")));
entries.add(new ItemStack(spawnEgg(THUMPER, 0x5b3a2b, 0xc58a48, "thumper")));
entries.add(new ItemStack(spawnEgg(JESTER, 0x6b2d8b, 0xd9b84f, "jester")));
entries.add(new ItemStack(spawnEgg(HYGRODERE, 0x42a6a6, 0x9ee7c4, "hygrodere")));
entries.add(new ItemStack(spawnEgg(GHOST_GIRL, 0xb44b55, 0xe9c9c9, "ghost_girl")));
entries.add(new ItemStack(spawnEgg(HOARDING_BUG, 0x5d3924, 0xc98c47, "hoarding_bug")));
entries.add(new ItemStack(spawnEgg(SNARE_FLEA, 0x7a553e, 0xc9ad8b, "snare_flea")));
entries.add(new ItemStack(spawnEgg(BUNKER_SPIDER, 0x342b26, 0x8a6548, "bunker_spider")));
entries.add(new ItemStack(spawnEgg(FOREST_KEEPER, 0x5d6842, 0xb2a36b, "forest_keeper")));
}).build());
private static Item spawnEgg(EntityType<?> type, int primary, int secondary, String name) {
return Registry.register(Registries.ITEM, id(name + "_spawn_egg"),
new SpawnEggItem(type, primary, secondary, new Item.Settings()));
}
public static Identifier id(String path) { return new Identifier(MOD_ID, path); }
@Override
public void onInitialize() {
for (EntityType<LethalMobEntity> type : new EntityType[]{
BRACKEN, COIL_HEAD, THUMPER, JESTER, HYGRODERE,
GHOST_GIRL, HOARDING_BUG, SNARE_FLEA, BUNKER_SPIDER, FOREST_KEEPER
}) {
FabricDefaultAttributeRegistry.register(type, LethalMobEntity.createAttributes());
}
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
dispatcher.register(CommandManager.literal("lethalmap")
.requires(source -> source.hasPermissionLevel(2))
.executes(context -> {
var player = context.getSource().getPlayerOrThrow();
BlockPos origin = player.getBlockPos().add(4, 0, 4);
buildFacility(context.getSource().getWorld(), origin);
context.getSource().sendFeedback(() -> Text.literal("Lethal Company: тестовая база построена!"), false);
return 1;
})));
}
private static void buildFacility(net.minecraft.server.world.ServerWorld world, BlockPos p) {
int w = 19, d = 15, h = 6;
// Floor
for (int x = 0; x < w; x++) for (int z = 0; z < d; z++)
world.setBlockState(p.add(x, 0, z), Blocks.IRON_BLOCK.getDefaultState());
// Outer walls and roof
for (int y = 1; y <= h; y++) {
for (int x = 0; x < w; x++) {
world.setBlockState(p.add(x, y, 0), Blocks.IRON_BLOCK.getDefaultState());
world.setBlockState(p.add(x, y, d - 1), Blocks.IRON_BLOCK.getDefaultState());
}
for (int z = 0; z < d; z++) {
world.setBlockState(p.add(0, y, z), Blocks.IRON_BLOCK.getDefaultState());
world.setBlockState(p.add(w - 1, y, z), Blocks.IRON_BLOCK.getDefaultState());
}
}
for (int x = 0; x < w; x++) for (int z = 0; z < d; z++)
world.setBlockState(p.add(x, h + 1, z), Blocks.IRON_BLOCK.getDefaultState());
// Corridor dividers and emergency lighting
for (int x = 3; x < w - 3; x++) {
world.setBlockState(p.add(x, 1, 5), Blocks.IRON_BLOCK.getDefaultState());
world.setBlockState(p.add(x, 1, 10), Blocks.IRON_BLOCK.getDefaultState());
}
for (int x = 2; x < w - 2; x += 4) {
world.setBlockState(p.add(x, 2, 2), Blocks.REDSTONE_LAMP.getDefaultState());
world.setBlockState(p.add(x, 2, 7), Blocks.REDSTONE_LAMP.getDefaultState());
world.setBlockState(p.add(x, 2, 12), Blocks.REDSTONE_LAMP.getDefaultState());
}
// Clear the entrance and carve three room doors
for (int y = 1; y <= 2; y++) {
world.setBlockState(p.add(w / 2, y, 0), Blocks.AIR.getDefaultState());
world.setBlockState(p.add(5, y, 5), Blocks.AIR.getDefaultState());
world.setBlockState(p.add(13, y, 5), Blocks.AIR.getDefaultState());
world.setBlockState(p.add(9, y, 10), Blocks.AIR.getDefaultState());
}
world.setBlockState(p.add(2, 1, 2), Blocks.BARREL.getDefaultState());
world.setBlockState(p.add(w - 3, 1, d - 3), Blocks.CHEST.getDefaultState());
}
}