Search in sources :

Example 1 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class ModContent method createRegistries.

@SubscribeEvent
public static void createRegistries(RegistryEvent.NewRegistry event) {
    // RegistryEvents are fired in alphabetic order.
    // Instruments have to be registered before Ceremonies.
    new RegistryBuilder<MusicInstrument>().setName(new ResourceLocation(Totemic.MOD_ID, "a_music_instruments")).setType(MusicInstrument.class).setMaxID(Byte.MAX_VALUE).disableSaving().create();
    new RegistryBuilder<TotemEffect>().setName(new ResourceLocation(Totemic.MOD_ID, "b_totem_effects")).setType(TotemEffect.class).setMaxID(Byte.MAX_VALUE).disableSaving().create();
    new RegistryBuilder<Ceremony>().setName(new ResourceLocation(Totemic.MOD_ID, "c_ceremonies")).setType(Ceremony.class).setMaxID(Byte.MAX_VALUE).disableSaving().create();
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) MusicInstrument(pokefenn.totemic.api.music.MusicInstrument) TotemEffect(pokefenn.totemic.api.totem.TotemEffect) Ceremony(pokefenn.totemic.api.ceremony.Ceremony) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class ComponentMedicineWheel method addComponentParts.

@Override
public boolean addComponentParts(World world, Random random, StructureBoundingBox bb) {
    if (averageGroundLvl < 0) {
        averageGroundLvl = getAverageGroundLevel(world, bb);
        if (averageGroundLvl < 0)
            return true;
        boundingBox.offset(0, averageGroundLvl - boundingBox.maxY + 6 - 1, 0);
    }
    fillWithAir(world, bb, 2, 0, 0, 6, 5, 0);
    fillWithAir(world, bb, 1, 0, 1, 7, 5, 1);
    fillWithAir(world, bb, 0, 0, 2, 8, 5, 6);
    fillWithAir(world, bb, 1, 0, 7, 7, 5, 7);
    fillWithAir(world, bb, 2, 0, 8, 6, 5, 8);
    // Create Totem Pole
    setBlockState(world, ModBlocks.totem_base.getDefaultState().withProperty(BlockTotemBase.WOOD, poleWood), 4, 0, 4, bb);
    List<TotemEffect> totemList = new ArrayList<>(TotemicRegistries.totemEffects().getValuesCollection());
    for (int i = 0; i < 5; i++) {
        int x = 4, y = 1 + i, z = 4;
        setBlockState(world, ModBlocks.totem_pole.getDefaultState().withProperty(BlockTotemPole.WOOD, poleWood), x, y, z, bb);
        BlockPos pos = new BlockPos(getXWithOffset(x, z), getYWithOffset(y), getZWithOffset(x, z));
        if (bb.isVecInside(pos))
            ((TileTotemPole) world.getTileEntity(pos)).setEffect(totemList.get(random.nextInt(totemList.size())));
    }
    // Place music instruments and torches
    setBlockState(world, ModBlocks.drum.getDefaultState(), 4, 0, 0, bb);
    setBlockState(world, ModBlocks.drum.getDefaultState(), 0, 0, 4, bb);
    setBlockState(world, ModBlocks.drum.getDefaultState(), 8, 0, 4, bb);
    for (int i = 0; i < 3; i++) setBlockState(world, ModBlocks.cedar_log.getDefaultState(), 4, i, 8, bb);
    setBlockState(world, ModBlocks.cedar_log.getDefaultState().withProperty(BlockCedarLog.LOG_AXIS, EnumAxis.Z), 4, 3, 8, bb);
    setBlockState(world, ModBlocks.cedar_log.getDefaultState().withProperty(BlockCedarLog.LOG_AXIS, EnumAxis.Z), 4, 3, 7, bb);
    setBlockState(world, ModBlocks.wind_chime.getDefaultState(), 4, 2, 7, bb);
    if (!isZombieInfested) {
        setBlockState(world, ModBlocks.totem_torch.getDefaultState(), 1, 0, 1, bb);
        setBlockState(world, ModBlocks.totem_torch.getDefaultState(), 7, 0, 1, bb);
        setBlockState(world, ModBlocks.totem_torch.getDefaultState(), 7, 0, 7, bb);
        setBlockState(world, ModBlocks.totem_torch.getDefaultState(), 1, 0, 7, bb);
    }
    // Clear above and make ground level
    IBlockState ground = (structureType != 1) ? Blocks.DIRT.getDefaultState() : Blocks.SAND.getDefaultState();
    IBlockState grass = getBiomeSpecificBlockState(Blocks.GRASS.getDefaultState());
    for (int z = 0; z < 9; z++) for (int x = 0; x < 9; x++) {
        // Only replace inside the circle
        if ((x == 0 || x == 8) && (z <= 1 || z >= 7) || (x == 1 || x == 7) && (z == 0 || z == 8))
            continue;
        clearCurrentPositionBlocksUpwards(world, x, 6, z, bb);
        replaceAirAndLiquidDownwards(world, ground, x, -1, z, bb);
        if (getBlockStateFromPos(world, x, -1, z, bb).getBlock() == Blocks.DIRT)
            setBlockState(world, grass, x, -1, z, bb);
    }
    // Create Medicine Wheel
    IBlockState cobble = getBiomeSpecificBlockState(Blocks.COBBLESTONE.getDefaultState());
    if (cobble.getBlock() == Blocks.SANDSTONE)
        cobble = Blocks.RED_SANDSTONE.getDefaultState();
    fillWithBlocks(world, bb, 4, -1, 0, 4, -1, 8, cobble, cobble, false);
    fillWithBlocks(world, bb, 0, -1, 4, 8, -1, 4, cobble, cobble, false);
    setBlockState(world, cobble, 5, -1, 0, bb);
    setBlockState(world, cobble, 6, -1, 0, bb);
    setBlockState(world, cobble, 7, -1, 1, bb);
    setBlockState(world, cobble, 8, -1, 2, bb);
    setBlockState(world, cobble, 8, -1, 3, bb);
    setBlockState(world, cobble, 8, -1, 5, bb);
    setBlockState(world, cobble, 8, -1, 6, bb);
    setBlockState(world, cobble, 7, -1, 7, bb);
    setBlockState(world, cobble, 6, -1, 8, bb);
    setBlockState(world, cobble, 5, -1, 8, bb);
    setBlockState(world, cobble, 3, -1, 8, bb);
    setBlockState(world, cobble, 2, -1, 8, bb);
    setBlockState(world, cobble, 1, -1, 7, bb);
    setBlockState(world, cobble, 0, -1, 6, bb);
    setBlockState(world, cobble, 0, -1, 5, bb);
    setBlockState(world, cobble, 0, -1, 3, bb);
    setBlockState(world, cobble, 0, -1, 2, bb);
    setBlockState(world, cobble, 1, -1, 1, bb);
    setBlockState(world, cobble, 2, -1, 0, bb);
    setBlockState(world, cobble, 3, -1, 0, bb);
    spawnVillagers(world, bb, 4, 1, 2, 1);
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) TotemEffect(pokefenn.totemic.api.totem.TotemEffect)

Example 3 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class TotemKnifeItem method useOn.

@SuppressWarnings("resource")
@Override
public InteractionResult useOn(UseOnContext c) {
    if (c.getPlayer().isCrouching()) {
        // TODO
        return InteractionResult.FAIL;
    } else {
        BlockState state = c.getLevel().getBlockState(c.getClickedPos());
        TotemWoodType woodType = TotemWoodType.fromLog(state);
        if (woodType == null) {
            // Fall back to oak if it is an unrecognized log type
            if (BlockTags.LOGS_THAT_BURN.contains(state.getBlock()))
                woodType = TotemWoodType.OAK;
            else
                return InteractionResult.FAIL;
        }
        BlockState newState;
        TotemEffect effect = getCarvingEffect(c.getItemInHand());
        if (effect != null) {
            newState = ModBlocks.getTotemPoles().get(woodType, effect).getStateForPlacement(new BlockPlaceContext(c));
        } else {
            newState = ModBlocks.getTotemBases().get(woodType).getStateForPlacement(new BlockPlaceContext(c));
        }
        c.getLevel().setBlock(c.getClickedPos(), newState, 3);
        newState.getBlock().setPlacedBy(c.getLevel(), c.getClickedPos(), newState, c.getPlayer(), c.getItemInHand());
        c.getItemInHand().hurtAndBreak(1, c.getPlayer(), player -> player.broadcastBreakEvent(c.getHand()));
        c.getLevel().playSound(c.getPlayer(), c.getClickedPos(), SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
        return InteractionResult.sidedSuccess(c.getLevel().isClientSide);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) TotemWoodType(pokefenn.totemic.api.TotemWoodType) TotemEffect(pokefenn.totemic.api.totem.TotemEffect)

Example 4 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class TileTotemBase method calculateTotemEffects.

private void calculateTotemEffects() {
    totemEffectList.clear();
    totemEffects.clear();
    for (int i = 0; i < TotemEffectAPI.MAX_POLE_SIZE; i++) {
        Block block = level.getBlockState(worldPosition.above(i + 1)).getBlock();
        if (block instanceof TotemPoleBlock) {
            TotemEffect effect = ((TotemPoleBlock) block).effect;
            totemEffectList.add(effect);
            totemEffects.add(effect);
        } else
            break;
    }
    // Calculate the greatest common divisor of all the intervals of the effects
    commonTotemEffectInterval = totemEffects.elementSet().stream().mapToInt(TotemEffect::getInterval).filter(// Integer.MAX_VALUE is a prime number, so we don't want it in the GCD calculation
    i -> i != Integer.MAX_VALUE).reduce(IntMath::gcd).orElse(Integer.MAX_VALUE);
}
Also used : Multiset(com.google.common.collect.Multiset) Direction(net.minecraft.core.Direction) BlockState(net.minecraft.world.level.block.state.BlockState) TotemPoleBlock(pokefenn.totemic.block.totem.TotemPoleBlock) ModTileEntities(pokefenn.totemic.init.ModTileEntities) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) TotemicCapabilities(pokefenn.totemic.api.TotemicCapabilities) TotemEffect(pokefenn.totemic.api.totem.TotemEffect) Capability(net.minecraftforge.common.capabilities.Capability) ArrayList(java.util.ArrayList) LazyOptional(net.minecraftforge.common.util.LazyOptional) List(java.util.List) IntMath(com.google.common.math.IntMath) MusicAcceptor(pokefenn.totemic.api.music.MusicAcceptor) HashMultiset(com.google.common.collect.HashMultiset) BlockPos(net.minecraft.core.BlockPos) TotemEffectAPI(pokefenn.totemic.api.totem.TotemEffectAPI) Block(net.minecraft.world.level.block.Block) Level(net.minecraft.world.level.Level) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IntMath(com.google.common.math.IntMath) TotemPoleBlock(pokefenn.totemic.block.totem.TotemPoleBlock) Block(net.minecraft.world.level.block.Block) TotemEffect(pokefenn.totemic.api.totem.TotemEffect) TotemPoleBlock(pokefenn.totemic.block.totem.TotemPoleBlock)

Example 5 with TotemEffect

use of pokefenn.totemic.api.totem.TotemEffect in project Totemic by TeamTotemic.

the class ModBlocks method init.

@SubscribeEvent
public static void init(RegistryEvent.Register<Block> event) {
    internallyRegisterTotemEffects();
    for (TotemWoodType woodType : TotemWoodType.getWoodTypes()) {
        Properties blockProperties = Properties.of(Material.WOOD, woodType.getWoodColor()).strength(2, 5).sound(SoundType.WOOD);
        TotemBaseBlock totemBase = new TotemBaseBlock(woodType, blockProperties);
        totemBase.setRegistryName(Totemic.MOD_ID, woodType.getName() + "_totem_base");
        event.getRegistry().register(totemBase);
        totemBases.put(woodType, totemBase);
        blocksWithItemBlock.add(totemBase);
        for (TotemEffect totemEffect : totemEffectsToRegister) {
            TotemPoleBlock totemPole = new TotemPoleBlock(woodType, totemEffect, blockProperties);
            totemPole.setRegistryName(Totemic.MOD_ID, woodType.getName() + "_totem_pole_" + totemEffect.getRegistryName().getPath());
            event.getRegistry().register(totemPole);
            totemPoles.put(woodType, totemEffect, totemPole);
            blocksWithItemBlock.add(totemPole);
        }
    }
}
Also used : TotemWoodType(pokefenn.totemic.api.TotemWoodType) Properties(net.minecraft.world.level.block.state.BlockBehaviour.Properties) TotemEffect(pokefenn.totemic.api.totem.TotemEffect) TotemBaseBlock(pokefenn.totemic.block.totem.TotemBaseBlock) TotemPoleBlock(pokefenn.totemic.block.totem.TotemPoleBlock) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

TotemEffect (pokefenn.totemic.api.totem.TotemEffect)10 Multiset (com.google.common.collect.Multiset)3 ArrayList (java.util.ArrayList)2 IBlockState (net.minecraft.block.state.IBlockState)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Level (net.minecraft.world.level.Level)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 TotemWoodType (pokefenn.totemic.api.TotemWoodType)2 TotemPoleBlock (pokefenn.totemic.block.totem.TotemPoleBlock)2 TileTotemPole (pokefenn.totemic.tileentity.totem.TileTotemPole)2 HashMultiset (com.google.common.collect.HashMultiset)1 IntMath (com.google.common.math.IntMath)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)1