Search in sources :

Example 6 with Blocks

use of net.minecraft.init.Blocks in project Solar by ArekkuusuJerii.

the class TileDilaton method pushExtension.

public void pushExtension(boolean powered) {
    if (!world.isRemote && !(!isActiveLazy() && !powered)) {
        ProfilerHelper.flagSection("[Dilaton] Redstone signal received");
        BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(getPos());
        EnumFacing facing = getFacingLazy();
        int range = powered ? getRedstonePower() + 1 : 16;
        int pointer = 0;
        if (isActiveLazy()) {
            ProfilerHelper.flagSection("[Dilaton] Locate nearest extension");
            boolean found = false;
            for (; pointer < range; pointer++) {
                if (!isPosValid(pos.move(facing)) || pointer >= range)
                    return;
                IBlockState state = world.getBlockState(pos);
                if (state.getBlock() == ModBlocks.DILATON_EXTENSION) {
                    world.setBlockToAir(pos);
                    found = true;
                    break;
                }
            }
            if (!found)
                return;
            if (!powered)
                pointer = 0;
        }
        ProfilerHelper.begin("[Dilaton] Gathering pushed blocks");
        if (!powered)
            facing = facing.getOpposite();
        List<Triple<IBlockState, NBTTagCompound, BlockPos>> pushed = Lists.newArrayList();
        List<BlockPos> removed = Lists.newArrayList();
        loop: for (; pointer < range; pointer++) {
            if (pos.move(facing).equals(getPos()) || !isPosValid(pos))
                break;
            IBlockState next = world.getBlockState(pos);
            if (next.getBlock() == Blocks.AIR)
                continue;
            float hardness = next.getBlockHardness(world, pos);
            if (hardness > 2000F || hardness < 0F)
                break;
            EnumPushReaction reaction;
            if (next.getMaterial() == Material.WATER)
                reaction = EnumPushReaction.IGNORE;
            else
                reaction = next.getMobilityFlag();
            switch(reaction) {
                case PUSH_ONLY:
                case NORMAL:
                    if (pushed.add(getStateTile(next, pos.toImmutable())) && pushed.size() > 15)
                        break loop;
                    else
                        ++range;
                    continue loop;
                case DESTROY:
                    removed.add(pos.toImmutable());
                    continue loop;
                case BLOCK:
                    break loop;
                case IGNORE:
            }
        }
        ProfilerHelper.interrupt("[Dilaton] Relocating pushed blocks");
        Set<BlockPos> deleted = Sets.newHashSet();
        if (pushed.size() <= 15) {
            pos.move(facing.getOpposite());
        }
        for (int i = 0, size = pushed.size(); i < size; i++) {
            if (isPosReplaceable(pos)) {
                for (int index = pushed.size() - 1; index >= 0; index--) {
                    Triple<IBlockState, NBTTagCompound, BlockPos> triplet = pushed.get(index);
                    if (setStateTile(triplet.getLeft(), triplet.getMiddle(), pos.toImmutable()))
                        removed.add(pos.toImmutable());
                    BlockPos oldPos = triplet.getRight();
                    if (deleted.add(oldPos))
                        deleted.removeIf(a -> a.equals(pos));
                    pos.move(facing.getOpposite());
                }
                deleted.forEach(delete -> {
                    if (world.getTileEntity(delete) != null)
                        world.removeTileEntity(delete);
                    world.setBlockToAir(delete);
                });
                break;
            } else if (!pushed.isEmpty())
                pushed.remove(pushed.size() - 1);
            pos.move(facing.getOpposite());
        }
        ProfilerHelper.flagSection("[Dilaton] Block drops");
        removed.forEach(p -> {
            IBlockState state = world.getBlockState(p);
            float chance = state.getBlock() instanceof BlockSnow ? -1.0F : 1.0F;
            state.getBlock().dropBlockAsItemWithChance(world, p, state, chance, 0);
            world.setBlockToAir(p);
        });
        ProfilerHelper.end();
        ProfilerHelper.flagSection("[Dilaton] Place extension");
        if (pos.equals(getPos().offset(facing.getOpposite()))) {
            if (isActiveLazy())
                world.setBlockState(getPos(), world.getBlockState(getPos()).withProperty(State.ACTIVE, false));
        } else if (!pos.equals(getPos())) {
            if (!isActiveLazy())
                world.setBlockState(getPos(), world.getBlockState(getPos()).withProperty(State.ACTIVE, true));
            IBlockState extension = ModBlocks.DILATON_EXTENSION.getDefaultState().withProperty(BlockDirectional.FACING, facing);
            world.setBlockState(pos, extension);
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) State(arekkuusu.solar.api.state.State) BlockSnow(net.minecraft.block.BlockSnow) Blocks(net.minecraft.init.Blocks) EnumFacing(net.minecraft.util.EnumFacing) Set(java.util.Set) ProfilerHelper(arekkuusu.solar.client.util.helper.ProfilerHelper) BlockPos(net.minecraft.util.math.BlockPos) Sets(com.google.common.collect.Sets) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Lists(com.google.common.collect.Lists) Material(net.minecraft.block.material.Material) BlockDirectional(net.minecraft.block.BlockDirectional) TileEntity(net.minecraft.tileentity.TileEntity) ModBlocks(arekkuusu.solar.common.block.ModBlocks) Triple(org.apache.commons.lang3.tuple.Triple) EnumPushReaction(net.minecraft.block.material.EnumPushReaction) BlockSnow(net.minecraft.block.BlockSnow) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Triple(org.apache.commons.lang3.tuple.Triple) BlockPos(net.minecraft.util.math.BlockPos) EnumPushReaction(net.minecraft.block.material.EnumPushReaction)

Example 7 with Blocks

use of net.minecraft.init.Blocks in project Tale-of-Kingdoms by Ivasik78.

the class SchematicHandler method update.

public void update(World world) {
    if (!this.buildingList.isEmpty()) {
        Schematic first = this.buildingList.get(0);
        if (first != null) {
            List<FakeBlock> blocks = first.getBlockList();
            List<FakeEntity> entities = first.getEntityList();
            for (int i = 0; i < first.speed; ++i) {
                if (index < blocks.size()) {
                    FakeBlock fakeBlock = blocks.get(index);
                    if (fakeBlock != null && world.getBlock(first.x + fakeBlock.posX, first.y + fakeBlock.posY, first.z + fakeBlock.posZ) != fakeBlock.block) {
                        if (fakeBlock.block == Blocks.air)
                            world.setBlockToAir(first.x + fakeBlock.posX, first.y + fakeBlock.posY, first.z + fakeBlock.posZ);
                        if (fakeBlock.block != Blocks.torch && fakeBlock.block != Blocks.wooden_door && fakeBlock.block != Blocks.ladder && fakeBlock.block != Blocks.trapdoor) {
                            world.setBlock(first.x + fakeBlock.posX, first.y + fakeBlock.posY, first.z + fakeBlock.posZ, fakeBlock.block, fakeBlock.metadata, 3);
                        } else
                            this.torchList.add(fakeBlock);
                    }
                    ++index;
                } else if (index < blocks.size() + entities.size()) {
                    FakeEntity entity = entities.get(index - blocks.size());
                    WorldProvider worldProvider = WorldProvider.get(world);
                    EntityLiving entity1 = (EntityLiving) UltimateHelper.INSTANCE.getEntity(entity.entityName, world);
                    if (entity1 != null) {
                        if (Buildings.INSTANCE.getBuilding(1)) {
                            entity1.setPosition((double) worldProvider.guildPosX + entity.posX, (double) worldProvider.guildPosY + entity.posY, (double) worldProvider.guildPosZ + entity.posZ);
                        } else {
                            entity1.setPosition((double) first.x + entity.posX, (double) first.y + entity.posY + 1.5D, (double) first.z + entity.posZ);
                        }
                        world.spawnEntityInWorld(entity1);
                    }
                    ++index;
                } else {
                    this.torchList.forEach(block -> world.setBlock(first.x + block.posX, first.y + block.posY, first.z + block.posZ, block.block, block.metadata, 3));
                    index = 0;
                    if (!this.buildingList.isEmpty())
                        this.buildingList.remove(0);
                    this.torchList.clear();
                }
            }
        }
    }
}
Also used : FakeEntity(kingdoms.api.entities.FakeEntity) List(java.util.List) Blocks(net.minecraft.init.Blocks) EntityLiving(net.minecraft.entity.EntityLiving) World(net.minecraft.world.World) FakeEntity(kingdoms.api.entities.FakeEntity) WorldProvider(kingdoms.server.WorldProvider) UltimateHelper(kingdoms.server.handlers.UltimateHelper) Buildings(kingdoms.server.handlers.Buildings) FakeBlock(kingdoms.api.blocks.FakeBlock) ArrayList(java.util.ArrayList) EntityLiving(net.minecraft.entity.EntityLiving) WorldProvider(kingdoms.server.WorldProvider) FakeBlock(kingdoms.api.blocks.FakeBlock)

Aggregations

Blocks (net.minecraft.init.Blocks)7 Block (net.minecraft.block.Block)5 IBlockState (net.minecraft.block.state.IBlockState)4 List (java.util.List)3 ItemStack (net.minecraft.item.ItemStack)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 Material (net.minecraft.block.material.Material)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Items (net.minecraft.init.Items)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockPos (net.minecraft.util.math.BlockPos)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Side (net.minecraftforge.fml.relauncher.Side)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 OreDictionary (net.minecraftforge.oredict.OreDictionary)2 State (arekkuusu.solar.api.state.State)1 ProfilerHelper (arekkuusu.solar.client.util.helper.ProfilerHelper)1 ModBlocks (arekkuusu.solar.common.block.ModBlocks)1