Search in sources :

Example 1 with BlockFrame

use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCE.

the class FoamSprayerBehavior method gatherFrameBlocks.

private static List<BlockPos> gatherFrameBlocks(World worldIn, BlockPos centerPos, int maxRadiusSq) {
    HashSet<BlockPos> observedSet = new HashSet<>();
    ArrayList<BlockPos> resultFrameBlocks = new ArrayList<>();
    observedSet.add(centerPos);
    resultFrameBlocks.add(centerPos);
    IBlockState frameState = null;
    Stack<EnumFacing> moveStack = new Stack<>();
    MutableBlockPos currentPos = new MutableBlockPos(centerPos);
    main: while (true) {
        for (EnumFacing facing : EnumFacing.VALUES) {
            currentPos.move(facing);
            IBlockState blockStateHere = worldIn.getBlockState(currentPos);
            // if there is node, and it can connect with previous node, add it to list, and set previous node as current
            if (blockStateHere.getBlock() instanceof BlockFrame && currentPos.distanceSq(centerPos) <= maxRadiusSq && (frameState == null || frameState == blockStateHere) && !observedSet.contains(currentPos)) {
                BlockPos immutablePos = currentPos.toImmutable();
                observedSet.add(immutablePos);
                resultFrameBlocks.add(immutablePos);
                moveStack.push(facing.getOpposite());
                frameState = blockStateHere;
                continue main;
            } else
                currentPos.move(facing.getOpposite());
        }
        if (!moveStack.isEmpty()) {
            currentPos.move(moveStack.pop());
        } else
            break;
    }
    resultFrameBlocks.sort(Comparator.comparing(it -> it.distanceSq(centerPos)));
    return resultFrameBlocks;
}
Also used : ModHandler(gregtech.api.recipes.ModHandler) java.util(java.util) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) MetaBlocks(gregtech.common.blocks.MetaBlocks) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) EnumHand(net.minecraft.util.EnumHand) Materials(gregtech.api.unification.material.Materials) BlockFrame(gregtech.common.blocks.BlockFrame) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) ItemStack(net.minecraft.item.ItemStack) IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) ActionResult(net.minecraft.util.ActionResult) IBlockState(net.minecraft.block.state.IBlockState) IItemCapabilityProvider(gregtech.api.items.metaitem.stats.IItemCapabilityProvider) IItemDurabilityManager(gregtech.api.items.metaitem.stats.IItemDurabilityManager) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) MathHelper(net.minecraft.util.math.MathHelper) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) ItemStack(net.minecraft.item.ItemStack) FluidStack(net.minecraftforge.fluids.FluidStack) BlockFrame(gregtech.common.blocks.BlockFrame)

Example 2 with BlockFrame

use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCE.

the class FoamSprayerBehavior method foamAllFrameBlocks.

private static int foamAllFrameBlocks(World world, BlockPos pos, int maxBlocksToFoam, boolean isSneaking) {
    List<BlockPos> frameBlocks = gatherFrameBlocks(world, pos, 1024);
    frameBlocks = frameBlocks.subList(0, Math.min(frameBlocks.size(), maxBlocksToFoam));
    // replace blocks without updating physics
    for (BlockPos framePos : frameBlocks) {
        IBlockState blockState = world.getBlockState(framePos);
        boolean isNormalFrame = ModHandler.isMaterialWood(((BlockFrame) blockState.getBlock()).frameMaterial) || isSneaking;
        if (isNormalFrame) {
            blockState.getBlock().dropBlockAsItem(world, framePos, blockState, 0);
        }
        IBlockState foamToPlace = isNormalFrame ? MetaBlocks.FOAM.getDefaultState() : MetaBlocks.REINFORCED_FOAM.getDefaultState();
        world.setBlockState(framePos, foamToPlace, 2);
    }
    // perform block physics updates
    for (BlockPos blockPos : frameBlocks) {
        IBlockState blockState = world.getBlockState(blockPos);
        world.notifyNeighborsRespectDebug(blockPos, blockState.getBlock(), true);
    }
    return frameBlocks.size();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) BlockFrame(gregtech.common.blocks.BlockFrame)

Example 3 with BlockFrame

use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCEu.

the class FrameBakedModel method getQuads.

@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    List<BakedQuad> quads = new ArrayList<>();
    if (side == null)
        return quads;
    if (state != null) {
        Material material = state.getValue(((BlockFrame) state.getBlock()).variantProperty);
        Map<EnumFacing, BakedQuad> materialFace = materialFaces.get(material.getMaterialIconSet());
        if (materialFace == null) {
            materialFaces.put(material.getMaterialIconSet(), materialFace = new Object2ObjectOpenHashMap<>());
        }
        BakedQuad materialFaceQuad = materialFace.get(side);
        if (materialFaceQuad == null) {
            materialFace.put(side, materialFaceQuad = ModelFactory.getBakery().makeBakedQuad(new Vector3f(0F, 0F, 0F), new Vector3f(16F, 16F, 16F), new BlockPartFace(side, 1, "", new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F, 0.0F, 0.0F, 16.0F, 16.0F }, 0)), ModelLoader.defaultTextureGetter().apply(MaterialIconType.frameGt.getBlockPath(material.getMaterialIconSet())), side, ModelRotation.X0_Y0, null, true, true));
        }
        quads.add(materialFaceQuad);
        particle.set(materialFaceQuad.getSprite());
    } else {
        ItemStack stack = FrameModelItemOverride.INSTANCE.stack.get();
        if (!stack.isEmpty()) {
            BlockFrame frame = (BlockFrame) ((ItemBlock) stack.getItem()).getBlock();
            IBlockState frameState = frame.getDefaultState().withProperty(frame.variantProperty, frame.variantProperty.getAllowedValues().get(stack.getMetadata()));
            for (EnumFacing face : EnumFacing.VALUES) {
                quads.addAll(getQuads(frameState, face, rand));
            }
        }
    }
    return quads;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) Material(gregtech.api.unification.material.Material) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Vector3f(org.lwjgl.util.vector.Vector3f) ItemStack(net.minecraft.item.ItemStack) BlockFrame(gregtech.common.blocks.BlockFrame) Nonnull(javax.annotation.Nonnull)

Example 4 with BlockFrame

use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCEu.

the class FoamSprayerBehavior method gatherFrameBlocks.

private static List<BlockPos> gatherFrameBlocks(World worldIn, BlockPos centerPos, int maxRadiusSq) {
    HashSet<BlockPos> observedSet = new HashSet<>();
    ArrayList<BlockPos> resultFrameBlocks = new ArrayList<>();
    observedSet.add(centerPos);
    resultFrameBlocks.add(centerPos);
    IBlockState frameState = null;
    Stack<EnumFacing> moveStack = new Stack<>();
    MutableBlockPos currentPos = new MutableBlockPos(centerPos);
    main: while (true) {
        for (EnumFacing facing : EnumFacing.VALUES) {
            currentPos.move(facing);
            IBlockState blockStateHere = worldIn.getBlockState(currentPos);
            // if there is node, and it can connect with previous node, add it to list, and set previous node as current
            if (blockStateHere.getBlock() instanceof BlockFrame && currentPos.distanceSq(centerPos) <= maxRadiusSq && (frameState == null || frameState == blockStateHere) && !observedSet.contains(currentPos)) {
                BlockPos immutablePos = currentPos.toImmutable();
                observedSet.add(immutablePos);
                resultFrameBlocks.add(immutablePos);
                moveStack.push(facing.getOpposite());
                frameState = blockStateHere;
                continue main;
            } else
                currentPos.move(facing.getOpposite());
        }
        if (!moveStack.isEmpty()) {
            currentPos.move(moveStack.pop());
        } else
            break;
    }
    resultFrameBlocks.sort(Comparator.comparing(it -> it.distanceSq(centerPos)));
    return resultFrameBlocks;
}
Also used : ModHandler(gregtech.api.recipes.ModHandler) java.util(java.util) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) MetaBlocks(gregtech.common.blocks.MetaBlocks) ICapabilityProvider(net.minecraftforge.common.capabilities.ICapabilityProvider) EnumHand(net.minecraft.util.EnumHand) Materials(gregtech.api.unification.material.Materials) BlockFrame(gregtech.common.blocks.BlockFrame) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) ItemStack(net.minecraft.item.ItemStack) IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) ActionResult(net.minecraft.util.ActionResult) IBlockState(net.minecraft.block.state.IBlockState) IItemCapabilityProvider(gregtech.api.items.metaitem.stats.IItemCapabilityProvider) IItemDurabilityManager(gregtech.api.items.metaitem.stats.IItemDurabilityManager) Material(net.minecraft.block.material.Material) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) MathHelper(net.minecraft.util.math.MathHelper) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) ItemStack(net.minecraft.item.ItemStack) FluidStack(net.minecraftforge.fluids.FluidStack) BlockFrame(gregtech.common.blocks.BlockFrame)

Example 5 with BlockFrame

use of gregtech.common.blocks.BlockFrame in project GregTech by GregTechCE.

the class FoamSprayerBehavior method onItemUse.

@Override
public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack itemStack = player.getHeldItem(hand);
    IFluidHandlerItem fluidHandlerItem = itemStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
    FluidStack fluidStack = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
    if (fluidStack != null && fluidStack.amount >= FLUID_PER_BLOCK) {
        BlockPos offsetPos = pos.offset(facing);
        IBlockState initialBlockState = world.getBlockState(pos);
        IBlockState offsetState = world.getBlockState(offsetPos);
        if (initialBlockState.getBlock() instanceof BlockFrame) {
            int blocksToFoam = fluidStack.amount / FLUID_PER_BLOCK;
            int blocksFoamed = foamAllFrameBlocks(world, pos, blocksToFoam, player.isSneaking());
            if (!player.capabilities.isCreativeMode) {
                fluidHandlerItem.drain(FLUID_PER_BLOCK * blocksFoamed, true);
            }
            return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
        } else if (offsetState.getBlock().isReplaceable(world, offsetPos)) {
            int blocksToFoam = fluidStack.amount / FLUID_PER_BLOCK;
            int blocksFoamed = foamReplacableBlocks(world, offsetPos, blocksToFoam);
            if (!player.capabilities.isCreativeMode) {
                fluidHandlerItem.drain(FLUID_PER_BLOCK * blocksFoamed, true);
            }
            return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
        }
    }
    return ActionResult.newResult(EnumActionResult.PASS, itemStack);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) ItemStack(net.minecraft.item.ItemStack) BlockFrame(gregtech.common.blocks.BlockFrame)

Aggregations

BlockFrame (gregtech.common.blocks.BlockFrame)7 IBlockState (net.minecraft.block.state.IBlockState)6 ItemStack (net.minecraft.item.ItemStack)5 BlockPos (net.minecraft.util.math.BlockPos)5 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)5 FluidStack (net.minecraftforge.fluids.FluidStack)4 IFluidHandlerItem (net.minecraftforge.fluids.capability.IFluidHandlerItem)4 FluidHandlerItemStack (net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack)4 EnumFacing (net.minecraft.util.EnumFacing)3 IItemBehaviour (gregtech.api.items.metaitem.stats.IItemBehaviour)2 IItemCapabilityProvider (gregtech.api.items.metaitem.stats.IItemCapabilityProvider)2 IItemDurabilityManager (gregtech.api.items.metaitem.stats.IItemDurabilityManager)2 ModHandler (gregtech.api.recipes.ModHandler)2 Material (gregtech.api.unification.material.Material)2 Materials (gregtech.api.unification.material.Materials)2 MetaBlocks (gregtech.common.blocks.MetaBlocks)2 java.util (java.util)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ActionResult (net.minecraft.util.ActionResult)2 EnumActionResult (net.minecraft.util.EnumActionResult)2